public function ProcessorTest::testProcessor in Advanced Queue 8
@covers ::processQueue @covers ::processJob
File
- tests/
src/ Kernel/ ProcessorTest.php, line 64
Class
- ProcessorTest
- @coversDefaultClass \Drupal\advancedqueue\Processor @group advancedqueue
Namespace
Drupal\Tests\advancedqueue\KernelCode
public function testProcessor() {
$first_job = Job::create('simple', [
'test' => '1',
]);
$second_job = Job::create('flexible', [
'expected_state' => Job::STATE_SUCCESS,
'expected_message' => 'Done!',
]);
$third_job = Job::create('flexible', [
'expected_exception' => 'DB down!',
]);
$fourth_job = Job::create('flexible', [
'expected_state' => Job::STATE_FAILURE,
'expected_message' => 'Failed!',
]);
$this->queue
->enqueueJob($first_job);
$this->queue
->enqueueJob($second_job);
$this->queue
->enqueueJob($third_job);
$this->queue
->enqueueJob($fourth_job);
$num_processed = $this->processor
->processQueue($this->queue);
$this
->assertEquals(4, $num_processed);
/** @var \Drupal\Core\Database\Connection $connection */
$connection = $this->container
->get('database');
$raw_jobs = $connection
->query('SELECT job_id, state, message FROM {advancedqueue}')
->fetchAllAssoc('job_id', \PDO::FETCH_ASSOC);
$this
->assertEquals([
'job_id' => '1',
'state' => Job::STATE_SUCCESS,
'message' => NULL,
], $raw_jobs[1]);
$this
->assertEquals([
'job_id' => '2',
'state' => Job::STATE_SUCCESS,
'message' => 'Done!',
], $raw_jobs[2]);
$this
->assertEquals([
'job_id' => '3',
'state' => Job::STATE_FAILURE,
'message' => 'DB down!',
], $raw_jobs[3]);
$this
->assertEquals([
'job_id' => '4',
'state' => Job::STATE_FAILURE,
'message' => 'Failed!',
], $raw_jobs[4]);
}