1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\TomPHP\HalClient\Resource; |
4
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
6
|
|
|
use TomPHP\HalClient\Exception\FieldNotFoundException; |
7
|
|
|
use TomPHP\HalClient\Resource\FieldNode; |
8
|
|
|
|
9
|
|
|
class FieldMapSpec extends ObjectBehavior |
10
|
|
|
{ |
11
|
|
|
function let(FieldNode $f1, FieldNode $f2) |
12
|
|
|
{ |
13
|
|
|
$this->beConstructedWith([ |
14
|
|
|
'field1' => $f1, |
15
|
|
|
'field2' => $f2, |
16
|
|
|
]); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
function it_returns_field_via_field_method(FieldNode $f1) |
20
|
|
|
{ |
21
|
|
|
$this->getField('field1')->shouldReturn($f1); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
function it_throws_if_field_is_not_found() |
25
|
|
|
{ |
26
|
|
|
$this->shouldThrow(new FieldNotFoundException('unknown-field')) |
27
|
|
|
->duringGetField('unknown-field'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
function it_returns_field_via_magic_method(FieldNode $f1) |
31
|
|
|
{ |
32
|
|
|
$this->field1->shouldReturn($f1); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
function it_does_not_match_if_critera_includes_unknown_field() |
36
|
|
|
{ |
37
|
|
|
$this->matches(['unknown_field' => 'some-value'])->shouldReturn(false); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
View Code Duplication |
function it_does_match_if_all_criteria_fields_match(FieldNode $f1, FieldNode $f2) |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
$f1->matches('search-value1')->willReturn(true); |
43
|
|
|
$f2->matches('search-value2')->willReturn(true); |
44
|
|
|
|
45
|
|
|
$this->matches([ |
46
|
|
|
'field1' => 'search-value1', |
47
|
|
|
'field2' => 'search-value2', |
48
|
|
|
])->shouldReturn(true); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
View Code Duplication |
function it_does_not_match_if_any_criteria_fields_fail_to_match(FieldNode $f1, FieldNode $f2) |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
$f1->matches('search-value1')->willReturn(true); |
54
|
|
|
$f2->matches('search-value2')->willReturn(false); |
55
|
|
|
|
56
|
|
|
$this->matches([ |
57
|
|
|
'field1' => 'search-value1', |
58
|
|
|
'field2' => 'search-value2', |
59
|
|
|
])->shouldReturn(false); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.