Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Fix testCount for PHP 7.2 #81

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
  • Loading branch information
remicollet committed Oct 24, 2017
commit 5c2f528c5e3b775b960adc128efc7717ff2db64c
12 changes: 12 additions & 0 deletions test/ArrayObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use assertCount.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a copy/paste from previous test, I don't want to do refactoring in a PR only design to fix a minor compatibility issue.

Feel free to open a separate PR if you really think this worth the work ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You add these new lines, so please use the correct method. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.
No time for Bikeshedding.

}

public function testExchangeArray()
{
$ar = new ArrayObject(['foo' => 'bar']);
Expand Down
17 changes: 17 additions & 0 deletions test/TestAsset/ArrayObjectObjectCount.php
Original file line number Diff line number Diff line change
@@ -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;
}
}