-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add base tests for commands (#27)
* add base tests for commands * fix config load * disable phpstan-strict-rules in rector.php * Revert "disable phpstan-strict-rules in rector.php" This reverts commit 5c5d115. * add rector separately * update rector version in the workflow * add suggestions from the the code review
- Loading branch information
Showing
15 changed files
with
555 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Commands; | ||
|
||
use CodeIgniter\Test\Filters\CITestStreamFilter; | ||
use Tests\Support\CLITestCase; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class QueueClearTest extends CLITestCase | ||
{ | ||
public function testRunWithNoQueueName(): void | ||
{ | ||
CITestStreamFilter::registration(); | ||
CITestStreamFilter::addErrorFilter(); | ||
|
||
$this->assertNotFalse(command('queue:clear')); | ||
$output = $this->parseOutput(CITestStreamFilter::$buffer); | ||
|
||
CITestStreamFilter::removeErrorFilter(); | ||
|
||
$this->assertSame('The queueName is not specified.', $output); | ||
} | ||
|
||
public function testRun(): void | ||
{ | ||
CITestStreamFilter::registration(); | ||
CITestStreamFilter::addOutputFilter(); | ||
|
||
$this->assertNotFalse(command('queue:clear test')); | ||
$output = $this->parseOutput(CITestStreamFilter::$buffer); | ||
|
||
CITestStreamFilter::removeOutputFilter(); | ||
|
||
$this->assertSame('Queue test has been cleared.', $output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Commands; | ||
|
||
use CodeIgniter\I18n\Time; | ||
use CodeIgniter\Queue\Models\QueueJobFailedModel; | ||
use CodeIgniter\Test\Filters\CITestStreamFilter; | ||
use Exception; | ||
use Tests\Support\CLITestCase; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class QueueFailedTest extends CLITestCase | ||
{ | ||
/** | ||
* @throws Exception | ||
*/ | ||
public function testRun(): void | ||
{ | ||
Time::setTestNow('2023-12-19 14:15:16'); | ||
|
||
fake(QueueJobFailedModel::class, [ | ||
'connection' => 'database', | ||
'queue' => 'test', | ||
'payload' => ['job' => 'failure', 'data' => ['key' => 'value']], | ||
'priority' => 'default', | ||
'exception' => 'Exception: Test error', | ||
]); | ||
|
||
CITestStreamFilter::registration(); | ||
CITestStreamFilter::addOutputFilter(); | ||
|
||
$this->assertNotFalse(command('queue:failed')); | ||
$output = $this->parseOutput(CITestStreamFilter::$buffer); | ||
|
||
CITestStreamFilter::removeOutputFilter(); | ||
|
||
$expect = <<<'EOT' | ||
+----+------------+-------+----------------------------+---------------------+ | ||
| ID | Connection | Queue | Class | Failed At | | ||
+----+------------+-------+----------------------------+---------------------+ | ||
| 1 | database | test | Tests\Support\Jobs\Failure | 2023-12-19 14:15:16 | | ||
+----+------------+-------+----------------------------+---------------------+ | ||
EOT; | ||
|
||
$this->assertSame($expect, $output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Commands; | ||
|
||
use CodeIgniter\I18n\Time; | ||
use CodeIgniter\Queue\Models\QueueJobFailedModel; | ||
use CodeIgniter\Test\Filters\CITestStreamFilter; | ||
use Exception; | ||
use Tests\Support\CLITestCase; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class QueueFlushTest extends CLITestCase | ||
{ | ||
/** | ||
* @throws Exception | ||
*/ | ||
public function testRun(): void | ||
{ | ||
Time::setTestNow('2023-12-19 14:15:16'); | ||
|
||
fake(QueueJobFailedModel::class, [ | ||
'connection' => 'database', | ||
'queue' => 'test', | ||
'payload' => ['job' => 'failure', 'data' => ['key' => 'value']], | ||
'priority' => 'default', | ||
'exception' => 'Exception: Test error', | ||
]); | ||
|
||
CITestStreamFilter::registration(); | ||
CITestStreamFilter::addOutputFilter(); | ||
|
||
$this->assertNotFalse(command('queue:flush')); | ||
$output = $this->parseOutput(CITestStreamFilter::$buffer); | ||
|
||
CITestStreamFilter::removeOutputFilter(); | ||
|
||
$this->assertSame('All failed jobs has been removed from the queue ', $output); | ||
} | ||
|
||
public function testRunWithQueue(): void | ||
{ | ||
Time::setTestNow('2023-12-19 14:15:16'); | ||
|
||
fake(QueueJobFailedModel::class, [ | ||
'connection' => 'database', | ||
'queue' => 'test', | ||
'payload' => ['job' => 'failure', 'data' => ['key' => 'value']], | ||
'priority' => 'default', | ||
'exception' => 'Exception: Test error', | ||
]); | ||
|
||
CITestStreamFilter::registration(); | ||
CITestStreamFilter::addOutputFilter(); | ||
|
||
$this->assertNotFalse(command('queue:flush -queue default')); | ||
$output = $this->parseOutput(CITestStreamFilter::$buffer); | ||
|
||
CITestStreamFilter::removeOutputFilter(); | ||
|
||
$this->assertSame('All failed jobs has been removed from the queue default', $output); | ||
} | ||
|
||
public function testRunWithQueueAndHour(): void | ||
{ | ||
Time::setTestNow('2023-12-19 14:15:16'); | ||
|
||
fake(QueueJobFailedModel::class, [ | ||
'connection' => 'database', | ||
'queue' => 'test', | ||
'payload' => ['job' => 'failure', 'data' => ['key' => 'value']], | ||
'priority' => 'default', | ||
'exception' => 'Exception: Test error', | ||
]); | ||
|
||
CITestStreamFilter::registration(); | ||
CITestStreamFilter::addOutputFilter(); | ||
|
||
$this->assertNotFalse(command('queue:flush -queue default -hours 2')); | ||
$output = $this->parseOutput(CITestStreamFilter::$buffer); | ||
|
||
CITestStreamFilter::removeOutputFilter(); | ||
|
||
$this->assertSame('All failed jobs older than 2 hours has been removed from the queue default', $output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Commands; | ||
|
||
use CodeIgniter\Queue\Models\QueueJobFailedModel; | ||
use CodeIgniter\Test\Filters\CITestStreamFilter; | ||
use Tests\Support\CLITestCase; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class QueueForgetTest extends CLITestCase | ||
{ | ||
public function testRunWithNoQueueName(): void | ||
{ | ||
CITestStreamFilter::registration(); | ||
CITestStreamFilter::addErrorFilter(); | ||
|
||
$this->assertNotFalse(command('queue:forget')); | ||
$output = $this->parseOutput(CITestStreamFilter::$buffer); | ||
|
||
CITestStreamFilter::removeErrorFilter(); | ||
|
||
$this->assertSame('The ID of the failed job is not specified.', $output); | ||
} | ||
|
||
public function testRunFailed(): void | ||
{ | ||
CITestStreamFilter::registration(); | ||
CITestStreamFilter::addOutputFilter(); | ||
|
||
$this->assertNotFalse(command('queue:forget 123')); | ||
$output = $this->parseOutput(CITestStreamFilter::$buffer); | ||
|
||
CITestStreamFilter::removeOutputFilter(); | ||
|
||
$this->assertSame('Could not find the failed job with ID 123', $output); | ||
} | ||
|
||
public function testRun(): void | ||
{ | ||
fake(QueueJobFailedModel::class, [ | ||
'connection' => 'database', | ||
'queue' => 'test', | ||
'payload' => ['job' => 'failure', 'data' => ['key' => 'value']], | ||
'priority' => 'default', | ||
'exception' => 'Exception: Test error', | ||
]); | ||
|
||
CITestStreamFilter::registration(); | ||
CITestStreamFilter::addOutputFilter(); | ||
|
||
$this->assertNotFalse(command('queue:forget 1')); | ||
$output = $this->parseOutput(CITestStreamFilter::$buffer); | ||
|
||
CITestStreamFilter::removeOutputFilter(); | ||
|
||
$this->assertSame('Failed job with ID 1 has been removed.', $output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Commands; | ||
|
||
use CodeIgniter\Test\Filters\CITestStreamFilter; | ||
use Tests\Support\CLITestCase; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class QueuePublishTest extends CLITestCase | ||
{ | ||
public function testRun(): void | ||
{ | ||
CITestStreamFilter::registration(); | ||
CITestStreamFilter::addOutputFilter(); | ||
|
||
$this->assertNotFalse(command('queue:publish')); | ||
$output = $this->parseOutput(CITestStreamFilter::$buffer); | ||
|
||
CITestStreamFilter::removeOutputFilter(); | ||
|
||
$this->assertSame(' Published! You can customize the configuration by editing the "app/Config/Queue.php" file.', $output); | ||
} | ||
} |
Oops, something went wrong.