|
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 Scriptotek\Alma\Exception\ResourceNotFound; |
|
10
|
|
|
use spec\Scriptotek\Alma\SpecHelper; |
|
11
|
|
|
|
|
12
|
|
|
class ReportSpec extends ObjectBehavior |
|
13
|
|
|
{ |
|
14
|
|
|
public function let(Client $almaClient) |
|
15
|
|
|
{ |
|
16
|
|
|
$this->beConstructedWith($almaClient, '/test/path'); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function it_is_initializable() |
|
20
|
|
|
{ |
|
21
|
|
|
$this->shouldHaveType(Report::class); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function it_supports_setting_headers(Client $almaClient) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->beConstructedWith($almaClient, '/test/path', ['a', 'b']); |
|
27
|
|
|
|
|
28
|
|
|
$this->headers->shouldBe(['a', 'b']); |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function it_supports_setting_filter(Client $almaClient) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->beConstructedWith($almaClient, '/test/path', ['a', 'b'], 'la la la'); |
|
34
|
|
|
|
|
35
|
|
|
$this->filter->shouldBe('la la la'); |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function it_parses_column_headers(Client $almaClient) |
|
39
|
|
|
{ |
|
40
|
|
|
$almaClient->getXML('/analytics/reports?path=%2Ftest%2Fpath&limit=1000') |
|
41
|
|
|
->shouldBeCalledTimes(1) |
|
42
|
|
|
->willReturn(SpecHelper::getDummyData('analytics_response.xml')); |
|
43
|
|
|
|
|
44
|
|
|
// $this->getHeaders()->shouldHaveCount(11); |
|
45
|
|
|
$this->getHeaders()->shouldContain('Event Start Date and Time'); |
|
46
|
|
|
|
|
47
|
|
|
$firstRow = $this->current(); |
|
48
|
|
|
$firstRow->shouldHaveType(Row::class); |
|
49
|
|
|
$firstRow['Event Start Date and Time']->shouldBe('2017-08-29T15:43:53'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function it_supports_resumption(Client $almaClient) |
|
53
|
|
|
{ |
|
54
|
|
|
$path = '/test/path'; |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
// To speed up tests |
|
57
|
|
|
Report::$retryDelayTime = 0; |
|
58
|
|
|
|
|
59
|
|
|
$almaClient->getXML('/analytics/reports?path=%2Ftest%2Fpath&limit=1000') |
|
60
|
|
|
->shouldBeCalledTimes(1) |
|
61
|
|
|
->willReturn(SpecHelper::getDummyData('analytics_response_part1.xml')); |
|
62
|
|
|
|
|
63
|
|
|
$almaClient->getXML('/analytics/reports?limit=1000&token=9672D715A8E2EAAA6F30DD22FC52BE4CCAE35E29D921E0AC8BE8C6734C9E1571B4E48EEFCA4046EFF8CD7D1662C2D0A7677D3AD05EDC3CA7F06182E34E9D7A2F') |
|
64
|
|
|
->shouldBeCalledTimes(3) |
|
65
|
|
|
->willReturn( |
|
66
|
|
|
|
|
67
|
|
|
// If Analytics is having a bad day, we might get a "still loading" response |
|
68
|
|
|
// See: https://bitbucket.org/uwlib/uwlib-alma-analytic-tools/wiki/Understanding_Analytic_GET_Requests#!analytic-still-loading |
|
69
|
|
|
SpecHelper::getDummyData('analytics_still_loading_response.xml'), |
|
70
|
|
|
SpecHelper::getDummyData('analytics_response_part2.xml'), |
|
71
|
|
|
SpecHelper::getDummyData('analytics_response_part3.xml') |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
$this->count()->shouldBe(150 + 150 + 88); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function it_might_not_exist(Client $almaClient) |
|
78
|
|
|
{ |
|
79
|
|
|
$almaClient->getXML('/analytics/reports?path=%2Ftest%2Fpath&limit=1000') |
|
80
|
|
|
->shouldBeCalledTimes(1) |
|
81
|
|
|
->willThrow(new ResourceNotFound('Path not found (/test/path)')); |
|
82
|
|
|
|
|
83
|
|
|
$this->exists()->shouldReturn(false); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
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@propertyannotation 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.