Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Dec 12, 2023
1 parent 8f7050c commit a898cec
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
17 changes: 17 additions & 0 deletions tests/Integration/Queue/QueueTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,21 @@ protected function defineEnvironment($app)
{
$this->driver = $app['config']->get('queue.default');
}

protected function runQueueWorkCommand(int $times = 1): void
{
if ($this->driver !== 'sync' && $times > 0) {
$count = 0;

do {
$this->artisan('queue:work', [
'connection' => 'database',
'--once' => true,
'--memory' => 1024,
])->assertSuccessful();

$count++;
} while ($count < $times);
}
}
}
33 changes: 20 additions & 13 deletions tests/Integration/Queue/WorkCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,34 @@ class WorkCommandTest extends QueueTestCase
{
use DatabaseMigrations;

protected function tearDown(): void
protected function setUp(): void
{
FirstJob::$ran = false;
SecondJob::$ran = false;
ThirdJob::$ran = false;
$this->beforeApplicationDestroyed(function () {
FirstJob::$ran = false;
SecondJob::$ran = false;
ThirdJob::$ran = false;
});

parent::tearDown();
parent::setUp();
}

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

if ($this->driver === 'sync') {
$this->markTestSkipped('Unable to test `queue:work` on `sync` driver');
}
}

public function testRunningOneJob()
{
Queue::connection('database')->push(new FirstJob);
Queue::connection('database')->push(new SecondJob);
Queue::push(new FirstJob);
Queue::push(new SecondJob);

$this->artisan('queue:work', [
'connection' => 'database',
'--once' => true,
'--memory' => 1024,
])->assertExitCode(0);
$this->runQueueWorkCommand();

$this->assertSame(1, Queue::connection('database')->size());
$this->assertSame(1, Queue::size());
$this->assertTrue(FirstJob::$ran);
$this->assertFalse(SecondJob::$ran);
}
Expand Down

0 comments on commit a898cec

Please sign in to comment.