Completed
Push — master ( 46ae11...0600cb )
by Dan Michael O.
02:25
created

ReportSpec::it_supports_resumption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 1
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
1
<?php
2
3
namespace spec\Scriptotek\Alma\Analytics;
4
5
use PhpSpec\ObjectBehavior;
6
use Scriptotek\Alma\Analytics\Report;
7
use Scriptotek\Alma\Analytics\Row;
8
use Scriptotek\Alma\Client;
9
use spec\Scriptotek\Alma\SpecHelper;
10
11
class ReportSpec extends ObjectBehavior
12
{
13
    public function let(Client $almaClient)
14
    {
15
        $path = 'xyz';
16
        $this->beConstructedWith($almaClient, $path);
17
        $almaClient->getXML('/analytics/reports', ['path' => $path, 'limit' => 1000, 'token' => null, 'filter' => null])
18
            ->willReturn(SpecHelper::getDummyData('analytics_response.xml'));
19
    }
20
21
    public function it_is_initializable()
22
    {
23
        $this->shouldHaveType(Report::class);
24
    }
25
26
    public function it_has_rows()
27
    {
28
        $this->rows->shouldImplement(\Generator::class);
0 ignored issues
show
Documentation introduced by
The property rows does not exist on object<spec\Scriptotek\Alma\Analytics\ReportSpec>. 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...
29
        $this->rows->current()->shouldBeAnInstanceOf(Row::class);
0 ignored issues
show
Documentation introduced by
The property rows does not exist on object<spec\Scriptotek\Alma\Analytics\ReportSpec>. 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...
30
        $this->getRows()->shouldHaveCount(14);
31
    }
32
33
    public function it_supports_setting_headers(Client $almaClient)
34
    {
35
        $this->beConstructedWith($almaClient, 'xyz', ['a', 'b']);
36
37
        $this->headers->shouldBe(['a', 'b']);
0 ignored issues
show
Documentation introduced by
The property headers does not exist on object<spec\Scriptotek\Alma\Analytics\ReportSpec>. 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...
38
    }
39
40
    public function it_supports_setting_filter(Client $almaClient)
41
    {
42
        $this->beConstructedWith($almaClient, 'xyz', ['a', 'b'], 'la la la');
43
44
        $this->filter->shouldBe('la la la');
0 ignored issues
show
Documentation introduced by
The property filter does not exist on object<spec\Scriptotek\Alma\Analytics\ReportSpec>. 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...
45
    }
46
47
    public function it_supports_resumption(Client $almaClient)
48
    {
49
        $path = 'xyz';
50
51
        $almaClient->getXML('/analytics/reports', ['path' => $path, 'limit' => 1000, 'token' => null, 'filter' => null])
52
            ->shouldBeCalledTimes(1)
53
            ->willReturn(SpecHelper::getDummyData('analytics_response_part1.xml'));
54
55
        $almaClient->getXML('/analytics/reports', ['path' => null, 'limit' => 1000, 'token' => '9672D715A8E2EAAA6F30DD22FC52BE4CCAE35E29D921E0AC8BE8C6734C9E1571B4E48EEFCA4046EFF8CD7D1662C2D0A7677D3AD05EDC3CA7F06182E34E9D7A2F', 'filter' => null])
56
            ->shouldBeCalledTimes(3)
57
            ->willReturn(
58
59
                # If Analytics has a bad day, we might get a "still loading" response
60
                # See: https://bitbucket.org/uwlib/uwlib-alma-analytic-tools/wiki/Understanding_Analytic_GET_Requests#!analytic-still-loading
61
                SpecHelper::getDummyData('analytics_still_loading_response.xml'),
62
63
                SpecHelper::getDummyData('analytics_response_part2.xml'),
64
                SpecHelper::getDummyData('analytics_response_part3.xml')
65
            );
66
67
        $this->getRows()->shouldHaveCount(150 + 150 + 88);
68
69
    }
70
}
71