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

FeesSpec::it_can_be_empty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
namespace spec\Scriptotek\Alma\Users;
4
5
use PhpSpec\ObjectBehavior;
6
use Psr\Http\Message\UriInterface;
7
use Scriptotek\Alma\Client as AlmaClient;
8
use Scriptotek\Alma\Users\Fee;
9
use Scriptotek\Alma\Users\Fees;
10
use Scriptotek\Alma\Users\User;
11
use spec\Scriptotek\Alma\SpecHelper;
12
13
class FeesSpec extends ObjectBehavior
14
{
15
    public function let(AlmaClient $client, User $user)
16
    {
17
        $user->id = '123435';
18
        $this->beConstructedWith($client, $user);
19
    }
20
21
    function it_is_initializable()
22
    {
23
        $this->shouldHaveType(Fees::class);
24
    }
25
26
    public function it_yields_fees(AlmaClient $client, UriInterface $url)
27
    {
28
        $client->buildUrl('/users/123435/fees', [])
29
            ->shouldBeCalled()
30
            ->willReturn($url);
31
32
        $client->getJSON($url)
33
            ->shouldBeCalled()
34
            ->willReturn(SpecHelper::getDummyData('fees_response.json'));
35
36
        $this->total_sum->shouldBe(750);
0 ignored issues
show
Documentation introduced by
The property total_sum does not exist on object<spec\Scriptotek\Alma\Users\FeesSpec>. 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...
37
38
        $this->rewind();
39
        $this->valid()->shouldBe(true);
40
        $this->current()->shouldBeAnInstanceOf(Fee::class);
41
42
        $this->shouldHaveCount(1);
43
    }
44
45
    public function it_can_be_empty(AlmaClient $client, UriInterface $url)
46
    {
47
        $client->buildUrl('/users/123435/fees', [])
48
            ->shouldBeCalled()
49
            ->willReturn($url);
50
51
        $client->getJSON($url)
52
            ->shouldBeCalled()
53
            ->willReturn(SpecHelper::getDummyData('zero_fees_response.json'));
54
55
        $this->rewind();
56
        $this->valid()->shouldBe(false);
57
58
        $this->shouldHaveCount(0);
59
    }
60
61
}
62