Skip to content

Commit

Permalink
[10.x] Test Improvements
Browse files Browse the repository at this point in the history
Verify #49389

Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Dec 19, 2023
1 parent 78fa6f2 commit aeab316
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/Integration/Database/Queue/QueueTransactionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Illuminate\Tests\Integration\Database\Queue;

use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\DB;
use Illuminate\Tests\Integration\Database\DatabaseTestCase;
use Orchestra\Testbench\Attributes\WithMigration;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Symfony\Component\Process\Exception\ProcessSignaledException;
use Throwable;

use function Orchestra\Testbench\remote;

#[RequiresPhpExtension('pcntl')]
#[WithMigration('laravel', 'queue')]
class QueueTransactionTest extends DatabaseTestCase
{
use DatabaseMigrations;

protected function defineEnvironment($app)
{
parent::defineEnvironment($app);

$config = $app['config'];

if ($config->get('database.default') === 'testing') {
$this->markTestSkipped('Test does not support using :memory: database connection');
}

$config->set(['queue.default' => 'database']);
}

public function testItCanHandleTimeoutJob()
{
dispatch(new Fixtures\TimeOutJobWithTransaction);

$this->assertSame(1, DB::table('jobs')->count());
$this->assertSame(0, DB::table('failed_jobs')->count());

try {
remote('queue:work --stop-when-empty', [
'DB_CONNECTION' => config('database.default'),
'QUEUE_CONNECTION' => config('queue.default'),
])->run();
} catch (Throwable $e) {
$this->assertInstanceOf(ProcessSignaledException::class, $e);
$this->assertSame('The process has been signaled with signal "9".', $e->getMessage());
}

$this->assertSame(0, DB::table('jobs')->count());
$this->assertSame(1, DB::table('failed_jobs')->count());
}
}

0 comments on commit aeab316

Please sign in to comment.