/**
  * Test findOne.
  */
 public function testFindOne()
 {
     $this->given($emptyDataSource = $this->emptyDataSource())->when($findResult = $emptyDataSource->findOne())->then->variable($findResult)->isNull();
     $this->given($randomDataSource = $this->randomDataSource())->when($findResult = $randomDataSource->findOne())->then->variable($findResult)->isNotNull();
     $this->given($datasource = $this->randomDataSource(Criteria::method('value')->gt(2), null, 1, 3))->when($findResult = $datasource->findOne())->then->integer($findResult->value())->isGreaterThan(2);
     $this->given($comparator = new Comparator(), $sortCriteria = new CallbackComparator(function ($a, $b) use($comparator) {
         return -1 * $comparator->compare($a, $b);
     }), $datasource = $this->randomDataSource(Criteria::method('value')->lt(10), $sortCriteria))->when($findResult = $datasource->findOne())->then->integer($findResult->value())->isEqualTo(9);
 }
Example #2
0
 /**
  * Returns the next available migration version.
  *
  * @return Version|null
  */
 public function nextAvailableVersion()
 {
     $version = Version::fromString('0.0.0');
     $latestMigration = $this->latestMigration();
     if ($latestMigration !== null) {
         $version = $latestMigration->version();
     }
     $migrations = $this->migrationsInFile->find(Criteria::method('version')->gt($version));
     if ($migrations->count() > 0) {
         return $migrations->toArray()[0]->version();
     }
     return;
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function load($streamName, IdInterface $aggregateId, Version $aggregateVersion, Version $applicationVersion)
 {
     $applicationKey = $this->getApplicationKey($applicationVersion);
     if (!$this->store->containsKey($applicationKey)) {
         throw new \RuntimeException(sprintf('The application %s not found in the event store.', $applicationKey));
     }
     /** @var ArrayHashMap $applicationCollection */
     $applicationCollection = $this->store->get($applicationKey);
     $streamKey = $this->getStreamKey($streamName, $aggregateVersion);
     if (!$applicationCollection->containsKey($streamKey)) {
         throw new \RuntimeException(sprintf('The stream name %s of application %s not found in the event store.', $streamKey, $applicationKey));
     }
     /** @var ArrayHashMap $streamCollection */
     $streamCollection = $applicationCollection->get($streamKey);
     $aggregateKey = $aggregateId->toNative();
     if (!$streamCollection->containsKey($aggregateKey)) {
         throw new \RuntimeException(sprintf('Aggregate id %s of the stream %s in the application %s not found in the event store.', $aggregateKey, $streamKey, $applicationKey));
     }
     /** @var ArrayList $aggregateIdCollection */
     $aggregateIdCollection = $streamCollection->get($aggregateKey);
     return new EventStream($streamName, $aggregateId, $aggregateIdCollection->find(Criteria::method('version')->gte($aggregateVersion->patch()))->toArray());
 }
 /**
  * Test visitMethod.
  */
 public function testVisitMethod()
 {
     $this->notSupportedOperationTest(Criteria::method('foo')->selector());
 }
Example #5
0
 /**
  * Test method.
  */
 public function testMethod()
 {
     $this->fieldSelectorTest(Criteria::method('foo'), Method::class, 'foo');
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function get(IdInterface $id)
 {
     return $this->collection->findOne(Criteria::method('id')->eq($id));
 }