|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Yokai\Batch\Tests\Bridge\Symfony\Console; |
| 6 | + |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | +use Symfony\Component\Console\Tester\CommandTester; |
| 9 | +use Yokai\Batch\Bridge\Symfony\Console\SetupStorageCommand; |
| 10 | +use Yokai\Batch\Exception\JobExecutionNotFoundException; |
| 11 | +use Yokai\Batch\JobExecution; |
| 12 | +use Yokai\Batch\Storage\JobExecutionStorageInterface; |
| 13 | +use Yokai\Batch\Storage\SetupableJobExecutionStorageInterface; |
| 14 | + |
| 15 | +final class SetupStorageCommandTest extends TestCase |
| 16 | +{ |
| 17 | + public function testSetupRequired(): void |
| 18 | + { |
| 19 | + $this->execute( |
| 20 | + $storage = new class() implements |
| 21 | + JobExecutionStorageInterface, |
| 22 | + SetupableJobExecutionStorageInterface { |
| 23 | + public bool $wasSetup = false; |
| 24 | + |
| 25 | + public function setup(): void |
| 26 | + { |
| 27 | + $this->wasSetup = true; |
| 28 | + } |
| 29 | + |
| 30 | + public function store(JobExecution $execution): void |
| 31 | + { |
| 32 | + } |
| 33 | + |
| 34 | + public function remove(JobExecution $execution): void |
| 35 | + { |
| 36 | + } |
| 37 | + |
| 38 | + public function retrieve(string $jobName, string $executionId): JobExecution |
| 39 | + { |
| 40 | + throw new JobExecutionNotFoundException($jobName, $executionId); |
| 41 | + } |
| 42 | + }, |
| 43 | + '[OK] The storage was set up successfully.', |
| 44 | + ); |
| 45 | + self::assertTrue($storage->wasSetup); |
| 46 | + } |
| 47 | + |
| 48 | + public function testSetupNotRequired(): void |
| 49 | + { |
| 50 | + $this->execute( |
| 51 | + new class() implements JobExecutionStorageInterface { |
| 52 | + public function store(JobExecution $execution): void |
| 53 | + { |
| 54 | + } |
| 55 | + |
| 56 | + public function remove(JobExecution $execution): void |
| 57 | + { |
| 58 | + } |
| 59 | + |
| 60 | + public function retrieve(string $jobName, string $executionId): JobExecution |
| 61 | + { |
| 62 | + throw new JobExecutionNotFoundException($jobName, $executionId); |
| 63 | + } |
| 64 | + }, |
| 65 | + '! [NOTE] The storage does not support setup.', |
| 66 | + ); |
| 67 | + } |
| 68 | + |
| 69 | + private function execute(JobExecutionStorageInterface $storage, string $expected): void |
| 70 | + { |
| 71 | + $tester = new CommandTester(new SetupStorageCommand($storage)); |
| 72 | + $tester->execute([]); |
| 73 | + $tester->assertCommandIsSuccessful(); |
| 74 | + self::assertSame($expected, \trim($tester->getDisplay(true))); |
| 75 | + } |
| 76 | +} |
0 commit comments