|
4 | 4 |
|
5 | 5 | namespace JobRunner\JobRunner\SymfonyConsole\Tests\Unit; |
6 | 6 |
|
7 | | -use DateTimeImmutable; |
8 | 7 | use JobRunner\JobRunner\Job\Job; |
9 | 8 | use JobRunner\JobRunner\SymfonyConsole\SymfonyConsoleEventListener; |
10 | 9 | use PHPUnit\Framework\Attributes\CoversClass; |
11 | 10 | use PHPUnit\Framework\TestCase; |
12 | | -use RuntimeException; |
13 | 11 | use Symfony\Component\Console\Helper\Table; |
14 | 12 | use Symfony\Component\Console\Output\ConsoleSectionOutput; |
15 | 13 |
|
16 | | -use function array_key_exists; |
17 | | - |
18 | 14 | #[CoversClass(SymfonyConsoleEventListener::class)] |
19 | 15 | class SymfonyConsoleEventListenerTest extends TestCase |
20 | 16 | { |
21 | | - /** @var array<string, int> */ |
22 | | - private array $matcher = []; |
23 | | - |
24 | | - private function getNextIncrement(string $name): int |
25 | | - { |
26 | | - if (! array_key_exists($name, $this->matcher)) { |
27 | | - $this->matcher[$name] = 0; |
28 | | - } |
29 | | - |
30 | | - $this->matcher[$name]++; |
31 | | - |
32 | | - return $this->matcher[$name]; |
33 | | - } |
34 | | - |
35 | 17 | public function testSuccess(): void |
36 | 18 | { |
37 | | - $table = self::createMock(Table::class); |
38 | | - $consoleSectionOutput = self::createMock(ConsoleSectionOutput::class); |
39 | | - $job = self::createMock(Job::class); |
40 | | - $nextHour = (new DateTimeImmutable())->setTime((int) (new DateTimeImmutable())->modify('+1 hour')->format('H'), 0, 0); |
| 19 | + $table = $this->createMock(Table::class); |
| 20 | + $consoleSectionOutput = $this->createMock(ConsoleSectionOutput::class); |
| 21 | + $job = $this->createMock(Job::class); |
41 | 22 |
|
42 | | - $table->expects($this->exactly(5))->method('render'); |
43 | 23 | $job->expects($this->any())->method('getName')->willReturn('myName'); |
44 | 24 | $job->expects($this->any())->method('getCronExpression')->willReturn('0 * * * *'); |
45 | 25 | $consoleSectionOutput->expects($this->exactly(5))->method('clear'); |
| 26 | + $table->expects($this->exactly(5))->method('render'); |
46 | 27 | $table->expects($this->once())->method('setHeaders')->with(['Job name', 'cron expression', 'next run date', 'state', 'output']); |
47 | | - $table->expects($this->exactly(5))->method('setRows')->with($this->callback(function (mixed $param) use ($nextHour) { |
48 | | - return $param === match ($this->getNextIncrement('setRows')) { |
49 | | - 1 => [['myName', '0 * * * *', $nextHour->format('Y-m-d H:i:s'), 'start', null]], |
50 | | - 2 => [['myName', '0 * * * *', $nextHour->format('Y-m-d H:i:s'), 'fail', 'toto']], |
51 | | - 3 => [['myName', '0 * * * *', $nextHour->format('Y-m-d H:i:s'), 'notDue', null]], |
52 | | - 4 => [['myName', '0 * * * *', $nextHour->format('Y-m-d H:i:s'), 'isLocked', null]], |
53 | | - 5 => [['myName', '0 * * * *', $nextHour->format('Y-m-d H:i:s'), 'success', 'toto']], |
54 | | - default => throw new RuntimeException() |
55 | | - }; |
56 | | - })); |
| 28 | + $table->expects($this->exactly(5))->method('setRows'); |
57 | 29 |
|
58 | 30 | $sUT = new SymfonyConsoleEventListener($consoleSectionOutput, $table); |
59 | 31 |
|
|
0 commit comments