IsArrayContainingInAnyOrderTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Hamcrest\Arrays;
  3. use Hamcrest\AbstractMatcherTest;
  4. class IsArrayContainingInAnyOrderTest extends AbstractMatcherTest
  5. {
  6. protected function createMatcher()
  7. {
  8. return IsArrayContainingInAnyOrder::arrayContainingInAnyOrder(array(1, 2));
  9. }
  10. public function testHasAReadableDescription()
  11. {
  12. $this->assertDescription('[<1>, <2>] in any order', containsInAnyOrder(array(1, 2)));
  13. }
  14. public function testMatchesItemsInAnyOrder()
  15. {
  16. $this->assertMatches(containsInAnyOrder(array(1, 2, 3)), array(1, 2, 3), 'in order');
  17. $this->assertMatches(containsInAnyOrder(array(1, 2, 3)), array(3, 2, 1), 'out of order');
  18. $this->assertMatches(containsInAnyOrder(array(1)), array(1), 'single');
  19. }
  20. public function testAppliesMatchersInAnyOrder()
  21. {
  22. $this->assertMatches(
  23. containsInAnyOrder(array(1, 2, 3)),
  24. array(1, 2, 3),
  25. 'in order'
  26. );
  27. $this->assertMatches(
  28. containsInAnyOrder(array(1, 2, 3)),
  29. array(3, 2, 1),
  30. 'out of order'
  31. );
  32. $this->assertMatches(
  33. containsInAnyOrder(array(1)),
  34. array(1),
  35. 'single'
  36. );
  37. }
  38. public function testMismatchesItemsInAnyOrder()
  39. {
  40. $matcher = containsInAnyOrder(array(1, 2, 3));
  41. $this->assertMismatchDescription('was null', $matcher, null);
  42. $this->assertMismatchDescription('No item matches: <1>, <2>, <3> in []', $matcher, array());
  43. $this->assertMismatchDescription('No item matches: <2>, <3> in [<1>]', $matcher, array(1));
  44. $this->assertMismatchDescription('Not matched: <4>', $matcher, array(4, 3, 2, 1));
  45. }
  46. }