Skip to content
This repository was archived by the owner on Aug 8, 2019. It is now read-only.

Commit 6c0069d

Browse files
committed
Merge pull request beberlei#43 from fritsjanb/assert_countable_test
Add Assertion::count test for \Countable
2 parents 7d1fe7d + 3f4522b commit 6c0069d

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

lib/Assert/Assertion.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -947,10 +947,10 @@ static public function __callStatic($method, $args)
947947
/**
948948
* Assert that the count of countable is equal to count.
949949
*
950-
* @param mixed $countable
951-
* @param int $count
952-
* @param string $message
953-
* @param string $propertyPath
950+
* @param array|\Countable $countable
951+
* @param int $count
952+
* @param string $message
953+
* @param string $propertyPath
954954
* @return void
955955
* @throws \Assert\AssertionFailedException
956956
*/

tests/Assert/Tests/AssertTest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,16 +821,36 @@ public function testAllWithNoValueThrows()
821821
public function testValidCount()
822822
{
823823
Assertion::count(array('Hi'), 1);
824+
Assertion::count(new OneCountable(), 1);
824825
}
825826

826-
public function testInvalidCount()
827+
public static function dataInvalidCount()
828+
{
829+
return array(
830+
array(array('Hi', 'There'), 3),
831+
array(new OneCountable(), 2),
832+
);
833+
}
834+
835+
/**
836+
* @dataProvider dataInvalidCount
837+
*/
838+
public function testInvalidCount($countable, $count)
827839
{
828840
$this->setExpectedException('Assert\AssertionFailedException', null, Assertion::INVALID_COUNT);
829-
Assertion::count(array('Hi', 'there'), 1);
841+
Assertion::count($countable, $count);
830842
}
831843
}
832844

833845
class ChildStdClass extends \stdClass
834846
{
835847

836848
}
849+
850+
class OneCountable implements \Countable
851+
{
852+
public function count()
853+
{
854+
return 1;
855+
}
856+
}

0 commit comments

Comments
 (0)