summaryrefslogtreecommitdiffstats
path: root/81.patch
blob: c90600d751506d5fb7b2f283b265fefd336b3a27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
From 5c2f528c5e3b775b960adc128efc7717ff2db64c Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@remirepo.net>
Date: Tue, 24 Oct 2017 10:49:02 +0200
Subject: [PATCH] Fix testCount for PHP 7.2

PHP 7.2 raise a deprecated message
  Parameter must be an array or an object that implements Countable

I think this should not be hidden (count could take care of this),
so this change declare the message as expected.

A new test is added for object which are really countable
---
 test/ArrayObjectTest.php                  | 12 ++++++++++++
 test/TestAsset/ArrayObjectObjectCount.php | 17 +++++++++++++++++
 2 files changed, 29 insertions(+)
 create mode 100644 test/TestAsset/ArrayObjectObjectCount.php

diff --git a/test/ArrayObjectTest.php b/test/ArrayObjectTest.php
index b09cab7e..1ab3e97b 100644
--- a/test/ArrayObjectTest.php
+++ b/test/ArrayObjectTest.php
@@ -103,10 +103,22 @@ public function testAsort()
 
     public function testCount()
     {
+        if (version_compare(PHP_VERSION, '7.2', '>=')) {
+            $this->setExpectedException(
+                'PHPUnit_Framework_Error_Warning',
+                'Parameter must be an array or an object that implements Countable'
+            );
+        }
         $ar = new ArrayObject(new TestAsset\ArrayObjectObjectVars());
         $this->assertEquals(1, $ar->count());
     }
 
+    public function testCountable()
+    {
+        $ar = new ArrayObject(new TestAsset\ArrayObjectObjectCount());
+        $this->assertEquals(42, $ar->count());
+    }
+
     public function testExchangeArray()
     {
         $ar = new ArrayObject(['foo' => 'bar']);
diff --git a/test/TestAsset/ArrayObjectObjectCount.php b/test/TestAsset/ArrayObjectObjectCount.php
new file mode 100644
index 00000000..7b40dbee
--- /dev/null
+++ b/test/TestAsset/ArrayObjectObjectCount.php
@@ -0,0 +1,17 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link      http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license   http://framework.zend.com/license/new-bsd New BSD License
+ */
+
+namespace ZendTest\Stdlib\TestAsset;
+
+class ArrayObjectObjectCount implements \Countable
+{
+   public function count() {
+       return 42;
+   }
+}