IsArrayContainingInOrderTest.php 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace Hamcrest\Arrays;
  3. use Hamcrest\AbstractMatcherTest;
  4. class IsArrayContainingInOrderTest extends AbstractMatcherTest
  5. {
  6. protected function createMatcher()
  7. {
  8. return IsArrayContainingInOrder::arrayContaining(array(1, 2));
  9. }
  10. public function testHasAReadableDescription()
  11. {
  12. $this->assertDescription('[<1>, <2>]', arrayContaining(array(1, 2)));
  13. }
  14. public function testMatchesItemsInOrder()
  15. {
  16. $this->assertMatches(arrayContaining(array(1, 2, 3)), array(1, 2, 3), 'in order');
  17. $this->assertMatches(arrayContaining(array(1)), array(1), 'single');
  18. }
  19. public function testAppliesMatchersInOrder()
  20. {
  21. $this->assertMatches(
  22. arrayContaining(array(1, 2, 3)),
  23. array(1, 2, 3),
  24. 'in order'
  25. );
  26. $this->assertMatches(arrayContaining(array(1)), array(1), 'single');
  27. }
  28. public function testMismatchesItemsInAnyOrder()
  29. {
  30. $matcher = arrayContaining(array(1, 2, 3));
  31. $this->assertMismatchDescription('was null', $matcher, null);
  32. $this->assertMismatchDescription('No item matched: <1>', $matcher, array());
  33. $this->assertMismatchDescription('No item matched: <2>', $matcher, array(1));
  34. $this->assertMismatchDescription('item with key 0: was <4>', $matcher, array(4, 3, 2, 1));
  35. $this->assertMismatchDescription('item with key 2: was <4>', $matcher, array(1, 2, 4));
  36. }
  37. }