From 7e0f3a9b5a5472f7b4a17cdb5efc73524e1d39b3 Mon Sep 17 00:00:00 2001 From: Constantine Karnaukhov Date: Sat, 29 May 2021 12:06:06 +0400 Subject: [PATCH] refactor: rename constrain to scope --- src/Factory.php | 34 +++++----- src/ORM.php | 2 +- src/Relation/Pivoted/PivotedPromise.php | 12 ++-- src/SchemaInterface.php | 35 +++++----- src/Select.php | 19 ++++-- src/Select/AbstractLoader.php | 44 ++++++++----- src/Select/ConstrainInterface.php | 18 ++--- src/Select/JoinableLoader.php | 48 +++++++------- src/Select/Loader/BelongsToLoader.php | 14 ++-- src/Select/Loader/HasManyLoader.php | 18 ++--- src/Select/Loader/HasOneLoader.php | 14 ++-- src/Select/Loader/ManyToManyLoader.php | 33 +++++----- src/Select/Loader/PivotLoader.php | 12 ++-- src/Select/QueryBuilder.php | 2 +- src/Select/QueryConstrain.php | 34 ++-------- src/Select/RootLoader.php | 8 +-- src/Select/Scope/QueryScope.php | 46 +++++++++++++ src/Select/ScopeInterface.php | 25 +++++++ src/Select/Source.php | 30 +++++++-- src/Select/SourceInterface.php | 17 ++++- src/Select/Traits/ConstrainTrait.php | 45 +++---------- src/Select/Traits/ScopeTrait.php | 66 +++++++++++++++++++ .../Classless/ClasslessHasManyPromiseTest.php | 4 +- .../ClasslessInverseRelationTest.php | 6 +- .../Postgres/SequenceDefaultValueTest.php | 4 +- tests/ORM/EmbeddedLoaderTest.php | 4 +- tests/ORM/Fixtures/DifferentSource.php | 21 +++++- ...yConstrain.php => LeveledHasManyScope.php} | 4 +- ...letedConstrain.php => NotDeletedScope.php} | 4 +- tests/ORM/Fixtures/ProfilePromise.php | 4 +- ...train.php => ShortLeveledHasManyScope.php} | 4 +- ...ortByIDConstrain.php => SortByIDScope.php} | 4 +- ...Constrain.php => SortByLevelDESCScope.php} | 4 +- ...evelConstrain.php => SortByLevelScope.php} | 4 +- ...tByMsgConstrain.php => SortByMsgScope.php} | 4 +- tests/ORM/Fixtures/UserPromise.php | 4 +- tests/ORM/HasManyConstrainTest.php | 36 +++++----- tests/ORM/HasManyNestedConditionTest.php | 4 +- tests/ORM/HasManyPromiseTest.php | 4 +- tests/ORM/HasManyRelationTest.php | 6 +- tests/ORM/HasManySourceTest.php | 46 ++++++------- tests/ORM/InstantiatorTest.php | 4 +- tests/ORM/InverseRelationTest.php | 6 +- tests/ORM/ManyToManyConstrainTest.php | 36 +++++----- tests/ORM/ManyToManyConstrainedPivotTest.php | 6 +- tests/ORM/ManyToManyConstrainedTest.php | 24 +++---- tests/ORM/ManyToManyDeepenedTest.php | 4 +- tests/ORM/ManyToManyPromiseEagerLoadTest.php | 8 +-- tests/ORM/ManyToManyPromiseTest.php | 4 +- tests/ORM/ManyToManyRelationTest.php | 3 +- .../Morphed/MorphedHasManyConstrainTest.php | 50 +++++++------- tests/ORM/QueryBuilderTest.php | 4 +- tests/ORM/RelationWithColumnAliasTest.php | 4 +- tests/ORM/SoftDeletesTest.php | 8 +-- tests/ORM/TypecastTest.php | 4 +- tests/ORM/UUIDTest.php | 4 +- 56 files changed, 532 insertions(+), 384 deletions(-) create mode 100644 src/Select/Scope/QueryScope.php create mode 100644 src/Select/ScopeInterface.php create mode 100644 src/Select/Traits/ScopeTrait.php rename tests/ORM/Fixtures/{LeveledHasManyConstrain.php => LeveledHasManyScope.php} (70%) rename tests/ORM/Fixtures/{NotDeletedConstrain.php => NotDeletedScope.php} (76%) rename tests/ORM/Fixtures/{ShortLeveledHasManyConstrain.php => ShortLeveledHasManyScope.php} (69%) rename tests/ORM/Fixtures/{SortByIDConstrain.php => SortByIDScope.php} (76%) rename tests/ORM/Fixtures/{SortByLevelDESCConstrain.php => SortByLevelDESCScope.php} (75%) rename tests/ORM/Fixtures/{SortByLevelConstrain.php => SortByLevelScope.php} (75%) rename tests/ORM/Fixtures/{SortByMsgConstrain.php => SortByMsgScope.php} (76%) diff --git a/src/Factory.php b/src/Factory.php index 005562107..1b901a68c 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -15,9 +15,9 @@ use Cycle\ORM\Exception\TypecastException; use Cycle\ORM\Mapper\Mapper; use Cycle\ORM\Relation\RelationInterface; -use Cycle\ORM\Select\ConstrainInterface; use Cycle\ORM\Select\LoaderInterface; use Cycle\ORM\Select\Repository; +use Cycle\ORM\Select\ScopeInterface; use Cycle\ORM\Select\Source; use Cycle\ORM\Select\SourceInterface; use Spiral\Core\Container; @@ -39,9 +39,9 @@ final class Factory implements FactoryInterface /** @var array */ private $defaults = [ Schema::REPOSITORY => Repository::class, - Schema::SOURCE => Source::class, - Schema::MAPPER => Mapper::class, - Schema::CONSTRAIN => null, + Schema::SOURCE => Source::class, + Schema::MAPPER => Mapper::class, + Schema::SCOPE => null, ]; /** @@ -86,8 +86,8 @@ public function mapper( return $this->factory->make( $class, [ - 'orm' => $orm, - 'role' => $role, + 'orm' => $orm, + 'role' => $role, 'schema' => $schema->define($role, Schema::SCHEMA) ] ); @@ -107,8 +107,8 @@ public function loader( return $this->config->getLoader($schema[Relation::TYPE])->resolve( $this->factory, [ - 'orm' => $orm, - 'name' => $relation, + 'orm' => $orm, + 'name' => $relation, 'target' => $schema[Relation::TARGET], 'schema' => $schema[Relation::SCHEMA] ] @@ -130,8 +130,8 @@ public function relation( return $this->config->getRelation($type)->resolve( $this->factory, [ - 'orm' => $orm, - 'name' => $relation, + 'orm' => $orm, + 'name' => $relation, 'target' => $relSchema[Relation::TARGET], 'schema' => $relSchema[Relation::SCHEMA] + [Relation::LOAD => $relSchema[Relation::LOAD] ?? null], ] @@ -165,8 +165,8 @@ public function repository( $class, [ 'select' => $select, - 'orm' => $orm, - 'role' => $role, + 'orm' => $orm, + 'role' => $role, ] ); } @@ -194,17 +194,17 @@ public function source( $schema->define($role, Schema::TABLE) ); - $constrain = $schema->define($role, Schema::CONSTRAIN) ?? $this->defaults[Schema::CONSTRAIN]; + $scope = $schema->define($role, Schema::SCOPE) ?? $this->defaults[Schema::SCOPE]; - if ($constrain === null) { + if ($scope === null) { return $source; } - if (!is_subclass_of($constrain, ConstrainInterface::class)) { - throw new TypecastException($constrain . ' does not implement ' . ConstrainInterface::class); + if (!is_subclass_of($scope, ScopeInterface::class)) { + throw new TypecastException($scope . ' does not implement ' . ScopeInterface::class); } - return $source->withConstrain(is_object($constrain) ? $constrain : $this->factory->make($constrain)); + return $source->withScope(is_object($scope) ? $scope : $this->factory->make($scope)); } /** diff --git a/src/ORM.php b/src/ORM.php index 87ec1e885..0294e9bbf 100644 --- a/src/ORM.php +++ b/src/ORM.php @@ -265,7 +265,7 @@ public function getRepository($entity): RepositoryInterface if ($this->schema->define($role, Schema::TABLE) !== null) { $select = new Select($this, $role); - $select->constrain($this->getSource($role)->getConstrain()); + $select->scope($this->getSource($role)->getScope()); } return $this->repositories[$role] = $this->factory->repository($this, $this->schema, $role, $select); diff --git a/src/Relation/Pivoted/PivotedPromise.php b/src/Relation/Pivoted/PivotedPromise.php index 62cc94e22..d8d78848e 100644 --- a/src/Relation/Pivoted/PivotedPromise.php +++ b/src/Relation/Pivoted/PivotedPromise.php @@ -44,9 +44,9 @@ final class PivotedPromise implements PromiseInterface /** * @param ORMInterface $orm - * @param string $target - * @param array $relationSchema - * @param mixed $innerKey + * @param string $target + * @param array $relationSchema + * @param mixed $innerKey */ public function __construct(ORMInterface $orm, string $target, array $relationSchema, $innerKey) { @@ -113,9 +113,9 @@ public function __resolve() /** @var ManyToManyLoader $loader */ $loader = $loader->withContext($loader, [ - 'constrain' => $this->orm->getSource($this->target)->getConstrain(), - 'as' => $this->target, - 'method' => JoinableLoader::POSTLOAD + 'scope' => $this->orm->getSource($this->target)->getScope(), + 'as' => $this->target, + 'method' => JoinableLoader::POSTLOAD ]); $query = $loader->configureQuery($query, [$this->innerKey]); diff --git a/src/SchemaInterface.php b/src/SchemaInterface.php index eb1cb028b..4637ceab3 100644 --- a/src/SchemaInterface.php +++ b/src/SchemaInterface.php @@ -18,21 +18,26 @@ interface SchemaInterface /* * Various segments of schema. */ - public const ROLE = 0; - public const ENTITY = 1; - public const MAPPER = 2; - public const SOURCE = 3; - public const REPOSITORY = 4; - public const DATABASE = 5; - public const TABLE = 6; - public const PRIMARY_KEY = 7; + public const ROLE = 0; + public const ENTITY = 1; + public const MAPPER = 2; + public const SOURCE = 3; + public const REPOSITORY = 4; + public const DATABASE = 5; + public const TABLE = 6; + public const PRIMARY_KEY = 7; public const FIND_BY_KEYS = 8; - public const COLUMNS = 9; - public const RELATIONS = 10; - public const CHILDREN = 11; - public const CONSTRAIN = 12; - public const TYPECAST = 13; - public const SCHEMA = 14; + public const COLUMNS = 9; + public const RELATIONS = 10; + public const CHILDREN = 11; + public const SCOPE = 12; + public const TYPECAST = 13; + public const SCHEMA = 14; + + /** + * @deprecated use {@see SchemaInterface::SCOPE} instead + */ + public const CONSTRAIN = self::SCOPE; /** * Return all roles defined within the schema. @@ -63,7 +68,7 @@ public function defines(string $role): bool; * Example: $schema->define(User::class, SchemaInterface::DATABASE); * * @param string $role - * @param int $property See ORM constants. + * @param int $property See ORM constants. * @return mixed * * @throws SchemaException diff --git a/src/Select.php b/src/Select.php index 942a857e3..69bb25323 100644 --- a/src/Select.php +++ b/src/Select.php @@ -17,6 +17,7 @@ use Cycle\ORM\Select\JoinableLoader; use Cycle\ORM\Select\QueryBuilder; use Cycle\ORM\Select\RootLoader; +use Cycle\ORM\Select\ScopeInterface; use IteratorAggregate; use Spiral\Database\Query\SelectQuery; use Spiral\Pagination\PaginableInterface; @@ -114,18 +115,28 @@ public function __clone() } /** - * Create new Selector with applied scope. By default no constrain used. + * Create new Selector with applied scope. By default no scope used. * - * @param ConstrainInterface|null $constrain + * @param ScopeInterface|null $scope * @return Select */ - public function constrain(ConstrainInterface $constrain = null): self + public function scope(?ScopeInterface $scope): self { - $this->loader->setConstrain($constrain); + $this->loader->setScope($scope); return $this; } + /** + * @deprecated Will be dropped in next major release. Use {@see scope()} instead. + * @param ConstrainInterface|null $constrain + * @return Select + */ + public function constrain(?ConstrainInterface $constrain = null): self + { + return $this->scope($constrain); + } + /** * Get Query proxy. * diff --git a/src/Select/AbstractLoader.php b/src/Select/AbstractLoader.php index 6cbafd73c..ab2125c1c 100644 --- a/src/Select/AbstractLoader.php +++ b/src/Select/AbstractLoader.php @@ -20,6 +20,7 @@ use Cycle\ORM\Schema; use Cycle\ORM\Select\Traits\AliasTrait; use Cycle\ORM\Select\Traits\ChainTrait; +use Cycle\ORM\Select\Traits\ScopeTrait; use Spiral\Database\Query\SelectQuery; /** @@ -45,14 +46,15 @@ abstract class AbstractLoader implements LoaderInterface { use ChainTrait; use AliasTrait; + use ScopeTrait; // Loading methods for data loaders. - public const INLOAD = 1; - public const POSTLOAD = 2; - public const JOIN = 3; + public const INLOAD = 1; + public const POSTLOAD = 2; + public const JOIN = 3; public const LEFT_JOIN = 4; - /** @var ORMInterface|SourceProviderInterface @internal */ + /** @var ORMInterface @internal */ protected $orm; /** @var string */ @@ -60,8 +62,8 @@ abstract class AbstractLoader implements LoaderInterface /** @var array */ protected $options = [ - 'load' => false, - 'constrain' => true, + 'load' => false, + 'scope' => true, ]; /** @var LoaderInterface[] */ @@ -75,12 +77,14 @@ abstract class AbstractLoader implements LoaderInterface /** * @param ORMInterface $orm - * @param string $target + * @param string $target */ public function __construct(ORMInterface $orm, string $target) { $this->orm = $orm; $this->target = $target; + + $this->setScope($this->getSource()->getScope()); } /** @@ -132,6 +136,8 @@ public function getSource(): SourceInterface */ public function withContext(LoaderInterface $parent, array $options = []): LoaderInterface { + $options = $this->prepareOptions($options); + // check that given options are known if (!empty($wrong = array_diff(array_keys($options), array_keys($this->options)))) { throw new LoaderException( @@ -154,9 +160,9 @@ public function withContext(LoaderInterface $parent, array $options = []): Loade * Load the relation. * * @param string $relation Relation name, or chain of relations separated by. - * @param array $options Loader options (to be applied to last chain element only). - * @param bool $join When set to true loaders will be forced into JOIN mode. - * @param bool $load Load relation data. + * @param array $options Loader options (to be applied to last chain element only). + * @param bool $join When set to true loaders will be forced into JOIN mode. + * @param bool $load Load relation data. * @return LoaderInterface Must return loader for a requested relation. * * @throws LoaderException @@ -279,7 +285,7 @@ abstract protected function initNode(): AbstractNode; */ protected function configureQuery(SelectQuery $query): SelectQuery { - $query = $this->applyConstrain($query); + $query = $this->applyScope($query); foreach ($this->join as $loader) { $query = $loader->configureQuery($query); @@ -294,12 +300,6 @@ protected function configureQuery(SelectQuery $query): SelectQuery return $query; } - /** - * @param SelectQuery $query - * @return SelectQuery - */ - abstract protected function applyConstrain(SelectQuery $query): SelectQuery; - /** * Define schema option associated with the entity. * @@ -325,4 +325,14 @@ protected function getEagerRelations(): \Generator } } } + + protected function prepareOptions(array $options): array + { + if (array_key_exists('constrain', $options) && !array_key_exists('scope', $options)) { + $options['scope'] = $options['constrain']; + } + unset($options['constrain']); + + return $options; + } } diff --git a/src/Select/ConstrainInterface.php b/src/Select/ConstrainInterface.php index d54bccba5..10c5cf814 100644 --- a/src/Select/ConstrainInterface.php +++ b/src/Select/ConstrainInterface.php @@ -11,15 +11,15 @@ namespace Cycle\ORM\Select; -/** - * Provides the ability to modify the selector and/or entity loader. Can be used to implement multi-table inheritance. - */ -interface ConstrainInterface -{ +use function class_alias; + +class_alias(ScopeInterface::class, __NAMESPACE__ . '\ConstrainInterface'); + +if (false) { /** - * Configure query and loader pair using proxy strategy. - * - * @param QueryBuilder $query + * @deprecated Use {@see ScopeInterface} instead. */ - public function apply(QueryBuilder $query); + interface ConstrainInterface extends ScopeInterface + { + } } diff --git a/src/Select/JoinableLoader.php b/src/Select/JoinableLoader.php index c29633d54..e2559a3da 100644 --- a/src/Select/JoinableLoader.php +++ b/src/Select/JoinableLoader.php @@ -16,7 +16,6 @@ use Cycle\ORM\Parser\AbstractNode; use Cycle\ORM\Schema; use Cycle\ORM\Select\Traits\ColumnsTrait; -use Cycle\ORM\Select\Traits\ConstrainTrait; use Spiral\Database\Query\SelectQuery; use Spiral\Database\StatementInterface; @@ -26,7 +25,6 @@ abstract class JoinableLoader extends AbstractLoader implements JoinableInterface { use ColumnsTrait; - use ConstrainTrait; /** * Default set of relation options. Child implementation might defined their of default options. @@ -35,25 +33,25 @@ abstract class JoinableLoader extends AbstractLoader implements JoinableInterfac */ protected $options = [ // load relation data - 'load' => false, + 'load' => false, // true or instance to enable, false or null to disable - 'constrain' => true, + 'scope' => true, // scope to be used for the relation - 'method' => null, + 'method' => null, // load method, see AbstractLoader constants - 'minify' => true, + 'minify' => true, // when true all loader columns will be minified (only for loading) - 'as' => null, + 'as' => null, // table alias - 'using' => null, + 'using' => null, // alias used by another relation - 'where' => null, + 'where' => null, // where conditions (if any) ]; @@ -66,9 +64,9 @@ abstract class JoinableLoader extends AbstractLoader implements JoinableInterfac /** * @param ORMInterface $orm - * @param string $name - * @param string $target - * @param array $schema + * @param string $name + * @param string $target + * @param array $schema */ public function __construct(ORMInterface $orm, string $name, string $target, array $schema) { @@ -102,9 +100,11 @@ public function getAlias(): string */ public function withContext(LoaderInterface $parent, array $options = []): LoaderInterface { + $options = $this->prepareOptions($options); + /** * @var AbstractLoader $parent - * @var self $loader + * @var self $loader */ $loader = parent::withContext($parent, $options); @@ -122,14 +122,12 @@ public function withContext(LoaderInterface $parent, array $options = []): Loade //Calculate table alias $loader->options['as'] = $loader->calculateAlias($parent); - if (array_key_exists('constrain', $options)) { - if ($loader->options['constrain'] instanceof ConstrainInterface) { - $loader->setConstrain($loader->options['constrain']); - } elseif (is_string($loader->options['constrain'])) { - $loader->setConstrain($this->orm->getFactory()->make($loader->options['constrain'])); + if (array_key_exists('scope', $options)) { + if ($loader->options['scope'] instanceof ScopeInterface) { + $loader->setScope($loader->options['scope']); + } elseif (is_string($loader->options['scope'])) { + $loader->setScope($this->orm->getFactory()->make($loader->options['scope'])); } - } else { - $loader->setConstrain($this->getSource()->getConstrain()); } if ($loader->isLoaded()) { @@ -204,7 +202,7 @@ public function isLoaded(): bool * Configure query with conditions, joins and columns. * * @param SelectQuery $query - * @param array $outerKeys Set of OUTER_KEY values collected by parent loader. + * @param array $outerKeys Set of OUTER_KEY values collected by parent loader. * @return SelectQuery */ public function configureQuery(SelectQuery $query, array $outerKeys = []): SelectQuery @@ -218,7 +216,7 @@ public function configureQuery(SelectQuery $query, array $outerKeys = []): Selec $this->mountColumns($query, $this->options['minify'], '', true); } - if ($this->options['load'] instanceof ConstrainInterface) { + if ($this->options['load'] instanceof ScopeInterface) { $this->options['load']->apply($this->makeQueryBuilder($query)); } @@ -234,10 +232,10 @@ public function configureQuery(SelectQuery $query, array $outerKeys = []): Selec * @param SelectQuery $query * @return SelectQuery */ - protected function applyConstrain(SelectQuery $query): SelectQuery + protected function applyScope(SelectQuery $query): SelectQuery { - if ($this->constrain !== null) { - $this->constrain->apply($this->makeQueryBuilder($query)); + if ($this->scope !== null) { + $this->scope->apply($this->makeQueryBuilder($query)); } return $query; diff --git a/src/Select/Loader/BelongsToLoader.php b/src/Select/Loader/BelongsToLoader.php index 2b8eed3d2..87264ac98 100644 --- a/src/Select/Loader/BelongsToLoader.php +++ b/src/Select/Loader/BelongsToLoader.php @@ -34,13 +34,13 @@ class BelongsToLoader extends JoinableLoader * @var array */ protected $options = [ - 'load' => false, - 'constrain' => true, - 'method' => self::POSTLOAD, - 'minify' => true, - 'as' => null, - 'using' => null, - 'where' => null, + 'load' => false, + 'scope' => true, + 'method' => self::POSTLOAD, + 'minify' => true, + 'as' => null, + 'using' => null, + 'where' => null, ]; /** diff --git a/src/Select/Loader/HasManyLoader.php b/src/Select/Loader/HasManyLoader.php index 7ce6f0688..21f79d263 100644 --- a/src/Select/Loader/HasManyLoader.php +++ b/src/Select/Loader/HasManyLoader.php @@ -35,14 +35,14 @@ class HasManyLoader extends JoinableLoader * @var array */ protected $options = [ - 'load' => false, - 'constrain' => true, - 'method' => self::POSTLOAD, - 'minify' => true, - 'as' => null, - 'using' => null, - 'where' => null, - 'orderBy' => null, + 'load' => false, + 'scope' => true, + 'method' => self::POSTLOAD, + 'minify' => true, + 'as' => null, + 'using' => null, + 'where' => null, + 'orderBy' => null, ]; /** @@ -60,7 +60,7 @@ public function __construct(ORMInterface $orm, string $name, string $target, arr */ public function configureQuery(SelectQuery $query, array $outerKeys = []): SelectQuery { - if ($this->isLoaded() && $this->isJoined() && (int) $query->getLimit() !== 0) { + if ($this->isLoaded() && $this->isJoined() && (int)$query->getLimit() !== 0) { throw new LoaderException('Unable to load data using join with limit on parent query'); } diff --git a/src/Select/Loader/HasOneLoader.php b/src/Select/Loader/HasOneLoader.php index c9f03f990..e5d9628ca 100644 --- a/src/Select/Loader/HasOneLoader.php +++ b/src/Select/Loader/HasOneLoader.php @@ -38,13 +38,13 @@ class HasOneLoader extends JoinableLoader * @var array */ protected $options = [ - 'load' => false, - 'constrain' => true, - 'method' => self::INLOAD, - 'minify' => true, - 'as' => null, - 'using' => null, - 'where' => null + 'load' => false, + 'scope' => true, + 'method' => self::INLOAD, + 'minify' => true, + 'as' => null, + 'using' => null, + 'where' => null ]; /** diff --git a/src/Select/Loader/ManyToManyLoader.php b/src/Select/Loader/ManyToManyLoader.php index 32c43de4d..cfa3e2641 100644 --- a/src/Select/Loader/ManyToManyLoader.php +++ b/src/Select/Loader/ManyToManyLoader.php @@ -24,7 +24,6 @@ use Cycle\ORM\Select\Traits\WhereTrait; use Spiral\Database\Injection\Parameter; use Spiral\Database\Query\SelectQuery; -use Spiral\Database\StatementInterface; class ManyToManyLoader extends JoinableLoader { @@ -37,15 +36,15 @@ class ManyToManyLoader extends JoinableLoader * @var array */ protected $options = [ - 'load' => false, - 'constrain' => true, - 'method' => self::POSTLOAD, - 'minify' => true, - 'as' => null, - 'using' => null, - 'where' => null, - 'orderBy' => null, - 'pivot' => null, + 'load' => false, + 'scope' => true, + 'method' => self::POSTLOAD, + 'minify' => true, + 'as' => null, + 'using' => null, + 'where' => null, + 'orderBy' => null, + 'pivot' => null, ]; /** @var PivotLoader */ @@ -73,17 +72,19 @@ public function __clone() /** * @param LoaderInterface $parent - * @param array $options + * @param array $options * @return LoaderInterface */ public function withContext(LoaderInterface $parent, array $options = []): LoaderInterface { + $options = $this->prepareOptions($options); + /** @var ManyToManyLoader $loader */ $loader = parent::withContext($parent, $options); $loader->pivot = $loader->pivot->withContext( $loader, [ - 'load' => $loader->isLoaded(), + 'load' => $loader->isLoaded(), 'method' => $options['method'] ?? self::JOIN, ] + ($options['pivot'] ?? []) ); @@ -93,9 +94,9 @@ public function withContext(LoaderInterface $parent, array $options = []): Loade /** * @param string $relation - * @param array $options - * @param bool $join - * @param bool $load + * @param array $options + * @param bool $join + * @param bool $load * @return LoaderInterface */ public function loadRelation( @@ -122,7 +123,7 @@ public function loadRelation( */ public function configureQuery(SelectQuery $query, array $outerKeys = []): SelectQuery { - if ($this->isLoaded() && $this->isJoined() && (int) $query->getLimit() !== 0) { + if ($this->isLoaded() && $this->isJoined() && (int)$query->getLimit() !== 0) { throw new LoaderException('Unable to load data using join with limit on parent query'); } diff --git a/src/Select/Loader/PivotLoader.php b/src/Select/Loader/PivotLoader.php index 6ef3017d8..57328e9cd 100644 --- a/src/Select/Loader/PivotLoader.php +++ b/src/Select/Loader/PivotLoader.php @@ -33,12 +33,12 @@ class PivotLoader extends JoinableLoader * @var array */ protected $options = [ - 'load' => false, - 'constrain' => true, - 'method' => self::JOIN, - 'minify' => true, - 'as' => null, - 'using' => null + 'load' => false, + 'scope' => true, + 'method' => self::JOIN, + 'minify' => true, + 'as' => null, + 'using' => null ]; /** diff --git a/src/Select/QueryBuilder.php b/src/Select/QueryBuilder.php index 031d4e1bc..69523f34f 100644 --- a/src/Select/QueryBuilder.php +++ b/src/Select/QueryBuilder.php @@ -151,7 +151,7 @@ public function resolve(string $identifier, bool $autoload = true): string $loader = $this->findLoader(substr($identifier, 0, $split), $autoload); if ($loader !== null) { return sprintf( - '%s.%s.', + '%s.%s', $loader->getAlias(), $loader->fieldAlias(substr($identifier, $split + 1)) ); diff --git a/src/Select/QueryConstrain.php b/src/Select/QueryConstrain.php index 221d50c41..f1d1b877d 100644 --- a/src/Select/QueryConstrain.php +++ b/src/Select/QueryConstrain.php @@ -1,42 +1,18 @@ where = $where; - $this->orderBy = $orderBy; - } +class_alias(Scope\QueryScope::class, __NAMESPACE__ . '\QueryConstrain'); +if (false) { /** - * @inheritdoc + * @deprecated Use {@see Scope\QueryScope} instead. */ - public function apply(QueryBuilder $query): void + class QueryConstrain extends Scope\QueryScope { - $query->where($this->where)->orderBy($this->orderBy); } } diff --git a/src/Select/RootLoader.php b/src/Select/RootLoader.php index de7b46e54..1a47be447 100644 --- a/src/Select/RootLoader.php +++ b/src/Select/RootLoader.php @@ -17,7 +17,6 @@ use Cycle\ORM\Parser\Typecast; use Cycle\ORM\Schema; use Cycle\ORM\Select\Traits\ColumnsTrait; -use Cycle\ORM\Select\Traits\ConstrainTrait; use Spiral\Database\Query\SelectQuery; use Spiral\Database\StatementInterface; @@ -30,12 +29,11 @@ final class RootLoader extends AbstractLoader { use ColumnsTrait; - use ConstrainTrait; /** @var array */ protected $options = [ - 'load' => true, - 'constrain' => true, + 'load' => true, + 'scope' => true, ]; /** @var SelectQuery */ @@ -43,7 +41,7 @@ final class RootLoader extends AbstractLoader /** * @param ORMInterface $orm - * @param string $target + * @param string $target */ public function __construct(ORMInterface $orm, string $target) { diff --git a/src/Select/Scope/QueryScope.php b/src/Select/Scope/QueryScope.php new file mode 100644 index 000000000..d660755af --- /dev/null +++ b/src/Select/Scope/QueryScope.php @@ -0,0 +1,46 @@ +where = $where; + $this->orderBy = $orderBy; + } + + /** + * @inheritdoc + */ + public function apply(QueryBuilder $query): void + { + $query->where($this->where)->orderBy($this->orderBy); + } +} diff --git a/src/Select/ScopeInterface.php b/src/Select/ScopeInterface.php new file mode 100644 index 000000000..34f3a2323 --- /dev/null +++ b/src/Select/ScopeInterface.php @@ -0,0 +1,25 @@ +constrain = $constrain; + $source->scope = $scope; return $source; } @@ -64,8 +64,26 @@ public function withConstrain(?ConstrainInterface $constrain): SourceInterface /** * @inheritdoc */ + public function getScope(): ?ScopeInterface + { + return $this->scope; + } + + /** + * @inheritdoc + * @deprecated Use {@see withScope()} instead. + */ + public function withConstrain(?ConstrainInterface $constrain): SourceInterface + { + return $this->withScope($constrain); + } + + /** + * @inheritdoc + * @deprecated Use {@see getScope()} instead. + */ public function getConstrain(): ?ConstrainInterface { - return $this->constrain; + return $this->getScope(); } } diff --git a/src/Select/SourceInterface.php b/src/Select/SourceInterface.php index f296f9803..26f417812 100644 --- a/src/Select/SourceInterface.php +++ b/src/Select/SourceInterface.php @@ -35,14 +35,27 @@ public function getTable(): string; /** * Associate query constrain (or remove association). * - * @param ConstrainInterface|null $constrain + * @param ScopeInterface|null $scope * @return SourceInterface */ - public function withConstrain(?ConstrainInterface $constrain): SourceInterface; + public function withScope(?ScopeInterface $scope): SourceInterface; /** * Return associated query constrain. * + * @return ScopeInterface|null + */ + public function getScope(): ?ScopeInterface; + + /** + * @deprecated Use {@see withScope()} instead. + * @param ConstrainInterface|null $constrain + * @return SourceInterface + */ + public function withConstrain(?ConstrainInterface $constrain): SourceInterface; + + /** + * @deprecated Use {@see getScope()} instead. * @return ConstrainInterface|null */ public function getConstrain(): ?ConstrainInterface; diff --git a/src/Select/Traits/ConstrainTrait.php b/src/Select/Traits/ConstrainTrait.php index eda2de7c5..73b06b0c7 100644 --- a/src/Select/Traits/ConstrainTrait.php +++ b/src/Select/Traits/ConstrainTrait.php @@ -11,47 +11,18 @@ namespace Cycle\ORM\Select\Traits; -use Cycle\ORM\Select\AbstractLoader; -use Cycle\ORM\Select\ConstrainInterface; -use Cycle\ORM\Select\QueryBuilder; -use Spiral\Database\Query\SelectQuery; +class_alias( + ScopeTrait::class, + __NAMESPACE__ . '\ConstrainTrait' +); -/** - * Provides the ability to assign the scope to the AbstractLoader. - */ -trait ConstrainTrait -{ - /** @var null|ConstrainInterface */ - protected $constrain; - - /** - * Associate scope with the selector. - * - * @param ConstrainInterface $constrain - * @return AbstractLoader|$this - */ - public function setConstrain(ConstrainInterface $constrain = null): self - { - $this->constrain = $constrain; - - return $this; - } - - /** - * @return string - */ - abstract public function getAlias(): string; +if (false) { /** - * @param SelectQuery $query - * @return SelectQuery + * @deprecated Use {@see ScopeTrait} instead. */ - protected function applyConstrain(SelectQuery $query): SelectQuery + trait ConstrainTrait { - if ($this->constrain !== null) { - $this->constrain->apply(new QueryBuilder($query, $this)); - } - - return $query; + use ScopeTrait; } } diff --git a/src/Select/Traits/ScopeTrait.php b/src/Select/Traits/ScopeTrait.php new file mode 100644 index 000000000..1629c5e5c --- /dev/null +++ b/src/Select/Traits/ScopeTrait.php @@ -0,0 +1,66 @@ +scope; + } + + /** + * Associate scope with the selector. + * @param ScopeInterface|null $scope + */ + public function setScope(?ScopeInterface $scope): void + { + $this->scope = $scope; + } + + /** + * @deprecated Use {@see setScope()} instead. + * @param ConstrainInterface|null $constrain + * @return AbstractLoader|$this + */ + public function setConstrain(?ConstrainInterface $constrain = null): self + { + $this->setScope($constrain); + + return $this; + } + + /** + * @param SelectQuery $query + * @return SelectQuery + */ + protected function applyScope(SelectQuery $query): SelectQuery + { + if ($this->scope !== null) { + $this->scope->apply(new QueryBuilder($query, $this)); + } + + return $query; + } +} diff --git a/tests/ORM/Classless/ClasslessHasManyPromiseTest.php b/tests/ORM/Classless/ClasslessHasManyPromiseTest.php index d8020e448..68c303a13 100644 --- a/tests/ORM/Classless/ClasslessHasManyPromiseTest.php +++ b/tests/ORM/Classless/ClasslessHasManyPromiseTest.php @@ -19,7 +19,7 @@ use Cycle\ORM\Schema; use Cycle\ORM\Select; use Cycle\ORM\Tests\BaseTest; -use Cycle\ORM\Tests\Fixtures\SortByIDConstrain; +use Cycle\ORM\Tests\Fixtures\SortByIDScope; use Cycle\ORM\Tests\Traits\TableTrait; use Cycle\ORM\Transaction; @@ -90,7 +90,7 @@ public function setUp(): void Schema::COLUMNS => ['id', 'user_id', 'message'], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => SortByIDConstrain::class + Schema::SCOPE => SortByIDScope::class ] ])); } diff --git a/tests/ORM/Classless/ClasslessInverseRelationTest.php b/tests/ORM/Classless/ClasslessInverseRelationTest.php index 2a5d9b726..77de9abca 100644 --- a/tests/ORM/Classless/ClasslessInverseRelationTest.php +++ b/tests/ORM/Classless/ClasslessInverseRelationTest.php @@ -17,7 +17,7 @@ use Cycle\ORM\Schema; use Cycle\ORM\Select; use Cycle\ORM\Tests\BaseTest; -use Cycle\ORM\Tests\Fixtures\SortByIDConstrain; +use Cycle\ORM\Tests\Fixtures\SortByIDScope; use Cycle\ORM\Tests\Traits\TableTrait; use Cycle\ORM\Transaction; @@ -79,7 +79,7 @@ public function setUp(): void ], ] ], - Schema::CONSTRAIN => SortByIDConstrain::class + Schema::SCOPE => SortByIDScope::class ], 'profile' => [ Schema::MAPPER => StdMapper::class, @@ -99,7 +99,7 @@ public function setUp(): void ], ], ], - Schema::CONSTRAIN => SortByIDConstrain::class + Schema::SCOPE => SortByIDScope::class ], ])); } diff --git a/tests/ORM/Driver/Postgres/SequenceDefaultValueTest.php b/tests/ORM/Driver/Postgres/SequenceDefaultValueTest.php index 5c1be200f..cdb151534 100644 --- a/tests/ORM/Driver/Postgres/SequenceDefaultValueTest.php +++ b/tests/ORM/Driver/Postgres/SequenceDefaultValueTest.php @@ -8,7 +8,7 @@ use Cycle\ORM\Schema; use Cycle\ORM\Select; use Cycle\ORM\Tests\BaseTest; -use Cycle\ORM\Tests\Fixtures\NotDeletedConstrain; +use Cycle\ORM\Tests\Fixtures\NotDeletedScope; use Cycle\ORM\Tests\Fixtures\SequenceDefaultValueMapper; use Cycle\ORM\Tests\Fixtures\User; use Cycle\ORM\Tests\Traits\TableTrait; @@ -56,7 +56,7 @@ public function setUp(): void ], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => NotDeletedConstrain::class + Schema::SCOPE => NotDeletedScope::class ] ] ) diff --git a/tests/ORM/EmbeddedLoaderTest.php b/tests/ORM/EmbeddedLoaderTest.php index 198326ec6..1410dea95 100644 --- a/tests/ORM/EmbeddedLoaderTest.php +++ b/tests/ORM/EmbeddedLoaderTest.php @@ -16,7 +16,7 @@ use Cycle\ORM\Schema; use Cycle\ORM\Select; use Cycle\ORM\Tests\Fixtures\Comment; -use Cycle\ORM\Tests\Fixtures\SortByIDConstrain; +use Cycle\ORM\Tests\Fixtures\SortByIDScope; use Cycle\ORM\Tests\Fixtures\User; use Cycle\ORM\Tests\Fixtures\UserCredentials; use Cycle\ORM\Tests\Traits\TableTrait; @@ -114,7 +114,7 @@ public function setUp(): void Schema::COLUMNS => ['id', 'user_id', 'message'], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => SortByIDConstrain::class + Schema::SCOPE => SortByIDScope::class ] ])); } diff --git a/tests/ORM/Fixtures/DifferentSource.php b/tests/ORM/Fixtures/DifferentSource.php index 79f2b33c1..0279143eb 100644 --- a/tests/ORM/Fixtures/DifferentSource.php +++ b/tests/ORM/Fixtures/DifferentSource.php @@ -5,25 +5,40 @@ namespace Cycle\ORM\Tests\Fixtures; use Cycle\ORM\Select\ConstrainInterface; +use Cycle\ORM\Select\ScopeInterface; use Cycle\ORM\Select\SourceInterface; use Spiral\Database\DatabaseInterface; class DifferentSource implements SourceInterface { - /** * @inheritDoc */ public function getDatabase(): DatabaseInterface { - // TODO: Implement getDatabase() method. - return null; + throw new \RuntimeException('Not implemented.'); } /** * @inheritDoc */ public function getTable(): string + { + throw new \RuntimeException('Not implemented.'); + } + + /** + * @inheritDoc + */ + public function withScope(?ScopeInterface $scope): SourceInterface + { + return $this; + } + + /** + * @inheritDoc + */ + public function getScope(): ?ScopeInterface { return null; } diff --git a/tests/ORM/Fixtures/LeveledHasManyConstrain.php b/tests/ORM/Fixtures/LeveledHasManyScope.php similarity index 70% rename from tests/ORM/Fixtures/LeveledHasManyConstrain.php rename to tests/ORM/Fixtures/LeveledHasManyScope.php index 47c3eba33..b706e3564 100644 --- a/tests/ORM/Fixtures/LeveledHasManyConstrain.php +++ b/tests/ORM/Fixtures/LeveledHasManyScope.php @@ -4,10 +4,10 @@ namespace Cycle\ORM\Tests\Fixtures; -use Cycle\ORM\Select\ConstrainInterface; use Cycle\ORM\Select\QueryBuilder; +use Cycle\ORM\Select\ScopeInterface; -class LeveledHasManyConstrain implements ConstrainInterface +class LeveledHasManyScope implements ScopeInterface { public function apply(QueryBuilder $query): void { diff --git a/tests/ORM/Fixtures/NotDeletedConstrain.php b/tests/ORM/Fixtures/NotDeletedScope.php similarity index 76% rename from tests/ORM/Fixtures/NotDeletedConstrain.php rename to tests/ORM/Fixtures/NotDeletedScope.php index d599faed6..a8664ade7 100644 --- a/tests/ORM/Fixtures/NotDeletedConstrain.php +++ b/tests/ORM/Fixtures/NotDeletedScope.php @@ -11,10 +11,10 @@ namespace Cycle\ORM\Tests\Fixtures; -use Cycle\ORM\Select\ConstrainInterface; use Cycle\ORM\Select\QueryBuilder; +use Cycle\ORM\Select\ScopeInterface; -class NotDeletedConstrain implements ConstrainInterface +class NotDeletedScope implements ScopeInterface { public function apply(QueryBuilder $query): void { diff --git a/tests/ORM/Fixtures/ProfilePromise.php b/tests/ORM/Fixtures/ProfilePromise.php index 6b8d7f31d..a3e455988 100644 --- a/tests/ORM/Fixtures/ProfilePromise.php +++ b/tests/ORM/Fixtures/ProfilePromise.php @@ -69,9 +69,7 @@ public function __resolve() { if (!is_null($this->orm)) { $select = new Select($this->orm, $this->target); - $data = $select->constrain( - $this->orm->getSource($this->target)->getConstrain() - )->where($this->scope)->fetchData(); + $data = $select->scope($this->orm->getSource($this->target)->getScope())->where($this->scope)->fetchData(); $this->orm->getMapper($this->target)->hydrate($this, $data[0]); diff --git a/tests/ORM/Fixtures/ShortLeveledHasManyConstrain.php b/tests/ORM/Fixtures/ShortLeveledHasManyScope.php similarity index 69% rename from tests/ORM/Fixtures/ShortLeveledHasManyConstrain.php rename to tests/ORM/Fixtures/ShortLeveledHasManyScope.php index 1de627d29..41260eaad 100644 --- a/tests/ORM/Fixtures/ShortLeveledHasManyConstrain.php +++ b/tests/ORM/Fixtures/ShortLeveledHasManyScope.php @@ -4,10 +4,10 @@ namespace Cycle\ORM\Tests\Fixtures; -use Cycle\ORM\Select\ConstrainInterface; use Cycle\ORM\Select\QueryBuilder; +use Cycle\ORM\Select\ScopeInterface; -class ShortLeveledHasManyConstrain implements ConstrainInterface +class ShortLeveledHasManyScope implements ScopeInterface { public function apply(QueryBuilder $query): void { diff --git a/tests/ORM/Fixtures/SortByIDConstrain.php b/tests/ORM/Fixtures/SortByIDScope.php similarity index 76% rename from tests/ORM/Fixtures/SortByIDConstrain.php rename to tests/ORM/Fixtures/SortByIDScope.php index 293b83273..6cab29bb7 100644 --- a/tests/ORM/Fixtures/SortByIDConstrain.php +++ b/tests/ORM/Fixtures/SortByIDScope.php @@ -11,10 +11,10 @@ namespace Cycle\ORM\Tests\Fixtures; -use Cycle\ORM\Select\ConstrainInterface; use Cycle\ORM\Select\QueryBuilder; +use Cycle\ORM\Select\ScopeInterface; -class SortByIDConstrain implements ConstrainInterface +class SortByIDScope implements ScopeInterface { public function apply(QueryBuilder $query): void { diff --git a/tests/ORM/Fixtures/SortByLevelDESCConstrain.php b/tests/ORM/Fixtures/SortByLevelDESCScope.php similarity index 75% rename from tests/ORM/Fixtures/SortByLevelDESCConstrain.php rename to tests/ORM/Fixtures/SortByLevelDESCScope.php index 62485d440..300d27197 100644 --- a/tests/ORM/Fixtures/SortByLevelDESCConstrain.php +++ b/tests/ORM/Fixtures/SortByLevelDESCScope.php @@ -11,10 +11,10 @@ namespace Cycle\ORM\Tests\Fixtures; -use Cycle\ORM\Select\ConstrainInterface; use Cycle\ORM\Select\QueryBuilder; +use Cycle\ORM\Select\ScopeInterface; -class SortByLevelDESCConstrain implements ConstrainInterface +class SortByLevelDESCScope implements ScopeInterface { public function apply(QueryBuilder $query): void { diff --git a/tests/ORM/Fixtures/SortByLevelConstrain.php b/tests/ORM/Fixtures/SortByLevelScope.php similarity index 75% rename from tests/ORM/Fixtures/SortByLevelConstrain.php rename to tests/ORM/Fixtures/SortByLevelScope.php index 4eac7f48a..c9c8404db 100644 --- a/tests/ORM/Fixtures/SortByLevelConstrain.php +++ b/tests/ORM/Fixtures/SortByLevelScope.php @@ -11,10 +11,10 @@ namespace Cycle\ORM\Tests\Fixtures; -use Cycle\ORM\Select\ConstrainInterface; use Cycle\ORM\Select\QueryBuilder; +use Cycle\ORM\Select\ScopeInterface; -class SortByLevelConstrain implements ConstrainInterface +class SortByLevelScope implements ScopeInterface { public function apply(QueryBuilder $query): void { diff --git a/tests/ORM/Fixtures/SortByMsgConstrain.php b/tests/ORM/Fixtures/SortByMsgScope.php similarity index 76% rename from tests/ORM/Fixtures/SortByMsgConstrain.php rename to tests/ORM/Fixtures/SortByMsgScope.php index d1e96e1e4..a0907145e 100644 --- a/tests/ORM/Fixtures/SortByMsgConstrain.php +++ b/tests/ORM/Fixtures/SortByMsgScope.php @@ -11,10 +11,10 @@ namespace Cycle\ORM\Tests\Fixtures; -use Cycle\ORM\Select\ConstrainInterface; use Cycle\ORM\Select\QueryBuilder; +use Cycle\ORM\Select\ScopeInterface; -class SortByMsgConstrain implements ConstrainInterface +class SortByMsgScope implements ScopeInterface { public function apply(QueryBuilder $query): void { diff --git a/tests/ORM/Fixtures/UserPromise.php b/tests/ORM/Fixtures/UserPromise.php index f57d28295..280d7d493 100644 --- a/tests/ORM/Fixtures/UserPromise.php +++ b/tests/ORM/Fixtures/UserPromise.php @@ -79,9 +79,7 @@ public function __resolve() // Fetching from the database $select = new Select($this->orm, $this->target); - $this->resolved = $select->constrain( - $this->orm->getSource($this->target)->getConstrain() - )->fetchOne($this->scope); + $this->resolved = $select->scope($this->orm->getSource($this->target)->getScope())->fetchOne($this->scope); $this->orm = null; } diff --git a/tests/ORM/HasManyConstrainTest.php b/tests/ORM/HasManyConstrainTest.php index 9dd80e412..11d2ab333 100644 --- a/tests/ORM/HasManyConstrainTest.php +++ b/tests/ORM/HasManyConstrainTest.php @@ -18,7 +18,7 @@ use Cycle\ORM\Select; use Cycle\ORM\Select\JoinableLoader; use Cycle\ORM\Tests\Fixtures\Comment; -use Cycle\ORM\Tests\Fixtures\SortByIDConstrain; +use Cycle\ORM\Tests\Fixtures\SortByIDScope; use Cycle\ORM\Tests\Fixtures\User; use Cycle\ORM\Tests\Traits\TableTrait; use Spiral\Database\Exception\StatementException; @@ -71,7 +71,7 @@ public function setUp(): void public function testConstrainOrdered(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'DESC']), ]); [$a, $b] = (new Select($this->orm, User::class))->load('comments')->fetchAll(); @@ -92,7 +92,7 @@ public function testConstrainOrdered(): void public function testConstrainOrderedAsc(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), ]); [$a, $b] = (new Select($this->orm, User::class))->load('comments')->fetchAll(); @@ -113,7 +113,7 @@ public function testConstrainOrderedAsc(): void public function testConstrainOrderedAscInLoad(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), ]); [$a, $b] = (new Select($this->orm, User::class))->load('comments', [ @@ -136,7 +136,7 @@ public function testConstrainOrderedAscInLoad(): void public function testConstrainOrderedPromisedAsc(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), ]); [$a, $b] = (new Select($this->orm, User::class))->fetchAll(); @@ -157,7 +157,7 @@ public function testConstrainOrderedPromisedAsc(): void public function testConstrainOrderedAndWhere(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), Relation::SCHEMA => [Relation::WHERE => ['@.level' => ['>=' => 2]]] ]); @@ -176,7 +176,7 @@ public function testConstrainOrderedAndWhere(): void public function testConstrainOrderedAndWherePromised(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), Relation::SCHEMA => [Relation::WHERE => ['@.level' => ['>=' => 2]]] ]); @@ -195,7 +195,7 @@ public function testConstrainOrderedAndWherePromised(): void public function testConstrainOrderedAndWhereReversed(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'DESC']), Relation::SCHEMA => [Relation::WHERE => ['@.level' => ['>=' => 2]]] ]); @@ -214,7 +214,7 @@ public function testConstrainOrderedAndWhereReversed(): void public function testConstrainOrderedAndWhereReversedInload(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'DESC']), Relation::SCHEMA => [Relation::WHERE => ['@.level' => ['>=' => 2]]] ]); @@ -235,7 +235,7 @@ public function testConstrainOrderedAndWhereReversedInload(): void public function testConstrainOrderedAndWhereReversedPromised(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'DESC']), Relation::SCHEMA => [Relation::WHERE => ['@.level' => ['>=' => 2]]] ]); @@ -254,7 +254,7 @@ public function testConstrainOrderedAndWhereReversedPromised(): void public function testConstrainOrderedAndCustomWhere(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), Relation::SCHEMA => [Relation::WHERE => ['@.level' => ['>=' => 2]]] ]); @@ -273,7 +273,7 @@ public function testConstrainOrderedAndCustomWhere(): void public function testConstrainOrderedAndCustomWhereInload(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), Relation::SCHEMA => [Relation::WHERE => ['@.level' => ['>=' => 2]]] ]); @@ -293,7 +293,7 @@ public function testConstrainOrderedAndCustomWhereInload(): void public function testOrderByWithConstrainOrdered(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), Relation::SCHEMA => [ Relation::ORDER_BY => ['@.level' => 'DESC'], ], @@ -445,7 +445,7 @@ public function testInloadWithConstrainOrderedAndWhere(): void { $this->orm = $this->withCommentsSchema([ Relation::SCHEMA => [Relation::WHERE => ['@.level' => ['>=' => 3]]], - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'DESC']), ]); // sort by users and then by comments and only include comments with level > 3 @@ -471,7 +471,7 @@ public function testInvalidOrderBy(): void $this->orm = $this->withCommentsSchema([ Relation::SCHEMA => [Relation::WHERE => ['@.level' => ['>=' => 3]]], - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.column' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.column' => 'DESC']), ]); // sort by users and then by comments and only include comments with level > 3 @@ -483,8 +483,8 @@ public function testInvalidOrderBy(): void protected function withCommentsSchema(array $relationSchema) { $eSchema = []; - if (isset($relationSchema[Schema::CONSTRAIN])) { - $eSchema[Schema::CONSTRAIN] = $relationSchema[Schema::CONSTRAIN]; + if (isset($relationSchema[Schema::SCOPE])) { + $eSchema[Schema::SCOPE] = $relationSchema[Schema::SCOPE]; } $rSchema = $relationSchema[Relation::SCHEMA] ?? []; @@ -509,7 +509,7 @@ protected function withCommentsSchema(array $relationSchema) ] + $rSchema, ] ], - Schema::CONSTRAIN => SortByIDConstrain::class + Schema::SCOPE => SortByIDScope::class ], Comment::class => [ Schema::ROLE => 'comment', diff --git a/tests/ORM/HasManyNestedConditionTest.php b/tests/ORM/HasManyNestedConditionTest.php index 3f16390fa..76927f7bb 100644 --- a/tests/ORM/HasManyNestedConditionTest.php +++ b/tests/ORM/HasManyNestedConditionTest.php @@ -17,7 +17,7 @@ use Cycle\ORM\Select; use Cycle\ORM\Tests\Fixtures\Comment; use Cycle\ORM\Tests\Fixtures\Post; -use Cycle\ORM\Tests\Fixtures\SortByIDConstrain; +use Cycle\ORM\Tests\Fixtures\SortByIDScope; use Cycle\ORM\Tests\Fixtures\User; use Cycle\ORM\Tests\Traits\TableTrait; use Spiral\Database\Injection\Expression; @@ -121,7 +121,7 @@ public function setUp(): void ], ] ], - Schema::CONSTRAIN => SortByIDConstrain::class + Schema::SCOPE => SortByIDScope::class ], Comment::class => [ Schema::ROLE => 'comment', diff --git a/tests/ORM/HasManyPromiseTest.php b/tests/ORM/HasManyPromiseTest.php index bb5474096..912244995 100644 --- a/tests/ORM/HasManyPromiseTest.php +++ b/tests/ORM/HasManyPromiseTest.php @@ -20,7 +20,7 @@ use Cycle\ORM\Select; use Cycle\ORM\Select\JoinableLoader; use Cycle\ORM\Tests\Fixtures\Comment; -use Cycle\ORM\Tests\Fixtures\SortByIDConstrain; +use Cycle\ORM\Tests\Fixtures\SortByIDScope; use Cycle\ORM\Tests\Fixtures\User; use Cycle\ORM\Tests\Traits\TableTrait; use Cycle\ORM\Transaction; @@ -95,7 +95,7 @@ public function setUp(): void Schema::COLUMNS => ['id', 'user_id', 'message'], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => SortByIDConstrain::class + Schema::SCOPE => SortByIDScope::class ] ])); diff --git a/tests/ORM/HasManyRelationTest.php b/tests/ORM/HasManyRelationTest.php index 0a03bbcf6..828c69615 100644 --- a/tests/ORM/HasManyRelationTest.php +++ b/tests/ORM/HasManyRelationTest.php @@ -19,7 +19,7 @@ use Cycle\ORM\Select; use Cycle\ORM\Select\JoinableLoader; use Cycle\ORM\Tests\Fixtures\Comment; -use Cycle\ORM\Tests\Fixtures\SortByIDConstrain; +use Cycle\ORM\Tests\Fixtures\SortByIDScope; use Cycle\ORM\Tests\Fixtures\User; use Cycle\ORM\Tests\Traits\TableTrait; use Cycle\ORM\Transaction; @@ -95,7 +95,7 @@ public function setUp(): void Schema::COLUMNS => ['id', 'user_id', 'message'], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => SortByIDConstrain::class + Schema::SCOPE => SortByIDScope::class ] ])); } @@ -345,7 +345,7 @@ public function testRemoveChildrenNullable(): void Schema::COLUMNS => ['id', 'user_id', 'message'], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => SortByIDConstrain::class + Schema::SCOPE => SortByIDScope::class ] ])); diff --git a/tests/ORM/HasManySourceTest.php b/tests/ORM/HasManySourceTest.php index 50d41a550..5c78029b3 100644 --- a/tests/ORM/HasManySourceTest.php +++ b/tests/ORM/HasManySourceTest.php @@ -16,8 +16,8 @@ use Cycle\ORM\Schema; use Cycle\ORM\Select; use Cycle\ORM\Tests\Fixtures\Comment; -use Cycle\ORM\Tests\Fixtures\LeveledHasManyConstrain; -use Cycle\ORM\Tests\Fixtures\ShortLeveledHasManyConstrain; +use Cycle\ORM\Tests\Fixtures\LeveledHasManyScope; +use Cycle\ORM\Tests\Fixtures\ShortLeveledHasManyScope; use Cycle\ORM\Tests\Fixtures\User; use Cycle\ORM\Tests\Traits\TableTrait; @@ -110,7 +110,7 @@ public function testSelectUsers(): void public function testSelectUsersWithScope(): void { $s = new Select($this->orm, User::class); - $res = $s->constrain(new Select\QueryConstrain(['@.balance' => 100]))->fetchAll(); + $res = $s->scope(new Select\Scope\QueryScope(['@.balance' => 100]))->fetchAll(); $this->assertCount(1, $res); $this->assertSame('hello@world.com', $res[0]->email); @@ -119,7 +119,7 @@ public function testSelectUsersWithScope(): void public function testSelectUserScopeCanNotBeOverwritten(): void { $s = new Select($this->orm, User::class); - $s->constrain(new Select\QueryConstrain(['@.balance' => 100])); + $s->scope(new Select\Scope\QueryScope(['@.balance' => 100])); $res = $s->where('user.balance', 200)->fetchAll(); @@ -129,7 +129,7 @@ public function testSelectUserScopeCanNotBeOverwritten(): void public function testSelectUserScopeCanNotBeOverwritten2(): void { $s = new Select($this->orm, User::class); - $s->constrain(new Select\QueryConstrain(['@.balance' => 100])); + $s->scope(new Select\Scope\QueryScope(['@.balance' => 100])); $res = $s->orWhere('user.balance', 200)->fetchAll(); @@ -139,7 +139,7 @@ public function testSelectUserScopeCanNotBeOverwritten2(): void public function testScopeWithOrderBy(): void { $s = new Select($this->orm, User::class); - $s->constrain(new Select\QueryConstrain([], ['@.balance' => 'DESC'])); + $s->scope(new Select\Scope\QueryScope([], ['@.balance' => 'DESC'])); $res = $s->fetchAll(); @@ -151,7 +151,7 @@ public function testScopeWithOrderBy(): void public function testRelated(): void { $s = new Select($this->orm, User::class); - $s->constrain(new Select\QueryConstrain([], ['@.balance' => 'DESC'])); + $s->scope(new Select\Scope\QueryScope([], ['@.balance' => 'DESC'])); $res = $s->load('comments')->fetchAll(); @@ -175,10 +175,10 @@ public function testRelated(): void public function testRelatedScope(): void { $s = new Select($this->orm, User::class); - $s->constrain(new Select\QueryConstrain([], ['@.balance' => 'DESC'])); + $s->scope(new Select\Scope\QueryScope([], ['@.balance' => 'DESC'])); $res = $s->load('comments', [ - 'constrain' => new Select\QueryConstrain(['@.level' => 4]) + 'constrain' => new Select\Scope\QueryScope(['@.level' => 4]) ])->fetchAll(); [$b, $a] = $res; @@ -192,11 +192,11 @@ public function testRelatedScope(): void public function testRelatedScopeInload(): void { $s = new Select($this->orm, User::class); - $s->constrain(new Select\QueryConstrain([], ['@.balance' => 'DESC'])); + $s->scope(new Select\Scope\QueryScope([], ['@.balance' => 'DESC'])); $res = $s->load('comments', [ 'method' => Select\JoinableLoader::INLOAD, - 'constrain' => new Select\QueryConstrain(['@.level' => 4]) + 'constrain' => new Select\Scope\QueryScope(['@.level' => 4]) ])->fetchAll(); [$b, $a] = $res; @@ -210,10 +210,10 @@ public function testRelatedScopeInload(): void public function testRelatedScopeOrdered(): void { $s = new Select($this->orm, User::class); - $s->constrain(new Select\QueryConstrain([], ['@.balance' => 'DESC'])); + $s->scope(new Select\Scope\QueryScope([], ['@.balance' => 'DESC'])); $res = $s->load('comments', [ - 'constrain' => new Select\QueryConstrain(['@.level' => ['>=' => 3]], ['@.level' => 'DESC']) + 'constrain' => new Select\Scope\QueryScope(['@.level' => ['>=' => 3]], ['@.level' => 'DESC']) ])->fetchAll(); [$b, $a] = $res; @@ -230,11 +230,11 @@ public function testRelatedScopeOrdered(): void public function testRelatedScopeOrderedInload(): void { $s = new Select($this->orm, User::class); - $s->constrain(new Select\QueryConstrain([], ['@.balance' => 'DESC'])); + $s->scope(new Select\Scope\QueryScope([], ['@.balance' => 'DESC'])); $res = $s->load('comments', [ 'method' => Select\JoinableLoader::INLOAD, - 'constrain' => new Select\QueryConstrain(['@.level' => ['>=' => 3]], ['@.level' => 'DESC']) + 'constrain' => new Select\Scope\QueryScope(['@.level' => ['>=' => 3]], ['@.level' => 'DESC']) ])->fetchAll(); [$b, $a] = $res; @@ -279,12 +279,12 @@ public function testScopeViaMapperRelation(): void Schema::COLUMNS => ['id', 'user_id', 'level', 'message'], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => LeveledHasManyConstrain::class + Schema::SCOPE => LeveledHasManyScope::class ] ])); $s = new Select($this->orm, User::class); - $s->constrain(new Select\QueryConstrain([], ['@.balance' => 'DESC'])); + $s->scope(new Select\Scope\QueryScope([], ['@.balance' => 'DESC'])); $res = $s->load('comments')->fetchAll(); @@ -330,12 +330,12 @@ public function testScopeViaMapperRelationInload(): void Schema::COLUMNS => ['id', 'user_id', 'level', 'message'], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => LeveledHasManyConstrain::class + Schema::SCOPE => LeveledHasManyScope::class ] ])); $s = new Select($this->orm, User::class); - $s->constrain(new Select\QueryConstrain([], ['@.balance' => 'DESC'])); + $s->scope(new Select\Scope\QueryScope([], ['@.balance' => 'DESC'])); $res = $s->load('comments', [ 'method' => Select\JoinableLoader::INLOAD, @@ -384,12 +384,12 @@ public function testScopeViaMapperRelationPromise(): void Schema::COLUMNS => ['id', 'user_id', 'level', 'message'], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => LeveledHasManyConstrain::class + Schema::SCOPE => LeveledHasManyScope::class ] ])); $s = new Select($this->orm, User::class); - $s->constrain(new Select\QueryConstrain([], ['@.balance' => 'DESC'])); + $s->scope(new Select\Scope\QueryScope([], ['@.balance' => 'DESC'])); $res = $s->fetchAll(); @@ -436,12 +436,12 @@ public function testScopeViaMapperRelationPromiseShort(): void Schema::COLUMNS => ['id', 'user_id', 'level', 'message'], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => ShortLeveledHasManyConstrain::class + Schema::SCOPE => ShortLeveledHasManyScope::class ] ])); $s = new Select($this->orm, User::class); - $s->constrain(new Select\QueryConstrain([], ['@.balance' => 'DESC'])); + $s->scope(new Select\Scope\QueryScope([], ['@.balance' => 'DESC'])); $res = $s->fetchAll(); diff --git a/tests/ORM/InstantiatorTest.php b/tests/ORM/InstantiatorTest.php index 3c6c174a8..14d73a775 100644 --- a/tests/ORM/InstantiatorTest.php +++ b/tests/ORM/InstantiatorTest.php @@ -16,7 +16,7 @@ use Cycle\ORM\Schema; use Cycle\ORM\Select; use Cycle\ORM\Tests\Fixtures\Comment; -use Cycle\ORM\Tests\Fixtures\SortByIDConstrain; +use Cycle\ORM\Tests\Fixtures\SortByIDScope; use Cycle\ORM\Tests\Fixtures\WithConstructor; use Cycle\ORM\Tests\Traits\TableTrait; use Cycle\ORM\Transaction; @@ -73,7 +73,7 @@ public function setUp(): void Schema::COLUMNS => ['id', 'user_id', 'message'], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => SortByIDConstrain::class + Schema::SCOPE => SortByIDScope::class ] ])); } diff --git a/tests/ORM/InverseRelationTest.php b/tests/ORM/InverseRelationTest.php index 5b2b770da..019aa690d 100644 --- a/tests/ORM/InverseRelationTest.php +++ b/tests/ORM/InverseRelationTest.php @@ -17,7 +17,7 @@ use Cycle\ORM\Schema; use Cycle\ORM\Select; use Cycle\ORM\Tests\Fixtures\Profile; -use Cycle\ORM\Tests\Fixtures\SortByIDConstrain; +use Cycle\ORM\Tests\Fixtures\SortByIDScope; use Cycle\ORM\Tests\Fixtures\User; use Cycle\ORM\Tests\Traits\TableTrait; use Cycle\ORM\Transaction; @@ -81,7 +81,7 @@ public function setUp(): void ], ] ], - Schema::CONSTRAIN => SortByIDConstrain::class + Schema::SCOPE => SortByIDScope::class ], Profile::class => [ Schema::ROLE => 'profile', @@ -102,7 +102,7 @@ public function setUp(): void ], ], ], - Schema::CONSTRAIN => SortByIDConstrain::class + Schema::SCOPE => SortByIDScope::class ], ])); } diff --git a/tests/ORM/ManyToManyConstrainTest.php b/tests/ORM/ManyToManyConstrainTest.php index cb710a004..09d8af1bb 100644 --- a/tests/ORM/ManyToManyConstrainTest.php +++ b/tests/ORM/ManyToManyConstrainTest.php @@ -91,7 +91,7 @@ public function setUp(): void public function testConstrainOrdered(): void { $this->orm = $this->withTagSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), ]); $selector = new Select($this->orm, User::class); @@ -118,7 +118,7 @@ public function testConstrainOrdered(): void public function testConstrainOrderedDesc(): void { $this->orm = $this->withTagSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'DESC']), ]); $selector = new Select($this->orm, User::class); @@ -145,7 +145,7 @@ public function testConstrainOrderedDesc(): void public function testConstrainOrderedInload(): void { $this->orm = $this->withTagSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), ]); $selector = new Select($this->orm, User::class); @@ -174,7 +174,7 @@ public function testConstrainOrderedInload(): void public function testWithOrderByAndConstrainOrdered(): void { $this->orm = $this->withTagSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'DESC']), Relation::SCHEMA => [Relation::ORDER_BY => ['@.level' => 'ASC']], ]); @@ -341,7 +341,7 @@ public function testWithOrderByAltered(): void public function testConstrainOrderedDESCInload(): void { $this->orm = $this->withTagSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'DESC']), ]); $selector = new Select($this->orm, User::class); @@ -370,7 +370,7 @@ public function testConstrainOrderedDESCInload(): void public function testConstrainOrderedPromisedASC(): void { $this->orm = $this->withTagSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), ]); $selector = new Select($this->orm, User::class); @@ -399,7 +399,7 @@ public function testConstrainOrderedPromisedASC(): void public function testConstrainOrderedPromisedDESC(): void { $this->orm = $this->withTagSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'DESC']), ]); $selector = new Select($this->orm, User::class); @@ -428,7 +428,7 @@ public function testConstrainOrderedPromisedDESC(): void public function testConstrainOrderedAndWhere(): void { $this->orm = $this->withTagSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), Relation::SCHEMA => [Relation::WHERE => ['@.level' => ['>=' => 3]]], ]); @@ -482,7 +482,7 @@ public function testWithOrderByAndWhere(): void public function testConstrainOrderedDESCAndWhere(): void { $this->orm = $this->withTagSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'DESC']), Relation::SCHEMA => [Relation::WHERE => ['@.level' => ['>=' => 3]]], ]); @@ -508,7 +508,7 @@ public function testConstrainOrderedDESCAndWhere(): void public function testConstrainOrderedAndWhereInload(): void { $this->orm = $this->withTagSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), Relation::SCHEMA => [Relation::WHERE => ['@.level' => ['>=' => 3]]], ]); @@ -536,7 +536,7 @@ public function testConstrainOrderedAndWhereInload(): void public function testConstrainOrderedDESCAndWhereInload(): void { $this->orm = $this->withTagSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'DESC']), Relation::SCHEMA => [Relation::WHERE => ['@.level' => ['>=' => 3]]], ]); @@ -564,7 +564,7 @@ public function testConstrainOrderedDESCAndWhereInload(): void public function testConstrainOrderedAndWherePromise(): void { $this->orm = $this->withTagSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), Relation::SCHEMA => [Relation::WHERE => ['@.level' => ['>=' => 3]]], ]); @@ -592,7 +592,7 @@ public function testConstrainOrderedAndWherePromise(): void public function testOrderedDESCAndWherePromise(): void { $this->orm = $this->withTagSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'DESC']), Relation::SCHEMA => [Relation::WHERE => ['@.level' => ['>=' => 3]]], ]); @@ -620,7 +620,7 @@ public function testOrderedDESCAndWherePromise(): void public function testCustomWhere(): void { $this->orm = $this->withTagSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'DESC']), Relation::SCHEMA => [Relation::WHERE => ['@.level' => ['>=' => 3]]], ]); @@ -643,7 +643,7 @@ public function testCustomWhere(): void public function testCustomWhereInload(): void { $this->orm = $this->withTagSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'DESC']), Relation::SCHEMA => [Relation::WHERE => ['@.level' => ['>=' => 3]]], ]); @@ -731,7 +731,7 @@ public function testInvalidOrderBy(): void $this->expectException(StatementException::class); $this->orm = $this->withTagSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.column' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.column' => 'ASC']), ]); $selector = new Select($this->orm, User::class); @@ -742,8 +742,8 @@ public function testInvalidOrderBy(): void protected function withTagSchema(array $relationSchema) { $eSchema = []; - if (isset($relationSchema[Schema::CONSTRAIN])) { - $eSchema[Schema::CONSTRAIN] = $relationSchema[Schema::CONSTRAIN]; + if (isset($relationSchema[Schema::SCOPE])) { + $eSchema[Schema::SCOPE] = $relationSchema[Schema::SCOPE]; } $rSchema = $relationSchema[Relation::SCHEMA] ?? []; diff --git a/tests/ORM/ManyToManyConstrainedPivotTest.php b/tests/ORM/ManyToManyConstrainedPivotTest.php index 68ff14c0a..1ad3a7cce 100644 --- a/tests/ORM/ManyToManyConstrainedPivotTest.php +++ b/tests/ORM/ManyToManyConstrainedPivotTest.php @@ -15,7 +15,7 @@ use Cycle\ORM\Relation; use Cycle\ORM\Schema; use Cycle\ORM\Select; -use Cycle\ORM\Tests\Fixtures\SortByLevelDESCConstrain; +use Cycle\ORM\Tests\Fixtures\SortByLevelDESCScope; use Cycle\ORM\Tests\Fixtures\Tag; use Cycle\ORM\Tests\Fixtures\TagContext; use Cycle\ORM\Tests\Fixtures\User; @@ -207,7 +207,7 @@ public function testLoadRelation(): void public function testLoadRelationOrderByPivotColumn(): void { $this->orm = $this->withPivotSchema([ - Schema::CONSTRAIN => SortByLevelDESCConstrain::class, + Schema::SCOPE => SortByLevelDESCScope::class, ]); $selector = new Select($this->orm, User::class); @@ -319,7 +319,7 @@ public function testLoadRelationOrderByPivotColumn(): void public function testLoaderRelationWithConstrain(): void { $this->orm = $this->withPivotSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain( + Schema::SCOPE => new Select\Scope\QueryScope( ['@.level' => ['>' => 3]], ['@.level' => 'DESC'] ), diff --git a/tests/ORM/ManyToManyConstrainedTest.php b/tests/ORM/ManyToManyConstrainedTest.php index 2160329f5..0468ac3ea 100644 --- a/tests/ORM/ManyToManyConstrainedTest.php +++ b/tests/ORM/ManyToManyConstrainedTest.php @@ -15,8 +15,8 @@ use Cycle\ORM\Relation; use Cycle\ORM\Schema; use Cycle\ORM\Select; -use Cycle\ORM\Tests\Fixtures\SortByLevelConstrain; -use Cycle\ORM\Tests\Fixtures\SortByLevelDESCConstrain; +use Cycle\ORM\Tests\Fixtures\SortByLevelDESCScope; +use Cycle\ORM\Tests\Fixtures\SortByLevelScope; use Cycle\ORM\Tests\Fixtures\Tag; use Cycle\ORM\Tests\Fixtures\TagContext; use Cycle\ORM\Tests\Fixtures\User; @@ -91,7 +91,7 @@ public function setUp(): void public function testOrderedByScope(): void { $this->orm = $this->withTagSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']) + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']) ]); $selector = new Select($this->orm, User::class); @@ -126,7 +126,7 @@ public function testOrderedByScopeDESC(): void * @var User $b */ [$a, $b] = $selector->load('tags', [ - 'constrain' => new Select\QueryConstrain([], ['@.level' => 'DESC']) + 'constrain' => new Select\Scope\QueryScope([], ['@.level' => 'DESC']) ])->fetchAll(); $this->assertCount(4, $a->tags); @@ -154,7 +154,7 @@ public function testScopeInload(): void */ [$a, $b] = $selector->load('tags', [ 'method' => Select\JoinableLoader::INLOAD, - 'constrain' => new Select\QueryConstrain([], ['@.level' => 'ASC']) + 'constrain' => new Select\Scope\QueryScope([], ['@.level' => 'ASC']) ])->orderBy('user.id')->fetchAll(); $this->assertCount(4, $a->tags); @@ -182,7 +182,7 @@ public function testOrderedDESCInload(): void */ [$a, $b] = $selector->load('tags', [ 'method' => Select\JoinableLoader::INLOAD, - 'constrain' => new Select\QueryConstrain([], ['@.level' => 'DESC']) + 'constrain' => new Select\Scope\QueryScope([], ['@.level' => 'DESC']) ])->orderBy('user.id')->fetchAll(); $this->assertCount(4, $a->tags); @@ -233,7 +233,7 @@ public function testGlobalConstrain(): void Schema::COLUMNS => ['id', 'name', 'level'], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => SortByLevelConstrain::class + Schema::SCOPE => SortByLevelScope::class ], TagContext::class => [ Schema::ROLE => 'tag_context', @@ -306,7 +306,7 @@ public function testGlobalConstrainDESC(): void Schema::COLUMNS => ['id', 'name', 'level'], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => SortByLevelDESCConstrain::class + Schema::SCOPE => SortByLevelDESCScope::class ], TagContext::class => [ Schema::ROLE => 'tag_context', @@ -379,7 +379,7 @@ public function testGlobalConstrainDESCButASC(): void Schema::COLUMNS => ['id', 'name', 'level'], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => SortByLevelDESCConstrain::class + Schema::SCOPE => SortByLevelDESCScope::class ], TagContext::class => [ Schema::ROLE => 'tag_context', @@ -401,7 +401,7 @@ public function testGlobalConstrainDESCButASC(): void * @var User $b */ [$a, $b] = $selector->load('tags', [ - 'constrain' => new SortByLevelConstrain() + 'constrain' => new SortByLevelScope() ])->orderBy('user.id')->fetchAll(); $this->captureReadQueries(); @@ -455,7 +455,7 @@ public function testGlobalConstrainPromised(): void Schema::COLUMNS => ['id', 'name', 'level'], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => SortByLevelConstrain::class + Schema::SCOPE => SortByLevelScope::class ], TagContext::class => [ Schema::ROLE => 'tag_context', @@ -529,7 +529,7 @@ public function testGlobalConstrainDESCPromised(): void Schema::COLUMNS => ['id', 'name', 'level'], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => SortByLevelDESCConstrain::class + Schema::SCOPE => SortByLevelDESCScope::class ], TagContext::class => [ Schema::ROLE => 'tag_context', diff --git a/tests/ORM/ManyToManyDeepenedTest.php b/tests/ORM/ManyToManyDeepenedTest.php index b2d0828b9..6a7da4c7f 100644 --- a/tests/ORM/ManyToManyDeepenedTest.php +++ b/tests/ORM/ManyToManyDeepenedTest.php @@ -17,7 +17,7 @@ use Cycle\ORM\Schema; use Cycle\ORM\Select; use Cycle\ORM\Tests\Fixtures\Image; -use Cycle\ORM\Tests\Fixtures\SortByIDConstrain; +use Cycle\ORM\Tests\Fixtures\SortByIDScope; use Cycle\ORM\Tests\Fixtures\Tag; use Cycle\ORM\Tests\Fixtures\TagContext; use Cycle\ORM\Tests\Fixtures\User; @@ -133,7 +133,7 @@ public function setUp(): void Schema::TYPECAST => ['id' => 'int'], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => SortByIDConstrain::class + Schema::SCOPE => SortByIDScope::class ], TagContext::class => [ Schema::ROLE => 'tag_context', diff --git a/tests/ORM/ManyToManyPromiseEagerLoadTest.php b/tests/ORM/ManyToManyPromiseEagerLoadTest.php index be3047731..88ee76c95 100644 --- a/tests/ORM/ManyToManyPromiseEagerLoadTest.php +++ b/tests/ORM/ManyToManyPromiseEagerLoadTest.php @@ -15,7 +15,7 @@ use Cycle\ORM\Relation; use Cycle\ORM\Schema; use Cycle\ORM\Select; -use Cycle\ORM\Tests\Fixtures\SortByIDConstrain; +use Cycle\ORM\Tests\Fixtures\SortByIDScope; use Cycle\ORM\Tests\Traits\TableTrait; abstract class ManyToManyPromiseEagerLoadTest extends BaseTest @@ -118,7 +118,7 @@ public function setUp(): void ], ] ], - Schema::CONSTRAIN => SortByIDConstrain::class + Schema::SCOPE => SortByIDScope::class ], 'version_distribution' => [ Schema::ROLE => 'version_context', @@ -152,7 +152,7 @@ public function setUp(): void ], ] ], - Schema::CONSTRAIN => SortByIDConstrain::class + Schema::SCOPE => SortByIDScope::class ], 'module' => [ Schema::ROLE => 'module', @@ -164,7 +164,7 @@ public function setUp(): void Schema::TYPECAST => ['id' => 'int'], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => SortByIDConstrain::class + Schema::SCOPE => SortByIDScope::class ] ])); } diff --git a/tests/ORM/ManyToManyPromiseTest.php b/tests/ORM/ManyToManyPromiseTest.php index 4196264b1..645b0027b 100644 --- a/tests/ORM/ManyToManyPromiseTest.php +++ b/tests/ORM/ManyToManyPromiseTest.php @@ -17,7 +17,7 @@ use Cycle\ORM\Relation; use Cycle\ORM\Schema; use Cycle\ORM\Select; -use Cycle\ORM\Tests\Fixtures\SortByIDConstrain; +use Cycle\ORM\Tests\Fixtures\SortByIDScope; use Cycle\ORM\Tests\Fixtures\Tag; use Cycle\ORM\Tests\Fixtures\TagContext; use Cycle\ORM\Tests\Fixtures\User; @@ -117,7 +117,7 @@ public function setUp(): void Schema::TYPECAST => ['id' => 'int'], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => SortByIDConstrain::class + Schema::SCOPE => SortByIDScope::class ], TagContext::class => [ Schema::ROLE => 'tag_context', diff --git a/tests/ORM/ManyToManyRelationTest.php b/tests/ORM/ManyToManyRelationTest.php index 7a9a7f484..2d729a7e5 100644 --- a/tests/ORM/ManyToManyRelationTest.php +++ b/tests/ORM/ManyToManyRelationTest.php @@ -13,7 +13,6 @@ use Cycle\ORM\Heap\Heap; use Cycle\ORM\Mapper\Mapper; -use Cycle\ORM\Promise\Collection\CollectionPromiseInterface; use Cycle\ORM\Relation; use Cycle\ORM\Schema; use Cycle\ORM\Select; @@ -202,7 +201,7 @@ public function testLoadRelationInload(): void $selector = new Select($this->orm, User::class); $selector->load('tags', [ 'method' => Select\JoinableLoader::INLOAD, - 'constrain' => new Select\QueryConstrain([], ['id' => 'ASC']) + 'constrain' => new Select\Scope\QueryScope([], ['id' => 'ASC']) ])->orderBy(['id' => 'ASC']); $this->assertSame([ diff --git a/tests/ORM/Morphed/MorphedHasManyConstrainTest.php b/tests/ORM/Morphed/MorphedHasManyConstrainTest.php index 1d9efaaa8..8e314f75e 100644 --- a/tests/ORM/Morphed/MorphedHasManyConstrainTest.php +++ b/tests/ORM/Morphed/MorphedHasManyConstrainTest.php @@ -19,7 +19,7 @@ use Cycle\ORM\Tests\BaseTest; use Cycle\ORM\Tests\Fixtures\Comment; use Cycle\ORM\Tests\Fixtures\Post; -use Cycle\ORM\Tests\Fixtures\SortByIDConstrain; +use Cycle\ORM\Tests\Fixtures\SortByIDScope; use Cycle\ORM\Tests\Fixtures\User; use Cycle\ORM\Tests\Traits\TableTrait; use Spiral\Database\Exception\StatementException; @@ -95,7 +95,7 @@ public function setUp(): void public function testOrdered(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'DESC']), ]); [$a, $b] = (new Select($this->orm, User::class))->load('comments')->fetchAll(); @@ -116,7 +116,7 @@ public function testOrdered(): void public function testOrderedASC(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), ]); [$a, $b] = (new Select($this->orm, User::class))->load('comments')->fetchAll(); @@ -137,7 +137,7 @@ public function testOrderedASC(): void public function testOrderedPosts(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'DESC']), ]); [$a, $b] = (new Select($this->orm, Post::class))->load('comments')->fetchAll(); @@ -158,7 +158,7 @@ public function testOrderedPosts(): void public function testOrderedPostsASC(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), ]); [$a, $b] = (new Select($this->orm, Post::class))->load('comments')->fetchAll(); @@ -179,7 +179,7 @@ public function testOrderedPostsASC(): void public function testOrderedInload(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'DESC']), ]); [$a, $b] = (new Select($this->orm, User::class))->load('comments', [ @@ -202,7 +202,7 @@ public function testOrderedInload(): void public function testOrderedASCInload(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), ]); [$a, $b] = (new Select($this->orm, User::class))->load('comments', [ @@ -225,7 +225,7 @@ public function testOrderedASCInload(): void public function testOrderedPostsInload(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'DESC']), ]); [$a, $b] = (new Select($this->orm, Post::class))->load('comments', [ @@ -248,7 +248,7 @@ public function testOrderedPostsInload(): void public function testOrderedPostsASCInload(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), ]); [$a, $b] = (new Select($this->orm, Post::class))->load('comments', [ @@ -271,7 +271,7 @@ public function testOrderedPostsASCInload(): void public function testOrderedPromisedASC(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), ]); [$a, $b] = (new Select($this->orm, User::class))->fetchAll(); @@ -292,7 +292,7 @@ public function testOrderedPromisedASC(): void public function testOrderedAndWhere(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), Relation::WHERE => ['@.level' => ['>=' => 2]] ]); @@ -311,7 +311,7 @@ public function testOrderedAndWhere(): void public function testOrderedAndWherePromised(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), Relation::WHERE => ['@.level' => ['>=' => 2]] ]); @@ -330,7 +330,7 @@ public function testOrderedAndWherePromised(): void public function testPostOrderedPromisedASC(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), ]); [$a, $b] = (new Select($this->orm, Post::class))->fetchAll(); @@ -351,7 +351,7 @@ public function testPostOrderedPromisedASC(): void public function testPostOrderedAndWhere(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), Relation::WHERE => ['@.level' => ['>=' => 2]] ]); @@ -370,7 +370,7 @@ public function testPostOrderedAndWhere(): void public function testPostOrderedAndWherePromised(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), Relation::WHERE => ['@.level' => ['>=' => 2]] ]); @@ -391,7 +391,7 @@ public function testPostOrderedAndWherePromised(): void public function testOrderedAndWhereReversed(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'DESC']), Relation::WHERE => ['@.level' => ['>=' => 2]] ]); @@ -410,7 +410,7 @@ public function testOrderedAndWhereReversed(): void public function testOrderedAndWhereReversedInload(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'DESC']), Relation::WHERE => ['@.level' => ['>=' => 2]] ]); @@ -432,7 +432,7 @@ public function testOrderedAndWhereReversedInload(): void public function testOrderedAndWhereReversedPromised(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'DESC']), Relation::WHERE => ['@.level' => ['>=' => 2]] ]); @@ -451,7 +451,7 @@ public function testOrderedAndWhereReversedPromised(): void public function testCustomWhere(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), Relation::WHERE => ['@.level' => ['>=' => 2]] ]); @@ -470,7 +470,7 @@ public function testCustomWhere(): void public function testCustomWhereInload(): void { $this->orm = $this->withCommentsSchema([ - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'ASC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'ASC']), Relation::WHERE => ['@.level' => ['>=' => 2]] ]); @@ -547,7 +547,7 @@ public function testInloadWithOrderAndWhere(): void { $this->orm = $this->withCommentsSchema([ Relation::WHERE => ['@.level' => ['>=' => 3]], - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.level' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.level' => 'DESC']), ]); // sort by users and then by comments and only include comments with level > 3 @@ -573,7 +573,7 @@ public function testInvalidOrderBy(): void $this->orm = $this->withCommentsSchema([ Relation::WHERE => ['@.level' => ['>=' => 3]], - Schema::CONSTRAIN => new Select\QueryConstrain([], ['@.column' => 'DESC']), + Schema::SCOPE => new Select\Scope\QueryScope([], ['@.column' => 'DESC']), ]); // sort by users and then by comments and only include comments with level > 3 @@ -587,8 +587,8 @@ protected function withCommentsSchema(array $relationSchema) $eSchema = []; $rSchema = []; - if (isset($relationSchema[Schema::CONSTRAIN])) { - $eSchema[Schema::CONSTRAIN] = $relationSchema[Schema::CONSTRAIN]; + if (isset($relationSchema[Schema::SCOPE])) { + $eSchema[Schema::SCOPE] = $relationSchema[Schema::SCOPE]; } if (isset($relationSchema[Relation::WHERE])) { @@ -617,7 +617,7 @@ protected function withCommentsSchema(array $relationSchema) ] + $rSchema, ] ], - Schema::CONSTRAIN => SortByIDConstrain::class + Schema::SCOPE => SortByIDScope::class ], Post::class => [ Schema::ROLE => 'post', diff --git a/tests/ORM/QueryBuilderTest.php b/tests/ORM/QueryBuilderTest.php index cd2ae659a..3b51b779e 100644 --- a/tests/ORM/QueryBuilderTest.php +++ b/tests/ORM/QueryBuilderTest.php @@ -16,7 +16,7 @@ use Cycle\ORM\Schema; use Cycle\ORM\Select; use Cycle\ORM\Tests\Fixtures\Comment; -use Cycle\ORM\Tests\Fixtures\SortByIDConstrain; +use Cycle\ORM\Tests\Fixtures\SortByIDScope; use Cycle\ORM\Tests\Fixtures\User; use Cycle\ORM\Tests\Traits\TableTrait; use Spiral\Database\Injection\Parameter; @@ -99,7 +99,7 @@ public function setUp(): void ], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => SortByIDConstrain::class + Schema::SCOPE => SortByIDScope::class ] ])); } diff --git a/tests/ORM/RelationWithColumnAliasTest.php b/tests/ORM/RelationWithColumnAliasTest.php index bfa4b2c39..9b5150835 100644 --- a/tests/ORM/RelationWithColumnAliasTest.php +++ b/tests/ORM/RelationWithColumnAliasTest.php @@ -20,7 +20,7 @@ use Cycle\ORM\Select; use Cycle\ORM\Select\JoinableLoader; use Cycle\ORM\Tests\Fixtures\Comment; -use Cycle\ORM\Tests\Fixtures\SortByIDConstrain; +use Cycle\ORM\Tests\Fixtures\SortByIDScope; use Cycle\ORM\Tests\Fixtures\User; use Cycle\ORM\Tests\Traits\TableTrait; use Cycle\ORM\Transaction; @@ -96,7 +96,7 @@ public function setUp(): void Schema::COLUMNS => ['id' => 'id_int', 'user_id' => 'user_id_int', 'message' => 'message_str'], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => SortByIDConstrain::class + Schema::SCOPE => SortByIDScope::class ] ])); } diff --git a/tests/ORM/SoftDeletesTest.php b/tests/ORM/SoftDeletesTest.php index 3f24a0517..78795281c 100644 --- a/tests/ORM/SoftDeletesTest.php +++ b/tests/ORM/SoftDeletesTest.php @@ -14,7 +14,7 @@ use Cycle\ORM\Heap\Heap; use Cycle\ORM\Schema; use Cycle\ORM\Select; -use Cycle\ORM\Tests\Fixtures\NotDeletedConstrain; +use Cycle\ORM\Tests\Fixtures\NotDeletedScope; use Cycle\ORM\Tests\Fixtures\SoftDeletedMapper; use Cycle\ORM\Tests\Fixtures\User; use Cycle\ORM\Tests\Traits\TableTrait; @@ -50,7 +50,7 @@ public function setUp(): void ], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => NotDeletedConstrain::class + Schema::SCOPE => NotDeletedScope::class ] ])); } @@ -92,12 +92,12 @@ public function testDelete(): void $orm = $this->orm->withHeap(new Heap()); $s = new Select($orm, User::class); - $s->constrain(new NotDeletedConstrain()); + $s->scope(new NotDeletedScope()); $this->assertNull($s->fetchOne()); $orm = $this->orm->withHeap(new Heap()); $s = new Select($orm, User::class); - $s->constrain(null); + $s->scope(null); $this->assertNotNull($s->fetchOne()); } } diff --git a/tests/ORM/TypecastTest.php b/tests/ORM/TypecastTest.php index c452f74b2..b1fc2ab07 100644 --- a/tests/ORM/TypecastTest.php +++ b/tests/ORM/TypecastTest.php @@ -16,7 +16,7 @@ use Cycle\ORM\Mapper\Mapper; use Cycle\ORM\Schema; use Cycle\ORM\Select; -use Cycle\ORM\Tests\Fixtures\SortByIDConstrain; +use Cycle\ORM\Tests\Fixtures\SortByIDScope; use Cycle\ORM\Tests\Fixtures\User; use Cycle\ORM\Tests\Traits\TableTrait; use Cycle\ORM\Transaction; @@ -59,7 +59,7 @@ public function setUp(): void ], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => SortByIDConstrain::class + Schema::SCOPE => SortByIDScope::class ] ])); } diff --git a/tests/ORM/UUIDTest.php b/tests/ORM/UUIDTest.php index 236808da8..47be284b2 100644 --- a/tests/ORM/UUIDTest.php +++ b/tests/ORM/UUIDTest.php @@ -17,7 +17,7 @@ use Cycle\ORM\Schema; use Cycle\ORM\Select; use Cycle\ORM\Tests\Fixtures\Comment; -use Cycle\ORM\Tests\Fixtures\SortByMsgConstrain; +use Cycle\ORM\Tests\Fixtures\SortByMsgScope; use Cycle\ORM\Tests\Fixtures\User; use Cycle\ORM\Tests\Fixtures\UUIDMapper; use Cycle\ORM\Tests\Traits\TableTrait; @@ -107,7 +107,7 @@ public function setUp(): void Schema::COLUMNS => ['id', 'user_id', 'message'], Schema::SCHEMA => [], Schema::RELATIONS => [], - Schema::CONSTRAIN => SortByMsgConstrain::class + Schema::SCOPE => SortByMsgScope::class ] ])); }