Passed
Push — master ( f2085b...b46880 )
by Dan Michael O.
08:55
created

HoldingSpec::expectRequest()   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 Scriptotek\Alma\Bibs\Bib;
7
use Scriptotek\Alma\Bibs\Holding;
8
use Scriptotek\Alma\Bibs\Item;
9
use Scriptotek\Alma\Client as AlmaClient;
10
use Scriptotek\Marc\Record;
11
use spec\Scriptotek\Alma\SpecHelper;
12
13
class HoldingSpec extends ObjectBehavior
14
{
15
    public function let(AlmaClient $client, Bib $bib)
16
    {
17
        $bib->mms_id = 'abc';
18
        $holdings_id = '123';
19
        $this->beConstructedWith($client, $bib, $holdings_id);
20
    }
21
22
    protected function expectRequest($client)
23
    {
24
        $client->getXML('/bibs/abc/holdings/123')
25
            ->shouldBeCalled()
26
            ->willReturn(SpecHelper::getDummyData('holding_response.xml'));
27
    }
28
29
    public function it_is_initializable()
30
    {
31
        $this->shouldHaveType(Holding::class);
32
    }
33
34
    public function it_fetches_record_data_when_needed(AlmaClient $client)
35
    {
36
        $this->expectRequest($client);
37
38
        $this->created_by->shouldBe('import');
0 ignored issues
show
Documentation introduced by
The property created_by does not exist on object<spec\Scriptotek\Alma\Bibs\HoldingSpec>. 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...
39
        $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\HoldingSpec>. 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
        $this->record->shouldHaveType(Record::class);
0 ignored issues
show
Documentation introduced by
The property record does not exist on object<spec\Scriptotek\Alma\Bibs\HoldingSpec>. 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...
42
    }
43
44
    public function it_has_items(AlmaClient $client)
45
    {
46
        $client->getJSON('/bibs/abc/holdings/123/items')
47
            ->shouldBeCalled()
48
            ->willReturn(SpecHelper::getDummyData('items_response.json'));
49
50
        $items = $this->items;
0 ignored issues
show
Documentation introduced by
The property items does not exist on object<spec\Scriptotek\Alma\Bibs\HoldingSpec>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
51
        $items->shouldHaveCount(9);
52
53
        $items->rewind();
54
        $items->valid()->shouldBe(true);
55
        $items->current()->shouldHaveType(Item::class);
56
    }
57
}
58