IsArrayContainingKeyValuePairTest.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace Hamcrest\Arrays;
  3. use Hamcrest\AbstractMatcherTest;
  4. class IsArrayContainingKeyValuePairTest extends AbstractMatcherTest
  5. {
  6. protected function createMatcher()
  7. {
  8. return IsArrayContainingKeyValuePair::hasKeyValuePair('irrelevant', 'irrelevant');
  9. }
  10. public function testMatchesArrayContainingMatchingKeyAndValue()
  11. {
  12. $array = array('a'=>1, 'b'=>2);
  13. $this->assertMatches(hasKeyValuePair(equalTo('a'), equalTo(1)), $array, 'matcherA');
  14. $this->assertMatches(hasKeyValuePair(equalTo('b'), equalTo(2)), $array, 'matcherB');
  15. $this->assertMismatchDescription(
  16. 'array was ["a" => <1>, "b" => <2>]',
  17. hasKeyValuePair(equalTo('c'), equalTo(3)),
  18. $array
  19. );
  20. }
  21. public function testDoesNotMatchNull()
  22. {
  23. $this->assertMismatchDescription('was null', hasKeyValuePair(anything(), anything()), null);
  24. }
  25. public function testHasReadableDescription()
  26. {
  27. $this->assertDescription('array containing ["a" => <2>]', hasKeyValuePair(equalTo('a'), equalTo(2)));
  28. }
  29. }