You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.2 KiB

3 years ago
  1. <?php
  2. namespace Hamcrest\Arrays;
  3. use Hamcrest\AbstractMatcherTest;
  4. class IsArrayContainingTest extends AbstractMatcherTest
  5. {
  6. protected function createMatcher()
  7. {
  8. return IsArrayContaining::hasItemInArray('irrelevant');
  9. }
  10. public function testMatchesAnArrayThatContainsAnElementMatchingTheGivenMatcher()
  11. {
  12. $this->assertMatches(
  13. hasItemInArray('a'),
  14. array('a', 'b', 'c'),
  15. "should matches array that contains 'a'"
  16. );
  17. }
  18. public function testDoesNotMatchAnArrayThatDoesntContainAnElementMatchingTheGivenMatcher()
  19. {
  20. $this->assertDoesNotMatch(
  21. hasItemInArray('a'),
  22. array('b', 'c'),
  23. "should not matches array that doesn't contain 'a'"
  24. );
  25. $this->assertDoesNotMatch(
  26. hasItemInArray('a'),
  27. array(),
  28. 'should not match empty array'
  29. );
  30. }
  31. public function testDoesNotMatchNull()
  32. {
  33. $this->assertDoesNotMatch(
  34. hasItemInArray('a'),
  35. null,
  36. 'should not match null'
  37. );
  38. }
  39. public function testHasAReadableDescription()
  40. {
  41. $this->assertDescription('an array containing "a"', hasItemInArray('a'));
  42. }
  43. }