Skip to content

Commit

Permalink
Fixes peppeocchi#94 by checking for an array parameter when creating …
Browse files Browse the repository at this point in the history
…an ID for the job.

Fixed a code formatting issue
  • Loading branch information
Philip Norton committed Nov 8, 2019
1 parent 44325d9 commit 7651656
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/GO/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ public function __construct($command, $args = [], $id = null)
} else {
if (is_string($command)) {
$this->id = md5($command);
} elseif (is_array($command)) {
$this->id = md5(serialize($command));
} else {
/* @var object $command */
$this->id = spl_object_hash($command);
Expand Down
9 changes: 9 additions & 0 deletions tests/GO/JobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public function testShouldAlwaysGenerateAnId()
return true;
});
$this->assertTrue(is_string($job2->getId()));

$job3 = new Job(['MyClass', 'myMethod']);
$this->assertTrue(is_string($job3->getId()));
}

public function testShouldGenerateIdFromSignature()
Expand All @@ -23,6 +26,9 @@ public function testShouldGenerateIdFromSignature()

$job2 = new Job('whoami');
$this->assertNotEquals($job1->getId(), $job2->getId());

$job3 = new Job(['MyClass', 'myMethod']);
$this->assertNotEquals($job1->getId(), $job3->getId());
}

public function testShouldAllowCustomId()
Expand All @@ -31,6 +37,9 @@ public function testShouldAllowCustomId()

$this->assertNotEquals(md5('ls'), $job->getId());
$this->assertEquals('aCustomId', $job->getId());

$job2 = new Job(['MyClass', 'myMethod'], null, 'myCustomId');
$this->assertEquals('myCustomId', $job2->getId());
}

public function testShouldKnowIfDue()
Expand Down

0 comments on commit 7651656

Please sign in to comment.