PageRenderTime 82ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/hamcrest-php/hamcrest/Hamcrest/Collection/IsTraversableWithSize.php

http://hamcrest.googlecode.com/
PHP | 43 lines | 25 code | 7 blank | 11 comment | 0 complexity | 4c8e8b242462e39c7d63c71dab1842da MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0
  1. <?php
  2. /*
  3. Copyright (c) 2009 hamcrest.org
  4. */
  5. require_once 'Hamcrest/FeatureMatcher.php';
  6. require_once 'Hamcrest/Matcher.php';
  7. require_once 'Hamcrest/Util.php';
  8. /**
  9. * Matches if traversable size satisfies a nested matcher.
  10. */
  11. class Hamcrest_Collection_IsTraversableWithSize extends Hamcrest_FeatureMatcher
  12. {
  13. public function __construct(Hamcrest_Matcher $sizeMatcher)
  14. {
  15. parent::__construct(self::TYPE_OBJECT, 'Traversable', $sizeMatcher,
  16. 'a traversable with size', 'traversable size');
  17. }
  18. protected function featureValueOf($actual)
  19. {
  20. $size = 0;
  21. foreach ($actual as $value)
  22. {
  23. $size++;
  24. }
  25. return $size;
  26. }
  27. /**
  28. * Does traversable size satisfy a given matcher?
  29. *
  30. * @factory
  31. */
  32. public static function traversableWithSize($size)
  33. {
  34. return new self(Hamcrest_Util::wrapValueWithIsEqual($size));
  35. }
  36. }