| 148 |
lars |
1 |
<?php
|
|
|
2 |
namespace Hamcrest\Core;
|
|
|
3 |
|
|
|
4 |
class CombinableMatcherTest extends \Hamcrest\AbstractMatcherTest
|
|
|
5 |
{
|
|
|
6 |
|
|
|
7 |
private $_either_3_or_4;
|
|
|
8 |
private $_not_3_and_not_4;
|
|
|
9 |
|
|
|
10 |
protected function setUp()
|
|
|
11 |
{
|
|
|
12 |
$this->_either_3_or_4 = \Hamcrest\Core\CombinableMatcher::either(equalTo(3))->orElse(equalTo(4));
|
|
|
13 |
$this->_not_3_and_not_4 = \Hamcrest\Core\CombinableMatcher::both(not(equalTo(3)))->andAlso(not(equalTo(4)));
|
|
|
14 |
}
|
|
|
15 |
|
|
|
16 |
protected function createMatcher()
|
|
|
17 |
{
|
|
|
18 |
return \Hamcrest\Core\CombinableMatcher::either(equalTo('irrelevant'))->orElse(equalTo('ignored'));
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
public function testBothAcceptsAndRejects()
|
|
|
22 |
{
|
|
|
23 |
assertThat(2, $this->_not_3_and_not_4);
|
|
|
24 |
assertThat(3, not($this->_not_3_and_not_4));
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
public function testAcceptsAndRejectsThreeAnds()
|
|
|
28 |
{
|
|
|
29 |
$tripleAnd = $this->_not_3_and_not_4->andAlso(equalTo(2));
|
|
|
30 |
assertThat(2, $tripleAnd);
|
|
|
31 |
assertThat(3, not($tripleAnd));
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
public function testBothDescribesItself()
|
|
|
35 |
{
|
|
|
36 |
$this->assertEquals('(not <3> and not <4>)', (string) $this->_not_3_and_not_4);
|
|
|
37 |
$this->assertMismatchDescription('was <3>', $this->_not_3_and_not_4, 3);
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
public function testEitherAcceptsAndRejects()
|
|
|
41 |
{
|
|
|
42 |
assertThat(3, $this->_either_3_or_4);
|
|
|
43 |
assertThat(6, not($this->_either_3_or_4));
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
public function testAcceptsAndRejectsThreeOrs()
|
|
|
47 |
{
|
|
|
48 |
$orTriple = $this->_either_3_or_4->orElse(greaterThan(10));
|
|
|
49 |
|
|
|
50 |
assertThat(11, $orTriple);
|
|
|
51 |
assertThat(9, not($orTriple));
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
public function testEitherDescribesItself()
|
|
|
55 |
{
|
|
|
56 |
$this->assertEquals('(<3> or <4>)', (string) $this->_either_3_or_4);
|
|
|
57 |
$this->assertMismatchDescription('was <6>', $this->_either_3_or_4, 6);
|
|
|
58 |
}
|
|
|
59 |
}
|