Skip to content

Commit

Permalink
[slim-skeleton-11.x] Test Improvements (#48225)
Browse files Browse the repository at this point in the history
* Test Improvements

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

---------

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone authored Aug 29, 2023
1 parent 12a684a commit 05ae303
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
26 changes: 14 additions & 12 deletions tests/Integration/Queue/JobChainingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,25 @@ class JobChainingTest extends TestCase
{
public static $catchCallbackRan = false;

protected function getEnvironmentSetUp($app)
protected function setUp(): void
{
$app['config']->set('queue.connections.sync1', [
'driver' => 'sync',
]);
$this->beforeApplicationDestroyed(function () {
JobChainingTestFirstJob::$ran = false;
JobChainingTestSecondJob::$ran = false;
JobChainingTestThirdJob::$ran = false;
static::$catchCallbackRan = false;
});

$app['config']->set('queue.connections.sync2', [
'driver' => 'sync',
]);
parent::setUp();
}

protected function tearDown(): void
protected function defineEnvironment($app)
{
JobChainingTestFirstJob::$ran = false;
JobChainingTestSecondJob::$ran = false;
JobChainingTestThirdJob::$ran = false;
static::$catchCallbackRan = false;
$app['config']->set([
'queue.default' => 'sync',
'queue.connections.sync1' => ['driver' => 'sync'],
'queue.connections.sync2' => ['driver' => 'sync'],
]);
}

public function testJobsCanBeChainedOnSuccess()
Expand Down
5 changes: 5 additions & 0 deletions tests/Integration/Queue/JobDispatchingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ protected function setUp(): void
parent::setUp();
}

protected function defineEnvironment($app)
{
$app['config']->set(['queue.default' => 'sync']);
}

public function testJobCanUseCustomMethodsAfterDispatch()
{
Job::dispatch('test')->replaceValue('new-test');
Expand Down
11 changes: 7 additions & 4 deletions tests/Integration/Queue/UniqueJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Bus;
use Orchestra\Testbench\Concerns\WithLaravelMigrations;
use Orchestra\Testbench\TestCase;

class UniqueJobTest extends TestCase
{
protected function defineDatabaseMigrations()
use WithLaravelMigrations;

protected function defineEnvironment($app)
{
$this->loadLaravelMigrations();
$app['config']->set(['queue.default' => 'database']);
}

public function testUniqueJobsAreNotDispatched()
Expand All @@ -43,7 +46,7 @@ public function testUniqueJobsAreNotDispatched()
public function testLockIsReleasedForSuccessfulJobs()
{
UniqueTestJob::$handled = false;
dispatch($job = new UniqueTestJob);
dispatch_sync($job = new UniqueTestJob);

$this->assertTrue($job::$handled);
$this->assertTrue($this->app->get(Cache::class)->lock($this->getLockKey($job), 10)->get());
Expand All @@ -56,7 +59,7 @@ public function testLockIsReleasedForFailedJobs()
$this->expectException(Exception::class);

try {
dispatch($job = new UniqueTestFailJob);
dispatch_sync($job = new UniqueTestFailJob);
} finally {
$this->assertTrue($job::$handled);
$this->assertTrue($this->app->get(Cache::class)->lock($this->getLockKey($job), 10)->get());
Expand Down

0 comments on commit 05ae303

Please sign in to comment.