Skip to content

Commit 7032b8f

Browse files
committed
#23: Add codetable tests and docs
1 parent 4f3bb4c commit 7032b8f

File tree

4 files changed

+212
-0
lines changed

4 files changed

+212
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ If the package doesn't fit your needs, you might take a look at the alternative
4343
* [Listing jobs](#listing-jobs)
4444
* [Retrieving information about a specific job](#retrieving-information-about-a-specific-job)
4545
* [Submitting a job](#submitting-a-job)
46+
* [Code Tables](#code-tables)
47+
* [Getting a single code table](#getting-a-codetable)
4648
* [Automatic retries on errors](#automatic-retries-on-errors)
4749
* [Laravel integration](#laravel-integration)
4850
* [Customizing the HTTP client stack](#customizing-the-http-client-stack)
@@ -530,6 +532,20 @@ $job = $alma->jobs['M43'];
530532
$instance = $alma->jobs['M43']->submit();
531533
```
532534

535+
## Code Tables
536+
537+
### Getting a Code Table
538+
539+
To fetch a code table
540+
541+
```php
542+
$ct = $alma->codetables->get('systemJobStatus');
543+
echo "Rows for ".$ct->sub_system->value."'s ".$ct->name."\n";
544+
foreach ($ct->row as $row) {
545+
echo "code: ".$row->code.", description: ".$row->description."\n";
546+
}
547+
```
548+
533549
## Automatic retries on errors
534550

535551
If the client receives a 429 (rate limiting) response from Alma, it will sleep for a short time (0.5 seconds by default)

spec/Conf/CodeTableSpec.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace spec\Scriptotek\Alma\CodeTable;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Prophecy\Argument;
7+
use Scriptotek\Alma\Conf\CodeTable;
8+
use Scriptotek\Alma\Conf\CodeTables;
9+
use Scriptotek\Alma\Client as AlmaClient;
10+
use Scriptotek\Alma\Exception\ResourceNotFound;
11+
use spec\Scriptotek\Alma\SpecHelper;
12+
13+
class CodeTableSpec extends ObjectBehavior
14+
{
15+
public function let(AlmaClient $client)
16+
{
17+
$this->beConstructedWith($client, 'systemJobStatus');
18+
}
19+
20+
protected function expectRequest($client)
21+
{
22+
$client->getXML('/conf/code-table/systemJobStatus')
23+
->shouldBeCalled()
24+
->willReturn(SpecHelper::getDummyData('codetable_response.json'));
25+
}
26+
27+
public function it_is_lazy(AlmaClient $client)
28+
{
29+
SpecHelper::expectNoRequests($client);
30+
$this->shouldHaveType(CodeTable::class);
31+
}
32+
33+
public function it_fetches_record_data_when_needed(AlmaClient $client)
34+
{
35+
$this->expectRequest($client);
36+
37+
$this->name->('systemJobStatus');
38+
$this->subSystem->value->shouldBe('INFRA');
39+
}
40+
41+
public function it_can_exist(AlmaClient $client)
42+
{
43+
$this->expectRequest($client);
44+
45+
$this->exists()->shouldBe(true);
46+
}
47+
}

spec/Conf/CodeTablesSpec.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace spec\Scriptotek\Alma\CodeTables;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Prophecy\Argument;
7+
use Scriptotek\Alma\Conf\CodeTable;
8+
use Scriptotek\Alma\Client as AlmaClient;
9+
use spec\Scriptotek\Alma\SpecHelper;
10+
11+
class CodeTablesSpec extends ObjectBehavior
12+
{
13+
public function let(AlmaClient $client)
14+
{
15+
$this->beConstructedWith($client);
16+
}
17+
18+
public function it_provides_a_lazy_interface_to_codetable_objects(AlmaClient $client)
19+
{
20+
SpecHelper::expectNoRequests($client);
21+
22+
$ctid = 'myCodeTable'; // str_random();
23+
$bib = $this->get($ctid);
24+
25+
$bib->shouldHaveType(CodeTable::class);
26+
$bib->code->shouldBe($ctid);
27+
}
28+
29+
public function it_provides_a_lazy_array_interface_to_codetable_objects(AlmaClient $client)
30+
{
31+
SpecHelper::expectNoRequests($client);
32+
33+
$ctid = 'myCodeTable'; // str_random();
34+
$ct = $this[$ctid];
35+
36+
$ct->shouldHaveType(CodeTable::class);
37+
$ct->code->shouldBe($ctid);
38+
}
39+
40+
}

spec/data/codetable_response.json

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{
2+
"name": "systemJobStatus",
3+
"description": "System Job Status",
4+
"sub_system": {
5+
"value": "INFRA",
6+
"desc": "Infra"
7+
},
8+
"patron_facing": true,
9+
"language": {
10+
"value": "en",
11+
"desc": "English"
12+
},
13+
"scope": {
14+
"institution_id": {
15+
"value": "01MY_INST",
16+
"desc": "My Institution"
17+
},
18+
"library_id": {
19+
"value": "",
20+
"desc": ""
21+
}
22+
},
23+
"row": [
24+
{
25+
"code": "QUEUED",
26+
"description": "Queued",
27+
"default": false,
28+
"enabled": true
29+
},
30+
{
31+
"code": "PENDING",
32+
"description": "Pending",
33+
"default": false,
34+
"enabled": true
35+
},
36+
{
37+
"code": "INITIALIZING",
38+
"description": "Initializing",
39+
"default": false,
40+
"enabled": true
41+
},
42+
{
43+
"code": "RUNNING",
44+
"description": "Running",
45+
"default": false,
46+
"enabled": true
47+
},
48+
{
49+
"code": "MANUAL_HANDLING_REQUIRED",
50+
"description": "Manual Handling Required",
51+
"default": false,
52+
"enabled": true
53+
},
54+
{
55+
"code": "FINALIZING",
56+
"description": "Finalizing",
57+
"default": false,
58+
"enabled": true
59+
},
60+
{
61+
"code": "COMPLETED_SUCCESS",
62+
"description": "Completed Successfully",
63+
"default": false,
64+
"enabled": true
65+
},
66+
{
67+
"code": "COMPLETED_NO_BULKS",
68+
"description": "Completed with no Bulks",
69+
"default": false,
70+
"enabled": true
71+
},
72+
{
73+
"code": "COMPLETED_FAILED",
74+
"description": "Completed with Errors",
75+
"default": false,
76+
"enabled": true
77+
},
78+
{
79+
"code": "FAILED",
80+
"description": "Failed",
81+
"default": false,
82+
"enabled": true
83+
},
84+
{
85+
"code": "COMPLETED_WARNING",
86+
"description": "Completed with Warnings",
87+
"default": false,
88+
"enabled": true
89+
},
90+
{
91+
"code": "USER_ABORTED",
92+
"description": "Aborted by User",
93+
"default": false,
94+
"enabled": true
95+
},
96+
{
97+
"code": "SYSTEM_ABORTED",
98+
"description": "Aborted by System",
99+
"default": false,
100+
"enabled": true
101+
},
102+
{
103+
"code": "SKIPPED",
104+
"description": "Skipped",
105+
"default": false,
106+
"enabled": true
107+
}
108+
]
109+
}

0 commit comments

Comments
 (0)