register() public method

public register ( Dumplie\SharedKernel\Application\Command\Extension $commandExtension, integer $priority )
$commandExtension Dumplie\SharedKernel\Application\Command\Extension
$priority integer
Exemplo n.º 1
0
 function it_execute_extension_points(Extension $extension)
 {
     $command = new AddToCart("SKU", 1, (string) CartId::generate());
     $extension->pre($command, Argument::type(ServiceLocator::class))->shouldBeCalled();
     $extension->post($command, Argument::type(ServiceLocator::class))->shouldBeCalled();
     $extension->expands($command)->willReturn(true);
     $this->registry->register($extension->getWrappedObject());
     $this->execute($command, function () {
     });
 }
Exemplo n.º 2
0
 public function test_transaction_extension_rollback()
 {
     $transaction = $this->prophesize(Transaction::class);
     $transaction->commit()->shouldNotBeCalled();
     $transaction->rollback()->shouldBeCalled();
     $factory = new FactoryStub($transaction->reveal());
     $transaction = new TransactionExtension($factory);
     $this->extensionRegistry->register($transaction);
     $this->expectException(ProductNotFoundException::class);
     $command = new AddToCart("SKU", 1, (string) CartId::generate());
     $this->commandBus->handle($command);
 }
Exemplo n.º 3
0
 public function test_extensions_execution_order()
 {
     $command = new CreateCart((string) CartId::generate(), 'PLN');
     $executionOrder = [];
     $prePromise = function () use(&$executionOrder) {
         $executionOrder[] = spl_object_hash($this);
     };
     $extension1 = $this->createExtensionProphecy($command, $prePromise);
     $extension2 = $this->createExtensionProphecy($command, $prePromise);
     $this->extensionRegistry->register($extension1->reveal(), 0);
     $this->extensionRegistry->register($extension2->reveal(), 1);
     $this->extensionRegistry->pre($command);
     $this->assertEquals([spl_object_hash($extension2), spl_object_hash($extension1)], $executionOrder);
 }
Exemplo n.º 4
0
 /**
  * @param array $handlers
  * @param array $commandExtension
  * @return \Dumplie\SharedKernel\Application\CommandBus
  */
 public function create(array $handlers = [], array $commandExtension = []) : \Dumplie\SharedKernel\Application\CommandBus
 {
     $commandHandlerMiddleware = new CommandHandlerMiddleware(new ClassNameExtractor(), new InMemoryLocator($handlers), new HandleInflector());
     $serviceLocator = new InMemoryServiceLocator();
     $extensionRegistry = new ExtensionRegistry($serviceLocator);
     foreach ($commandExtension as $extension) {
         $extensionRegistry->register($extension);
     }
     $extensionMiddleware = new ExtensionMiddleware($extensionRegistry);
     return new CommandBus(new Tactician([$extensionMiddleware, $commandHandlerMiddleware]));
 }