Skip to content

Commit 1dfaf07

Browse files
committed
Fix JobInstances (#19)
Make `JobInstances` refer to the `Job` object rather than the `job_id` string. This aligns with the approach taken in the other classes.
1 parent 8c7508a commit 1dfaf07

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

spec/Conf/JobInstanceSpec.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class JobInstanceSpec extends ObjectBehavior
1111
{
1212
public function let(AlmaClient $client, Job $job)
1313
{
14+
$job->job_id = '123';
1415
$instanceId = '1108569450000121';
1516
$this->beConstructedWith($client, $job, $instanceId);
1617
}

spec/Conf/JobInstancesSpec.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ public function it_provides_a_lazy_interface_to_jobinstance_objects(AlmaClient $
2222

2323
$jobId = '1108569450000121';
2424
$instanceId = '1108569450000121';
25-
$jobInstance = $this->get($jobId, $instanceId);
25+
$jobInstance = $this->get($instanceId);
2626
$jobInstance->shouldBeAnInstanceOf(JobInstance::class);
2727
}
2828

29-
public function it_provides_jobintances(AlmaClient $client)
29+
public function it_provides_job_instances(AlmaClient $client)
3030
{
3131
$jobId = '1108569450000121';
32-
$client->getJSON("/conf/jobs/{$jobId}/instances")
32+
$client->getJSON("/conf/jobs/{$jobId}/instances?offset=0&limit=10")
3333
->shouldBeCalled()
3434
->willReturn(SpecHelper::getDummyData('jobinstances_response.json'));
3535

src/Conf/Job.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ class Job extends LazyResource
2323
* @param Client $client
2424
* @param string $job_id
2525
*/
26-
public function __construct(Client $client, $job_id)
26+
public function __construct(Client $client, string $job_id)
2727
{
2828
parent::__construct($client);
2929
$this->job_id = $job_id;
30-
$this->instances = new JobInstances($client, $job_id);
30+
$this->instances = new JobInstances($client, $this);
3131
}
3232

3333
/**

src/Conf/JobInstance.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
*/
1111
class JobInstance extends LazyResource
1212
{
13-
/** @var string */
14-
public $job_id;
13+
/** @var Job */
14+
public $job;
1515

1616
/** @var string */
1717
public $job_instance_id;
@@ -20,12 +20,12 @@ class JobInstance extends LazyResource
2020
* JobInstance constructor.
2121
*
2222
* @param Client $client
23-
* @param string $job_id
23+
* @param Job $job
2424
* @param string $job_instance_id
2525
*/
26-
public function __construct(Client $client, $job_id, $job_instance_id)
26+
public function __construct(Client $client, Job $job, string $job_instance_id)
2727
{
28-
$this->job_id = $job_id;
28+
$this->job = $job;
2929
$this->job_instance_id = $job_instance_id;
3030
parent::__construct($client);
3131
}
@@ -49,6 +49,6 @@ protected function isInitialized($data)
4949
*/
5050
protected function urlBase()
5151
{
52-
return "/conf/jobs/{$this->job_id}/instances/{$this->job_instance_id}";
52+
return "/conf/jobs/{$this->job->job_id}/instances/{$this->job_instance_id}";
5353
}
5454
}

src/Conf/JobInstances.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,31 @@ class JobInstances extends SimplePaginatedList implements \ArrayAccess, \Countab
1616
use ReadOnlyArrayAccess;
1717
use IterableCollection;
1818

19-
/** @var string */
20-
public $job_id;
19+
/** @var Job */
20+
public $job;
2121

2222
/**
2323
* Job Instances constructor.
2424
*
2525
* @param Client $client
26-
* @param string $job_id
26+
* @param Job $job
2727
*/
28-
public function __construct(Client $client, $job_id)
28+
public function __construct(Client $client, Job $job)
2929
{
30-
$this->job_id = $job_id;
3130
parent::__construct($client, 'job_instance');
31+
$this->job = $job;
3232
}
3333

3434
/**
35-
* Get a single Job Instance by its job_id and instance_id.
35+
* Get a single Job Instance by its instance_id.
3636
*
37-
* @param string $job_id
3837
* @param string $instance_id
3938
*
4039
* @return JobInstance
4140
*/
42-
public function get($job_id, $instance_id)
41+
public function get(string $instance_id)
4342
{
44-
return JobInstance::make($this->client, $job_id, $instance_id);
43+
return JobInstance::make($this->client, $this->job, $instance_id);
4544
}
4645

4746
/**
@@ -53,7 +52,7 @@ public function get($job_id, $instance_id)
5352
*/
5453
protected function convertToResource($data)
5554
{
56-
return JobInstance::make($this->client, $data->job_info->id, $data->id)
55+
return JobInstance::make($this->client, $this->job, $data->id)
5756
->init($data);
5857
}
5958

@@ -64,6 +63,6 @@ protected function convertToResource($data)
6463
*/
6564
protected function urlBase()
6665
{
67-
return "/conf/jobs/{$this->job_id}/instances";
66+
return "/conf/jobs/{$this->job->job_id}/instances";
6867
}
6968
}

0 commit comments

Comments
 (0)