Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

Commit

Permalink
Fix typehint of JobBuriedEvent to accept \Throwable (#20)
Browse files Browse the repository at this point in the history
Otherwise this will result in an unrelated TypeError exception.
  • Loading branch information
vstm authored and pkruithof committed Nov 13, 2019
1 parent 753d5fc commit 236139e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/TreeHouse/WorkerBundle/Event/JobBuriedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ class JobBuriedEvent extends Event
/**
* Exception that caused the job to be buried
*
* @var \Exception
* @var \Throwable
*/
protected $exception;

/**
* JobBuriedEvent constructor.
*
* @param Job $job
* @param \Exception $exception
* @param \Throwable $exception
* @param int $attempts
*/
public function __construct(Job $job, \Exception $exception, $attempts)
public function __construct(Job $job, \Throwable $exception, $attempts)
{
$this->job = $job;
$this->exception = $exception;
Expand All @@ -49,7 +49,7 @@ public function getJob()
}

/**
* @return \Exception
* @return \Throwable
*/
public function getException()
{
Expand Down
35 changes: 35 additions & 0 deletions tests/TreeHouse/WorkerBundle/QueueManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\OptionsResolver\OptionsResolver;
use TreeHouse\WorkerBundle\Event\ExecutionEvent;
use TreeHouse\WorkerBundle\Event\JobBuriedEvent;
use TreeHouse\WorkerBundle\Event\JobEvent;
use TreeHouse\WorkerBundle\Exception\AbortException;
use TreeHouse\WorkerBundle\Exception\RescheduleException;
Expand Down Expand Up @@ -884,6 +885,40 @@ public function testFatalErrorCatch()

$this->assertEquals(false, $this->manager->executeJob($job));
}

public function testFatalErrorCatchWithNoRetries()
{
$executor = new FatalErrorExecutor();
$this->manager->addExecutor($executor);

$data = [];
$job = new Job(1234, json_encode($data));
$stats = [
'tube' => 'fatal.error',
'releases' => 2,
'pri' => PheanstalkInterface::DEFAULT_PRIORITY,
];

$this->pheanstalk
->expects($this->once())
->method('statsJob')
->with($job)
->will($this->returnValue($stats))
;

$this->pheanstalk
->expects($this->once())
->method('bury')
->with($job)
;

$this->assertEquals(false, $this->manager->executeJob($job));

$events = $this->dispatcher->getDispatchedEvents();
static::assertArrayHasKey(WorkerEvents::JOB_BURIED_EVENT, $events);
static::assertCount(1, $events[WorkerEvents::JOB_BURIED_EVENT]);
static::assertInstanceOf(JobBuriedEvent::class, $events[WorkerEvents::JOB_BURIED_EVENT][0]);
}
}

class Executor implements ExecutorInterface
Expand Down

0 comments on commit 236139e

Please sign in to comment.