菜谱项目

IsTraversableWithSizeTest.php 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Hamcrest\Collection;
  3. class IsTraversableWithSizeTest extends \Hamcrest\AbstractMatcherTest
  4. {
  5. protected function createMatcher()
  6. {
  7. return \Hamcrest\Collection\IsTraversableWithSize::traversableWithSize(
  8. equalTo(2)
  9. );
  10. }
  11. public function testMatchesWhenSizeIsCorrect()
  12. {
  13. $this->assertMatches(
  14. traversableWithSize(equalTo(3)),
  15. new \ArrayObject(array(1, 2, 3)),
  16. 'correct size'
  17. );
  18. }
  19. public function testDoesNotMatchWhenSizeIsIncorrect()
  20. {
  21. $this->assertDoesNotMatch(
  22. traversableWithSize(equalTo(2)),
  23. new \ArrayObject(array(1, 2, 3)),
  24. 'incorrect size'
  25. );
  26. }
  27. public function testDoesNotMatchNull()
  28. {
  29. $this->assertDoesNotMatch(
  30. traversableWithSize(3),
  31. null,
  32. 'should not match null'
  33. );
  34. }
  35. public function testProvidesConvenientShortcutForTraversableWithSizeEqualTo()
  36. {
  37. $this->assertMatches(
  38. traversableWithSize(3),
  39. new \ArrayObject(array(1, 2, 3)),
  40. 'correct size'
  41. );
  42. }
  43. public function testHasAReadableDescription()
  44. {
  45. $this->assertDescription(
  46. 'a traversable with size <3>',
  47. traversableWithSize(equalTo(3))
  48. );
  49. }
  50. }