菜谱项目

IsArrayWithSizeTest.php 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace Hamcrest\Arrays;
  3. use Hamcrest\AbstractMatcherTest;
  4. class IsArrayWithSizeTest extends AbstractMatcherTest
  5. {
  6. protected function createMatcher()
  7. {
  8. return IsArrayWithSize::arrayWithSize(equalTo(2));
  9. }
  10. public function testMatchesWhenSizeIsCorrect()
  11. {
  12. $this->assertMatches(arrayWithSize(equalTo(3)), array(1, 2, 3), 'correct size');
  13. $this->assertDoesNotMatch(arrayWithSize(equalTo(2)), array(1, 2, 3), 'incorrect size');
  14. }
  15. public function testProvidesConvenientShortcutForArrayWithSizeEqualTo()
  16. {
  17. $this->assertMatches(arrayWithSize(3), array(1, 2, 3), 'correct size');
  18. $this->assertDoesNotMatch(arrayWithSize(2), array(1, 2, 3), 'incorrect size');
  19. }
  20. public function testEmptyArray()
  21. {
  22. $this->assertMatches(emptyArray(), array(), 'correct size');
  23. $this->assertDoesNotMatch(emptyArray(), array(1), 'incorrect size');
  24. }
  25. public function testHasAReadableDescription()
  26. {
  27. $this->assertDescription('an array with size <3>', arrayWithSize(equalTo(3)));
  28. $this->assertDescription('an empty array', emptyArray());
  29. }
  30. }