|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace SimpleBus\SymfonyBridge\Tests\Functional; |
| 4 | + |
| 5 | +use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Nested\NestedCommand; |
| 6 | +use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Nested\PostExecutionRecord; |
| 7 | +use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Nested\PreExecutionRecord; |
| 8 | +use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Nested\RecordsBag; |
| 9 | +use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\TestKernel; |
| 10 | +use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
| 11 | + |
| 12 | +final class NestedCommandExecutionOrderConfigurationTest extends KernelTestCase |
| 13 | +{ |
| 14 | + protected static function getKernelClass(): string |
| 15 | + { |
| 16 | + return TestKernel::class; |
| 17 | + } |
| 18 | + |
| 19 | + /** |
| 20 | + * @test |
| 21 | + */ |
| 22 | + public function nested_commands_are_executed_sequentially_by_default(): void |
| 23 | + { |
| 24 | + self::bootKernel(['environment' => 'config1']); |
| 25 | + $container = self::$kernel->getContainer(); |
| 26 | + |
| 27 | + $commandBus = $container->get('command_bus'); |
| 28 | + $command = new NestedCommand(); |
| 29 | + $commandBus->handle($command); |
| 30 | + |
| 31 | + /** @var RecordsBag $recorder */ |
| 32 | + $recorder = $container->get('nesting_records_bag'); |
| 33 | + |
| 34 | + $this->assertEquals( |
| 35 | + [ |
| 36 | + new PreExecutionRecord(0), |
| 37 | + new PostExecutionRecord(0), |
| 38 | + new PreExecutionRecord(1), |
| 39 | + new PostExecutionRecord(1), |
| 40 | + new PreExecutionRecord(2), |
| 41 | + new PostExecutionRecord(2), |
| 42 | + |
| 43 | + ], |
| 44 | + $recorder->records |
| 45 | + ); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * @test |
| 50 | + */ |
| 51 | + public function disabling_finishes_command_before_handling_next_middleware_keeps_command_nesting(): void |
| 52 | + { |
| 53 | + self::bootKernel(['environment' => 'config3']); |
| 54 | + $container = self::$kernel->getContainer(); |
| 55 | + |
| 56 | + $commandBus = $container->get('command_bus'); |
| 57 | + $command = new NestedCommand(); |
| 58 | + $commandBus->handle($command); |
| 59 | + |
| 60 | + /** @var RecordsBag $recorder */ |
| 61 | + $recorder = $container->get('nesting_records_bag'); |
| 62 | + |
| 63 | + $this->assertEquals( |
| 64 | + [ |
| 65 | + new PreExecutionRecord(0), |
| 66 | + new PreExecutionRecord(1), |
| 67 | + new PreExecutionRecord(2), |
| 68 | + new PostExecutionRecord(2), |
| 69 | + new PostExecutionRecord(1), |
| 70 | + new PostExecutionRecord(0), |
| 71 | + |
| 72 | + ], |
| 73 | + $recorder->records |
| 74 | + ); |
| 75 | + } |
| 76 | + |
| 77 | + /** {@inheritdoc} */ |
| 78 | + protected function tearDown() |
| 79 | + { |
| 80 | + parent::tearDown(); |
| 81 | + |
| 82 | + static::$class = null; |
| 83 | + static::$kernel = null; |
| 84 | + } |
| 85 | +} |
0 commit comments