1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Scriptotek\Alma\Bibs; |
4
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
6
|
|
|
use Prophecy\Argument; |
7
|
|
|
use Scriptotek\Alma\Bibs\Bib; |
8
|
|
|
use Scriptotek\Alma\Bibs\Bibs; |
9
|
|
|
use Scriptotek\Alma\Bibs\Holdings; |
10
|
|
|
use Scriptotek\Alma\Client as AlmaClient; |
11
|
|
|
use Scriptotek\Alma\Exception\ResourceNotFound; |
12
|
|
|
use Scriptotek\Alma\Users\Requests; |
13
|
|
|
use Scriptotek\Marc\Record; |
14
|
|
|
use spec\Scriptotek\Alma\SpecHelper; |
15
|
|
|
|
16
|
|
|
class BibSpec extends ObjectBehavior |
17
|
|
|
{ |
18
|
|
|
public function let(AlmaClient $client) |
19
|
|
|
{ |
20
|
|
|
$this->beConstructedWith($client, '999104760474702204'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
protected function expectRequest($client) |
24
|
|
|
{ |
25
|
|
|
$client->getXML('/bibs/999104760474702204') |
26
|
|
|
->shouldBeCalled() |
27
|
|
|
->willReturn(SpecHelper::getDummyData('bib_response_iz.xml')); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function it_is_lazy(AlmaClient $client) |
31
|
|
|
{ |
32
|
|
|
SpecHelper::expectNoRequests($client); |
33
|
|
|
$this->shouldHaveType(Bib::class); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function it_fetches_record_data_when_needed(AlmaClient $client) |
37
|
|
|
{ |
38
|
|
|
$this->expectRequest($client); |
39
|
|
|
|
40
|
|
|
$this->created_by->shouldBe('import'); |
|
|
|
|
41
|
|
|
$this->created_date->shouldBe('2015-11-05Z'); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function it_can_exist(AlmaClient $client) |
45
|
|
|
{ |
46
|
|
|
$this->expectRequest($client); |
47
|
|
|
|
48
|
|
|
$this->exists()->shouldBe(true); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function it_links_to_network_zone(AlmaClient $client, AlmaClient $nz, Bibs $bibs, Bib $nz_bib) |
52
|
|
|
{ |
53
|
|
|
$this->expectRequest($client); |
54
|
|
|
|
55
|
|
|
$client->nz = $nz; |
56
|
|
|
$nz->bibs = $bibs; |
57
|
|
|
$bibs->get('999104760474702201') |
58
|
|
|
->shouldBeCalled() |
59
|
|
|
->willReturn($nz_bib); |
60
|
|
|
|
61
|
|
|
$this->getNzRecord()->shouldHaveType(Bib::class); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function it_provides_lazy_access_to_holdings(AlmaClient $client) |
65
|
|
|
{ |
66
|
|
|
SpecHelper::expectNoRequests($client); |
67
|
|
|
$this->holdings->shouldHaveType(Holdings::class); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function it_has_a_MARC_record(AlmaClient $client) |
71
|
|
|
{ |
72
|
|
|
$this->expectRequest($client); |
73
|
|
|
|
74
|
|
|
$this->record->shouldHaveType(Record::class); |
|
|
|
|
75
|
|
|
$this->record->getField('245')->getSubfield('a')->getData()->shouldBe('Lonely hearts of the cosmos :'); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function it_can_be_edited(AlmaClient $client) |
79
|
|
|
{ |
80
|
|
|
$this->expectRequest($client); |
81
|
|
|
|
82
|
|
|
$this->record->getField('245')->getSubfield('a')->setData('New title'); |
|
|
|
|
83
|
|
|
|
84
|
|
|
$client->putXML('/bibs/999104760474702204', Argument::containingString('New title')) |
85
|
|
|
->shouldBeCalled(); |
86
|
|
|
|
87
|
|
|
$this->save(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function it_catches_resource_not_found(AlmaClient $client) |
91
|
|
|
{ |
92
|
|
|
$client->getXML('/bibs/999104760474702204') |
93
|
|
|
->shouldBeCalled() |
94
|
|
|
->willThrow(ResourceNotFound::class); |
95
|
|
|
|
96
|
|
|
$this->exists()->shouldBe(false); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function it_has_requests() |
100
|
|
|
{ |
101
|
|
|
$this->requests->shouldHaveType(Requests::class); |
|
|
|
|
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
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.