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