Completed
Push — master ( 804c7f...1d2ba7 )
by Dan Michael O.
01:59
created

PortfolioSpec::it_fetches_data_when_needed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
rs 10
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 Scriptotek\Alma\Bibs\Bib;
8
use Scriptotek\Alma\Bibs\Portfolio;
9
use Scriptotek\Alma\Bibs\Portfolios;
10
use Scriptotek\Alma\Client as AlmaClient;
11
use Scriptotek\Alma\Electronic\Collection;
12
use spec\Scriptotek\Alma\SpecHelper;
13
14
class PortfolioSpec extends ObjectBehavior
15
{
16
    public function let(AlmaClient $client, Bib $bib)
17
    {
18
        $bib->mms_id = 'abc';
19
        $portfolio_id = '123';
20
        $this->beConstructedWith($client, $bib, $portfolio_id);
21
    }
22
23
    function it_is_initializable()
24
    {
25
        $this->shouldHaveType(Portfolio::class);
26
    }
27
28
    protected function expectRequest($client)
29
    {
30
        $client->getJSON('/bibs/abc/portfolios/123')
31
            ->shouldBeCalled()
32
            ->willReturn(SpecHelper::getDummyData('portfolio_response.json'));
33
    }
34
35
    public function it_fetches_data_when_needed(AlmaClient $client)
36
    {
37
        $this->expectRequest($client);
38
39
        $this->availability->desc->shouldBe('Available');
0 ignored issues
show
Documentation introduced by
The property availability does not exist on object<spec\Scriptotek\Alma\Bibs\PortfolioSpec>. 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...
40
    }
41
42
    public function it_belongs_to_collection(AlmaClient $client)
43
    {
44
        $this->expectRequest($client);
45
46
        $this->getElectronicCollection()->shouldHaveType(Collection::class);
47
        $this->electronic_collection->shouldHaveType(Collection::class);
0 ignored issues
show
Documentation introduced by
The property electronic_collection does not exist on object<spec\Scriptotek\Alma\Bibs\PortfolioSpec>. 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...
48
    }}
49