protected function setUp() { parent::setUp(); $this->orderId = OrderId::generate(); $this->order = Order::orderProduct($this->orderId, ProductId::generate(), 100); $this->contract = Contract::with(Order::class); }
/** * @test * @depends it_should_commit_and_fetch_events * @dataProvider providePersistence * @param Persistence $persistence */ public function it_should_throw_when_events_have_been_committed_elsewhere(Persistence $persistence) { $commitId = CommitId::generate(); $streamContract = Contract::with('My.Contract'); $streamId = OrderId::generate(); $eventEnvelope = EventEnvelope::wrap(EventId::generate(), Contract::with("My.SomethingHasHappened"), "My payload2"); $this->setExpectedException(OptimisticConcurrencyFailed::class); $persistence->commit($commitId, $streamContract, $streamId, $expectedStreamVersion = 1, [$eventEnvelope]); }
/** * @test */ public function it_should_behave_the_same_after_reconstitution() { $orderId = OrderId::generate(); $history = new DomainEventsArray([new ProductWasOrdered($orderId, ProductId::generate(), 100), new PaymentWasMade($orderId, 50)]); $order = Order::reconstituteFrom($history); $order->pay(50); $changes = $order->getChanges(); $this->assertCount(2, $changes); $this->assertInstanceOf(PaymentWasMade::class, $changes[0]); $this->assertInstanceOf(OrderWasPaidInFull::class, $changes[1]); }
/** * @test */ public function it_should_protect_invariants() { $orderId = OrderId::generate(); $order = Order::orderProduct($orderId, ProductId::generate(), 100); $order->pay(50); $order->pay(50); $changes = $order->getChanges(); $this->assertCount(4, $changes); $this->assertInstanceOf(ProductWasOrdered::class, $changes[0]); $this->assertInstanceOf(PaymentWasMade::class, $changes[1]); $this->assertInstanceOf(PaymentWasMade::class, $changes[2]); $this->assertInstanceOf(OrderWasPaidInFull::class, $changes[3]); }
/** * @test * @dataProvider providePersistence * @param Persistence $persistence */ public function retrieved_order_should_behave_the_same_as_the_original_order(Persistence $persistence) { $unitOfWork = $this->buildUnitOfWork($persistence); $repository = new OrderRepository($unitOfWork); $orderId = OrderId::generate(); $order = Order::orderProduct($orderId, ProductId::generate(), 100); $repository->add($order); $unitOfWork->commit(); $retrievedOrder = $repository->get($orderId); /** @var $retrievedOrder Order */ $retrievedOrder->pay(50); $retrievedOrder->pay(50); $changes = $retrievedOrder->getChanges(); $this->assertCount(3, $changes); $this->assertInstanceOf(PaymentWasMade::class, $changes[0]); $this->assertInstanceOf(PaymentWasMade::class, $changes[1]); $this->assertInstanceOf(OrderWasPaidInFull::class, $changes[2]); }
/** * @test */ public function it_should_throw_on_malformed_uuid() { $this->setExpectedException(\InvalidArgumentException::class); OrderId::fromString('bad-uuid'); }
protected function setUp() { parent::setUp(); $this->order = Order::orderProduct(OrderId::generate(), ProductId::generate(), 100); }