/** * {@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)))); }
/** * @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; }
/** * 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; }
/** * @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; }
/** * 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)); }
/** * {@inheritdoc} */ public function indexOf($element) { $criteria = Criteria::same($element); foreach ($this->elements as $key => $value) { if ($criteria->evaluate($value)) { return $key; } } return -1; }
/** * {@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 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); }
/** * {@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)); }
/** * Test not. */ public function testNot() { $this->given($specification = Criteria::gt(5))->given($criteria = Criteria::not($specification))->then()->variable($criteria)->isEqualTo($specification->not()); }
/** * {@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(); } }
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(); }
/** * {@inheritdoc} */ protected function comparator() { return Comparator::by(Criteria::property('age')); }
/** * 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(); }
/** * 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(); }
/** * {@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; }
/** * 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); }
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(); }