Test Failed
Push — master ( c6b6d3...528954 )
by Dan Michael O.
03:21
created

BibSpec::it_catches_resource_not_found()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
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\Bibs\Bibs;
10
use Scriptotek\Alma\Bibs\Holding;
11
use Scriptotek\Alma\Bibs\Holdings;
12
use Scriptotek\Alma\Client as AlmaClient;
13
use Scriptotek\Alma\Exception\ResourceNotFound;
14
use Scriptotek\Marc\Record;
15
use spec\Scriptotek\Alma\SpecHelper;
16
17
class BibSpec extends ObjectBehavior
18
{
19
    public function let(AlmaClient $client, UriInterface $url)
0 ignored issues
show
Unused Code introduced by
The parameter $url is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
20
    {
21
        $mms_id = '999104760474702204';
22
        $this->beConstructedWith($client, $mms_id);
23
    }
24
25
    protected function expectRequest($client, $url) {
26
        $client->buildUrl('/bibs/999104760474702204', [])
27
            ->shouldBeCalled()
28
            ->willReturn($url);
29
30
        $client->getJSON($url)
31
            ->shouldBeCalled()
32
            ->willReturn(SpecHelper::getDummyData('bib_response_iz.json'));
33
    }
34
35
    public function it_is_lazy(AlmaClient $client)
36
    {
37
        SpecHelper::expectNoRequests($client);
38
        $this->shouldHaveType(Bib::class);
39
    }
40
41
    public function it_loads_bib_data_when_needed(AlmaClient $client, UriInterface $url)
42
    {
43
        $this->expectRequest($client, $url);
44
45
        $this->created_date->shouldBe('2015-11-05Z');
0 ignored issues
show
Documentation introduced by
The property created_date does not exist on object<spec\Scriptotek\Alma\Bibs\BibSpec>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
46
    }
47
48
    public function it_loads_bib_data_when_needed2(AlmaClient $client, UriInterface $url)
49
    {
50
        $this->expectRequest($client, $url);
51
52
        $this->exists()->shouldBe(true);
53
    }
54
55
    public function it_links_to_network_zone(AlmaClient $client, AlmaClient $nz, Bibs $bibs, Bib $nz_bib, UriInterface $url)
56
    {
57
        $this->expectRequest($client, $url);
58
59
        $client->nz = $nz;
60
        $nz->bibs = $bibs;
61
        $bibs->get('999104760474702201')
62
            ->shouldBeCalled()
63
            ->willReturn($nz_bib);
64
65
        $this->getNzRecord()->shouldHaveType(Bib::class);
66
    }
67
68
    public function it_provides_lazy_access_to_holdings(AlmaClient $client)
69
    {
70
        SpecHelper::expectNoRequests($client);
71
        $this->holdings->shouldHaveType(Holdings::class);
0 ignored issues
show
Documentation introduced by
The property holdings does not exist on object<spec\Scriptotek\Alma\Bibs\BibSpec>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
72
    }
73
74
    public function it_has_a_MARC_record(AlmaClient $client, UriInterface $url)
75
    {
76
        $this->expectRequest($client, $url);
77
78
        $this->record->shouldHaveType(Record::class);
0 ignored issues
show
Documentation introduced by
The property record does not exist on object<spec\Scriptotek\Alma\Bibs\BibSpec>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
79
        $this->record->getField('245')->getSubfield('a')->getData()->shouldBe('Lonely hearts of the cosmos :');
0 ignored issues
show
Documentation introduced by
The property record does not exist on object<spec\Scriptotek\Alma\Bibs\BibSpec>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
80
    }
81
82
    public function it_can_be_edited(AlmaClient $client, UriInterface $url)
83
    {
84
        $this->expectRequest($client, $url);
85
86
        $this->record->getField('245')->getSubfield('a')->setData('New title');
0 ignored issues
show
Documentation introduced by
The property record does not exist on object<spec\Scriptotek\Alma\Bibs\BibSpec>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
87
88
        $client->putJSON('/bibs/999104760474702204', Argument::containingString('New title'))
89
            ->shouldBeCalled();
90
        $this->save();
91
    }
92
93
    public function it_catches_resource_not_found(AlmaClient $client, UriInterface $url)
94
    {
95
        $client->buildUrl('/bibs/999104760474702204', [])
96
            ->shouldBeCalled()
97
            ->willReturn($url);
98
99
        $client->getJSON($url)
100
            ->shouldBeCalled()
101
            ->willThrow(ResourceNotFound::class);
102
103
        $this->exists()->shouldBe(false);
104
    }
105
}
106