remotelyliving /
php-command-bus
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace RemotelyLiving\PHPCommandBus\Tests\Integration; |
||
| 6 | |||
| 7 | use PHPUnit\Framework\TestCase; |
||
| 8 | use Psr\Log\Test\TestLogger; |
||
| 9 | use RemotelyLiving\PHPCommandBus\Middleware; |
||
| 10 | use RemotelyLiving\PHPCommandBus\CommandBus; |
||
| 11 | use RemotelyLiving\PHPCommandBus\Resolver; |
||
| 12 | use RemotelyLiving\PHPCommandBus\Interfaces; |
||
| 13 | use RemotelyLiving\PHPCommandBus\Tests\Stubs; |
||
| 14 | |||
| 15 | abstract class AbstractTestCase extends TestCase |
||
| 16 | { |
||
| 17 | protected ?TestLogger $testLogger = null; |
||
| 18 | |||
| 19 | public function getTestLogger(): TestLogger |
||
| 20 | { |
||
| 21 | if ($this->testLogger === null) { |
||
| 22 | $this->testLogger = new TestLogger(); |
||
| 23 | } |
||
| 24 | |||
| 25 | return $this->testLogger; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 26 | } |
||
| 27 | |||
| 28 | public function createConfiguredCommandBus(): Interfaces\CommandBus |
||
| 29 | { |
||
| 30 | $commandLogger = new Middleware\CommandLogger(); |
||
| 31 | $commandLogger->setLogger($this->getTestLogger()); |
||
| 32 | |||
| 33 | $container = new Stubs\Container([ |
||
| 34 | Stubs\Commands\PublishDraft::class => new Stubs\Handlers\PublishDraft(), |
||
| 35 | ]); |
||
| 36 | |||
| 37 | $resolver = Resolver::create($container); |
||
| 38 | $lazyFn = function (): Interfaces\Handler { |
||
| 39 | return new Stubs\Handlers\ReserveRoom(); |
||
| 40 | }; |
||
| 41 | |||
| 42 | $resolver->pushHandlerDeferred(Stubs\Commands\ReserveRoom::class, $lazyFn); |
||
| 43 | |||
| 44 | return CommandBus::create($resolver) |
||
| 45 | ->pushMiddleware($commandLogger); |
||
| 46 | } |
||
| 47 | } |
||
| 48 |