Skip to content

Commit 1e5a44d

Browse files
committed
Fix Jobs test (#19)
Fix test and add an extra check for blank responses, to make it easier to spot problems like this in the future.
1 parent 9a48c0b commit 1e5a44d

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

spec/Conf/JobsSpec.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace spec\Scriptotek\Alma\Conf;
44

55
use PhpSpec\ObjectBehavior;
6+
use Prophecy\Argument;
67
use Scriptotek\Alma\Client as AlmaClient;
78
use Scriptotek\Alma\Conf\Job;
89
use spec\Scriptotek\Alma\SpecHelper;
@@ -12,8 +13,6 @@ class JobsSpec extends ObjectBehavior
1213
public function let(AlmaClient $client)
1314
{
1415
$this->beConstructedWith($client);
15-
$client->getJSON('/conf/jobs')
16-
->willReturn(SpecHelper::getDummyData('jobs_response.json'));
1716
}
1817

1918
public function it_provides_a_lazy_interface_to_job_objects(AlmaClient $client)
@@ -27,8 +26,12 @@ public function it_provides_a_lazy_interface_to_job_objects(AlmaClient $client)
2726
$job->job_id->shouldBe($job_id);
2827
}
2928

30-
public function it_provides_jobs()
29+
public function it_provides_jobs(AlmaClient $client)
3130
{
31+
$client->getJSON(Argument::containingString('/conf/jobs?'))
32+
->shouldBeCalled()
33+
->willReturn(SpecHelper::getDummyData('jobs_response.json'));
34+
3235
$this->all()->shouldBeArray();
3336
$this->all()[0]->shouldBeAnInstanceOf(Job::class);
3437
}

src/Model/SimplePaginatedList.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@ protected function fetchBatch()
2424
return;
2525
}
2626

27-
$response = $this->client->getJSON($this->url('', [
27+
$url = $this->url('', [
2828
'offset' => $this->offset,
2929
'limit' => $this->limit,
30-
]));
30+
]);
31+
32+
$response = $this->client->getJSON($url);
33+
34+
if (is_null($response)) {
35+
throw new \RuntimeException("Empty response from URL: $url");
36+
}
3137

3238
return $this->onData($response);
3339
}

0 commit comments

Comments
 (0)