1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Scriptotek\Alma\Bibs; |
4
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
6
|
|
|
use Scriptotek\Alma\Bibs\Bib; |
7
|
|
|
use Scriptotek\Alma\Bibs\Holding; |
8
|
|
|
use Scriptotek\Alma\Bibs\Holdings; |
9
|
|
|
use Scriptotek\Alma\Client as AlmaClient; |
10
|
|
|
use spec\Scriptotek\Alma\SpecHelper; |
11
|
|
|
|
12
|
|
|
class HoldingsSpec extends ObjectBehavior |
13
|
|
|
{ |
14
|
|
|
public function let(AlmaClient $client, Bib $bib) |
15
|
|
|
{ |
16
|
|
|
$bib->mms_id = 'abc'; |
17
|
|
|
$this->beConstructedWith($client, $bib); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function it_is_initializable() |
21
|
|
|
{ |
22
|
|
|
$this->shouldHaveType(Holdings::class); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
protected function expectRequest($client) |
26
|
|
|
{ |
27
|
|
|
$client->getJSON('/bibs/abc/holdings') |
28
|
|
|
->shouldBeCalled() |
29
|
|
|
->willReturn(SpecHelper::getDummyData('holdings_response.json')); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
View Code Duplication |
public function it_provides_a_lazy_interface_to_holding_objects(AlmaClient $client, Bib $bib) |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
SpecHelper::expectNoRequests($client); |
35
|
|
|
|
36
|
|
|
$holding_id = '12345'; // str_random(); |
37
|
|
|
$holding = $this->get($holding_id); |
38
|
|
|
|
39
|
|
|
$holding->shouldHaveType(Holding::class); |
40
|
|
|
$holding->bib->shouldBe($bib); |
41
|
|
|
$holding->holding_id->shouldBe($holding_id); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
View Code Duplication |
public function it_provides_a_lazy_array_interface_to_holding_objects(AlmaClient $client, Bib $bib) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
SpecHelper::expectNoRequests($client); |
47
|
|
|
|
48
|
|
|
$holding_id = '90123'; // str_random(); |
49
|
|
|
$holding = $this[$holding_id]; |
50
|
|
|
|
51
|
|
|
$holding->shouldHaveType(Holding::class); |
52
|
|
|
$holding->bib->shouldBe($bib); |
53
|
|
|
$holding->holding_id->shouldBe($holding_id); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function it_is_countable(AlmaClient $client) |
57
|
|
|
{ |
58
|
|
|
$this->expectRequest($client); |
59
|
|
|
|
60
|
|
|
$this->shouldHaveCount(2); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function it_provides_an_iterator_interface_to_holding_objects(AlmaClient $client) |
64
|
|
|
{ |
65
|
|
|
$this->expectRequest($client); |
66
|
|
|
|
67
|
|
|
$this->shouldImplement('Iterator'); |
68
|
|
|
|
69
|
|
|
$this->current()->shouldHaveType(Holding::class); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function it_provides_basic_data_without_loading_the_full_record(AlmaClient $client) |
73
|
|
|
{ |
74
|
|
|
$this->expectRequest($client); |
75
|
|
|
|
76
|
|
|
$this->shouldHaveCount(2); |
77
|
|
|
$this->all()[0]->shouldHaveType(Holding::class); |
78
|
|
|
$this->all()[0]->library->desc->shouldBe('BURNS'); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
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.