| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace Test\Michel\PQueueBundle;
- use Michel\PQueueBundle\Command\PQueueWorkerRunCommand;
- use Symfony\Bundle\FrameworkBundle\Console\Application;
- use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
- use Symfony\Component\Console\Tester\CommandTester;
- use Test\Michel\PQueueBundle\Fixtures\TestKernel;
- class CommandTest extends KernelTestCase
- {
- protected static function getKernelClass(): string
- {
- return TestKernel::class;
- }
- protected function setUp(): void
- {
- self::bootKernel();
- }
- public function testPQueueWorkerRunCommand(): void
- {
- $application = new Application(self::$kernel);
- /**
- * @var PQueueWorkerRunCommand $command
- */
- $command = self::$kernel->getContainer()->get(PQueueWorkerRunCommand::class);
- $application->add($command);
- $commandTester = new CommandTester($application->find('pqueue:worker:run'));
- $exitCode = $commandTester->execute([
- '--stop-when-empty' => true,
- '--memory-limit' => '64'
- ]);
- $this->assertSame(0, $exitCode, 'Command should return success code 0');
- $display = trim($commandTester->getDisplay());
- $display = preg_replace('/\e\[[0-9;]*m/', '', $display);
- $this->assertStringContainsStringIgnoringCase(
- 'Worker started.',
- $display
- );
- $optionsDisplay = [
- 'Stop when empty : Yes',
- ' Idle sleep : 10 s',
- ' Retry delay : 60 s'
- ];
- foreach ($optionsDisplay as $expectedLine) {
- $this->assertStringContainsString($expectedLine, $display, "Expected line '{$expectedLine}' not found in command output.");
- }
- }
- }
|