Inheritance: extends Dumplie\SharedKernel\Domain\Identity\UUID
 function it_rethrows_exception_and_rollbacks_transaction_in_catch_exception_command_endpoint(Factory $factory, Transaction $transaction, ServiceLocator $serviceLocator)
 {
     $command = new CreateCart((string) CartId::generate(), "PLN");
     $factory->open()->willReturn($transaction);
     $transaction->rollback()->shouldBeCalled();
     $this->pre($command, $serviceLocator);
     $this->shouldThrow(\Exception::class)->during('catchException', [$command, new \Exception(), $serviceLocator]);
 }
Example #2
0
 public function test_compound_command_serialization()
 {
     $compoundCommand = new AddToCart("SKU_1", 5, (string) CartId::generate());
     $serialized = serialize($compoundCommand);
     $unserialized = unserialize($serialized);
     $this->assertEquals("SKU_1", $unserialized->sku());
     $this->assertEquals(5, $unserialized->quantity());
 }
 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 () {
     });
 }
 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);
 }
Example #5
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);
 }
Example #6
0
 function let()
 {
     $this->beConstructedWith(CartId::generate(), 'EUR');
 }
 /**
  * @param string $currency
  * @param array $skuCodes
  *
  * @return CartId
  */
 public function createNewCartWithProducts(string $currency = 'EUR', array $skuCodes = []) : CartId
 {
     $cartId = CartId::generate();
     $command = new CreateCart((string) $cartId, $currency);
     $this->commandBus->handle($command);
     foreach ($skuCodes as $sku) {
         $addToCartCommand = new AddToCart($sku, 1, (string) $cartId);
         $this->commandBus->handle($addToCartCommand);
     }
     return $cartId;
 }
Example #8
0
 function it_throws_exception_when_cart_is_empty(Products $products, Carts $carts)
 {
     $cart = new Cart(CartId::generate(), 'EUR');
     $carts->getById(Argument::type(CartId::class))->willReturn($cart);
     $this->shouldThrow(EmptyCartException::class)->during('placeOrder', [OrderId::generate(), $products, $carts]);
 }