public function testLoadAndStoreAggregate() { DefaultUnitOfWork::startAndGet(); $aggregate = new StubAggregate(); $aggregate->doSomething(); /*$this->lockManager->expects($this->exactly(2)) ->method('obtainLock') ->with($this->equalTo($aggregate->getIdentifier())); $this->lockManager->expects($this->exactly(2)) ->method('releaseLock') ->with($this->equalTo($aggregate->getIdentifier()));*/ $this->testSubject->add($aggregate); CurrentUnitOfWork::commit(); DefaultUnitOfWork::startAndGet(); $loadedAggregate = $this->testSubject->load($aggregate->getIdentifier(), 0); //verify(lockManager).obtainLock(aggregate.getIdentifier()); $loadedAggregate->doSomething(); CurrentUnitOfWork::commit(); /* $lockManager = Phake::mock(get_class($this->lockManager)); \Phake::inOrder( \Phake::verify($lockManager)->validateLock(), \Phake::verify($lockManager)->releaseLock() );*/ //InOrder inOrder = inOrder(lockManager); // inOrder.verify(lockManager, atLeastOnce()).validateLock(loadedAggregate); // verify(mockEventBus, times(2)).publish(any(DomainEventMessage.class)); // inOrder.verify(lockManager).releaseLock(loadedAggregate.getIdentifier()); }
public function testCommandHandlerLoadsSameAggregateTwice() { DefaultUnitOfWork::startAndGet(); $stubAggregate = new StubAggregate($this->aggregateIdentifier); $stubAggregate->doSomething(); $this->repository->add($stubAggregate); CurrentUnitOfWork::commit(); DefaultUnitOfWork::startAndGet(); $this->repository->load($this->aggregateIdentifier)->doSomething(); $this->repository->load($this->aggregateIdentifier)->doSomething(); CurrentUnitOfWork::commit(); $es = $this->mockEventStore->readEvents("", $this->aggregateIdentifier); $this->assertTrue($es->hasNext()); $this->assertEquals(0, $es->next()->getScn()); $this->assertTrue($es->hasNext()); $this->assertEquals(1, $es->next()->getScn()); $this->assertTrue($es->hasNext()); $this->assertEquals(2, $es->next()->getScn()); $this->assertFalse($es->hasNext()); }
public function testLoadAndSaveWithoutConflictingChanges() { $conflictResolver = $this->getMock('Governor\\Framework\\EventSourcing\\ConflictResolverInterface'); $identifier = Uuid::uuid1()->toString(); $event2 = new GenericDomainEventMessage($identifier, 2, new \stdClass(), MetaData::emptyInstance()); $event3 = new GenericDomainEventMessage($identifier, 3, new \stdClass(), MetaData::emptyInstance()); $this->mockEventStore->expects($this->once())->method('readEvents')->with($this->identicalTo("test"), $this->identicalTo($identifier))->will($this->returnValue(new SimpleDomainEventStream(array(new GenericDomainEventMessage($identifier, 1, new \stdClass()), $event2, $event3)))); $this->testSubject->setConflictResolver($conflictResolver); $actual = $this->testSubject->load($identifier, 3); $conflictResolver->expects($this->never())->method('resolveConflicts'); $actual->apply(new StubDomainEvent()); $conflictResolver->expects($this->never())->method('resolveConflicts'); CurrentUnitOfWork::commit(); }