Completed
Push — master ( 9d90d4...cee823 )
by Dan Michael O.
03:06
created

BibsSpec::it_accepts_expand_parameter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
namespace spec\Scriptotek\Alma\Bibs;
4
5
use PhpSpec\ObjectBehavior;
6
use Prophecy\Argument;
7
use Psr\Http\Message\UriInterface;
8
use Scriptotek\Alma\Bibs\Bib;
9
use Scriptotek\Alma\Client as AlmaClient;
10
use Scriptotek\Marc\Record;
11
use Scriptotek\Sru\Client as SruClient;
12
use Scriptotek\Sru\Record as SruRecord;
13
use spec\Scriptotek\Alma\SpecHelper;
14
15
class BibsSpec extends ObjectBehavior
16
{
17
    public function let(AlmaClient $client, SruClient $sru)
18
    {
19
        $this->beConstructedWith($client);
20
        $client->sru = $sru;
21
    }
22
23 View Code Duplication
    public function it_provides_a_lazy_interface_to_bib_objects(AlmaClient $client)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
24
    {
25
        SpecHelper::expectNoRequests($client);
26
27
        $mms_id = '123'; // str_random();
28
        $bib = $this->get($mms_id);
29
30
        $bib->shouldHaveType(Bib::class);
31
        $bib->mms_id->shouldBe($mms_id);
32
    }
33
34 View Code Duplication
    public function it_provides_a_lazy_array_interface_to_bib_objects(AlmaClient $client)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
35
    {
36
        SpecHelper::expectNoRequests($client);
37
38
        $mms_id = '123'; // str_random();
39
        $bib = $this[$mms_id];
40
41
        $bib->shouldHaveType(Bib::class);
42
        $bib->mms_id->shouldBe($mms_id);
43
    }
44
45 View Code Duplication
    public function it_accepts_expand_parameter(AlmaClient $client, UriInterface $url)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
46
    {
47
        $client->buildUrl('/bibs/12345', ['expand' => 'p_avail'])
48
            ->shouldBeCalled()
49
            ->willReturn($url);
50
51
        $client->getJSON($url)
52
            ->shouldBeCalled()
53
            ->willReturn(SpecHelper::getDummyData('bib_response_with_availability.json'));
54
55
        $this->get('12345', 'p_avail')->record;
56
    }
57
58
    public function it_provides_lookup_by_isbn(AlmaClient $client, SruClient $sru)
59
    {
60
        SpecHelper::expectNoRequests($client);
61
        $client->assertHasSruClient()->shouldBeCalled()->willReturn(true);
62
63
        $sru->all('alma.isbn="123"', 1)
64
            ->shouldBeCalled()
65
            ->willReturn([SruRecord::make(
66
                1,
67
                '<record><controlfield tag="001">990114012304702201</controlfield></record>'
68
            )]);
69
70
        $bib = $this->fromIsbn('123');
71
        $bib->shouldHaveType(Bib::class);
72
73
        // This operation should be lazy
74
        $bib->mms_id->shouldBe('990114012304702201');
75
76
        // This operation should also be lazy
77
        $bib->record->shouldBeAnInstanceOf(Record::class);
78
    }
79
80
    public function it_returns_null_given_unknown_isbn(AlmaClient $client, SruClient $sru)
81
    {
82
        SpecHelper::expectNoRequests($client);
83
        $client->assertHasSruClient()->shouldBeCalled()->willReturn(true);
84
85
        $sru->all('alma.isbn="123"', 1)
86
            ->shouldBeCalled()
87
            ->willReturn([]);
88
89
        $bib = $this->fromIsbn('123');
90
        $bib->shouldBe(null);
91
    }
92
93
    public function it_supports_lookup_by_holding_id(AlmaClient $client)
94
    {
95
        $client->getJSON('/bibs', Argument::containing('12345'))
96
            ->shouldBeCalled()
97
            ->willReturn(SpecHelper::getDummyData('bibs_holdings.json'));
98
99
        $bib = $this->fromHoldingsId('12345');
100
        $bib->shouldHaveType(Bib::class);
101
        $bib->mms_id->shouldBe('990006312214702204');
102
    }
103
104
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
105
    public function it_returns_a_bib_object_given_a_barcode(AlmaClient $client)
106
    {
107
    }
108
    */
109
}
110