1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Scriptotek\Alma\Bibs; |
4
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
6
|
|
|
use Psr\Http\Message\UriInterface; |
7
|
|
|
use Scriptotek\Alma\Bibs\Bib; |
8
|
|
|
use Scriptotek\Alma\Bibs\Holding; |
9
|
|
|
use Scriptotek\Alma\Bibs\Item; |
10
|
|
|
use Scriptotek\Alma\Client as AlmaClient; |
11
|
|
|
use Scriptotek\Alma\Bibs\ScanInResponse; |
12
|
|
|
use Scriptotek\Alma\Conf\Library; |
13
|
|
|
use Scriptotek\Alma\Users\Loan; |
14
|
|
|
use Scriptotek\Alma\Users\User; |
15
|
|
|
use spec\Scriptotek\Alma\SpecHelper; |
16
|
|
|
|
17
|
|
|
class ItemSpec extends ObjectBehavior |
18
|
|
|
{ |
19
|
|
|
public function let(AlmaClient $client, Bib $bib, Holding $holding) |
20
|
|
|
{ |
21
|
|
|
$bib->mms_id = '990006312214702204'; |
22
|
|
|
$holding->holding_id = '22163771200002204'; |
23
|
|
|
$item_id = '23163771190002204'; |
24
|
|
|
|
25
|
|
|
$this->beConstructedWith($client, $bib, $holding, $item_id); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function it_is_initializable() |
29
|
|
|
{ |
30
|
|
|
$this->shouldHaveType(Item::class); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function it_can_be_checked_out(AlmaClient $client, User $user, Library $library, UriInterface $url) |
34
|
|
|
{ |
35
|
|
|
$client->buildUrl('/bibs/990006312214702204/holdings/22163771200002204/items/23163771190002204/loans', ['user_id' => 'Dan Michael']) |
36
|
|
|
->willReturn($url); |
37
|
|
|
|
38
|
|
|
$client->postJSON($url, [ |
39
|
|
|
'library' => ['value' => 'THAT LIBRARY'], 'circ_desk' => ['value' => 'DEFAULT_CIRC_DESK']]) |
40
|
|
|
->shouldBeCalled() |
41
|
|
|
->willReturn(SpecHelper::getDummyData('create_loan_response.json')); |
42
|
|
|
|
43
|
|
|
$user->id = 'Dan Michael'; |
44
|
|
|
$library->code = 'THAT LIBRARY'; |
45
|
|
|
|
46
|
|
|
$this->checkOut($user, $library) |
47
|
|
|
->shouldHaveType(Loan::class); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
View Code Duplication |
function it_can_be_on_loan(AlmaClient $client, User $user, Library $library, UriInterface $url) |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$client->buildUrl('/bibs/990006312214702204/holdings/22163771200002204/items/23163771190002204/loans', []) |
53
|
|
|
->willReturn($url); |
54
|
|
|
|
55
|
|
|
$client->getJSON($url) |
56
|
|
|
->shouldBeCalled() |
57
|
|
|
->willReturn(SpecHelper::getDummyData('item_loan_response.json')); |
58
|
|
|
|
59
|
|
|
$this->getLoan()->shouldHaveType(Loan::class); |
60
|
|
|
$this->loan->shouldHaveType(Loan::class); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
View Code Duplication |
function it_can_be_available(AlmaClient $client, User $user, Library $library, UriInterface $url) |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
$client->buildUrl('/bibs/990006312214702204/holdings/22163771200002204/items/23163771190002204/loans', []) |
66
|
|
|
->willReturn($url); |
67
|
|
|
|
68
|
|
|
$client->getJSON($url) |
69
|
|
|
->shouldBeCalled() |
70
|
|
|
->willReturn(SpecHelper::getDummyData('item_no_loan_response.json')); |
71
|
|
|
|
72
|
|
|
$this->getLoan()->shouldBe(null); |
73
|
|
|
$this->loan->shouldBe(null); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
function it_can_be_scanned_in(AlmaClient $client, Library $library, UriInterface $url) |
77
|
|
|
{ |
78
|
|
|
$client->buildUrl('/bibs/990006312214702204/holdings/22163771200002204/items/23163771190002204', [ |
79
|
|
|
'op' => 'scan', |
80
|
|
|
'library' => 'THAT LIBRARY', |
81
|
|
|
'circ_desk' => 'DEFAULT_CIRC_DESK', |
82
|
|
|
])->willReturn($url); |
83
|
|
|
|
84
|
|
|
$client->postJSON($url) |
85
|
|
|
->shouldBeCalled() |
86
|
|
|
->willReturn(SpecHelper::getDummyData('scanin_transit_response.json')); |
87
|
|
|
|
88
|
|
|
$library->code = 'THAT LIBRARY'; |
89
|
|
|
|
90
|
|
|
$this->scanIn($library) |
91
|
|
|
->shouldHaveType(ScanInResponse::class); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
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.