|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Yokai\Batch\Tests\Logger; |
| 6 | + |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | +use Yokai\Batch\Event\PostExecuteEvent; |
| 9 | +use Yokai\Batch\Event\PreExecuteEvent; |
| 10 | +use Yokai\Batch\JobExecution; |
| 11 | +use Yokai\Batch\Logger\BatchLogger; |
| 12 | +use Yokai\Batch\Tests\Dummy\DebugEventDispatcher; |
| 13 | + |
| 14 | +class BatchLoggerTest extends TestCase |
| 15 | +{ |
| 16 | + public function testLaunch(): void |
| 17 | + { |
| 18 | + $dispatcher = new DebugEventDispatcher(); |
| 19 | + $logger = new BatchLogger(); |
| 20 | + |
| 21 | + $dispatcher->addListener(PreExecuteEvent::class, [$logger, 'onPreExecute']); |
| 22 | + $dispatcher->addListener(PostExecuteEvent::class, [$logger, 'onPostExecute']); |
| 23 | + |
| 24 | + $execution = JobExecution::createRoot('123', 'test.job_executor'); |
| 25 | + |
| 26 | + $logger->log('info', 'before'); |
| 27 | + $preExecuteEvent = new PreExecuteEvent($execution); |
| 28 | + $dispatcher->dispatch($preExecuteEvent); |
| 29 | + |
| 30 | + $logger->log('info', 'between'); |
| 31 | + |
| 32 | + $postExecuteEvent = new PostExecuteEvent($execution); |
| 33 | + $dispatcher->dispatch($postExecuteEvent); |
| 34 | + $logger->log('info', 'after'); |
| 35 | + |
| 36 | + self::assertStringNotContainsString('before', $execution->getLogs()->__toString()); |
| 37 | + self::assertStringContainsString('between', $execution->getLogs()->__toString()); |
| 38 | + self::assertStringNotContainsString('after', $execution->getLogs()->__toString()); |
| 39 | + } |
| 40 | +} |
0 commit comments