Skip to content

Commit

Permalink
Fixed wrong commit
Browse files Browse the repository at this point in the history
  • Loading branch information
waltertamboer committed Jan 29, 2020
1 parent 03776d2 commit ecbd996
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Storage/InMemory/DelayedJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,25 @@ public function __construct(StoredJobInterface $storedJob, ?int $delay, ?int $pr
$this->priority = $priority;
}

/**
* @codeCoverageIgnore
*/
public function getStoredJob(): StoredJobInterface
{
return $this->storedJob;
}

/**
* @codeCoverageIgnore
*/
public function getDelay(): ?int
{
return $this->delay;
}

/**
* @codeCoverageIgnore
*/
public function getPriority(): ?int
{
return $this->priority;
Expand All @@ -52,6 +61,6 @@ public function isReady(): bool
$nextTime += $this->delay;
}

return $nextTime < time();
return $nextTime <= time();
}
}
50 changes: 50 additions & 0 deletions tests/Storage/InMemory/DelayedJobTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace ChessZebra\JobSystem\Storage\InMemory;

use ChessZebra\JobSystem\Job\Job;
use PHPUnit\Framework\TestCase;

final class DelayedJobTest extends TestCase
{
/**
* Tests if the isReady method returns true when the job is actually ready.
*
* @covers \ChessZebra\JobSystem\Storage\InMemory\DelayedJob::__construct
* @covers \ChessZebra\JobSystem\Storage\InMemory\DelayedJob::isReady
*/
public function testReadyToRumble(): void
{
// Arrange
$job = new Job('', []);
$storedJob = new StoredJob($job, 1);
$delayedJob = new DelayedJob($storedJob, null, null);

// Act
$result = $delayedJob->isReady();

// Assert
static::assertTrue($result);
}
/**
* Tests if the isReady method returns falsse when the job is no ready yet.
*
* @covers \ChessZebra\JobSystem\Storage\InMemory\DelayedJob::__construct
* @covers \ChessZebra\JobSystem\Storage\InMemory\DelayedJob::isReady
*/
public function testWaitForReady(): void
{
// Arrange
$job = new Job('', []);
$storedJob = new StoredJob($job, 1);
$delayedJob = new DelayedJob($storedJob, 1, null);

// Act
$result = $delayedJob->isReady();

// Assert
static::assertFalse($result);
}
}

0 comments on commit ecbd996

Please sign in to comment.