/**
  * {@inheritdoc}
  */
 protected function projectDataProvider()
 {
     $forEachProjector = new ForEachProjector(Selectors::key('list'), new ObjectProjector());
     /** @var \Cubiche\Core\Projection\WhereProjector $projector */
     $projector = $this->newTestedInstance(Criteria::property('foo')->eq(1), $forEachProjector);
     $result = new DefaultProjectionBuilder();
     $result->set('foo', 1);
     return array(array($projector, array('list' => array((object) array('foo' => 1), (object) array('foo' => 2), (object) array('foo' => 3))), new \ArrayIterator(array($result))));
 }
Beispiel #2
0
 /**
  * @param mixed $value
  *
  * @return $this
  */
 public function notContains($value)
 {
     $collection = $this->valueAsCollection();
     if ($collection->findOne(Criteria::eq($value)) !== null) {
         $this->fail($this->getLocale()->_('The list contain an element with this value %s', $value));
     } else {
         $this->pass();
     }
     return $this;
 }
Beispiel #3
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;
 }
Beispiel #4
0
 /**
  * @param MiddlewareInterface $middleware
  *
  * @return int|null
  */
 protected function middlewarePriority(MiddlewareInterface $middleware)
 {
     /** @var ArrayList $collection */
     foreach ($this->middlewares as $priority => $collection) {
         $targetMiddleware = $collection->findOne(Criteria::eq($middleware));
         if ($targetMiddleware !== null) {
             return $priority;
         }
     }
     return;
 }
Beispiel #5
0
 /**
  * Test findOne.
  */
 public function testFindOne()
 {
     $this->given($unique = $this->uniqueValue(), $criteria = Criteria::eq($unique), $emptyCollection = $this->emptyCollection())->when($findResult = $emptyCollection->findOne($criteria))->then()->variable($findResult)->isNull()->and()->when($emptyCollection->add($unique), $findResult = $emptyCollection->findOne($criteria))->then()->variable($findResult)->isEqualTo($unique);
     $this->given($unique = $this->uniqueValue(), $criteria = Criteria::eq($unique), $randomCollection = $this->randomCollection())->when($findResult = $randomCollection->findOne($criteria))->then()->variable($findResult)->isNull()->and()->when($randomCollection->add($unique), $findResult = $randomCollection->findOne($criteria))->then()->variable($findResult)->isEqualTo($unique);
 }
 public function testFilteredDataSource()
 {
     $this->given($searchCriteria = Criteria::false(), $emptyDataSource = $this->emptyDataSource())->then->boolean($emptyDataSource->isFiltered())->isFalse()->and->when($filteredDataSource = $emptyDataSource->filteredDataSource($searchCriteria))->then->boolean($filteredDataSource->isFiltered())->isTrue()->variable($filteredDataSource->searchCriteria())->isEqualTo($searchCriteria);
     $this->given($searchCriteria = Criteria::true(), $filteredCriteria = Criteria::false(), $randomDataSource = $this->randomDataSource($searchCriteria))->then->boolean($randomDataSource->isFiltered())->isTrue()->and->when($filteredDataSource = $randomDataSource->filteredDataSource($filteredCriteria))->then->boolean($filteredDataSource->isFiltered())->isTrue()->variable($filteredDataSource->searchCriteria())->isEqualTo($searchCriteria->andX($filteredCriteria));
 }
Beispiel #7
0
 /**
  * {@inheritdoc}
  */
 public function indexOf($element)
 {
     $criteria = Criteria::same($element);
     foreach ($this->elements as $key => $value) {
         if ($criteria->evaluate($value)) {
             return $key;
         }
     }
     return -1;
 }
Beispiel #8
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());
 }
Beispiel #9
0
 /**
  * Test evaluate at least zero.
  */
 public function testEvaluateAtLeastZero()
 {
     $this->given($atLeast = $this->newTestedInstance(0, Criteria::this(), Criteria::gt(5)))->then()->boolean($atLeast->evaluate(array()))->isTrue()->boolean($atLeast->evaluate(array(1, 2, 3)))->isTrue();
 }
 /**
  * Test findOne.
  */
 public function testFindOne()
 {
     $this->given($repository = $this->emptyRepository())->and($value = $this->randomValue())->when($repository->persist($value))->then()->object($repository->findOne(Criteria::property('id')->eq($value->id())))->isEqualTo($value);
 }
Beispiel #11
0
 /**
  * {@inheritdoc}
  */
 public function defaultConstructorArguments()
 {
     return array(Criteria::this(), Criteria::gt(5));
 }
 /**
  * Test visitAtLeast.
  */
 public function testAtLeast()
 {
     $this->visitTest(Criteria::property('foo')->any(Criteria::property('bar')->gt(10)), function () {
         $qb = $this->createQueryBuilder();
         return $qb->field('foo')->elemMatch($qb->expr()->field('bar')->gt(10));
     });
     $this->notSupportedOperationTest(Criteria::property('foo')->atLeast(2, Criteria::property('bar')->gt(10)));
 }
 /**
  * {@inheritdoc}
  */
 public function defaultConstructorArguments()
 {
     return array(Criteria::lte(25), Criteria::gt(30));
 }
Beispiel #14
0
 /**
  * Test not.
  */
 public function testNot()
 {
     $this->given($specification = Criteria::gt(5))->given($criteria = Criteria::not($specification))->then()->variable($criteria)->isEqualTo($specification->not());
 }
Beispiel #15
0
 /**
  * {@inheritdoc}
  */
 public function get(IdInterface $id)
 {
     return $this->collection->findOne(Criteria::method('id')->eq($id));
 }
 /**
  * @param QueryBuilder $queryBuilder1
  * @param QueryBuilder $queryBuilder2
  *
  * @return bool
  */
 protected function hasSameOperator(QueryBuilder $queryBuilder1, QueryBuilder $queryBuilder2)
 {
     $intersection = new ArrayHashMap(\array_intersect_key($queryBuilder1->getQueryArray(), $queryBuilder2->getQueryArray()));
     return $intersection->keys()->findOne(Criteria::callback(function ($value) {
         return \strpos($value, '$') === 0;
     })) !== null;
 }
 /**
  * @return \Cubiche\Core\Specification\SpecificationInterface
  */
 protected function newRandomSpecification()
 {
     switch (\rand(0, 3)) {
         case 0:
             return Criteria::eq(5);
         case 1:
             return Criteria::gte(5);
         case 2:
             return Criteria::property('foo')->lte(10);
         case 3:
         default:
             return Criteria::false();
     }
 }
Beispiel #18
0
 public function testIsFiltered()
 {
     $this->given($datasource = $this->randomDataSource())->then->boolean($datasource->isFiltered())->isFalse()->given($searchCriteria = Criteria::false(), $datasource = $this->randomDataSource($searchCriteria))->then->boolean($datasource->isFiltered())->isTrue();
 }
Beispiel #19
0
 /**
  * {@inheritdoc}
  */
 protected function comparator()
 {
     return Comparator::by(Criteria::property('age'));
 }
Beispiel #20
0
 /**
  * Test find.
  */
 public function testFind()
 {
     $this->given($unique = $this->uniqueValue(), $criteria = Criteria::same($unique), $emptyCollection = $this->emptyCollection())->when($findResult = $emptyCollection->find($criteria))->then()->collection($findResult)->isEmpty();
     $this->given($unique = $this->uniqueValue(), $criteria = Criteria::same($unique), $randomCollection = $this->randomCollection())->when($findResult = $randomCollection->find($criteria))->then()->collection($findResult)->isEmpty();
 }
Beispiel #21
0
 /**
  * Test evaluate Equatable instance.
  */
 public function testEvaluateEquatable()
 {
     $this->given($eq = Criteria::eq(new Value(5)))->then()->boolean($eq->evaluate(new Value(5)))->isTrue()->boolean($eq->evaluate(new Value(5.0)))->isTrue()->boolean($eq->evaluate(new Value(4)))->isFalse();
 }
Beispiel #22
0
 /**
  * {@inheritdoc}
  */
 public function remove($element)
 {
     $criteria = Criteria::same($element);
     foreach ($this->elements as $key => $value) {
         if ($criteria->evaluate($value)) {
             unset($this->elements[$key]);
             $this->elements = array_values($this->elements);
             return true;
         }
     }
     return false;
 }
Beispiel #23
0
 /**
  * Test find.
  */
 public function testFind()
 {
     parent::testFind();
     $this->given($unique = $this->uniqueValue(), $criteria = Criteria::same($unique), $emptyCollection = $this->emptyCollection())->when($emptyCollection->set('foo', $unique))->and($findResult = $emptyCollection->find($criteria))->then()->hashmap($findResult)->size()->isEqualTo(1)->array($findResult->toArray())->contains($unique);
     $this->given($unique = $this->uniqueValue(), $criteria = Criteria::same($unique), $randomCollection = $this->randomCollection())->when($randomCollection->set('bar', $unique))->and($findResult = $randomCollection->find($criteria))->then()->array($findResult->toArray())->contains($unique);
 }
Beispiel #24
0
 public function testKeys()
 {
     $this->given($collection = $this->emptyCollection())->then()->variable($collection->keys()->findOne(Criteria::eq('foo')))->isNull()->variable($collection->keys()->findOne(Criteria::eq('bar')))->isNull()->and()->when($collection->set('foo', 12))->and($collection->set('bar', 'baz'))->then()->variable($collection->keys()->findOne(Criteria::eq('foo')))->isNotNull()->variable($collection->keys()->findOne(Criteria::eq('bar')))->isNotNull();
 }