public function testStorage() { $id = TicketId::generate(); $message = DomainMessage::create($id, 1, new TicketWasCreated($id, 'iqbal', 'Cannot save data.')); $this->storage->append('Ticket', $message, 'OK'); $eventStream = $this->storage->findEventFromBeginning('Ticket', $id); $events = $eventStream->all(); $this->assertCount(1, $eventStream); $this->assertInstanceOf('\\Borobudur\\EventSourcing\\Test\\Event\\TicketWasCreated', $events[0]->getPayload()); }
public function testCommit() { $id = TicketId::generate(); $this->storage->beginTransaction(); $this->assertTrue($this->storage->isTransactional()); $this->append($id); $this->storage->commit(); $this->assertFalse($this->storage->isTransactional()); $eventStream = $this->storage->findEventFromBeginning('Ticket', $id); $events = $eventStream->all(); $this->assertCount(1, $eventStream); $this->assertInstanceOf('\\Borobudur\\EventSourcing\\Test\\Event\\TicketWasCreated', $events[0]->getPayload()); }
public function testPersistEvent() { $ticket = Ticket::open(TicketId::generate(), 'iqbal', 'Error when delete data.'); $this->assertEquals('iqbal', $ticket->getName()); $this->assertEquals('Error when delete data.', $ticket->getMessage()); $this->assertEquals('open', $ticket->getStatus()); $ticket->close(); $this->assertEquals('closed', $ticket->getStatus()); $stream = $ticket->getUncommittedEvents(); $events = $stream->all(); $this->assertCount(2, $stream); $this->assertInstanceOf('\\Borobudur\\EventSourcing\\Test\\Event\\TicketWasCreated', $events[0]->getPayload()); $this->assertInstanceOf('\\Borobudur\\EventSourcing\\Test\\Event\\TicketWasClosed', $events[1]->getPayload()); }
public function testSourceEvents() { $id = TicketId::generate(); $ticket = Ticket::open($id, 'iqbal', 'Wrong data type!'); $this->repository->persist($ticket); /** @var Ticket $ticket */ $ticket = $this->repository->find($id); $this->assertEquals((string) $id, (string) $ticket->getId()); $this->assertEquals('iqbal', $ticket->getName()); $this->assertEquals('Wrong data type!', $ticket->getMessage()); $this->assertEquals('open', $ticket->getStatus()); $ticket->close(); $this->repository->persist($ticket); $ticket = $this->repository->find($ticket->getId()); $this->assertEquals('closed', $ticket->getStatus()); return $id; }
public function testSnapshot() { $id = TicketId::generate(); $this->storage->beginTransaction(); $this->create($id, 'Iqbal', 'Hello world'); $snapshot = $this->snapshot->find($id, '\\Borobudur\\EventSourcing\\Test\\Entity\\Ticket', 'ticket'); $this->assertNull($snapshot); /** @var Ticket $ticket */ $ticket = $this->repository->find($id); $ticket->rename('Danu'); $this->repository->persist($ticket); $snapshot = $this->snapshot->find($id, '\\Borobudur\\EventSourcing\\Test\\Entity\\Ticket', 'ticket'); $this->assertEquals(2, $snapshot->getVersion()); $ticket->close(); $this->repository->persist($ticket); $snapshot = $this->snapshot->find($id, '\\Borobudur\\EventSourcing\\Test\\Entity\\Ticket', 'ticket'); $this->assertEquals(2, $snapshot->getVersion()); $ticket = $this->repository->find($id); $this->assertEquals(3, $ticket->getVersion()); $this->storage->commit(); }