1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Scriptotek\Alma\Analytics; |
4
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
6
|
|
|
use Psr\Http\Message\UriInterface; |
7
|
|
|
use Scriptotek\Alma\Analytics\Report; |
8
|
|
|
use Scriptotek\Alma\Analytics\Row; |
9
|
|
|
use Scriptotek\Alma\Analytics\Rows; |
10
|
|
|
use Scriptotek\Alma\Client; |
11
|
|
|
use Scriptotek\Alma\Exception\ResourceNotFound; |
12
|
|
|
use spec\Scriptotek\Alma\SpecHelper; |
13
|
|
|
|
14
|
|
|
class ReportSpec extends ObjectBehavior |
15
|
|
|
{ |
16
|
|
|
public function let(Client $almaClient) |
17
|
|
|
{ |
18
|
|
|
$this->beConstructedWith($almaClient, '/test/path'); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function it_is_initializable() |
22
|
|
|
{ |
23
|
|
|
$this->shouldHaveType(Report::class); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function it_supports_setting_headers(Client $almaClient) |
27
|
|
|
{ |
28
|
|
|
$this->beConstructedWith($almaClient, '/test/path', ['a', 'b']); |
29
|
|
|
|
30
|
|
|
$this->headers->shouldBe(['a', 'b']); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function it_supports_setting_filter(Client $almaClient) |
34
|
|
|
{ |
35
|
|
|
$this->beConstructedWith($almaClient, '/test/path', ['a', 'b'], 'la la la'); |
36
|
|
|
|
37
|
|
|
$this->filter->shouldBe('la la la'); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
View Code Duplication |
public function it_can_be_counted(Client $almaClient, UriInterface $url) |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
$almaClient->buildUrl('/analytics/reports', [ |
43
|
|
|
'path' => '/test/path', |
44
|
|
|
'limit' => 1000, |
45
|
|
|
'token' => null, |
46
|
|
|
'filter' => null, |
47
|
|
|
])->shouldBeCalled()->willReturn($url); |
48
|
|
|
|
49
|
|
|
$almaClient->getXML($url) |
50
|
|
|
->shouldBeCalledTimes(1) |
51
|
|
|
->willReturn(SpecHelper::getDummyData('analytics_response.xml')); |
52
|
|
|
|
53
|
|
|
$this->exists()->shouldReturn(true); |
54
|
|
|
$this->shouldHaveCount(25); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function it_parses_column_headers(Client $almaClient, UriInterface $url) |
58
|
|
|
{ |
59
|
|
|
$almaClient->buildUrl('/analytics/reports', [ |
60
|
|
|
'path' => '/test/path', |
61
|
|
|
'limit' => 1000, |
62
|
|
|
'token' => null, |
63
|
|
|
'filter' => null, |
64
|
|
|
])->shouldBeCalled()->willReturn($url); |
65
|
|
|
|
66
|
|
|
$almaClient->getXML($url) |
67
|
|
|
->shouldBeCalledTimes(1) |
68
|
|
|
->willReturn(SpecHelper::getDummyData('analytics_response.xml')); |
69
|
|
|
|
70
|
|
|
$this->getHeaders()->shouldHaveCount(11); |
71
|
|
|
$this->getHeaders()->shouldContain('Event Start Date and Time'); |
72
|
|
|
|
73
|
|
|
$this->rewind(); |
74
|
|
|
$this->valid(); |
75
|
|
|
$firstRow = $this->current(); |
76
|
|
|
$firstRow->shouldHaveType(Row::class); |
77
|
|
|
$firstRow['Event Start Date and Time']->shouldBe('2017-08-29T15:43:53'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function it_supports_resumption(Client $almaClient, UriInterface $url1, UriInterface $url2) |
81
|
|
|
{ |
82
|
|
|
$path = '/test/path'; |
83
|
|
|
|
84
|
|
|
// To speed up tests |
85
|
|
|
Report::$retryDelayTime = 0; |
86
|
|
|
|
87
|
|
|
$almaClient->buildUrl('/analytics/reports', [ |
88
|
|
|
'path' => $path, |
89
|
|
|
'limit' => 1000, |
90
|
|
|
'token' => null, |
91
|
|
|
'filter' => null, |
92
|
|
|
])->shouldBeCalled()->willReturn($url1); |
93
|
|
|
|
94
|
|
|
$almaClient->getXML($url1) |
95
|
|
|
->shouldBeCalledTimes(1) |
96
|
|
|
->willReturn(SpecHelper::getDummyData('analytics_response_part1.xml')); |
97
|
|
|
|
98
|
|
|
$almaClient->buildUrl('/analytics/reports', [ |
99
|
|
|
'path' => null, |
100
|
|
|
'limit' => 1000, |
101
|
|
|
'token' => '9672D715A8E2EAAA6F30DD22FC52BE4CCAE35E29D921E0AC8BE8C6734C9E1571B4E48EEFCA4046EFF8CD7D1662C2D0A7677D3AD05EDC3CA7F06182E34E9D7A2F', |
102
|
|
|
'filter' => null, |
103
|
|
|
])->shouldBeCalled()->willReturn($url2); |
104
|
|
|
|
105
|
|
|
$almaClient->getXML($url2) |
106
|
|
|
->shouldBeCalledTimes(3) |
107
|
|
|
->willReturn( |
108
|
|
|
|
109
|
|
|
// If Analytics is having a bad day, we might get a "still loading" response |
110
|
|
|
// See: https://bitbucket.org/uwlib/uwlib-alma-analytic-tools/wiki/Understanding_Analytic_GET_Requests#!analytic-still-loading |
111
|
|
|
SpecHelper::getDummyData('analytics_still_loading_response.xml'), |
112
|
|
|
SpecHelper::getDummyData('analytics_response_part2.xml'), |
113
|
|
|
SpecHelper::getDummyData('analytics_response_part3.xml') |
114
|
|
|
); |
115
|
|
|
|
116
|
|
|
$this->shouldHaveCount(150 + 150 + 88); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
View Code Duplication |
public function it_might_not_exist(Client $almaClient, UriInterface $url) |
|
|
|
|
120
|
|
|
{ |
121
|
|
|
$almaClient->buildUrl('/analytics/reports', [ |
122
|
|
|
'path' => '/test/path', |
123
|
|
|
'limit' => 1000, |
124
|
|
|
'token' => null, |
125
|
|
|
'filter' => null, |
126
|
|
|
])->shouldBeCalled()->willReturn($url); |
127
|
|
|
|
128
|
|
|
$almaClient->getXML($url) |
129
|
|
|
->shouldBeCalledTimes(1) |
130
|
|
|
->willThrow(new ResourceNotFound('Path not found (/test/path)')); |
131
|
|
|
|
132
|
|
|
$this->exists()->shouldReturn(false); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
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.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.