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\Client as AlmaClient; |
9
|
|
|
use Scriptotek\Marc\Record; |
10
|
|
|
use Scriptotek\Sru\Client as SruClient; |
11
|
|
|
use Scriptotek\Sru\Record as SruRecord; |
12
|
|
|
use spec\Scriptotek\Alma\SpecHelper; |
13
|
|
|
|
14
|
|
|
class BibsSpec extends ObjectBehavior |
15
|
|
|
{ |
16
|
|
|
public function let(AlmaClient $client, SruClient $sru) |
17
|
|
|
{ |
18
|
|
|
$this->beConstructedWith($client); |
19
|
|
|
$client->sru = $sru; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
View Code Duplication |
public function it_provides_a_lazy_interface_to_bib_objects(AlmaClient $client) |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
SpecHelper::expectNoRequests($client); |
25
|
|
|
|
26
|
|
|
$mms_id = '123'; // str_random(); |
27
|
|
|
$bib = $this->get($mms_id); |
28
|
|
|
|
29
|
|
|
$bib->shouldHaveType(Bib::class); |
30
|
|
|
$bib->mms_id->shouldBe($mms_id); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
View Code Duplication |
public function it_provides_a_lazy_array_interface_to_bib_objects(AlmaClient $client) |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
SpecHelper::expectNoRequests($client); |
36
|
|
|
|
37
|
|
|
$mms_id = '123'; // str_random(); |
38
|
|
|
$bib = $this[$mms_id]; |
39
|
|
|
|
40
|
|
|
$bib->shouldHaveType(Bib::class); |
41
|
|
|
$bib->mms_id->shouldBe($mms_id); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function it_accepts_expand_parameter(AlmaClient $client) |
45
|
|
|
{ |
46
|
|
|
$client->getXML('/bibs/12345?expand=p_avail') |
47
|
|
|
->shouldBeCalled() |
48
|
|
|
->willReturn(SpecHelper::getDummyData('bib_response_with_availability.xml')); |
49
|
|
|
|
50
|
|
|
$this->get('12345', 'p_avail')->record; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function it_provides_lookup_by_isbn(AlmaClient $client, SruClient $sru) |
54
|
|
|
{ |
55
|
|
|
SpecHelper::expectNoRequests($client); |
56
|
|
|
$client->assertHasSruClient()->shouldBeCalled()->willReturn(true); |
57
|
|
|
|
58
|
|
|
$sru->all('alma.isbn="123"', 1) |
59
|
|
|
->shouldBeCalled() |
60
|
|
|
->willReturn([SruRecord::make( |
61
|
|
|
1, |
62
|
|
|
'<record xmlns="http://www.loc.gov/MARC21/slim"><controlfield tag="001">990114012304702201</controlfield></record>' |
63
|
|
|
)]); |
64
|
|
|
|
65
|
|
|
$bib = $this->fromIsbn('123'); |
66
|
|
|
$bib->shouldHaveType(Bib::class); |
67
|
|
|
|
68
|
|
|
// This operation should be lazy |
69
|
|
|
$bib->mms_id->shouldBe('990114012304702201'); |
70
|
|
|
|
71
|
|
|
// This operation should also be lazy |
72
|
|
|
$bib->record->shouldBeAnInstanceOf(Record::class); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function it_returns_null_given_unknown_isbn(AlmaClient $client, SruClient $sru) |
76
|
|
|
{ |
77
|
|
|
SpecHelper::expectNoRequests($client); |
78
|
|
|
$client->assertHasSruClient()->shouldBeCalled()->willReturn(true); |
79
|
|
|
|
80
|
|
|
$sru->all('alma.isbn="123"', 1) |
81
|
|
|
->shouldBeCalled() |
82
|
|
|
->willReturn([]); |
83
|
|
|
|
84
|
|
|
$bib = $this->fromIsbn('123'); |
85
|
|
|
$bib->shouldBe(null); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function it_supports_lookup_by_holding_id(AlmaClient $client) |
89
|
|
|
{ |
90
|
|
|
$client->getXML('/bibs', Argument::containing('12345')) |
91
|
|
|
->shouldBeCalled() |
92
|
|
|
->willReturn(SpecHelper::getDummyData('bibs_holdings.xml')); |
93
|
|
|
|
94
|
|
|
$bib = $this->fromHoldingsId('12345'); |
95
|
|
|
$bib->shouldHaveType(Bib::class); |
96
|
|
|
$bib->mms_id->shouldBe('999900137074702204'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/* |
100
|
|
|
public function it_returns_a_bib_object_given_a_barcode(AlmaClient $client) |
101
|
|
|
{ |
102
|
|
|
} |
103
|
|
|
*/ |
104
|
|
|
} |
105
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.