public function testChangesCanBeCleared() { $aggregateRoot = UnitTestAggregate::schedule('Unit-Test'); $this->assertCount(1, $aggregateRoot->getChanges()); $this->assertTrue($aggregateRoot->hasChanges()); $aggregateRoot->clearCommittedChanges($aggregateRoot->getChanges()); $this->assertCount(0, $aggregateRoot->getChanges()); $this->assertFalse($aggregateRoot->hasChanges()); }
public function testCanGetATrackedAggregateRootById() { $repository = new UnitTestAggregateRepository($this->event_store, $this->collection); $aggregate_root = UnitTestAggregate::schedule('Unit-Test'); $repository->track($aggregate_root); $tracked = $repository->getWithId(new Identifier('Unit-Test-ID')); $this->assertSame($aggregate_root, $tracked); $this->assertTrue($repository->isTracked($tracked)); }
public function testCanLoopOverCollectionMoreThanOnce() { $collection = new AggregateRootCollection(); $aggregate_root = UnitTestAggregate::schedule('Unit-Test'); $collection->attach($aggregate_root); echo "Loop 1:"; foreach ($collection as $key => $aggregate) { echo "\nKey: {$key}, ID: {$aggregate->getIdentifier()}"; } echo "\nLoop 2:"; foreach ($collection as $key => $aggregate) { echo "\nKey: {$key}, ID: {$aggregate->getIdentifier()}"; } $this->expectOutputString("Loop 1:\nKey: 0, ID: Unit-Test-ID\nLoop 2:\nKey: 0, ID: Unit-Test-ID"); }