/hamcrest-php/hamcrest/Hamcrest/Collection/IsTraversableWithSize.php
PHP | 43 lines | 25 code | 7 blank | 11 comment | 0 complexity | 4c8e8b242462e39c7d63c71dab1842da MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0
- <?php
- /*
- Copyright (c) 2009 hamcrest.org
- */
- require_once 'Hamcrest/FeatureMatcher.php';
- require_once 'Hamcrest/Matcher.php';
- require_once 'Hamcrest/Util.php';
- /**
- * Matches if traversable size satisfies a nested matcher.
- */
- class Hamcrest_Collection_IsTraversableWithSize extends Hamcrest_FeatureMatcher
- {
- public function __construct(Hamcrest_Matcher $sizeMatcher)
- {
- parent::__construct(self::TYPE_OBJECT, 'Traversable', $sizeMatcher,
- 'a traversable with size', 'traversable size');
- }
- protected function featureValueOf($actual)
- {
- $size = 0;
- foreach ($actual as $value)
- {
- $size++;
- }
- return $size;
- }
- /**
- * Does traversable size satisfy a given matcher?
- *
- * @factory
- */
- public static function traversableWithSize($size)
- {
- return new self(Hamcrest_Util::wrapValueWithIsEqual($size));
- }
- }