diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4bc65d0a1b6..6b33c58ceea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,10 +52,6 @@ jobs: ini-values: memory_limit=-1 tools: pecl, composer coverage: none - - name: Download PHPArkitect PHAR - run: | - wget -q https://github.com/phparkitect/arkitect/releases/latest/download/phparkitect.phar - chmod +x phparkitect.phar - name: Get composer cache directory id: composercache run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT @@ -68,8 +64,7 @@ jobs: - name: Update project dependencies run: | composer update --no-interaction --no-progress --ansi - - name: Run PHPArkitect - run: ./phparkitect.phar check + - run: php components.php php-cs-fixer: name: PHP CS Fixer (PHP ${{ matrix.php }}) @@ -145,8 +140,6 @@ jobs: rm -Rf tests/Fixtures/app/var/cache/* tests/Fixtures/app/console cache:warmup - name: Run PHPStan analysis - env: - SYMFONY_PHPUNIT_VERSION: '9.5' run: | ./vendor/bin/phpstan --version ./vendor/bin/phpstan analyse --no-interaction --no-progress --ansi @@ -244,6 +237,9 @@ jobs: - GraphQl - Serializer - Symfony + - Doctrine/Common + - Doctrine/Orm + - Doctrine/Odm include: - php: '8.1' coverage: true @@ -768,8 +764,6 @@ jobs: restore-keys: ${{ runner.os }}-composer- - name: Update project dependencies run: composer update --prefer-lowest --no-interaction --no-progress --ansi - - name: Install PHPUnit - run: vendor/bin/simple-phpunit --version - name: Clear test app cache run: tests/Fixtures/app/console cache:clear --ansi - name: Run Behat tests @@ -1033,12 +1027,10 @@ jobs: run: rm -Rf tests/Fixtures/app/var/cache/* - name: Update project dependencies run: composer update --prefer-lowest --no-interaction --no-progress --ansi - - name: Install PHPUnit - run: vendor/bin/simple-phpunit --version - name: Clear test app cache run: tests/Fixtures/app/console cache:clear --ansi - name: Run PHPUnit tests - run: vendor/bin/simple-phpunit + run: vendor/bin/phpunit env: SYMFONY_DEPRECATIONS_HELPER: max[self]=0&ignoreFile=./tests/.ignored-deprecations @@ -1077,8 +1069,6 @@ jobs: run: rm -Rf tests/Fixtures/app/var/cache/* - name: Update project dependencies run: composer update --prefer-lowest --no-interaction --no-progress --ansi - - name: Install PHPUnit - run: vendor/bin/simple-phpunit --version - name: Clear test app cache run: tests/Fixtures/app/console cache:clear --ansi - name: Run Behat tests diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 89495254045..f790b3b5e99 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -18,7 +18,8 @@ 'tests/Fixtures/app/var', 'docs/guides', 'docs/var', - '**vendor**' + 'src/Doctrine/Orm/Tests/var', + 'src/Doctrine/Odm/Tests/var' ]) ->notPath('src/Symfony/Bundle/DependencyInjection/Configuration.php') ->notPath('src/Annotation/ApiFilter.php') // temporary diff --git a/components.php b/components.php new file mode 100644 index 00000000000..b2530fbb686 --- /dev/null +++ b/components.php @@ -0,0 +1,168 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +/* + * This script checks for dependencies between our components + * and fails if a component has a wrong dependency. + */ +use Symfony\Component\Filesystem\Path; +use Symfony\Component\Finder\Finder; + +$loader = require './vendor/autoload.php'; +$namespace = 'ApiPlatform'; +$prefix = 'api-platform'; +$ignoreList = ['ApiPlatform\\Api', 'ApiPlatform\\Exception', 'ApiPlatform\\Util']; +$stopOnFailure = in_array('--stop-on-failure', $_SERVER['argv'], true); +$skipPaths = [__DIR__.'/src/GraphQl/Resolver/Stage']; + +/** + * Reads the beginning of a PHP class and returns "use" instructions matching our namespace. + */ +$class_uses_namespaces = function (ReflectionClass $r) use ($namespace): \Generator { + $fp = fopen($r->getFileName(), 'r'); + $u = 'use'; + $c = false; + while (($buffer = fgets($fp, 4096)) !== false) { + if ($c && \PHP_EOL === $buffer) { + break; + } + + if (!str_starts_with($buffer, $u)) { + continue; + } + + $c = true; + $buffer = substr($buffer, 4, -2); + if (str_starts_with($buffer, $namespace)) { + yield substr($buffer, 0, strpos($buffer, ' ') ?: null); + } + } + + fclose($fp); +}; + +// Creates and require the map of dependencies +$directories = []; +$map = []; +foreach (Finder::create()->in('src')->notPath('vendor')->name('composer.json') as $f) { + if (null === ($component = json_decode($f->getContents(), true))) { + continue; + } + + $filter = fn ($v) => str_starts_with($v, $prefix); + $dependencies = + array_merge( + array_filter(array_keys((array) $component['require']), $filter), + array_filter(array_keys((array) $component['require-dev'] ?? []), $filter) + ); + + $map[$component['name']] = ['namespace' => substr(key($component['autoload']['psr-4']), 0, -1), 'dependencies' => $dependencies]; + $directories[] = substr($f->getRealPath(), 0, -14); + + foreach (Finder::create()->in($f->getPath())->notPath('vendor')->notPath('var')->name('*.php')->notName('*.tpl.php')->notName('bootstrap.php') as $f) { + require_once $f->getRealPath(); + } +} + +// create a PSR map of dependencies +$psrMap = []; +foreach ($map as $component) { + $depsPsr = []; + foreach ($component['dependencies'] as $d) { + $depsPsr[] = $map[$d]['namespace']; + } + + $psrMap[$component['namespace']] = $depsPsr; +} + +$warned = []; +$getComponentNamespace = function (ReflectionClass $r, ReflectionClass $inside = null) use ($psrMap, $warned, $ignoreList, $namespace) { + $ns = $r->getNamespaceName(); + // Find this components namespace + $nsParts = explode('\\', $ns); + $n = count($nsParts); + $componentNs = $nsParts[0].'\\'.$nsParts[1]; + $i = 2; + + while (!isset($psrMap[$componentNs]) && $i < $n) { + if ($part = ($nsParts[$i++] ?? null)) { + $componentNs .= '\\'.$part; + } + } + + if (!isset($psrMap[$componentNs])) { + if (in_array($componentNs, $ignoreList, true)) { + return null; + } + + $guess = $nsParts[0].'\\'.$nsParts[1]; + if ($warned[$guess] ?? true) { + echo sprintf('"%s" is not an %s component at "%s" %s', $guess, $namespace, ($inside ?? $r)->getFileName(), \PHP_EOL); + $warned[$guess] = false; + } + + return null; + } + + return $componentNs; +}; + +$exitCode = 0; +$lnamespace = strlen($namespace); +foreach (array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits()) as $className) { + $r = new ReflectionClass($className); + $ns = $r->getNamespaceName(); + + foreach ($skipPaths as $base) { + if (!($fileName = $r->getFileName())) { + continue; + } + + if (Path::isBasePath($skipPaths[0], $fileName)) { + continue 2; + } + } + + if (!str_starts_with($ns, $namespace)) { + continue; + } + + $componentNs = $getComponentNamespace($r); + + if (!$componentNs) { + continue; + } + + foreach ($class_uses_namespaces($r) as $u) { + if (str_starts_with($u, $componentNs)) { + continue; + } + + $useNs = $getComponentNamespace(new ReflectionClass($u), $r); + + if (!$useNs || $useNs === $componentNs) { + continue; + } + + if (!in_array($useNs, $psrMap[$componentNs], true)) { + echo sprintf('"%s" uses "%s" although "%s" is not one of its dependencies %s', $className, $u, $useNs, \PHP_EOL); + $exitCode = 1; + + if ($stopOnFailure) { + exit($exitCode); + } + } + } +} + +exit($exitCode); diff --git a/composer.json b/composer.json index f7b965bb550..a7efa293cc6 100644 --- a/composer.json +++ b/composer.json @@ -28,13 +28,13 @@ "psr/cache": "^1.0 || ^2.0 || ^3.0", "psr/container": "^1.0 || ^2.0", "symfony/deprecation-contracts": "^3.1", - "symfony/http-foundation": "^6.1 || ^7.0", - "symfony/http-kernel": "^6.1 || ^7.0", - "symfony/property-access": "^6.1 || ^7.0", - "symfony/property-info": "^6.1 || ^7.0", - "symfony/serializer": "^6.1 || ^7.0", + "symfony/http-foundation": "^6.4 || ^7.0", + "symfony/http-kernel": "^6.4 || ^7.0", + "symfony/property-access": "^6.4 || ^7.0", + "symfony/property-info": "^6.4 || ^7.0", + "symfony/serializer": "^6.4 || ^7.0", "symfony/translation-contracts": "^3.3", - "symfony/web-link": "^6.1 || ^7.0", + "symfony/web-link": "^6.4 || ^7.0", "willdurand/negotiation": "^3.0" }, "require-dev": { @@ -57,47 +57,47 @@ "phpspec/prophecy-phpunit": "^2.0", "phpstan/extension-installer": "^1.1", "phpstan/phpdoc-parser": "^1.13", - "phpstan/phpstan": "^1.1", + "phpstan/phpstan": "^1.10", "phpstan/phpstan-doctrine": "^1.0", "phpstan/phpstan-phpunit": "^1.0", "phpstan/phpstan-symfony": "^1.0", - "phpunit/phpunit": "^9.5", + "phpunit/phpunit": "^9.6", "psr/log": "^1.0 || ^2.0 || ^3.0", "ramsey/uuid": "^3.9.7 || ^4.0", "ramsey/uuid-doctrine": "^1.4 || ^2.0", "sebastian/comparator": "<5.0", "soyuka/contexts": "v3.3.9", "soyuka/stubs-mongodb": "^1.0", - "symfony/asset": "^6.1 || ^7.0", - "symfony/browser-kit": "^6.1 || ^7.0", - "symfony/cache": "^6.1 || ^7.0", - "symfony/config": "^6.1 || ^7.0", - "symfony/console": "^6.1 || ^7.0", - "symfony/css-selector": "^6.1 || ^7.0", - "symfony/dependency-injection": "^6.1 || ^7.0.12", - "symfony/doctrine-bridge": "^6.1 || ^7.0", - "symfony/dom-crawler": "^6.1 || ^7.0", - "symfony/error-handler": "^6.1 || ^7.0", - "symfony/event-dispatcher": "^6.1 || ^7.0", - "symfony/expression-language": "^6.1 || ^7.0", - "symfony/finder": "^6.1 || ^7.0", - "symfony/form": "^6.1 || ^7.0", - "symfony/framework-bundle": "^6.1 || ^7.0", - "symfony/http-client": "^6.1 || ^7.0", - "symfony/intl": "^6.1 || ^7.0", + "symfony/asset": "^6.4 || ^7.0", + "symfony/browser-kit": "^6.4 || ^7.0", + "symfony/cache": "^6.4 || ^7.0", + "symfony/config": "^6.4 || ^7.0", + "symfony/console": "^6.4 || ^7.0", + "symfony/css-selector": "^6.4 || ^7.0", + "symfony/dependency-injection": "^6.4 || ^7.0.12", + "symfony/doctrine-bridge": "^6.4 || ^7.0", + "symfony/dom-crawler": "^6.4 || ^7.0", + "symfony/error-handler": "^6.4 || ^7.0", + "symfony/event-dispatcher": "^6.4 || ^7.0", + "symfony/expression-language": "^6.4 || ^7.0", + "symfony/finder": "^6.4 || ^7.0", + "symfony/form": "^6.4 || ^7.0", + "symfony/framework-bundle": "^6.4 || ^7.0", + "symfony/http-client": "^6.4 || ^7.0", + "symfony/intl": "^6.4 || ^7.0", "symfony/maker-bundle": "^1.24", "symfony/mercure-bundle": "*", - "symfony/messenger": "^6.1 || ^7.0", - "symfony/phpunit-bridge": "^6.1 || ^7.0", - "symfony/routing": "^6.1 || ^7.0", - "symfony/security-bundle": "^6.1 || ^7.0", - "symfony/security-core": "^6.1 || ^7.0", - "symfony/stopwatch": "^6.1 || ^7.0", - "symfony/twig-bundle": "^6.1 || ^7.0", - "symfony/uid": "^6.1 || ^7.0", - "symfony/validator": "^6.1 || ^7.0", - "symfony/web-profiler-bundle": "^6.1 || ^7.0", - "symfony/yaml": "^6.1 || ^7.0", + "symfony/messenger": "^6.4 || ^7.0", + "symfony/phpunit-bridge": "^6.4 || ^7.0", + "symfony/routing": "^6.4 || ^7.0", + "symfony/security-bundle": "^6.4 || ^7.0", + "symfony/security-core": "^6.4 || ^7.0", + "symfony/stopwatch": "^6.4 || ^7.0", + "symfony/twig-bundle": "^6.4 || ^7.0", + "symfony/uid": "^6.4 || ^7.0", + "symfony/validator": "^6.4 || ^7.0", + "symfony/web-profiler-bundle": "^6.4 || ^7.0", + "symfony/yaml": "^6.4 || ^7.0", "twig/twig": "^1.42.3 || ^2.12 || ^3.0", "webonyx/graphql-php": "^14.0 || ^15.0" }, @@ -157,7 +157,7 @@ "dev-main": "3.3.x-dev" }, "symfony": { - "require": "^6.1 || ^7.0" + "require": "^6.4 || ^7.0" } } } diff --git a/phparkitect-baseline.json b/phparkitect-baseline.json deleted file mode 100644 index 54ab60e8266..00000000000 --- a/phparkitect-baseline.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "violations": [ - ], - "stopOnFailure": false -} diff --git a/phparkitect.php b/phparkitect.php deleted file mode 100644 index 91e71043c58..00000000000 --- a/phparkitect.php +++ /dev/null @@ -1,70 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -use Arkitect\ClassSet; -use Arkitect\CLI\Config; -use Arkitect\RuleBuilders\Architecture\Architecture; - -return static function (Config $config): void { - $classSet = ClassSet::fromDir(__DIR__.'/src') - ->excludePath('*/vendor/*') - ->excludePath('*/Tests/*'); - - $config->add($classSet, ...Architecture::withComponents() - ->component('DoctrineCommon')->definedBy('ApiPlatform\Doctrine\Common\*') - ->component('Documentation')->definedBy('ApiPlatform\Documentation\*') - ->component('Elasticsearch')->definedBy('ApiPlatform\Elasticsearch\*') - ->component('GraphQl')->definedBy('ApiPlatform\GraphQl\*') - ->component('HttpCache')->definedBy('ApiPlatform\HttpCache\*') - ->component('Hydra')->definedBy('ApiPlatform\Hydra\*') - ->component('JsonLd')->definedBy('ApiPlatform\JsonLd\*') - ->component('JsonSchema')->definedBy('ApiPlatform\JsonSchema\*') - ->component('Metadata')->definedBy('ApiPlatform\Metadata\*') - ->component('OpenApi')->definedBy('ApiPlatform\OpenApi\*') - ->component('ParameterValidator')->definedBy('ApiPlatform\ParameterValidator\*') - ->component('RamseyUuid')->definedBy('ApiPlatform\RamseyUuid\*') - ->component('Serializer')->definedBy('ApiPlatform\Serializer\*') - ->component('State')->definedBy('ApiPlatform\State\*') - ->component('Symfony')->definedBy('ApiPlatform\Symfony\*') - ->component('Validator')->definedBy('ApiPlatform\Validator\*') - - ->where('DoctrineCommon')->mayDependOnComponents('Metadata', 'State') - ->where('Documentation')->mayDependOnComponents('Metadata', 'OpenApi', 'State') - ->where('Elasticsearch')->mayDependOnComponents('Metadata', 'Serializer', 'State') - ->where('GraphQl')->mayDependOnComponents('Metadata', 'Serializer', 'State', 'Validator') - ->where('HttpCache')->mayDependOnComponents('Metadata', 'State') - ->where('Hydra')->mayDependOnComponents('Metadata', 'State', 'JsonLd', 'Serializer', 'JsonSchema') - ->where('JsonLd')->mayDependOnComponents('Metadata', 'State', 'Serializer') - ->where('JsonSchema')->mayDependOnComponents('Metadata') - ->where('OpenApi')->mayDependOnComponents('JsonSchema', 'Metadata', 'State') - ->where('RamseyUuid')->mayDependOnComponents('Metadata') - ->where('Serializer')->mayDependOnComponents('Metadata', 'State') - ->where('Symfony')->mayDependOnComponents( - 'Documentation', - 'GraphQl', - 'Metadata', - 'State', - 'Validator', - 'Serializer', - 'JsonSchema', - 'JsonLd', - 'OpenApi', - 'ParameterValidator', - 'HttpCache', - 'Elasticsearch' - ) - ->where('Validator')->mayDependOnComponents('Metadata') - - ->rules() - ); -}; diff --git a/phpstan.neon.dist b/phpstan.neon.dist index baf9ea0b4bd..03e6f9f4d42 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -27,7 +27,10 @@ parameters: # Templates for Maker - src/Symfony/Maker/Resources/skeleton # subtree split - - **vendor** + - src/Doctrine/Orm/Tests/var/* + - src/Doctrine/Odm/Tests/var/* + - src/Doctrine/*/vendor/* + - src/*/vendor/* # Symfony 6 support - src/OpenApi/Serializer/CacheableSupportsMethodInterface.php - src/Serializer/CacheableSupportsMethodInterface.php @@ -90,9 +93,6 @@ parameters: - message: '#^Service "[^"]+" is private.$#' path: src - - - message: '#^Property .+ is unused.$#' - path: tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineDummy.php - message: '#^Class .+ not found.$#' path: src/Elasticsearch/Tests diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c4c10132275..2afecb3bf9a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -30,6 +30,7 @@ tests vendor src/**/Tests/ + src/Doctrine/**/Tests/ .php-cs-fixer.dist.php diff --git a/src/Action/ExceptionAction.php b/src/Action/ExceptionAction.php index fc662490531..b6425fdc693 100644 --- a/src/Action/ExceptionAction.php +++ b/src/Action/ExceptionAction.php @@ -20,6 +20,7 @@ use ApiPlatform\Symfony\Util\RequestAttributesExtractor; use ApiPlatform\Symfony\Validator\Exception\ConstraintViolationListAwareExceptionInterface; use ApiPlatform\Util\ErrorFormatGuesser; +use ApiPlatform\Validator\Exception\ConstraintViolationListAwareExceptionInterface as ApiPlatformConstraintViolationListAwareExceptionInterface; use Symfony\Component\ErrorHandler\Exception\FlattenException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -77,7 +78,7 @@ public function __invoke(FlattenException $exception, Request $request): Respons $context = ['statusCode' => $statusCode, 'rfc_7807_compliant_errors' => $operation?->getExtraProperties()['rfc_7807_compliant_errors'] ?? false]; $error = $request->attributes->get('exception') ?? $exception; - if ($error instanceof ConstraintViolationListAwareExceptionInterface) { + if ($error instanceof ConstraintViolationListAwareExceptionInterface || $error instanceof ApiPlatformConstraintViolationListAwareExceptionInterface) { $error = $error->getConstraintViolationList(); } elseif (method_exists($error, 'getViolations') && $error->getViolations() instanceof ConstraintViolationListInterface) { $error = $error->getViolations(); diff --git a/src/Api/composer.json b/src/Api/composer.json deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/Doctrine/Common/.gitattributes b/src/Doctrine/Common/.gitattributes new file mode 100644 index 00000000000..ae3c2e1685a --- /dev/null +++ b/src/Doctrine/Common/.gitattributes @@ -0,0 +1,2 @@ +/.gitignore export-ignore +/Tests export-ignore diff --git a/src/Doctrine/Common/Filter/BooleanFilterTrait.php b/src/Doctrine/Common/Filter/BooleanFilterTrait.php index 95525ef7816..f906836b755 100644 --- a/src/Doctrine/Common/Filter/BooleanFilterTrait.php +++ b/src/Doctrine/Common/Filter/BooleanFilterTrait.php @@ -14,7 +14,7 @@ namespace ApiPlatform\Doctrine\Common\Filter; use ApiPlatform\Doctrine\Common\PropertyHelperTrait; -use ApiPlatform\Exception\InvalidArgumentException; +use ApiPlatform\Metadata\Exception\InvalidArgumentException; use Psr\Log\LoggerInterface; /** diff --git a/src/Doctrine/Common/Filter/DateFilterTrait.php b/src/Doctrine/Common/Filter/DateFilterTrait.php index 9b55b2d00ab..f5ceb6d5874 100644 --- a/src/Doctrine/Common/Filter/DateFilterTrait.php +++ b/src/Doctrine/Common/Filter/DateFilterTrait.php @@ -14,7 +14,7 @@ namespace ApiPlatform\Doctrine\Common\Filter; use ApiPlatform\Doctrine\Common\PropertyHelperTrait; -use ApiPlatform\Exception\InvalidArgumentException; +use ApiPlatform\Metadata\Exception\InvalidArgumentException; /** * Trait for filtering the collection by date intervals. diff --git a/src/Doctrine/Common/Filter/ExistsFilterTrait.php b/src/Doctrine/Common/Filter/ExistsFilterTrait.php index ce5648fca64..88a3da57746 100644 --- a/src/Doctrine/Common/Filter/ExistsFilterTrait.php +++ b/src/Doctrine/Common/Filter/ExistsFilterTrait.php @@ -14,7 +14,7 @@ namespace ApiPlatform\Doctrine\Common\Filter; use ApiPlatform\Doctrine\Common\PropertyHelperTrait; -use ApiPlatform\Exception\InvalidArgumentException; +use ApiPlatform\Metadata\Exception\InvalidArgumentException; use Psr\Log\LoggerInterface; /** diff --git a/src/Doctrine/Common/Filter/NumericFilterTrait.php b/src/Doctrine/Common/Filter/NumericFilterTrait.php index 153a4deb09d..8136fb01b5b 100644 --- a/src/Doctrine/Common/Filter/NumericFilterTrait.php +++ b/src/Doctrine/Common/Filter/NumericFilterTrait.php @@ -14,7 +14,7 @@ namespace ApiPlatform\Doctrine\Common\Filter; use ApiPlatform\Doctrine\Common\PropertyHelperTrait; -use ApiPlatform\Exception\InvalidArgumentException; +use ApiPlatform\Metadata\Exception\InvalidArgumentException; use Psr\Log\LoggerInterface; /** diff --git a/src/Doctrine/Common/Filter/RangeFilterTrait.php b/src/Doctrine/Common/Filter/RangeFilterTrait.php index 6dbadab2e80..895488d1cb3 100644 --- a/src/Doctrine/Common/Filter/RangeFilterTrait.php +++ b/src/Doctrine/Common/Filter/RangeFilterTrait.php @@ -14,7 +14,7 @@ namespace ApiPlatform\Doctrine\Common\Filter; use ApiPlatform\Doctrine\Common\PropertyHelperTrait; -use ApiPlatform\Exception\InvalidArgumentException; +use ApiPlatform\Metadata\Exception\InvalidArgumentException; use Psr\Log\LoggerInterface; /** diff --git a/src/Doctrine/Common/Filter/SearchFilterTrait.php b/src/Doctrine/Common/Filter/SearchFilterTrait.php index e85bbf8a056..6a54b1e211b 100644 --- a/src/Doctrine/Common/Filter/SearchFilterTrait.php +++ b/src/Doctrine/Common/Filter/SearchFilterTrait.php @@ -16,7 +16,7 @@ use ApiPlatform\Api\IdentifiersExtractorInterface as LegacyIdentifiersExtractorInterface; use ApiPlatform\Api\IriConverterInterface as LegacyIriConverterInterface; use ApiPlatform\Doctrine\Common\PropertyHelperTrait; -use ApiPlatform\Exception\InvalidArgumentException; +use ApiPlatform\Metadata\Exception\InvalidArgumentException; use ApiPlatform\Metadata\IdentifiersExtractorInterface; use ApiPlatform\Metadata\IriConverterInterface; use Psr\Log\LoggerInterface; diff --git a/src/Doctrine/Common/State/LinksHandlerLocatorTrait.php b/src/Doctrine/Common/State/LinksHandlerLocatorTrait.php index 84f8960d993..8c09fae6e52 100644 --- a/src/Doctrine/Common/State/LinksHandlerLocatorTrait.php +++ b/src/Doctrine/Common/State/LinksHandlerLocatorTrait.php @@ -13,7 +13,6 @@ namespace ApiPlatform\Doctrine\Common\State; -use ApiPlatform\Doctrine\Orm\State\Options; use ApiPlatform\Metadata\Exception\RuntimeException; use ApiPlatform\Metadata\Operation; use Psr\Container\ContainerInterface; diff --git a/src/Doctrine/Common/State/Options.php b/src/Doctrine/Common/State/Options.php new file mode 100644 index 00000000000..df42fc6cb84 --- /dev/null +++ b/src/Doctrine/Common/State/Options.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Doctrine\Common\State; + +use ApiPlatform\State\OptionsInterface; + +class Options implements OptionsInterface +{ + /** + * @param mixed $handleLinks experimental callable, typed mixed as we may want a service name in the future + */ + public function __construct( + protected mixed $handleLinks = null, + ) { + } + + public function getHandleLinks(): mixed + { + return $this->handleLinks; + } + + public function withHandleLinks(mixed $handleLinks): self + { + $self = clone $this; + $self->handleLinks = $handleLinks; + + return $self; + } +} diff --git a/tests/Doctrine/Common/Filter/BooleanFilterTestTrait.php b/src/Doctrine/Common/Tests/Filter/BooleanFilterTestTrait.php similarity index 98% rename from tests/Doctrine/Common/Filter/BooleanFilterTestTrait.php rename to src/Doctrine/Common/Tests/Filter/BooleanFilterTestTrait.php index 3b7c6442bc1..090ef4b0667 100644 --- a/tests/Doctrine/Common/Filter/BooleanFilterTestTrait.php +++ b/src/Doctrine/Common/Tests/Filter/BooleanFilterTestTrait.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Common\Filter; +namespace ApiPlatform\Doctrine\Common\Tests\Filter; /** * @author Amrouche Hamza diff --git a/tests/Doctrine/Common/Filter/DateFilterTestTrait.php b/src/Doctrine/Common/Tests/Filter/DateFilterTestTrait.php similarity index 99% rename from tests/Doctrine/Common/Filter/DateFilterTestTrait.php rename to src/Doctrine/Common/Tests/Filter/DateFilterTestTrait.php index 95fe94d71f1..e47b22517f2 100644 --- a/tests/Doctrine/Common/Filter/DateFilterTestTrait.php +++ b/src/Doctrine/Common/Tests/Filter/DateFilterTestTrait.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Common\Filter; +namespace ApiPlatform\Doctrine\Common\Tests\Filter; /** * @author Théo FIDRY diff --git a/tests/Doctrine/Common/Filter/ExistsFilterTestTrait.php b/src/Doctrine/Common/Tests/Filter/ExistsFilterTestTrait.php similarity index 99% rename from tests/Doctrine/Common/Filter/ExistsFilterTestTrait.php rename to src/Doctrine/Common/Tests/Filter/ExistsFilterTestTrait.php index c74262fbd74..f7e294b6e3f 100644 --- a/tests/Doctrine/Common/Filter/ExistsFilterTestTrait.php +++ b/src/Doctrine/Common/Tests/Filter/ExistsFilterTestTrait.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Common\Filter; +namespace ApiPlatform\Doctrine\Common\Tests\Filter; /** * @author Antoine Bluchet diff --git a/tests/Doctrine/Common/Filter/NumericFilterTestTrait.php b/src/Doctrine/Common/Tests/Filter/NumericFilterTestTrait.php similarity index 99% rename from tests/Doctrine/Common/Filter/NumericFilterTestTrait.php rename to src/Doctrine/Common/Tests/Filter/NumericFilterTestTrait.php index d019b08afea..91b63e4b2ff 100644 --- a/tests/Doctrine/Common/Filter/NumericFilterTestTrait.php +++ b/src/Doctrine/Common/Tests/Filter/NumericFilterTestTrait.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Common\Filter; +namespace ApiPlatform\Doctrine\Common\Tests\Filter; /** * @author Amrouche Hamza diff --git a/tests/Doctrine/Common/Filter/OrderFilterTestTrait.php b/src/Doctrine/Common/Tests/Filter/OrderFilterTestTrait.php similarity index 99% rename from tests/Doctrine/Common/Filter/OrderFilterTestTrait.php rename to src/Doctrine/Common/Tests/Filter/OrderFilterTestTrait.php index f6d1ae833a2..374e0ba239d 100644 --- a/tests/Doctrine/Common/Filter/OrderFilterTestTrait.php +++ b/src/Doctrine/Common/Tests/Filter/OrderFilterTestTrait.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Common\Filter; +namespace ApiPlatform\Doctrine\Common\Tests\Filter; /** * @author Théo FIDRY diff --git a/tests/Doctrine/Common/Filter/RangeFilterTestTrait.php b/src/Doctrine/Common/Tests/Filter/RangeFilterTestTrait.php similarity index 98% rename from tests/Doctrine/Common/Filter/RangeFilterTestTrait.php rename to src/Doctrine/Common/Tests/Filter/RangeFilterTestTrait.php index 5b0520597c5..029b938caa3 100644 --- a/tests/Doctrine/Common/Filter/RangeFilterTestTrait.php +++ b/src/Doctrine/Common/Tests/Filter/RangeFilterTestTrait.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Common\Filter; +namespace ApiPlatform\Doctrine\Common\Tests\Filter; /** * @author Lee Siong Chan diff --git a/tests/Doctrine/Common/Filter/SearchFilterTestTrait.php b/src/Doctrine/Common/Tests/Filter/SearchFilterTestTrait.php similarity index 99% rename from tests/Doctrine/Common/Filter/SearchFilterTestTrait.php rename to src/Doctrine/Common/Tests/Filter/SearchFilterTestTrait.php index bcfad26191e..5cf9cd54f26 100644 --- a/tests/Doctrine/Common/Filter/SearchFilterTestTrait.php +++ b/src/Doctrine/Common/Tests/Filter/SearchFilterTestTrait.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Common\Filter; +namespace ApiPlatform\Doctrine\Common\Tests\Filter; /** * @author Julien Deniau diff --git a/src/Doctrine/Common/Tests/Fixtures/TestBundle/Entity/RelatedDummy.php b/src/Doctrine/Common/Tests/Fixtures/TestBundle/Entity/RelatedDummy.php index 718c00e5a06..fff67d6e77e 100644 --- a/src/Doctrine/Common/Tests/Fixtures/TestBundle/Entity/RelatedDummy.php +++ b/src/Doctrine/Common/Tests/Fixtures/TestBundle/Entity/RelatedDummy.php @@ -13,10 +13,6 @@ namespace ApiPlatform\Doctrine\Common\Tests\Fixtures\TestBundle\Entity; -use ApiPlatform\Doctrine\Orm\Filter\DateFilter; -use ApiPlatform\Doctrine\Orm\Filter\ExistsFilter; -use ApiPlatform\Doctrine\Orm\Filter\SearchFilter; -use ApiPlatform\Metadata\ApiFilter; use ApiPlatform\Metadata\ApiProperty; use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\Get; @@ -51,7 +47,6 @@ #[ApiResource(uriTemplate: '/related_owned_dummies/{id}/owning_dummy/related_dummies/{relatedDummies}{._format}', uriVariables: ['id' => new Link(fromClass: RelatedOwnedDummy::class, identifiers: ['id'], fromProperty: 'owningDummy'), 'owningDummy' => new Link(fromClass: Dummy::class, identifiers: [], expandedValue: 'owning_dummy', fromProperty: 'relatedDummies'), 'relatedDummies' => new Link(fromClass: self::class, identifiers: ['id'])], status: 200, types: ['https://schema.org/Product'], filters: ['related_dummy.friends', 'related_dummy.complex_sub_query'], normalizationContext: ['groups' => ['friends']], operations: [new Get()])] #[ApiResource(uriTemplate: '/related_owning_dummies/{id}/owned_dummy/related_dummies{._format}', uriVariables: ['id' => new Link(fromClass: RelatedOwningDummy::class, identifiers: ['id'], fromProperty: 'ownedDummy'), 'ownedDummy' => new Link(fromClass: Dummy::class, identifiers: [], expandedValue: 'owned_dummy', fromProperty: 'relatedDummies')], status: 200, types: ['https://schema.org/Product'], filters: ['related_dummy.friends', 'related_dummy.complex_sub_query'], normalizationContext: ['groups' => ['friends']], operations: [new GetCollection()])] #[ApiResource(uriTemplate: '/related_owning_dummies/{id}/owned_dummy/related_dummies/{relatedDummies}{._format}', uriVariables: ['id' => new Link(fromClass: RelatedOwningDummy::class, identifiers: ['id'], fromProperty: 'ownedDummy'), 'ownedDummy' => new Link(fromClass: Dummy::class, identifiers: [], expandedValue: 'owned_dummy', fromProperty: 'relatedDummies'), 'relatedDummies' => new Link(fromClass: self::class, identifiers: ['id'])], status: 200, types: ['https://schema.org/Product'], filters: ['related_dummy.friends', 'related_dummy.complex_sub_query'], normalizationContext: ['groups' => ['friends']], operations: [new Get()])] -#[ApiFilter(filterClass: SearchFilter::class, properties: ['id'])] #[ORM\Entity] class RelatedDummy extends ParentDummy implements \Stringable { @@ -73,8 +68,6 @@ class RelatedDummy extends ParentDummy implements \Stringable #[ApiProperty(deprecationReason: 'This property is deprecated for upgrade test')] #[ORM\Column] #[Groups(['barcelona', 'chicago', 'friends'])] - #[ApiFilter(filterClass: SearchFilter::class)] - #[ApiFilter(filterClass: ExistsFilter::class)] protected $symfony = 'symfony'; /** @@ -83,7 +76,6 @@ class RelatedDummy extends ParentDummy implements \Stringable #[ORM\Column(type: 'datetime', nullable: true)] #[Assert\DateTime] #[Groups(['friends'])] - #[ApiFilter(filterClass: DateFilter::class)] public $dummyDate; #[ORM\ManyToOne(targetEntity: ThirdLevel::class, cascade: ['persist'])] diff --git a/src/Doctrine/Common/Tests/Fixtures/TestBundle/Entity/RelatedToDummyFriend.php b/src/Doctrine/Common/Tests/Fixtures/TestBundle/Entity/RelatedToDummyFriend.php index 45fca2fa8b5..ecaf3785583 100644 --- a/src/Doctrine/Common/Tests/Fixtures/TestBundle/Entity/RelatedToDummyFriend.php +++ b/src/Doctrine/Common/Tests/Fixtures/TestBundle/Entity/RelatedToDummyFriend.php @@ -17,7 +17,6 @@ use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Link; -use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyFriend; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; diff --git a/src/Doctrine/Common/Tests/Fixtures/TestBundle/Entity/ThirdLevel.php b/src/Doctrine/Common/Tests/Fixtures/TestBundle/Entity/ThirdLevel.php index 948101bac72..d2c4e6ea31a 100644 --- a/src/Doctrine/Common/Tests/Fixtures/TestBundle/Entity/ThirdLevel.php +++ b/src/Doctrine/Common/Tests/Fixtures/TestBundle/Entity/ThirdLevel.php @@ -16,7 +16,6 @@ use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\Get; use ApiPlatform\Metadata\Link; -use ApiPlatform\Tests\Fixtures\TestBundle\Entity\FourthLevel; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\Groups; diff --git a/src/Doctrine/Common/composer.json b/src/Doctrine/Common/composer.json index 52272764052..9f5353a1a27 100644 --- a/src/Doctrine/Common/composer.json +++ b/src/Doctrine/Common/composer.json @@ -23,20 +23,18 @@ ], "require": { "php": ">=8.1", + "api-platform/metadata": "*@dev || ^3.1", "api-platform/state": "*@dev || ^3.1", - "api-platform/metadata": "*@dev || ^3.1" + "doctrine/collections": "^2.1", + "doctrine/common": "^3.2.2", + "doctrine/persistence": "^3.2" }, "require-dev": { - "symfony/phpunit-bridge": "^6.1", - "phpstan/phpdoc-parser": "^1.16", - "symfony/routing": "^6.1", - "symfony/yaml": "^6.1", - "symfony/config": "^6.1", - "doctrine/orm": "^2.14", - "doctrine/mongodb-odm": "^2.2", - "doctrine/mongodb-odm-bundle": "^4.0", - "doctrine/common": "^3.2.2", - "phpspec/prophecy-phpunit": "^2.0" + "doctrine/mongodb-odm": "^2.6", + "doctrine/orm": "^2.17", + "phpspec/prophecy-phpunit": "^2.0", + "phpunit/phpunit": "^10.0", + "symfony/phpunit-bridge": "^6.4 || ^7.0" }, "conflict": { "doctrine/persistence": "<1.3" @@ -62,7 +60,7 @@ "dev-main": "3.2.x-dev" }, "symfony": { - "require": "^6.1" + "require": "^6.4" } }, "repositories": [ diff --git a/src/Doctrine/Common/phpunit.xml.dist b/src/Doctrine/Common/phpunit.xml.dist index 326841db8f3..968fa633da6 100644 --- a/src/Doctrine/Common/phpunit.xml.dist +++ b/src/Doctrine/Common/phpunit.xml.dist @@ -1,31 +1,20 @@ - - - - - - - - - ./Tests/ - - - - - - ./ - - - ./Tests - ./vendor - - + + + + + + + ./Tests/ + + + + + ./ + + + ./Tests + ./vendor + + - diff --git a/src/Doctrine/Odm/.gitattributes b/src/Doctrine/Odm/.gitattributes new file mode 100644 index 00000000000..ae3c2e1685a --- /dev/null +++ b/src/Doctrine/Odm/.gitattributes @@ -0,0 +1,2 @@ +/.gitignore export-ignore +/Tests export-ignore diff --git a/src/Doctrine/Odm/.gitignore b/src/Doctrine/Odm/.gitignore new file mode 100644 index 00000000000..2db77de0df4 --- /dev/null +++ b/src/Doctrine/Odm/.gitignore @@ -0,0 +1,5 @@ +/composer.lock +/vendor +/.phpunit.result.cache +/.phpunit.cache +/Tests/var diff --git a/src/Doctrine/Odm/Extension/PaginationExtension.php b/src/Doctrine/Odm/Extension/PaginationExtension.php index 1456207a327..97da9973159 100644 --- a/src/Doctrine/Odm/Extension/PaginationExtension.php +++ b/src/Doctrine/Odm/Extension/PaginationExtension.php @@ -14,7 +14,7 @@ namespace ApiPlatform\Doctrine\Odm\Extension; use ApiPlatform\Doctrine\Odm\Paginator; -use ApiPlatform\Exception\RuntimeException; +use ApiPlatform\Metadata\Exception\RuntimeException; use ApiPlatform\Metadata\Operation; use ApiPlatform\State\Pagination\Pagination; use Doctrine\ODM\MongoDB\Aggregation\Builder; diff --git a/src/Doctrine/Odm/Filter/DateFilter.php b/src/Doctrine/Odm/Filter/DateFilter.php index 0b848b2a49b..bd2426932e5 100644 --- a/src/Doctrine/Odm/Filter/DateFilter.php +++ b/src/Doctrine/Odm/Filter/DateFilter.php @@ -15,7 +15,7 @@ use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface; use ApiPlatform\Doctrine\Common\Filter\DateFilterTrait; -use ApiPlatform\Exception\InvalidArgumentException; +use ApiPlatform\Metadata\Exception\InvalidArgumentException; use ApiPlatform\Metadata\Operation; use Doctrine\ODM\MongoDB\Aggregation\Builder; use Doctrine\ODM\MongoDB\Types\Type as MongoDbType; diff --git a/src/Doctrine/Odm/Filter/SearchFilter.php b/src/Doctrine/Odm/Filter/SearchFilter.php index 230fff70fe1..63870618639 100644 --- a/src/Doctrine/Odm/Filter/SearchFilter.php +++ b/src/Doctrine/Odm/Filter/SearchFilter.php @@ -17,7 +17,7 @@ use ApiPlatform\Api\IriConverterInterface as LegacyIriConverterInterface; use ApiPlatform\Doctrine\Common\Filter\SearchFilterInterface; use ApiPlatform\Doctrine\Common\Filter\SearchFilterTrait; -use ApiPlatform\Exception\InvalidArgumentException; +use ApiPlatform\Metadata\Exception\InvalidArgumentException; use ApiPlatform\Metadata\IdentifiersExtractorInterface; use ApiPlatform\Metadata\IriConverterInterface; use ApiPlatform\Metadata\Operation; diff --git a/src/Doctrine/Odm/LICENSE b/src/Doctrine/Odm/LICENSE new file mode 100644 index 00000000000..1ca98eeb824 --- /dev/null +++ b/src/Doctrine/Odm/LICENSE @@ -0,0 +1,21 @@ +The MIT license + +Copyright (c) 2015-present Kévin Dunglas + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/src/Doctrine/Odm/Paginator.php b/src/Doctrine/Odm/Paginator.php index 8639094175f..4bd028ec0e0 100644 --- a/src/Doctrine/Odm/Paginator.php +++ b/src/Doctrine/Odm/Paginator.php @@ -13,7 +13,7 @@ namespace ApiPlatform\Doctrine\Odm; -use ApiPlatform\Exception\InvalidArgumentException; +use ApiPlatform\Metadata\Exception\InvalidArgumentException; use ApiPlatform\State\Pagination\PaginatorInterface; use Doctrine\ODM\MongoDB\Iterator\Iterator; use Doctrine\ODM\MongoDB\UnitOfWork; diff --git a/src/Doctrine/Odm/PropertyHelperTrait.php b/src/Doctrine/Odm/PropertyHelperTrait.php index 449168b281b..c368df150c7 100644 --- a/src/Doctrine/Odm/PropertyHelperTrait.php +++ b/src/Doctrine/Odm/PropertyHelperTrait.php @@ -13,7 +13,7 @@ namespace ApiPlatform\Doctrine\Odm; -use ApiPlatform\Exception\InvalidArgumentException; +use ApiPlatform\Metadata\Exception\InvalidArgumentException; use Doctrine\ODM\MongoDB\Aggregation\Builder; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata as MongoDbOdmClassMetadata; use Doctrine\ODM\MongoDB\Mapping\MappingException; diff --git a/src/Doctrine/Odm/State/CollectionProvider.php b/src/Doctrine/Odm/State/CollectionProvider.php index 84d9cc7fd27..5825788e2e3 100644 --- a/src/Doctrine/Odm/State/CollectionProvider.php +++ b/src/Doctrine/Odm/State/CollectionProvider.php @@ -16,7 +16,7 @@ use ApiPlatform\Doctrine\Common\State\LinksHandlerLocatorTrait; use ApiPlatform\Doctrine\Odm\Extension\AggregationCollectionExtensionInterface; use ApiPlatform\Doctrine\Odm\Extension\AggregationResultCollectionExtensionInterface; -use ApiPlatform\Exception\RuntimeException; +use ApiPlatform\Metadata\Exception\RuntimeException; use ApiPlatform\Metadata\Operation; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\State\ProviderInterface; diff --git a/src/Doctrine/Odm/State/ItemProvider.php b/src/Doctrine/Odm/State/ItemProvider.php index 04f728e0b0c..6c4c76ccec6 100644 --- a/src/Doctrine/Odm/State/ItemProvider.php +++ b/src/Doctrine/Odm/State/ItemProvider.php @@ -16,7 +16,7 @@ use ApiPlatform\Doctrine\Common\State\LinksHandlerLocatorTrait; use ApiPlatform\Doctrine\Odm\Extension\AggregationItemExtensionInterface; use ApiPlatform\Doctrine\Odm\Extension\AggregationResultItemExtensionInterface; -use ApiPlatform\Exception\RuntimeException; +use ApiPlatform\Metadata\Exception\RuntimeException; use ApiPlatform\Metadata\Operation; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\State\ProviderInterface; diff --git a/src/Doctrine/Odm/State/LinksHandler.php b/src/Doctrine/Odm/State/LinksHandler.php new file mode 100644 index 00000000000..15520025e32 --- /dev/null +++ b/src/Doctrine/Odm/State/LinksHandler.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Doctrine\Odm\State; + +use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; +use Doctrine\ODM\MongoDB\Aggregation\Builder; +use Doctrine\Persistence\ManagerRegistry; + +final class LinksHandler implements LinksHandlerInterface +{ + use LinksHandlerTrait { + handleLinks as private handle; + } + + public function __construct(ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory, ManagerRegistry $managerRegistry) + { + $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory; + $this->managerRegistry = $managerRegistry; + } + + public function handleLinks(Builder $aggregationBuilder, array $uriVariables, array $context): void + { + $this->handle($aggregationBuilder, $uriVariables, $context, $context['documentClass'], $context['operation']); + } +} diff --git a/src/Doctrine/Odm/State/LinksHandlerInterface.php b/src/Doctrine/Odm/State/LinksHandlerInterface.php index a60421fe1f9..99e46168324 100644 --- a/src/Doctrine/Odm/State/LinksHandlerInterface.php +++ b/src/Doctrine/Odm/State/LinksHandlerInterface.php @@ -26,8 +26,8 @@ interface LinksHandlerInterface * * @see LinksHandlerTrait * - * @param array $uriVariables - * @param array{entityClass: string, operation: Operation}&array $context + * @param array $uriVariables + * @param array{documentClass: string, operation: Operation}&array $context */ public function handleLinks(Builder $aggregationBuilder, array $uriVariables, array $context): void; } diff --git a/src/Doctrine/Odm/State/Options.php b/src/Doctrine/Odm/State/Options.php index 919c10f8045..459d6bc49ec 100644 --- a/src/Doctrine/Odm/State/Options.php +++ b/src/Doctrine/Odm/State/Options.php @@ -13,9 +13,10 @@ namespace ApiPlatform\Doctrine\Odm\State; +use ApiPlatform\Doctrine\Common\State\Options as CommonOptions; use ApiPlatform\State\OptionsInterface; -class Options implements OptionsInterface +class Options extends CommonOptions implements OptionsInterface { /** * @param mixed $handleLinks experimental callable, typed mixed as we may want a service name in the future @@ -24,8 +25,9 @@ class Options implements OptionsInterface */ public function __construct( protected ?string $documentClass = null, - protected mixed $handleLinks = null, + mixed $handleLinks = null, ) { + parent::__construct(handleLinks: $handleLinks); } public function getDocumentClass(): ?string @@ -40,17 +42,4 @@ public function withDocumentClass(?string $documentClass): self return $self; } - - public function getHandleLinks(): mixed - { - return $this->handleLinks; - } - - public function withHandleLinks(mixed $handleLinks): self - { - $self = clone $this; - $self->handleLinks = $handleLinks; - - return $self; - } } diff --git a/src/Doctrine/Odm/Tests/AppKernel.php b/src/Doctrine/Odm/Tests/AppKernel.php new file mode 100644 index 00000000000..6a07f359d97 --- /dev/null +++ b/src/Doctrine/Odm/Tests/AppKernel.php @@ -0,0 +1,88 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Doctrine\Odm\Tests; + +use ApiPlatform\Symfony\Bundle\ApiPlatformBundle; +use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle; +use Symfony\Bundle\FrameworkBundle\FrameworkBundle; +use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; +use Symfony\Component\Config\Loader\LoaderInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\HttpKernel\Kernel; + +/** + * AppKernel for tests. + * + * @author Kévin Dunglas + */ +class AppKernel extends Kernel +{ + use MicroKernelTrait; + + public function __construct(string $environment, bool $debug) + { + parent::__construct($environment, $debug); + + // patch for behat/symfony2-extension not supporting %env(APP_ENV)% + $this->environment = $_SERVER['APP_ENV'] ?? $environment; + } + + public function registerBundles(): array + { + return [ + new ApiPlatformBundle(), + new FrameworkBundle(), + new DoctrineMongoDBBundle(), + ]; + } + + public function getProjectDir(): string + { + return __DIR__; + } + + protected function configureRoutes($routes): void + { + } + + protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader): void + { + $c->setParameter('kernel.project_dir', __DIR__); + + $cookie = ['cookie_secure' => true, 'cookie_samesite' => 'lax', 'handler_id' => 'session.handler.native_file']; + $config = [ + 'secret' => 'dunglas.fr', + 'validation' => ['enable_attributes' => true, 'email_validation_mode' => 'html5'], + 'serializer' => ['enable_attributes' => true], + 'test' => null, + 'session' => ['storage_factory_id' => 'session.storage.factory.mock_file'] + $cookie, + 'profiler' => ['enabled' => false], + 'property_access' => ['enabled' => true], + 'php_errors' => ['log' => true], + 'router' => ['utf8' => true], + 'http_method_override' => false, + 'annotations' => false, + 'handle_all_throwables' => true, + 'uid' => ['default_uuid_version' => 7, 'time_based_uuid_version' => 7], + ]; + + $c->prependExtensionConfig('framework', $config); + + $loader->load(__DIR__.'/config.yml'); + } + + protected function build(ContainerBuilder $container): void + { + } +} diff --git a/src/Test/DoctrineMongoDbOdmFilterTestCase.php b/src/Doctrine/Odm/Tests/DoctrineMongoDbOdmFilterTestCase.php similarity index 98% rename from src/Test/DoctrineMongoDbOdmFilterTestCase.php rename to src/Doctrine/Odm/Tests/DoctrineMongoDbOdmFilterTestCase.php index a87cf891c4f..3837a048fa6 100644 --- a/src/Test/DoctrineMongoDbOdmFilterTestCase.php +++ b/src/Doctrine/Odm/Tests/DoctrineMongoDbOdmFilterTestCase.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Test; +namespace ApiPlatform\Doctrine\Odm\Tests; use ApiPlatform\Doctrine\Odm\Filter\FilterInterface; use Doctrine\ODM\MongoDB\DocumentManager; diff --git a/src/Test/DoctrineMongoDbOdmSetup.php b/src/Doctrine/Odm/Tests/DoctrineMongoDbOdmSetup.php similarity index 98% rename from src/Test/DoctrineMongoDbOdmSetup.php rename to src/Doctrine/Odm/Tests/DoctrineMongoDbOdmSetup.php index d514ae85568..f0348a64453 100644 --- a/src/Test/DoctrineMongoDbOdmSetup.php +++ b/src/Doctrine/Odm/Tests/DoctrineMongoDbOdmSetup.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Test; +namespace ApiPlatform\Doctrine\Odm\Tests; use Doctrine\Common\Cache\Cache; use Doctrine\Common\Cache\CacheProvider; diff --git a/src/Test/DoctrineMongoDbOdmTestCase.php b/src/Doctrine/Odm/Tests/DoctrineMongoDbOdmTestCase.php similarity index 97% rename from src/Test/DoctrineMongoDbOdmTestCase.php rename to src/Doctrine/Odm/Tests/DoctrineMongoDbOdmTestCase.php index 307342b4da0..48eae27ed6a 100644 --- a/src/Test/DoctrineMongoDbOdmTestCase.php +++ b/src/Doctrine/Odm/Tests/DoctrineMongoDbOdmTestCase.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Test; +namespace ApiPlatform\Doctrine\Odm\Tests; use Doctrine\ODM\MongoDB\Configuration; use Doctrine\ODM\MongoDB\DocumentManager; diff --git a/tests/Doctrine/Odm/Extension/FilterExtensionTest.php b/src/Doctrine/Odm/Tests/Extension/FilterExtensionTest.php similarity index 93% rename from tests/Doctrine/Odm/Extension/FilterExtensionTest.php rename to src/Doctrine/Odm/Tests/Extension/FilterExtensionTest.php index 0f80c6a7a08..d90104ca55d 100644 --- a/tests/Doctrine/Odm/Extension/FilterExtensionTest.php +++ b/src/Doctrine/Odm/Tests/Extension/FilterExtensionTest.php @@ -11,13 +11,13 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\Extension; +namespace ApiPlatform\Doctrine\Odm\Tests\Extension; -use ApiPlatform\Api\FilterInterface as ApiFilterInterface; use ApiPlatform\Doctrine\Odm\Extension\FilterExtension; use ApiPlatform\Doctrine\Odm\Filter\FilterInterface; +use ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document\Dummy; +use ApiPlatform\Metadata\FilterInterface as ApiFilterInterface; use ApiPlatform\Metadata\GetCollection; -use ApiPlatform\Tests\Fixtures\TestBundle\Document\Dummy; use Doctrine\ODM\MongoDB\Aggregation\Builder; use PHPUnit\Framework\TestCase; use Prophecy\Argument; diff --git a/tests/Doctrine/Odm/Extension/OrderExtensionTest.php b/src/Doctrine/Odm/Tests/Extension/OrderExtensionTest.php similarity index 98% rename from tests/Doctrine/Odm/Extension/OrderExtensionTest.php rename to src/Doctrine/Odm/Tests/Extension/OrderExtensionTest.php index 654955acc40..db157f582d8 100644 --- a/tests/Doctrine/Odm/Extension/OrderExtensionTest.php +++ b/src/Doctrine/Odm/Tests/Extension/OrderExtensionTest.php @@ -11,11 +11,11 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\Extension; +namespace ApiPlatform\Doctrine\Odm\Tests\Extension; use ApiPlatform\Doctrine\Odm\Extension\OrderExtension; +use ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document\Dummy; use ApiPlatform\Metadata\GetCollection; -use ApiPlatform\Tests\Fixtures\TestBundle\Document\Dummy; use Doctrine\ODM\MongoDB\Aggregation\Builder; use Doctrine\ODM\MongoDB\Aggregation\Stage\Lookup; use Doctrine\ODM\MongoDB\Aggregation\Stage\Sort; diff --git a/tests/Doctrine/Odm/Extension/PaginationExtensionTest.php b/src/Doctrine/Odm/Tests/Extension/PaginationExtensionTest.php similarity index 98% rename from tests/Doctrine/Odm/Extension/PaginationExtensionTest.php rename to src/Doctrine/Odm/Tests/Extension/PaginationExtensionTest.php index 4f28ef88f9c..ed880c214df 100644 --- a/tests/Doctrine/Odm/Extension/PaginationExtensionTest.php +++ b/src/Doctrine/Odm/Tests/Extension/PaginationExtensionTest.php @@ -11,17 +11,17 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\Extension; +namespace ApiPlatform\Doctrine\Odm\Tests\Extension; use ApiPlatform\Doctrine\Odm\Extension\PaginationExtension; use ApiPlatform\Doctrine\Odm\Paginator; -use ApiPlatform\Exception\InvalidArgumentException; +use ApiPlatform\Doctrine\Odm\Tests\DoctrineMongoDbOdmSetup; +use ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document\Dummy; +use ApiPlatform\Metadata\Exception\InvalidArgumentException; use ApiPlatform\Metadata\GetCollection; use ApiPlatform\State\Pagination\Pagination; use ApiPlatform\State\Pagination\PaginatorInterface; use ApiPlatform\State\Pagination\PartialPaginatorInterface; -use ApiPlatform\Test\DoctrineMongoDbOdmSetup; -use ApiPlatform\Tests\Fixtures\TestBundle\Document\Dummy; use Doctrine\ODM\MongoDB\Aggregation\Builder; use Doctrine\ODM\MongoDB\Aggregation\Stage\Count; use Doctrine\ODM\MongoDB\Aggregation\Stage\Facet; diff --git a/tests/Doctrine/Odm/Filter/BooleanFilterTest.php b/src/Doctrine/Odm/Tests/Filter/BooleanFilterTest.php similarity index 92% rename from tests/Doctrine/Odm/Filter/BooleanFilterTest.php rename to src/Doctrine/Odm/Tests/Filter/BooleanFilterTest.php index 86c0c0aa876..0b52592ea85 100644 --- a/tests/Doctrine/Odm/Filter/BooleanFilterTest.php +++ b/src/Doctrine/Odm/Tests/Filter/BooleanFilterTest.php @@ -11,12 +11,12 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\Filter; +namespace ApiPlatform\Doctrine\Odm\Tests\Filter; +use ApiPlatform\Doctrine\Common\Tests\Filter\BooleanFilterTestTrait; use ApiPlatform\Doctrine\Odm\Filter\BooleanFilter; -use ApiPlatform\Test\DoctrineMongoDbOdmFilterTestCase; -use ApiPlatform\Tests\Doctrine\Common\Filter\BooleanFilterTestTrait; -use ApiPlatform\Tests\Fixtures\TestBundle\Document\Dummy; +use ApiPlatform\Doctrine\Odm\Tests\DoctrineMongoDbOdmFilterTestCase; +use ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document\Dummy; /** * @group mongodb diff --git a/tests/Doctrine/Odm/Filter/DateFilterTest.php b/src/Doctrine/Odm/Tests/Filter/DateFilterTest.php similarity index 98% rename from tests/Doctrine/Odm/Filter/DateFilterTest.php rename to src/Doctrine/Odm/Tests/Filter/DateFilterTest.php index 0f05385c746..f36b87ce128 100644 --- a/tests/Doctrine/Odm/Filter/DateFilterTest.php +++ b/src/Doctrine/Odm/Tests/Filter/DateFilterTest.php @@ -11,12 +11,12 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\Filter; +namespace ApiPlatform\Doctrine\Odm\Tests\Filter; +use ApiPlatform\Doctrine\Common\Tests\Filter\DateFilterTestTrait; use ApiPlatform\Doctrine\Odm\Filter\DateFilter; -use ApiPlatform\Test\DoctrineMongoDbOdmFilterTestCase; -use ApiPlatform\Tests\Doctrine\Common\Filter\DateFilterTestTrait; -use ApiPlatform\Tests\Fixtures\TestBundle\Document\Dummy; +use ApiPlatform\Doctrine\Odm\Tests\DoctrineMongoDbOdmFilterTestCase; +use ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document\Dummy; use MongoDB\BSON\UTCDateTime; /** diff --git a/tests/Doctrine/Odm/Filter/ExistsFilterTest.php b/src/Doctrine/Odm/Tests/Filter/ExistsFilterTest.php similarity index 98% rename from tests/Doctrine/Odm/Filter/ExistsFilterTest.php rename to src/Doctrine/Odm/Tests/Filter/ExistsFilterTest.php index 4348617e5e2..230c384103c 100644 --- a/tests/Doctrine/Odm/Filter/ExistsFilterTest.php +++ b/src/Doctrine/Odm/Tests/Filter/ExistsFilterTest.php @@ -11,12 +11,12 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\Filter; +namespace ApiPlatform\Doctrine\Odm\Tests\Filter; +use ApiPlatform\Doctrine\Common\Tests\Filter\ExistsFilterTestTrait; use ApiPlatform\Doctrine\Odm\Filter\ExistsFilter; -use ApiPlatform\Test\DoctrineMongoDbOdmFilterTestCase; -use ApiPlatform\Tests\Doctrine\Common\Filter\ExistsFilterTestTrait; -use ApiPlatform\Tests\Fixtures\TestBundle\Document\Dummy; +use ApiPlatform\Doctrine\Odm\Tests\DoctrineMongoDbOdmFilterTestCase; +use ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document\Dummy; use Doctrine\Persistence\ManagerRegistry; /** diff --git a/tests/Doctrine/Odm/Filter/NumericFilterTest.php b/src/Doctrine/Odm/Tests/Filter/NumericFilterTest.php similarity index 95% rename from tests/Doctrine/Odm/Filter/NumericFilterTest.php rename to src/Doctrine/Odm/Tests/Filter/NumericFilterTest.php index 32216a47799..e14732b1691 100644 --- a/tests/Doctrine/Odm/Filter/NumericFilterTest.php +++ b/src/Doctrine/Odm/Tests/Filter/NumericFilterTest.php @@ -11,12 +11,12 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\Filter; +namespace ApiPlatform\Doctrine\Odm\Tests\Filter; +use ApiPlatform\Doctrine\Common\Tests\Filter\NumericFilterTestTrait; use ApiPlatform\Doctrine\Odm\Filter\NumericFilter; -use ApiPlatform\Test\DoctrineMongoDbOdmFilterTestCase; -use ApiPlatform\Tests\Doctrine\Common\Filter\NumericFilterTestTrait; -use ApiPlatform\Tests\Fixtures\TestBundle\Document\Dummy; +use ApiPlatform\Doctrine\Odm\Tests\DoctrineMongoDbOdmFilterTestCase; +use ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document\Dummy; /** * @group mongodb diff --git a/tests/Doctrine/Odm/Filter/OrderFilterTest.php b/src/Doctrine/Odm/Tests/Filter/OrderFilterTest.php similarity index 98% rename from tests/Doctrine/Odm/Filter/OrderFilterTest.php rename to src/Doctrine/Odm/Tests/Filter/OrderFilterTest.php index 43ceb21de3e..479f23621b4 100644 --- a/tests/Doctrine/Odm/Filter/OrderFilterTest.php +++ b/src/Doctrine/Odm/Tests/Filter/OrderFilterTest.php @@ -11,14 +11,14 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\Filter; +namespace ApiPlatform\Doctrine\Odm\Tests\Filter; +use ApiPlatform\Doctrine\Common\Tests\Filter\OrderFilterTestTrait; use ApiPlatform\Doctrine\Odm\Filter\OrderFilter; -use ApiPlatform\Test\DoctrineMongoDbOdmFilterTestCase; -use ApiPlatform\Tests\Doctrine\Common\Filter\OrderFilterTestTrait; -use ApiPlatform\Tests\Fixtures\TestBundle\Document\Dummy; -use ApiPlatform\Tests\Fixtures\TestBundle\Document\EmbeddedDummy; -use ApiPlatform\Tests\Fixtures\TestBundle\Serializer\NameConverter\CustomConverter; +use ApiPlatform\Doctrine\Odm\Tests\DoctrineMongoDbOdmFilterTestCase; +use ApiPlatform\Doctrine\Odm\Tests\Fixtures\CustomConverter; +use ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document\Dummy; +use ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document\EmbeddedDummy; use Doctrine\Persistence\ManagerRegistry; /** diff --git a/tests/Doctrine/Odm/Filter/RangeFilterTest.php b/src/Doctrine/Odm/Tests/Filter/RangeFilterTest.php similarity index 98% rename from tests/Doctrine/Odm/Filter/RangeFilterTest.php rename to src/Doctrine/Odm/Tests/Filter/RangeFilterTest.php index ef58e7ca771..177ae9f6c59 100644 --- a/tests/Doctrine/Odm/Filter/RangeFilterTest.php +++ b/src/Doctrine/Odm/Tests/Filter/RangeFilterTest.php @@ -11,12 +11,12 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\Filter; +namespace ApiPlatform\Doctrine\Odm\Tests\Filter; +use ApiPlatform\Doctrine\Common\Tests\Filter\RangeFilterTestTrait; use ApiPlatform\Doctrine\Odm\Filter\RangeFilter; -use ApiPlatform\Test\DoctrineMongoDbOdmFilterTestCase; -use ApiPlatform\Tests\Doctrine\Common\Filter\RangeFilterTestTrait; -use ApiPlatform\Tests\Fixtures\TestBundle\Document\Dummy; +use ApiPlatform\Doctrine\Odm\Tests\DoctrineMongoDbOdmFilterTestCase; +use ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document\Dummy; /** * @group mongodb diff --git a/tests/Doctrine/Odm/Filter/SearchFilterTest.php b/src/Doctrine/Odm/Tests/Filter/SearchFilterTest.php similarity index 98% rename from tests/Doctrine/Odm/Filter/SearchFilterTest.php rename to src/Doctrine/Odm/Tests/Filter/SearchFilterTest.php index 845e3a3d11c..284a1e1b207 100644 --- a/tests/Doctrine/Odm/Filter/SearchFilterTest.php +++ b/src/Doctrine/Odm/Tests/Filter/SearchFilterTest.php @@ -11,16 +11,16 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\Filter; +namespace ApiPlatform\Doctrine\Odm\Tests\Filter; +use ApiPlatform\Doctrine\Common\Tests\Filter\SearchFilterTestTrait; use ApiPlatform\Doctrine\Odm\Filter\SearchFilter; -use ApiPlatform\Exception\InvalidArgumentException; +use ApiPlatform\Doctrine\Odm\Tests\DoctrineMongoDbOdmFilterTestCase; +use ApiPlatform\Doctrine\Odm\Tests\Fixtures\CustomConverter; +use ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document\Dummy; +use ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document\RelatedDummy; +use ApiPlatform\Metadata\Exception\InvalidArgumentException; use ApiPlatform\Metadata\IriConverterInterface; -use ApiPlatform\Test\DoctrineMongoDbOdmFilterTestCase; -use ApiPlatform\Tests\Doctrine\Common\Filter\SearchFilterTestTrait; -use ApiPlatform\Tests\Fixtures\TestBundle\Document\Dummy; -use ApiPlatform\Tests\Fixtures\TestBundle\Document\RelatedDummy; -use ApiPlatform\Tests\Fixtures\TestBundle\Serializer\NameConverter\CustomConverter; use Doctrine\Persistence\ManagerRegistry; use MongoDB\BSON\Regex; use Prophecy\Argument; diff --git a/src/Doctrine/Odm/Tests/Fixtures/CustomConverter.php b/src/Doctrine/Odm/Tests/Fixtures/CustomConverter.php new file mode 100644 index 00000000000..4b5a85d9e8d --- /dev/null +++ b/src/Doctrine/Odm/Tests/Fixtures/CustomConverter.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Doctrine\Odm\Tests\Fixtures; + +use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter; + +/** + * Custom converter that will only convert a property named "nameConverted" + * with the same logic as Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter. + */ +class CustomConverter extends CamelCaseToSnakeCaseNameConverter +{ + public function normalize(string $propertyName): string + { + return 'nameConverted' === $propertyName ? parent::normalize($propertyName) : $propertyName; + } + + public function denormalize(string $propertyName): string + { + return 'name_converted' === $propertyName ? parent::denormalize($propertyName) : $propertyName; + } +} diff --git a/src/Doctrine/Odm/Tests/Fixtures/Document/Dummy.php b/src/Doctrine/Odm/Tests/Fixtures/Document/Dummy.php new file mode 100644 index 00000000000..12f8acbca75 --- /dev/null +++ b/src/Doctrine/Odm/Tests/Fixtures/Document/Dummy.php @@ -0,0 +1,259 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document; + +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; +use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; +use Symfony\Component\Validator\Constraints as Assert; + +/** + * Dummy. + * + * @author Kévin Dunglas + * @author Alexandre Delplace + */ +#[ODM\Document] +class Dummy +{ + #[ODM\Id(strategy: 'INCREMENT', type: 'int', nullable: true)] + private ?int $id = null; + /** + * @var string|null The dummy name + */ + #[Assert\NotBlank] + #[ODM\Field(type: 'string')] + private $name; + /** + * @var string|null The dummy name alias + */ + #[ODM\Field(nullable: true)] + private $alias; + /** + * @var array|null foo + */ + private ?array $foo = null; + /** + * @var string|null A short description of the item + */ + #[ODM\Field(type: 'string', nullable: true)] + public $description; + /** + * @var string|null A dummy + */ + #[ODM\Field(nullable: true)] + public $dummy; + /** + * @var bool|null A dummy boolean + */ + #[ODM\Field(type: 'bool', nullable: true)] + public ?bool $dummyBoolean = null; + /** + * @var \DateTime|null A dummy date + */ + #[ODM\Field(type: 'date', nullable: true)] + public $dummyDate; + /** + * @var float|null A dummy float + */ + #[ODM\Field(type: 'float', nullable: true)] + public $dummyFloat; + /** + * @var float|null A dummy price + */ + #[ODM\Field(type: 'float', nullable: true)] + public $dummyPrice; + #[ODM\ReferenceOne(targetDocument: RelatedDummy::class, storeAs: 'id', nullable: true)] + public ?RelatedDummy $relatedDummy = null; + #[ODM\ReferenceMany(targetDocument: RelatedDummy::class, storeAs: 'id', nullable: true)] + public Collection|iterable $relatedDummies; + #[ODM\Field(type: 'hash', nullable: true)] + public array $jsonData = []; + #[ODM\Field(type: 'collection', nullable: true)] + public array $arrayData = []; + /** + * @var string|null + */ + #[ODM\Field(nullable: true)] + public $nameConverted; + /** + * @var RelatedOwnedDummy|null + */ + #[ODM\ReferenceOne(targetDocument: RelatedOwnedDummy::class, cascade: ['persist'], mappedBy: 'owningDummy', nullable: true)] + public $relatedOwnedDummy; + /** + * @var RelatedOwningDummy|null + */ + #[ODM\ReferenceOne(targetDocument: RelatedOwningDummy::class, cascade: ['persist'], inversedBy: 'ownedDummy', nullable: true, storeAs: 'id')] + public $relatedOwningDummy; + + public static function staticMethod(): void + { + } + + public function __construct() + { + $this->relatedDummies = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function setId($id): void + { + $this->id = $id; + } + + public function setName($name): void + { + $this->name = $name; + } + + public function getName() + { + return $this->name; + } + + public function setAlias($alias): void + { + $this->alias = $alias; + } + + public function getAlias() + { + return $this->alias; + } + + public function setDescription($description): void + { + $this->description = $description; + } + + public function getDescription() + { + return $this->description; + } + + public function getFoo(): ?array + { + return $this->foo; + } + + public function setFoo(array $foo = null): void + { + $this->foo = $foo; + } + + public function setDummyDate(\DateTime $dummyDate = null): void + { + $this->dummyDate = $dummyDate; + } + + public function getDummyDate() + { + return $this->dummyDate; + } + + public function setDummyPrice($dummyPrice) + { + $this->dummyPrice = $dummyPrice; + + return $this; + } + + public function getDummyPrice() + { + return $this->dummyPrice; + } + + public function setJsonData(array $jsonData): void + { + $this->jsonData = $jsonData; + } + + public function getJsonData(): array + { + return $this->jsonData; + } + + public function setArrayData(array $arrayData): void + { + $this->arrayData = $arrayData; + } + + public function getArrayData(): array + { + return $this->arrayData; + } + + public function getRelatedDummy(): ?RelatedDummy + { + return $this->relatedDummy; + } + + public function setRelatedDummy(RelatedDummy $relatedDummy): void + { + $this->relatedDummy = $relatedDummy; + } + + public function addRelatedDummy(RelatedDummy $relatedDummy): void + { + $this->relatedDummies->add($relatedDummy); + } + + public function getRelatedOwnedDummy() + { + return $this->relatedOwnedDummy; + } + + public function setRelatedOwnedDummy(RelatedOwnedDummy $relatedOwnedDummy): void + { + $this->relatedOwnedDummy = $relatedOwnedDummy; + if ($this !== $this->relatedOwnedDummy->getOwningDummy()) { + $this->relatedOwnedDummy->setOwningDummy($this); + } + } + + public function getRelatedOwningDummy() + { + return $this->relatedOwningDummy; + } + + public function setRelatedOwningDummy(RelatedOwningDummy $relatedOwningDummy): void + { + $this->relatedOwningDummy = $relatedOwningDummy; + } + + public function isDummyBoolean(): ?bool + { + return $this->dummyBoolean; + } + + public function setDummyBoolean(?bool $dummyBoolean): void + { + $this->dummyBoolean = $dummyBoolean; + } + + public function setDummy($dummy = null): void + { + $this->dummy = $dummy; + } + + public function getDummy() + { + return $this->dummy; + } +} diff --git a/src/Doctrine/Odm/Tests/Fixtures/Document/DummyFriend.php b/src/Doctrine/Odm/Tests/Fixtures/Document/DummyFriend.php new file mode 100644 index 00000000000..d9b73088005 --- /dev/null +++ b/src/Doctrine/Odm/Tests/Fixtures/Document/DummyFriend.php @@ -0,0 +1,78 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document; + +use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; + +/** + * Dummy Friend. + * + * @author Kévin Dunglas + * @author Alan Poulain + */ +#[ODM\Document] +class DummyFriend implements \Stringable +{ + /** + * @var int|null The id + */ + #[ODM\Id(strategy: 'INCREMENT', type: 'int')] + private ?int $id = null; + /** + * @var string|null The dummy name + */ + #[ODM\Field(type: 'string')] + private ?string $name = null; + + /** + * Get id. + */ + public function getId(): ?int + { + return $this->id; + } + + /** + * Set id. + * + * @param int $id the value to set + */ + public function setId($id): void + { + $this->id = $id; + } + + /** + * Get name. + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * Set name. + * + * @param string $name the value to set + */ + public function setName(string $name): void + { + $this->name = $name; + } + + public function __toString(): string + { + return (string) $this->getId(); + } +} diff --git a/src/Doctrine/Odm/Tests/Fixtures/Document/EmbeddableDummy.php b/src/Doctrine/Odm/Tests/Fixtures/Document/EmbeddableDummy.php new file mode 100644 index 00000000000..8bd82bdbe33 --- /dev/null +++ b/src/Doctrine/Odm/Tests/Fixtures/Document/EmbeddableDummy.php @@ -0,0 +1,122 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document; + +use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; + +/** + * Embeddable Dummy. + * + * @author Jordan Samouh + * @author Alexandre Delplace + */ +#[ODM\EmbeddedDocument] +class EmbeddableDummy +{ + /** + * @var string|null The dummy name + */ + #[ODM\Field(type: 'string')] + private ?string $dummyName = null; + /** + * @var bool|null A dummy boolean + */ + #[ODM\Field(type: 'bool')] + public ?bool $dummyBoolean = null; + /** + * @var \DateTime|null A dummy date + */ + #[ODM\Field(type: 'date')] + public ?\DateTime $dummyDate = null; + /** + * @var float|null A dummy float + */ + #[ODM\Field(type: 'float')] + public ?float $dummyFloat = null; + /** + * @var float|null A dummy price + */ + #[ODM\Field(type: 'float')] + public ?float $dummyPrice = null; + #[ODM\Field(type: 'string')] + protected ?string $symfony = null; + + public static function staticMethod(): void + { + } + + public function __construct() + { + } + + public function getDummyName(): ?string + { + return $this->dummyName; + } + + public function setDummyName(string $dummyName): void + { + $this->dummyName = $dummyName; + } + + public function isDummyBoolean(): ?bool + { + return $this->dummyBoolean; + } + + public function setDummyBoolean(bool $dummyBoolean): void + { + $this->dummyBoolean = $dummyBoolean; + } + + public function getDummyDate(): ?\DateTime + { + return $this->dummyDate; + } + + public function setDummyDate(\DateTime $dummyDate): void + { + $this->dummyDate = $dummyDate; + } + + public function getDummyFloat(): ?float + { + return $this->dummyFloat; + } + + public function setDummyFloat(float $dummyFloat): void + { + $this->dummyFloat = $dummyFloat; + } + + public function getDummyPrice(): ?float + { + return $this->dummyPrice; + } + + public function setDummyPrice(float $dummyPrice): void + { + $this->dummyPrice = $dummyPrice; + } + + public function getSymfony(): ?string + { + return $this->symfony; + } + + public function setSymfony(string $symfony): void + { + $this->symfony = $symfony; + } +} diff --git a/src/Doctrine/Odm/Tests/Fixtures/Document/EmbeddedDummy.php b/src/Doctrine/Odm/Tests/Fixtures/Document/EmbeddedDummy.php new file mode 100644 index 00000000000..c2b45ac471c --- /dev/null +++ b/src/Doctrine/Odm/Tests/Fixtures/Document/EmbeddedDummy.php @@ -0,0 +1,103 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document; + +use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; + +/** + * Embedded Dummy. + * + * @author Jordan Samouh + * @author Alexandre Delplace + */ +#[ODM\Document] +class EmbeddedDummy +{ + /** + * @var int|null The id + */ + #[ODM\Id(strategy: 'INCREMENT', type: 'int')] + private ?int $id = null; + /** + * @var string|null The dummy name + */ + #[ODM\Field(type: 'string')] + private ?string $name = null; + /** + * @var \DateTime|null A dummy date + */ + #[ODM\Field(type: 'date')] + public ?\DateTime $dummyDate = null; + #[ODM\EmbedOne(targetDocument: EmbeddableDummy::class)] + public ?EmbeddableDummy $embeddedDummy = null; + /** + * @var RelatedDummy|null A related dummy + */ + #[ODM\ReferenceOne(targetDocument: RelatedDummy::class, storeAs: 'id')] + public ?RelatedDummy $relatedDummy = null; + + public static function staticMethod(): void + { + } + + public function __construct() + { + $this->embeddedDummy = new EmbeddableDummy(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(string $name): void + { + $this->name = $name; + } + + public function getEmbeddedDummy(): EmbeddableDummy + { + return $this->embeddedDummy; + } + + public function setEmbeddedDummy(EmbeddableDummy $embeddedDummy): void + { + $this->embeddedDummy = $embeddedDummy; + } + + public function getDummyDate(): ?\DateTime + { + return $this->dummyDate; + } + + public function setDummyDate(\DateTime $dummyDate): void + { + $this->dummyDate = $dummyDate; + } + + public function getRelatedDummy(): ?RelatedDummy + { + return $this->relatedDummy; + } + + public function setRelatedDummy(RelatedDummy $relatedDummy): void + { + $this->relatedDummy = $relatedDummy; + } +} diff --git a/src/Doctrine/Odm/Tests/Fixtures/Document/FourthLevel.php b/src/Doctrine/Odm/Tests/Fixtures/Document/FourthLevel.php new file mode 100644 index 00000000000..38dfc0488b1 --- /dev/null +++ b/src/Doctrine/Odm/Tests/Fixtures/Document/FourthLevel.php @@ -0,0 +1,51 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document; + +use Doctrine\Common\Collections\Collection; +use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; + +/** + * Fourth Level. + * + * @author Alan Poulain + */ +#[ODM\Document] +class FourthLevel +{ + /** + * @var int|null The id + */ + #[ODM\Id(strategy: 'INCREMENT', type: 'int')] + private ?int $id = null; + #[ODM\Field(type: 'int')] + private ?int $level = 4; + #[ODM\ReferenceMany(targetDocument: ThirdLevel::class, cascade: ['persist'], mappedBy: 'badFourthLevel', storeAs: 'id')] + public Collection|iterable|null $badThirdLevel = null; + + public function getId(): ?int + { + return $this->id; + } + + public function getLevel(): ?int + { + return $this->level; + } + + public function setLevel(int $level): void + { + $this->level = $level; + } +} diff --git a/src/Doctrine/Odm/Tests/Fixtures/Document/ParentDummy.php b/src/Doctrine/Odm/Tests/Fixtures/Document/ParentDummy.php new file mode 100644 index 00000000000..5fbc24e3b08 --- /dev/null +++ b/src/Doctrine/Odm/Tests/Fixtures/Document/ParentDummy.php @@ -0,0 +1,42 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document; + +use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; + +/** + * Parent Dummy. + * + * @author Kévin Dunglas + * @author Alexandre Delplace + */ +#[ODM\MappedSuperclass] +class ParentDummy +{ + /** + * @var int The age + */ + #[ODM\Field(type: 'int', nullable: true)] + private $age; + + public function getAge() + { + return $this->age; + } + + public function setAge($age) + { + return $this->age = $age; + } +} diff --git a/src/Doctrine/Odm/Tests/Fixtures/Document/ProviderDocument.php b/src/Doctrine/Odm/Tests/Fixtures/Document/ProviderDocument.php new file mode 100644 index 00000000000..df9fd7b905a --- /dev/null +++ b/src/Doctrine/Odm/Tests/Fixtures/Document/ProviderDocument.php @@ -0,0 +1,44 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document; + +use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; + +/** + * ProviderEntity. + */ +#[ODM\Document] +class ProviderDocument +{ + #[ODM\Id(strategy: 'INCREMENT', type: 'int')] + private ?int $id = null; + + #[ODM\Field] + private ?string $foo = null; + + public function getId(): ?int + { + return $this->id; + } + + public function getFoo(): string + { + return $this->foo; + } + + public function setFoo(string $foo): void + { + $this->foo = $foo; + } +} diff --git a/src/Doctrine/Odm/Tests/Fixtures/Document/RelatedDummy.php b/src/Doctrine/Odm/Tests/Fixtures/Document/RelatedDummy.php new file mode 100644 index 00000000000..e186a9d76bb --- /dev/null +++ b/src/Doctrine/Odm/Tests/Fixtures/Document/RelatedDummy.php @@ -0,0 +1,153 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document; + +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; +use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; + +/** + * Related Dummy. + * + * @author Kévin Dunglas + * @author Alexandre Delplace + */ +#[ODM\Document] +class RelatedDummy extends ParentDummy implements \Stringable +{ + #[ODM\Id(strategy: 'INCREMENT', type: 'int')] + private $id; + /** + * @var string A name + */ + #[ODM\Field(type: 'string', nullable: true)] + public $name; + #[ODM\Field(type: 'string')] + protected $symfony = 'symfony'; + /** + * @var \DateTime A dummy date + */ + #[ODM\Field(type: 'date', nullable: true)] + public $dummyDate; + #[ODM\ReferenceOne(targetDocument: ThirdLevel::class, cascade: ['persist'], nullable: true, storeAs: 'id', inversedBy: 'relatedDummies')] + public ?ThirdLevel $thirdLevel = null; + #[ODM\ReferenceMany(targetDocument: RelatedToDummyFriend::class, cascade: ['persist'], mappedBy: 'relatedDummy', storeAs: 'id')] + public Collection|iterable $relatedToDummyFriend; + #[ODM\Field(type: 'bool')] + public ?bool $dummyBoolean = null; + #[ODM\EmbedOne(targetDocument: EmbeddableDummy::class)] + public ?EmbeddableDummy $embeddedDummy = null; + + public function __construct() + { + $this->relatedToDummyFriend = new ArrayCollection(); + $this->embeddedDummy = new EmbeddableDummy(); + } + + public function getId() + { + return $this->id; + } + + public function setId($id): void + { + $this->id = $id; + } + + public function setName($name): void + { + $this->name = $name; + } + + public function getName() + { + return $this->name; + } + + public function getSymfony() + { + return $this->symfony; + } + + public function setSymfony($symfony): void + { + $this->symfony = $symfony; + } + + public function setDummyDate(\DateTime $dummyDate): void + { + $this->dummyDate = $dummyDate; + } + + public function getDummyDate() + { + return $this->dummyDate; + } + + public function isDummyBoolean(): ?bool + { + return $this->dummyBoolean; + } + + /** + * @param bool $dummyBoolean + */ + public function setDummyBoolean($dummyBoolean): void + { + $this->dummyBoolean = $dummyBoolean; + } + + public function getThirdLevel(): ?ThirdLevel + { + return $this->thirdLevel; + } + + public function setThirdLevel(ThirdLevel $thirdLevel = null): void + { + $this->thirdLevel = $thirdLevel; + } + + /** + * Get relatedToDummyFriend. + */ + public function getRelatedToDummyFriend(): Collection|iterable + { + return $this->relatedToDummyFriend; + } + + /** + * Set relatedToDummyFriend. + * + * @param RelatedToDummyFriend $relatedToDummyFriend the value to set + */ + public function addRelatedToDummyFriend(RelatedToDummyFriend $relatedToDummyFriend): void + { + $this->relatedToDummyFriend->add($relatedToDummyFriend); + } + + public function getEmbeddedDummy(): EmbeddableDummy + { + return $this->embeddedDummy; + } + + public function setEmbeddedDummy(EmbeddableDummy $embeddedDummy): void + { + $this->embeddedDummy = $embeddedDummy; + } + + public function __toString(): string + { + return (string) $this->getId(); + } +} diff --git a/src/Doctrine/Odm/Tests/Fixtures/Document/RelatedOwnedDummy.php b/src/Doctrine/Odm/Tests/Fixtures/Document/RelatedOwnedDummy.php new file mode 100644 index 00000000000..c3232611776 --- /dev/null +++ b/src/Doctrine/Odm/Tests/Fixtures/Document/RelatedOwnedDummy.php @@ -0,0 +1,74 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document; + +use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; + +/** + * Related Owned Dummy. + * + * @author Sergey V. Ryabov + * @author Alan Poulain + */ +#[ODM\Document] +class RelatedOwnedDummy +{ + #[ODM\Id(strategy: 'INCREMENT', type: 'int')] + private $id; + /** + * @var string|null A name + */ + #[ODM\Field(type: 'string')] + public $name; + #[ODM\ReferenceOne(targetDocument: Dummy::class, cascade: ['persist'], inversedBy: 'relatedOwnedDummy', storeAs: 'id')] + public ?Dummy $owningDummy = null; + + public function getId() + { + return $this->id; + } + + public function setId($id): void + { + $this->id = $id; + } + + public function setName($name): void + { + $this->name = $name; + } + + public function getName() + { + return $this->name; + } + + /** + * Get owning dummy. + */ + public function getOwningDummy(): ?Dummy + { + return $this->owningDummy; + } + + /** + * Set owning dummy. + * + * @param Dummy $owningDummy the value to set + */ + public function setOwningDummy(Dummy $owningDummy): void + { + $this->owningDummy = $owningDummy; + } +} diff --git a/src/Doctrine/Odm/Tests/Fixtures/Document/RelatedOwningDummy.php b/src/Doctrine/Odm/Tests/Fixtures/Document/RelatedOwningDummy.php new file mode 100644 index 00000000000..7a0df1cb8a3 --- /dev/null +++ b/src/Doctrine/Odm/Tests/Fixtures/Document/RelatedOwningDummy.php @@ -0,0 +1,77 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document; + +use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; + +/** + * Related Owning Dummy. + * + * @author Sergey V. Ryabov + * @author Alan Poulain + */ +#[ODM\Document] +class RelatedOwningDummy +{ + #[ODM\Id(strategy: 'INCREMENT', type: 'int')] + private $id; + /** + * @var string A name + */ + #[ODM\Field(type: 'string')] + public $name; + #[ODM\ReferenceOne(targetDocument: Dummy::class, cascade: ['persist'], mappedBy: 'relatedOwningDummy')] + public ?Dummy $ownedDummy = null; + + public function getId() + { + return $this->id; + } + + public function setId($id): void + { + $this->id = $id; + } + + public function setName($name): void + { + $this->name = $name; + } + + public function getName() + { + return $this->name; + } + + /** + * Get owned dummy. + */ + public function getOwnedDummy(): Dummy + { + return $this->ownedDummy; + } + + /** + * Set owned dummy. + * + * @param Dummy $ownedDummy the value to set + */ + public function setOwnedDummy(Dummy $ownedDummy): void + { + $this->ownedDummy = $ownedDummy; + if ($this !== $this->ownedDummy->getRelatedOwningDummy()) { + $this->ownedDummy->setRelatedOwningDummy($this); + } + } +} diff --git a/src/Doctrine/Odm/Tests/Fixtures/Document/RelatedToDummyFriend.php b/src/Doctrine/Odm/Tests/Fixtures/Document/RelatedToDummyFriend.php new file mode 100644 index 00000000000..81f5647d89c --- /dev/null +++ b/src/Doctrine/Odm/Tests/Fixtures/Document/RelatedToDummyFriend.php @@ -0,0 +1,109 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document; + +use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; + +/** + * Related To Dummy Friend represent an association table for a manytomany relation. + */ +#[ODM\Document] +class RelatedToDummyFriend +{ + #[ODM\Id(strategy: 'INCREMENT', type: 'int')] + private $id; + /** + * @var string The dummy name + */ + #[ODM\Field(type: 'string')] + private $name; + /** + * @var string|null The dummy description + */ + #[ODM\Field(type: 'string')] + private ?string $description = null; + #[ODM\ReferenceOne(targetDocument: DummyFriend::class, storeAs: 'id')] + private DummyFriend $dummyFriend; + #[ODM\ReferenceOne(targetDocument: RelatedDummy::class, inversedBy: 'relatedToDummyFriend', storeAs: 'id')] + private RelatedDummy $relatedDummy; + + public function getId() + { + return $this->id; + } + + public function setId($id): void + { + $this->id = $id; + } + + public function setName($name): void + { + $this->name = $name; + } + + public function getName() + { + return $this->name; + } + + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param string|null $description + */ + public function setDescription($description): void + { + $this->description = $description; + } + + /** + * Gets dummyFriend. + */ + public function getDummyFriend(): DummyFriend + { + return $this->dummyFriend; + } + + /** + * Sets dummyFriend. + * + * @param DummyFriend $dummyFriend the value to set + */ + public function setDummyFriend(DummyFriend $dummyFriend): void + { + $this->dummyFriend = $dummyFriend; + } + + /** + * Gets relatedDummy. + */ + public function getRelatedDummy(): RelatedDummy + { + return $this->relatedDummy; + } + + /** + * Sets relatedDummy. + * + * @param RelatedDummy $relatedDummy the value to set + */ + public function setRelatedDummy(RelatedDummy $relatedDummy): void + { + $this->relatedDummy = $relatedDummy; + } +} diff --git a/src/Doctrine/Odm/Tests/Fixtures/Document/ThirdLevel.php b/src/Doctrine/Odm/Tests/Fixtures/Document/ThirdLevel.php new file mode 100644 index 00000000000..0601aab9950 --- /dev/null +++ b/src/Doctrine/Odm/Tests/Fixtures/Document/ThirdLevel.php @@ -0,0 +1,84 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document; + +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; +use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; + +/** + * Third Level. + * + * @author Kévin Dunglas + * @author Alexandre Delplace + */ +#[ODM\Document] +class ThirdLevel +{ + /** + * @var int|null The id + */ + #[ODM\Id(strategy: 'INCREMENT', type: 'int')] + private ?int $id = null; + #[ODM\Field(type: 'int')] + private int $level = 3; + #[ODM\Field(type: 'bool')] + private bool $test = true; + #[ODM\ReferenceOne(targetDocument: FourthLevel::class, cascade: ['persist'], storeAs: 'id')] + public ?FourthLevel $fourthLevel = null; + #[ODM\ReferenceOne(targetDocument: FourthLevel::class, cascade: ['persist'])] + public $badFourthLevel; + #[ODM\ReferenceMany(mappedBy: 'thirdLevel', targetDocument: RelatedDummy::class)] + public Collection|iterable $relatedDummies; + + public function __construct() + { + $this->relatedDummies = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getLevel(): int + { + return $this->level; + } + + public function setLevel(int $level): void + { + $this->level = $level; + } + + public function isTest(): bool + { + return $this->test; + } + + public function setTest(bool $test): void + { + $this->test = $test; + } + + public function getFourthLevel(): ?FourthLevel + { + return $this->fourthLevel; + } + + public function setFourthLevel(FourthLevel $fourthLevel = null): void + { + $this->fourthLevel = $fourthLevel; + } +} diff --git a/tests/Doctrine/Odm/Metadata/Property/DoctrineMongoDbOdmPropertyMetadataFactoryTest.php b/src/Doctrine/Odm/Tests/Metadata/Property/DoctrineMongoDbOdmPropertyMetadataFactoryTest.php similarity index 97% rename from tests/Doctrine/Odm/Metadata/Property/DoctrineMongoDbOdmPropertyMetadataFactoryTest.php rename to src/Doctrine/Odm/Tests/Metadata/Property/DoctrineMongoDbOdmPropertyMetadataFactoryTest.php index f40642e777f..6b98b56a2d4 100644 --- a/tests/Doctrine/Odm/Metadata/Property/DoctrineMongoDbOdmPropertyMetadataFactoryTest.php +++ b/src/Doctrine/Odm/Tests/Metadata/Property/DoctrineMongoDbOdmPropertyMetadataFactoryTest.php @@ -11,12 +11,12 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\Metadata\Property; +namespace ApiPlatform\Doctrine\Odm\Tests\Metadata\Property; use ApiPlatform\Doctrine\Odm\Metadata\Property\DoctrineMongoDbOdmPropertyMetadataFactory; +use ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document\Dummy; use ApiPlatform\Metadata\ApiProperty; use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface; -use ApiPlatform\Tests\Fixtures\TestBundle\Document\Dummy; use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; use Doctrine\Persistence\ManagerRegistry; diff --git a/tests/Doctrine/Odm/Metadata/Resource/DoctrineMongoDbOdmResourceCollectionMetadataFactoryTest.php b/src/Doctrine/Odm/Tests/Metadata/Resource/DoctrineMongoDbOdmResourceCollectionMetadataFactoryTest.php similarity index 97% rename from tests/Doctrine/Odm/Metadata/Resource/DoctrineMongoDbOdmResourceCollectionMetadataFactoryTest.php rename to src/Doctrine/Odm/Tests/Metadata/Resource/DoctrineMongoDbOdmResourceCollectionMetadataFactoryTest.php index deb100f26ce..a09c2798d38 100644 --- a/tests/Doctrine/Odm/Metadata/Resource/DoctrineMongoDbOdmResourceCollectionMetadataFactoryTest.php +++ b/src/Doctrine/Odm/Tests/Metadata/Resource/DoctrineMongoDbOdmResourceCollectionMetadataFactoryTest.php @@ -11,11 +11,12 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\Metadata\Resource; +namespace ApiPlatform\Doctrine\Odm\Tests\Metadata\Resource; use ApiPlatform\Doctrine\Odm\Metadata\Resource\DoctrineMongoDbOdmResourceCollectionMetadataFactory; use ApiPlatform\Doctrine\Odm\State\CollectionProvider; use ApiPlatform\Doctrine\Odm\State\ItemProvider; +use ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document\Dummy; use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\Delete; use ApiPlatform\Metadata\Get; @@ -24,7 +25,6 @@ use ApiPlatform\Metadata\Operations; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\Metadata\Resource\ResourceMetadataCollection; -use ApiPlatform\Tests\Fixtures\TestBundle\Document\Dummy; use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\Persistence\ManagerRegistry; use PHPUnit\Framework\TestCase; diff --git a/tests/Doctrine/Odm/PaginatorTest.php b/src/Doctrine/Odm/Tests/PaginatorTest.php similarity index 97% rename from tests/Doctrine/Odm/PaginatorTest.php rename to src/Doctrine/Odm/Tests/PaginatorTest.php index bd0bc3325f0..1bae284239e 100644 --- a/tests/Doctrine/Odm/PaginatorTest.php +++ b/src/Doctrine/Odm/Tests/PaginatorTest.php @@ -11,12 +11,11 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm; +namespace ApiPlatform\Doctrine\Odm\Tests; use ApiPlatform\Doctrine\Odm\Paginator; -use ApiPlatform\Exception\InvalidArgumentException; -use ApiPlatform\Test\DoctrineMongoDbOdmSetup; -use ApiPlatform\Tests\Fixtures\TestBundle\Document\Dummy; +use ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document\Dummy; +use ApiPlatform\Metadata\Exception\InvalidArgumentException; use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Iterator\Iterator; use PHPUnit\Framework\TestCase; diff --git a/tests/Doctrine/Odm/PropertyInfo/DoctrineExtractorTest.php b/src/Doctrine/Odm/Tests/PropertyInfo/DoctrineExtractorTest.php similarity index 91% rename from tests/Doctrine/Odm/PropertyInfo/DoctrineExtractorTest.php rename to src/Doctrine/Odm/Tests/PropertyInfo/DoctrineExtractorTest.php index e6eb44768f1..6dfaf129f17 100644 --- a/tests/Doctrine/Odm/PropertyInfo/DoctrineExtractorTest.php +++ b/src/Doctrine/Odm/Tests/PropertyInfo/DoctrineExtractorTest.php @@ -11,19 +11,19 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\PropertyInfo; +namespace ApiPlatform\Doctrine\Odm\Tests\PropertyInfo; use ApiPlatform\Doctrine\Odm\PropertyInfo\DoctrineExtractor; -use ApiPlatform\Test\DoctrineMongoDbOdmSetup; -use ApiPlatform\Tests\Doctrine\Odm\PropertyInfo\Fixtures\DoctrineDummy; -use ApiPlatform\Tests\Doctrine\Odm\PropertyInfo\Fixtures\DoctrineEmbeddable; -use ApiPlatform\Tests\Doctrine\Odm\PropertyInfo\Fixtures\DoctrineEnum; -use ApiPlatform\Tests\Doctrine\Odm\PropertyInfo\Fixtures\DoctrineFooType; -use ApiPlatform\Tests\Doctrine\Odm\PropertyInfo\Fixtures\DoctrineGeneratedValue; -use ApiPlatform\Tests\Doctrine\Odm\PropertyInfo\Fixtures\DoctrineRelation; -use ApiPlatform\Tests\Doctrine\Odm\PropertyInfo\Fixtures\DoctrineWithEmbedded; -use ApiPlatform\Tests\Doctrine\Odm\PropertyInfo\Fixtures\EnumInt; -use ApiPlatform\Tests\Doctrine\Odm\PropertyInfo\Fixtures\EnumString; +use ApiPlatform\Doctrine\Odm\Tests\DoctrineMongoDbOdmSetup; +use ApiPlatform\Doctrine\Odm\Tests\PropertyInfo\Fixtures\DoctrineDummy; +use ApiPlatform\Doctrine\Odm\Tests\PropertyInfo\Fixtures\DoctrineEmbeddable; +use ApiPlatform\Doctrine\Odm\Tests\PropertyInfo\Fixtures\DoctrineEnum; +use ApiPlatform\Doctrine\Odm\Tests\PropertyInfo\Fixtures\DoctrineFooType; +use ApiPlatform\Doctrine\Odm\Tests\PropertyInfo\Fixtures\DoctrineGeneratedValue; +use ApiPlatform\Doctrine\Odm\Tests\PropertyInfo\Fixtures\DoctrineRelation; +use ApiPlatform\Doctrine\Odm\Tests\PropertyInfo\Fixtures\DoctrineWithEmbedded; +use ApiPlatform\Doctrine\Odm\Tests\PropertyInfo\Fixtures\EnumInt; +use ApiPlatform\Doctrine\Odm\Tests\PropertyInfo\Fixtures\EnumString; use Doctrine\Common\Collections\Collection; use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Types\Type as MongoDbType; diff --git a/tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineDummy.php b/src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/DoctrineDummy.php similarity index 73% rename from tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineDummy.php rename to src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/DoctrineDummy.php index 63d29dfa109..6dfc701bb07 100644 --- a/tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineDummy.php +++ b/src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/DoctrineDummy.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\PropertyInfo\Fixtures; +namespace ApiPlatform\Doctrine\Odm\Tests\PropertyInfo\Fixtures; use Doctrine\ODM\MongoDB\Mapping\Annotations\Document; use Doctrine\ODM\MongoDB\Mapping\Annotations\Field; @@ -59,43 +59,43 @@ class DoctrineDummy protected $binUuidRfc4122; #[Field(type: 'timestamp')] - private $timestamp; + private $timestamp; // @phpstan-ignore-line #[Field(type: 'date')] - private $date; + private $date; // @phpstan-ignore-line #[Field(type: 'date_immutable')] - private $dateImmutable; + private $dateImmutable; // @phpstan-ignore-line #[Field(type: 'float')] - private $float; + private $float; // @phpstan-ignore-line #[Field(type: 'bool')] - private $bool; + private $bool; // @phpstan-ignore-line #[Field(type: 'custom_foo')] - private $customFoo; + private $customFoo; // @phpstan-ignore-line #[Field(type: 'int')] - private $int; + private $int; // @phpstan-ignore-line #[Field(type: 'string')] - private $string; + private $string; // @phpstan-ignore-line #[Field(type: 'key')] - private $key; + private $key; // @phpstan-ignore-line #[Field(type: 'hash')] - private $hash; + private $hash; // @phpstan-ignore-line #[Field(type: 'collection')] - private $collection; + private $collection; // @phpstan-ignore-line #[Field(type: 'object_id')] - private $objectId; + private $objectId; // @phpstan-ignore-line #[Field(type: 'raw')] - private $raw; + private $raw; // @phpstan-ignore-line public $notMapped; } diff --git a/tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineEmbeddable.php b/src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/DoctrineEmbeddable.php similarity index 89% rename from tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineEmbeddable.php rename to src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/DoctrineEmbeddable.php index 7ff0e97ca22..1114eb6aee0 100644 --- a/tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineEmbeddable.php +++ b/src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/DoctrineEmbeddable.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\PropertyInfo\Fixtures; +namespace ApiPlatform\Doctrine\Odm\Tests\PropertyInfo\Fixtures; use Doctrine\ODM\MongoDB\Mapping\Annotations\EmbeddedDocument; use Doctrine\ODM\MongoDB\Mapping\Annotations\Field; diff --git a/tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineEnum.php b/src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/DoctrineEnum.php similarity index 92% rename from tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineEnum.php rename to src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/DoctrineEnum.php index 57efa0ec47e..7fe69bfc0a4 100644 --- a/tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineEnum.php +++ b/src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/DoctrineEnum.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\PropertyInfo\Fixtures; +namespace ApiPlatform\Doctrine\Odm\Tests\PropertyInfo\Fixtures; use Doctrine\ODM\MongoDB\Mapping\Annotations\Document; use Doctrine\ODM\MongoDB\Mapping\Annotations\Field; diff --git a/tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineFooType.php b/src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/DoctrineFooType.php similarity index 94% rename from tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineFooType.php rename to src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/DoctrineFooType.php index a27758f3288..713421f643b 100644 --- a/tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineFooType.php +++ b/src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/DoctrineFooType.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\PropertyInfo\Fixtures; +namespace ApiPlatform\Doctrine\Odm\Tests\PropertyInfo\Fixtures; use Doctrine\ODM\MongoDB\Types\Type; diff --git a/tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineGeneratedValue.php b/src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/DoctrineGeneratedValue.php similarity index 91% rename from tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineGeneratedValue.php rename to src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/DoctrineGeneratedValue.php index 7b72407a291..1d1046de1d3 100644 --- a/tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineGeneratedValue.php +++ b/src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/DoctrineGeneratedValue.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\PropertyInfo\Fixtures; +namespace ApiPlatform\Doctrine\Odm\Tests\PropertyInfo\Fixtures; use Doctrine\ODM\MongoDB\Mapping\Annotations\Document; use Doctrine\ODM\MongoDB\Mapping\Annotations\Field; diff --git a/tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineRelation.php b/src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/DoctrineRelation.php similarity index 91% rename from tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineRelation.php rename to src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/DoctrineRelation.php index b391726b910..130a2b8985a 100644 --- a/tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineRelation.php +++ b/src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/DoctrineRelation.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\PropertyInfo\Fixtures; +namespace ApiPlatform\Doctrine\Odm\Tests\PropertyInfo\Fixtures; use Doctrine\ODM\MongoDB\Mapping\Annotations\Document; use Doctrine\ODM\MongoDB\Mapping\Annotations\Id; diff --git a/tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineWithEmbedded.php b/src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/DoctrineWithEmbedded.php similarity index 92% rename from tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineWithEmbedded.php rename to src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/DoctrineWithEmbedded.php index fd47ec1ffad..0a8747f544b 100644 --- a/tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineWithEmbedded.php +++ b/src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/DoctrineWithEmbedded.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\PropertyInfo\Fixtures; +namespace ApiPlatform\Doctrine\Odm\Tests\PropertyInfo\Fixtures; use Doctrine\ODM\MongoDB\Mapping\Annotations\Document; use Doctrine\ODM\MongoDB\Mapping\Annotations\EmbedMany; diff --git a/tests/Doctrine/Odm/PropertyInfo/Fixtures/EnumInt.php b/src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/EnumInt.php similarity index 83% rename from tests/Doctrine/Odm/PropertyInfo/Fixtures/EnumInt.php rename to src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/EnumInt.php index 0fc31cff2a5..c96c7f82a0e 100644 --- a/tests/Doctrine/Odm/PropertyInfo/Fixtures/EnumInt.php +++ b/src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/EnumInt.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\PropertyInfo\Fixtures; +namespace ApiPlatform\Doctrine\Odm\Tests\PropertyInfo\Fixtures; enum EnumInt: int { diff --git a/tests/Doctrine/Odm/PropertyInfo/Fixtures/EnumString.php b/src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/EnumString.php similarity index 83% rename from tests/Doctrine/Odm/PropertyInfo/Fixtures/EnumString.php rename to src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/EnumString.php index f96c6e29bd3..34d90f73dd4 100644 --- a/tests/Doctrine/Odm/PropertyInfo/Fixtures/EnumString.php +++ b/src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/EnumString.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\PropertyInfo\Fixtures; +namespace ApiPlatform\Doctrine\Odm\Tests\PropertyInfo\Fixtures; enum EnumString: string { diff --git a/tests/Doctrine/Odm/PropertyInfo/Fixtures/Foo.php b/src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/Foo.php similarity index 85% rename from tests/Doctrine/Odm/PropertyInfo/Fixtures/Foo.php rename to src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/Foo.php index 1a5b7d87fda..2bd54d4ebc9 100644 --- a/tests/Doctrine/Odm/PropertyInfo/Fixtures/Foo.php +++ b/src/Doctrine/Odm/Tests/PropertyInfo/Fixtures/Foo.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\PropertyInfo\Fixtures; +namespace ApiPlatform\Doctrine\Odm\Tests\PropertyInfo\Fixtures; /** * @author Teoh Han Hui diff --git a/tests/Doctrine/Odm/State/CollectionProviderTest.php b/src/Doctrine/Odm/Tests/State/CollectionProviderTest.php similarity index 64% rename from tests/Doctrine/Odm/State/CollectionProviderTest.php rename to src/Doctrine/Odm/Tests/State/CollectionProviderTest.php index 784d4c0e39a..5d81c5d90cf 100644 --- a/tests/Doctrine/Odm/State/CollectionProviderTest.php +++ b/src/Doctrine/Odm/Tests/State/CollectionProviderTest.php @@ -11,16 +11,15 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\State; +namespace ApiPlatform\Doctrine\Odm\Tests\State; use ApiPlatform\Doctrine\Odm\Extension\AggregationCollectionExtensionInterface; use ApiPlatform\Doctrine\Odm\Extension\AggregationResultCollectionExtensionInterface; use ApiPlatform\Doctrine\Odm\State\CollectionProvider; -use ApiPlatform\Doctrine\Odm\State\Options; -use ApiPlatform\Exception\RuntimeException; +use ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document\ProviderDocument; +use ApiPlatform\Metadata\Exception\RuntimeException; use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; -use ApiPlatform\Tests\Fixtures\TestBundle\Document\ProviderEntity; use Doctrine\ODM\MongoDB\Aggregation\Builder; use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Iterator\Iterator; @@ -57,7 +56,7 @@ public function testGetCollection(): void $iterator = $this->prophesize(Iterator::class)->reveal(); $aggregationBuilderProphecy = $this->prophesize(Builder::class); - $aggregationBuilderProphecy->hydrate(ProviderEntity::class)->willReturn($aggregationBuilderProphecy)->shouldBeCalled(); + $aggregationBuilderProphecy->hydrate(ProviderDocument::class)->willReturn($aggregationBuilderProphecy)->shouldBeCalled(); $aggregationBuilderProphecy->execute([])->willReturn($iterator)->shouldBeCalled(); $aggregationBuilder = $aggregationBuilderProphecy->reveal(); @@ -65,14 +64,14 @@ public function testGetCollection(): void $repositoryProphecy->createAggregationBuilder()->willReturn($aggregationBuilder)->shouldBeCalled(); $managerProphecy = $this->prophesize(DocumentManager::class); - $managerProphecy->getRepository(ProviderEntity::class)->willReturn($repositoryProphecy->reveal())->shouldBeCalled(); + $managerProphecy->getRepository(ProviderDocument::class)->willReturn($repositoryProphecy->reveal())->shouldBeCalled(); - $this->managerRegistryProphecy->getManagerForClass(ProviderEntity::class)->willReturn($managerProphecy->reveal())->shouldBeCalled(); + $this->managerRegistryProphecy->getManagerForClass(ProviderDocument::class)->willReturn($managerProphecy->reveal())->shouldBeCalled(); - $operation = (new GetCollection())->withName('foo')->withClass(ProviderEntity::class); + $operation = (new GetCollection())->withName('foo')->withClass(ProviderDocument::class); $extensionProphecy = $this->prophesize(AggregationCollectionExtensionInterface::class); - $extensionProphecy->applyToCollection($aggregationBuilder, ProviderEntity::class, $operation, [])->shouldBeCalled(); + $extensionProphecy->applyToCollection($aggregationBuilder, ProviderDocument::class, $operation, [])->shouldBeCalled(); $dataProvider = new CollectionProvider($this->resourceMetadataFactoryProphecy->reveal(), $this->managerRegistryProphecy->reveal(), [$extensionProphecy->reveal()]); $this->assertSame($iterator, $dataProvider->provide($operation, [])); @@ -83,7 +82,7 @@ public function testGetCollectionWithExecuteOptions(): void $iterator = $this->prophesize(Iterator::class)->reveal(); $aggregationBuilderProphecy = $this->prophesize(Builder::class); - $aggregationBuilderProphecy->hydrate(ProviderEntity::class)->willReturn($aggregationBuilderProphecy)->shouldBeCalled(); + $aggregationBuilderProphecy->hydrate(ProviderDocument::class)->willReturn($aggregationBuilderProphecy)->shouldBeCalled(); $aggregationBuilderProphecy->execute(['allowDiskUse' => true])->willReturn($iterator)->shouldBeCalled(); $aggregationBuilder = $aggregationBuilderProphecy->reveal(); @@ -91,14 +90,14 @@ public function testGetCollectionWithExecuteOptions(): void $repositoryProphecy->createAggregationBuilder()->willReturn($aggregationBuilder)->shouldBeCalled(); $managerProphecy = $this->prophesize(DocumentManager::class); - $managerProphecy->getRepository(ProviderEntity::class)->willReturn($repositoryProphecy->reveal())->shouldBeCalled(); + $managerProphecy->getRepository(ProviderDocument::class)->willReturn($repositoryProphecy->reveal())->shouldBeCalled(); - $this->managerRegistryProphecy->getManagerForClass(ProviderEntity::class)->willReturn($managerProphecy->reveal())->shouldBeCalled(); + $this->managerRegistryProphecy->getManagerForClass(ProviderDocument::class)->willReturn($managerProphecy->reveal())->shouldBeCalled(); - $operation = (new GetCollection())->withExtraProperties(['doctrine_mongodb' => ['execute_options' => ['allowDiskUse' => true]]])->withName('foo')->withClass(ProviderEntity::class); + $operation = (new GetCollection())->withExtraProperties(['doctrine_mongodb' => ['execute_options' => ['allowDiskUse' => true]]])->withName('foo')->withClass(ProviderDocument::class); $extensionProphecy = $this->prophesize(AggregationCollectionExtensionInterface::class); - $extensionProphecy->applyToCollection($aggregationBuilder, ProviderEntity::class, $operation, [])->shouldBeCalled(); + $extensionProphecy->applyToCollection($aggregationBuilder, ProviderDocument::class, $operation, [])->shouldBeCalled(); $dataProvider = new CollectionProvider($this->resourceMetadataFactoryProphecy->reveal(), $this->managerRegistryProphecy->reveal(), [$extensionProphecy->reveal()]); $this->assertSame($iterator, $dataProvider->provide($operation, [])); @@ -113,16 +112,16 @@ public function testAggregationResultExtension(): void $repositoryProphecy->createAggregationBuilder()->willReturn($aggregationBuilder)->shouldBeCalled(); $managerProphecy = $this->prophesize(DocumentManager::class); - $managerProphecy->getRepository(ProviderEntity::class)->willReturn($repositoryProphecy->reveal())->shouldBeCalled(); + $managerProphecy->getRepository(ProviderDocument::class)->willReturn($repositoryProphecy->reveal())->shouldBeCalled(); - $this->managerRegistryProphecy->getManagerForClass(ProviderEntity::class)->willReturn($managerProphecy->reveal())->shouldBeCalled(); + $this->managerRegistryProphecy->getManagerForClass(ProviderDocument::class)->willReturn($managerProphecy->reveal())->shouldBeCalled(); - $operation = (new GetCollection())->withName('foo')->withClass(ProviderEntity::class); + $operation = (new GetCollection())->withName('foo')->withClass(ProviderDocument::class); $extensionProphecy = $this->prophesize(AggregationResultCollectionExtensionInterface::class); - $extensionProphecy->applyToCollection($aggregationBuilder, ProviderEntity::class, $operation, [])->shouldBeCalled(); - $extensionProphecy->supportsResult(ProviderEntity::class, $operation, [])->willReturn(true)->shouldBeCalled(); - $extensionProphecy->getResult($aggregationBuilder, ProviderEntity::class, $operation, [])->willReturn([])->shouldBeCalled(); + $extensionProphecy->applyToCollection($aggregationBuilder, ProviderDocument::class, $operation, [])->shouldBeCalled(); + $extensionProphecy->supportsResult(ProviderDocument::class, $operation, [])->willReturn(true)->shouldBeCalled(); + $extensionProphecy->getResult($aggregationBuilder, ProviderDocument::class, $operation, [])->willReturn([])->shouldBeCalled(); $dataProvider = new CollectionProvider($this->resourceMetadataFactoryProphecy->reveal(), $this->managerRegistryProphecy->reveal(), [$extensionProphecy->reveal()]); $this->assertEquals([], $dataProvider->provide($operation, [])); @@ -131,17 +130,17 @@ public function testAggregationResultExtension(): void public function testCannotCreateAggregationBuilder(): void { $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('The repository for "ApiPlatform\Tests\Fixtures\TestBundle\Document\ProviderEntity" must be an instance of "Doctrine\ODM\MongoDB\Repository\DocumentRepository".'); + $this->expectExceptionMessage('The repository for "ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document\ProviderDocument" must be an instance of "Doctrine\ODM\MongoDB\Repository\DocumentRepository".'); $repositoryProphecy = $this->prophesize(ObjectRepository::class); $managerProphecy = $this->prophesize(DocumentManager::class); - $managerProphecy->getRepository(ProviderEntity::class)->willReturn($repositoryProphecy->reveal())->shouldBeCalled(); + $managerProphecy->getRepository(ProviderDocument::class)->willReturn($repositoryProphecy->reveal())->shouldBeCalled(); - $this->managerRegistryProphecy->getManagerForClass(ProviderEntity::class)->willReturn($managerProphecy->reveal())->shouldBeCalled(); + $this->managerRegistryProphecy->getManagerForClass(ProviderDocument::class)->willReturn($managerProphecy->reveal())->shouldBeCalled(); $dataProvider = new CollectionProvider($this->resourceMetadataFactoryProphecy->reveal(), $this->managerRegistryProphecy->reveal()); - $operation = (new GetCollection())->withName('foo')->withClass(ProviderEntity::class); + $operation = (new GetCollection())->withName('foo')->withClass(ProviderDocument::class); $this->assertEquals([], $dataProvider->provide($operation, [])); } @@ -150,7 +149,7 @@ public function testOperationNotFound(): void $iterator = $this->prophesize(Iterator::class)->reveal(); $aggregationBuilderProphecy = $this->prophesize(Builder::class); - $aggregationBuilderProphecy->hydrate(ProviderEntity::class)->willReturn($aggregationBuilderProphecy)->shouldBeCalled(); + $aggregationBuilderProphecy->hydrate(ProviderDocument::class)->willReturn($aggregationBuilderProphecy)->shouldBeCalled(); $aggregationBuilderProphecy->execute([])->willReturn($iterator)->shouldBeCalled(); $aggregationBuilder = $aggregationBuilderProphecy->reveal(); @@ -158,40 +157,16 @@ public function testOperationNotFound(): void $repositoryProphecy->createAggregationBuilder()->willReturn($aggregationBuilder)->shouldBeCalled(); $managerProphecy = $this->prophesize(DocumentManager::class); - $managerProphecy->getRepository(ProviderEntity::class)->willReturn($repositoryProphecy->reveal())->shouldBeCalled(); + $managerProphecy->getRepository(ProviderDocument::class)->willReturn($repositoryProphecy->reveal())->shouldBeCalled(); - $this->managerRegistryProphecy->getManagerForClass(ProviderEntity::class)->willReturn($managerProphecy->reveal())->shouldBeCalled(); + $this->managerRegistryProphecy->getManagerForClass(ProviderDocument::class)->willReturn($managerProphecy->reveal())->shouldBeCalled(); - $operation = new GetCollection(name: 'bar', class: ProviderEntity::class); + $operation = new GetCollection(name: 'bar', class: ProviderDocument::class); $extensionProphecy = $this->prophesize(AggregationCollectionExtensionInterface::class); - $extensionProphecy->applyToCollection($aggregationBuilder, ProviderEntity::class, $operation, [])->shouldBeCalled(); + $extensionProphecy->applyToCollection($aggregationBuilder, ProviderDocument::class, $operation, [])->shouldBeCalled(); $dataProvider = new CollectionProvider($this->resourceMetadataFactoryProphecy->reveal(), $this->managerRegistryProphecy->reveal(), [$extensionProphecy->reveal()]); $this->assertSame($iterator, $dataProvider->provide($operation, [])); } - - /** - * @group legacy - */ - public function testHandleLinksCallable(): void - { - $this->expectDeprecation('The Doctrine\ODM\MongoDB\Aggregation\Builder::execute method is deprecated (This method was deprecated in doctrine/mongodb-odm 2.2. Please use getAggregation() instead.).'); - $class = 'foo'; - $resourceMetadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); - $it = $this->createStub(Iterator::class); - $it->method('current')->willReturn(null); - $aggregationBuilder = $this->createStub(Builder::class); - $aggregationBuilder->method('hydrate')->willReturnSelf(); - $aggregationBuilder->method('execute')->willReturn($it); - $repository = $this->createStub(DocumentRepository::class); - $repository->method('createAggregationBuilder')->willReturn($aggregationBuilder); - $manager = $this->createStub(DocumentManager::class); - $manager->method('getRepository')->willReturn($repository); - $managerRegistry = $this->createStub(ManagerRegistry::class); - $managerRegistry->method('getManagerForClass')->willReturn($manager); - $operation = new GetCollection(class: $class, stateOptions: new Options(handleLinks: fn () => $this->assertTrue(true))); - $dataProvider = new CollectionProvider($resourceMetadata, $managerRegistry); - $dataProvider->provide($operation, ['id' => 1]); - } } diff --git a/tests/Doctrine/Odm/State/ItemProviderTest.php b/src/Doctrine/Odm/Tests/State/ItemProviderTest.php similarity index 69% rename from tests/Doctrine/Odm/State/ItemProviderTest.php rename to src/Doctrine/Odm/Tests/State/ItemProviderTest.php index 89bdc3ecd71..721c3fd8fa5 100644 --- a/tests/Doctrine/Odm/State/ItemProviderTest.php +++ b/src/Doctrine/Odm/Tests/State/ItemProviderTest.php @@ -11,17 +11,16 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Odm\State; +namespace ApiPlatform\Doctrine\Odm\Tests\State; use ApiPlatform\Doctrine\Odm\Extension\AggregationItemExtensionInterface; use ApiPlatform\Doctrine\Odm\Extension\AggregationResultItemExtensionInterface; use ApiPlatform\Doctrine\Odm\State\ItemProvider; -use ApiPlatform\Doctrine\Odm\State\Options; -use ApiPlatform\Exception\RuntimeException; +use ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document\ProviderDocument; +use ApiPlatform\Metadata\Exception\RuntimeException; use ApiPlatform\Metadata\Get; use ApiPlatform\Metadata\Link; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; -use ApiPlatform\Tests\Fixtures\TestBundle\Document\ProviderEntity; use Doctrine\ODM\MongoDB\Aggregation\Builder; use Doctrine\ODM\MongoDB\Aggregation\Stage\MatchStage as AggregationMatch; use Doctrine\ODM\MongoDB\DocumentManager; @@ -57,19 +56,19 @@ public function testGetItemSingleIdentifier(): void $aggregationBuilderProphecy = $this->prophesize(Builder::class); $aggregationBuilderProphecy->match()->willReturn($matchProphecy->reveal())->shouldBeCalled(); - $aggregationBuilderProphecy->hydrate(ProviderEntity::class)->willReturn($aggregationBuilderProphecy)->shouldBeCalled(); + $aggregationBuilderProphecy->hydrate(ProviderDocument::class)->willReturn($aggregationBuilderProphecy)->shouldBeCalled(); $aggregationBuilderProphecy->execute([])->willReturn($iterator->reveal())->shouldBeCalled(); $aggregationBuilder = $aggregationBuilderProphecy->reveal(); - $managerRegistry = $this->getManagerRegistry(ProviderEntity::class, $aggregationBuilder); + $managerRegistry = $this->getManagerRegistry(ProviderDocument::class, $aggregationBuilder); $operation = (new Get()) - ->withUriVariables([(new Link())->withFromClass(ProviderEntity::class)->withIdentifiers(['id'])]) - ->withClass(ProviderEntity::class) + ->withUriVariables([(new Link())->withFromClass(ProviderDocument::class)->withIdentifiers(['id'])]) + ->withClass(ProviderDocument::class) ->withName('foo'); $extensionProphecy = $this->prophesize(AggregationItemExtensionInterface::class); - $extensionProphecy->applyToItem($aggregationBuilder, ProviderEntity::class, ['id' => 1], $operation, $context)->shouldBeCalled(); + $extensionProphecy->applyToItem($aggregationBuilder, ProviderDocument::class, ['id' => 1], $operation, $context)->shouldBeCalled(); $dataProvider = new ItemProvider($this->prophesize(ResourceMetadataCollectionFactoryInterface::class)->reveal(), $managerRegistry, [$extensionProphecy->reveal()]); @@ -90,20 +89,20 @@ public function testGetItemWithExecuteOptions(): void $aggregationBuilderProphecy = $this->prophesize(Builder::class); $aggregationBuilderProphecy->match()->willReturn($matchProphecy->reveal())->shouldBeCalled(); - $aggregationBuilderProphecy->hydrate(ProviderEntity::class)->willReturn($aggregationBuilderProphecy)->shouldBeCalled(); + $aggregationBuilderProphecy->hydrate(ProviderDocument::class)->willReturn($aggregationBuilderProphecy)->shouldBeCalled(); $aggregationBuilderProphecy->execute(['allowDiskUse' => true])->willReturn($iterator->reveal())->shouldBeCalled(); $aggregationBuilder = $aggregationBuilderProphecy->reveal(); - $managerRegistry = $this->getManagerRegistry(ProviderEntity::class, $aggregationBuilder); + $managerRegistry = $this->getManagerRegistry(ProviderDocument::class, $aggregationBuilder); $operation = (new Get()) - ->withUriVariables([(new Link())->withFromClass(ProviderEntity::class)->withIdentifiers(['id'])]) - ->withClass(ProviderEntity::class) + ->withUriVariables([(new Link())->withFromClass(ProviderDocument::class)->withIdentifiers(['id'])]) + ->withClass(ProviderDocument::class) ->withName('foo') ->withExtraProperties(['doctrine_mongodb' => ['execute_options' => ['allowDiskUse' => true]]]); $extensionProphecy = $this->prophesize(AggregationItemExtensionInterface::class); - $extensionProphecy->applyToItem($aggregationBuilder, ProviderEntity::class, ['id' => 1], $operation, $context)->shouldBeCalled(); + $extensionProphecy->applyToItem($aggregationBuilder, ProviderDocument::class, ['id' => 1], $operation, $context)->shouldBeCalled(); $dataProvider = new ItemProvider($this->prophesize(ResourceMetadataCollectionFactoryInterface::class)->reveal(), $managerRegistry, [$extensionProphecy->reveal()]); @@ -124,20 +123,20 @@ public function testGetItemDoubleIdentifier(): void $aggregationBuilderProphecy = $this->prophesize(Builder::class); $aggregationBuilderProphecy->match()->willReturn($matchProphecy->reveal())->shouldBeCalled(); - $aggregationBuilderProphecy->hydrate(ProviderEntity::class)->willReturn($aggregationBuilderProphecy)->shouldBeCalled(); + $aggregationBuilderProphecy->hydrate(ProviderDocument::class)->willReturn($aggregationBuilderProphecy)->shouldBeCalled(); $aggregationBuilderProphecy->execute([])->willReturn($iterator->reveal())->shouldBeCalled(); $aggregationBuilder = $aggregationBuilderProphecy->reveal(); - $managerRegistry = $this->getManagerRegistry(ProviderEntity::class, $aggregationBuilder); + $managerRegistry = $this->getManagerRegistry(ProviderDocument::class, $aggregationBuilder); $operation = (new Get()) - ->withUriVariables([(new Link())->withFromClass(ProviderEntity::class)->withIdentifiers(['ida', 'idb'])]) - ->withClass(ProviderEntity::class) + ->withUriVariables([(new Link())->withFromClass(ProviderDocument::class)->withIdentifiers(['ida', 'idb'])]) + ->withClass(ProviderDocument::class) ->withName('foo'); $context = []; $extensionProphecy = $this->prophesize(AggregationItemExtensionInterface::class); - $extensionProphecy->applyToItem($aggregationBuilder, ProviderEntity::class, ['ida' => 1, 'idb' => 2], $operation, $context)->shouldBeCalled(); + $extensionProphecy->applyToItem($aggregationBuilder, ProviderDocument::class, ['ida' => 1, 'idb' => 2], $operation, $context)->shouldBeCalled(); $dataProvider = new ItemProvider($this->prophesize(ResourceMetadataCollectionFactoryInterface::class)->reveal(), $managerRegistry, [$extensionProphecy->reveal()]); @@ -156,18 +155,18 @@ public function testAggregationResultExtension(): void $aggregationBuilderProphecy->match()->willReturn($matchProphecy->reveal())->shouldBeCalled(); $aggregationBuilder = $aggregationBuilderProphecy->reveal(); - $managerRegistry = $this->getManagerRegistry(ProviderEntity::class, $aggregationBuilder); + $managerRegistry = $this->getManagerRegistry(ProviderDocument::class, $aggregationBuilder); $operation = (new Get()) - ->withUriVariables([(new Link())->withFromClass(ProviderEntity::class)->withIdentifiers(['id'])]) - ->withClass(ProviderEntity::class) + ->withUriVariables([(new Link())->withFromClass(ProviderDocument::class)->withIdentifiers(['id'])]) + ->withClass(ProviderDocument::class) ->withName('foo'); $context = []; $extensionProphecy = $this->prophesize(AggregationResultItemExtensionInterface::class); - $extensionProphecy->applyToItem($aggregationBuilder, ProviderEntity::class, ['id' => 1], $operation, $context)->shouldBeCalled(); - $extensionProphecy->supportsResult(ProviderEntity::class, $operation, $context)->willReturn(true)->shouldBeCalled(); - $extensionProphecy->getResult($aggregationBuilder, ProviderEntity::class, $operation, $context)->willReturn($returnObject)->shouldBeCalled(); + $extensionProphecy->applyToItem($aggregationBuilder, ProviderDocument::class, ['id' => 1], $operation, $context)->shouldBeCalled(); + $extensionProphecy->supportsResult(ProviderDocument::class, $operation, $context)->willReturn(true)->shouldBeCalled(); + $extensionProphecy->getResult($aggregationBuilder, ProviderDocument::class, $operation, $context)->willReturn($returnObject)->shouldBeCalled(); $dataProvider = new ItemProvider($this->prophesize(ResourceMetadataCollectionFactoryInterface::class)->reveal(), $managerRegistry, [$extensionProphecy->reveal()]); @@ -177,19 +176,19 @@ public function testAggregationResultExtension(): void public function testCannotCreateAggregationBuilder(): void { $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('The repository for "ApiPlatform\Tests\Fixtures\TestBundle\Document\ProviderEntity" must be an instance of "Doctrine\ODM\MongoDB\Repository\DocumentRepository".'); + $this->expectExceptionMessage('The repository for "ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document\ProviderDocument" must be an instance of "Doctrine\ODM\MongoDB\Repository\DocumentRepository".'); $repositoryProphecy = $this->prophesize(ObjectRepository::class); $managerProphecy = $this->prophesize(ObjectManager::class); - $managerProphecy->getRepository(ProviderEntity::class)->willReturn($repositoryProphecy->reveal()); + $managerProphecy->getRepository(ProviderDocument::class)->willReturn($repositoryProphecy->reveal()); $managerRegistryProphecy = $this->prophesize(ManagerRegistry::class); - $managerRegistryProphecy->getManagerForClass(ProviderEntity::class)->willReturn($managerProphecy->reveal()); + $managerRegistryProphecy->getManagerForClass(ProviderDocument::class)->willReturn($managerProphecy->reveal()); $extensionProphecy = $this->prophesize(AggregationItemExtensionInterface::class); - (new ItemProvider($this->prophesize(ResourceMetadataCollectionFactoryInterface::class)->reveal(), $managerRegistryProphecy->reveal(), [$extensionProphecy->reveal()]))->provide((new Get())->withClass(ProviderEntity::class), [], []); + (new ItemProvider($this->prophesize(ResourceMetadataCollectionFactoryInterface::class)->reveal(), $managerRegistryProphecy->reveal(), [$extensionProphecy->reveal()]))->provide((new Get())->withClass(ProviderDocument::class), [], []); } /** @@ -212,32 +211,8 @@ private function getManagerRegistry(string $resourceClass, Builder $aggregationB $managerProphecy->getClassMetadata($resourceClass)->willReturn($classMetadataProphecy->reveal()); $managerRegistryProphecy = $this->prophesize(ManagerRegistry::class); - $managerRegistryProphecy->getManagerForClass(ProviderEntity::class)->willReturn($managerProphecy->reveal()); + $managerRegistryProphecy->getManagerForClass(ProviderDocument::class)->willReturn($managerProphecy->reveal()); return $managerRegistryProphecy->reveal(); } - - /** - * @group legacy - */ - public function testHandleLinksCallable(): void - { - $this->expectDeprecation('The Doctrine\ODM\MongoDB\Aggregation\Builder::execute method is deprecated (This method was deprecated in doctrine/mongodb-odm 2.2. Please use getAggregation() instead.).'); - $class = 'foo'; - $resourceMetadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); - $it = $this->createStub(Iterator::class); - $it->method('current')->willReturn(null); - $aggregationBuilder = $this->createStub(Builder::class); - $aggregationBuilder->method('hydrate')->willReturnSelf(); - $aggregationBuilder->method('execute')->willReturn($it); - $repository = $this->createStub(DocumentRepository::class); - $repository->method('createAggregationBuilder')->willReturn($aggregationBuilder); - $manager = $this->createStub(DocumentManager::class); - $manager->method('getRepository')->willReturn($repository); - $managerRegistry = $this->createStub(ManagerRegistry::class); - $managerRegistry->method('getManagerForClass')->willReturn($manager); - $operation = new Get(class: $class, stateOptions: new Options(handleLinks: fn () => $this->assertTrue(true))); - $dataProvider = new ItemProvider($resourceMetadata, $managerRegistry); - $dataProvider->provide($operation, ['id' => 1]); - } } diff --git a/src/Doctrine/Odm/Tests/bootstrap.php b/src/Doctrine/Odm/Tests/bootstrap.php new file mode 100644 index 00000000000..567c2c9815b --- /dev/null +++ b/src/Doctrine/Odm/Tests/bootstrap.php @@ -0,0 +1,17 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +$loader = require __DIR__.'/../vendor/autoload.php'; +require __DIR__.'/AppKernel.php'; + +return $loader; diff --git a/src/Doctrine/Odm/Tests/config.yml b/src/Doctrine/Odm/Tests/config.yml new file mode 100644 index 00000000000..ab416fd583d --- /dev/null +++ b/src/Doctrine/Odm/Tests/config.yml @@ -0,0 +1,32 @@ +parameters: + env(MONGODB_DB): api_platform_test + env(MONGODB_URL): mongodb://localhost:27017 + +doctrine_mongodb: + connections: + default: + server: '%env(resolve:MONGODB_URL)%' + options: {} + default_database: '%env(resolve:MONGODB_DB)%' + document_managers: + default: + mappings: + TestBundle: + type: 'attribute' + dir: '%kernel.project_dir%/Fixtures/Document' + prefix: 'ApiPlatform\Doctrine\Odm\Tests\Fixtures\Document' + +api_platform: + formats: + json: ['application/json'] + doctrine: false + doctrine_mongodb_odm: true + mapping: + paths: + - '%kernel.project_dir%/Fixtures/Document' + +services: + test.property_accessor: + alias: property_accessor + public: true + diff --git a/src/Doctrine/Odm/composer.json b/src/Doctrine/Odm/composer.json new file mode 100644 index 00000000000..29718fd5cee --- /dev/null +++ b/src/Doctrine/Odm/composer.json @@ -0,0 +1,88 @@ +{ + "name": "api-platform/doctrine-odm", + "description": "Doctrine MongoDB ODM bridge", + "type": "library", + "keywords": [ + "Doctrine", + "ODM", + "MongoDB" + ], + "homepage": "https://api-platform.com", + "license": "MIT", + "authors": [ + { + "name": "Kévin Dunglas", + "email": "kevin@dunglas.fr", + "homepage": "https://dunglas.fr" + }, + { + "name": "API Platform Community", + "homepage": "https://api-platform.com/community/contributors" + } + ], + "require": { + "php": ">=8.1", + "api-platform/doctrine-common": "*@dev || ^3.1", + "api-platform/metadata": "*@dev || ^3.1", + "api-platform/state": "*@dev || ^3.1", + "doctrine/mongodb-odm": "^2.2", + "doctrine/mongodb-odm-bundle": "^5.0", + "symfony/property-info": "^6.4 || ^7.0" + }, + "require-dev": { + "api-platform/parameter-validator": "*@dev || ^3.2", + "api-platform/symfony": "*@dev || ^3.2", + "doctrine/doctrine-bundle": "^2.11", + "phpspec/prophecy-phpunit": "^2.0", + "phpunit/phpunit": "^10.0", + "symfony/cache": "^6.4 || ^7.0", + "symfony/framework-bundle": "^6.4 || ^7.0", + "symfony/phpunit-bridge": "^6.4 || ^7.0", + "symfony/serializer": "^6.4 || ^7.0", + "symfony/yaml": "^6.4 || ^7.0" + }, + "autoload": { + "psr-4": { + "ApiPlatform\\Doctrine\\Odm\\": "" + } + }, + "config": { + "preferred-install": { + "*": "dist" + }, + "sort-packages": true, + "allow-plugins": { + "php-http/discovery": false + } + }, + "extra": { + "branch-alias": { + "dev-main": "3.2.x-dev" + }, + "symfony": { + "require": "^6.4" + } + }, + "repositories": [ + { + "type": "path", + "url": "../../Metadata" + }, + { + "type": "path", + "url": "../../State" + }, + { + "type": "path", + "url": "../Common" + }, + { + "type": "path", + "url": "../../Symfony" + }, + { + "type": "path", + "url": "../../ParameterValidator" + } + ] +} diff --git a/src/Doctrine/Odm/phpunit.xml.dist b/src/Doctrine/Odm/phpunit.xml.dist new file mode 100644 index 00000000000..44fe7563e18 --- /dev/null +++ b/src/Doctrine/Odm/phpunit.xml.dist @@ -0,0 +1,22 @@ + + + + + + + + + + ./Tests/ + + + + + ./ + + + ./Tests + ./vendor + + + diff --git a/src/Doctrine/Orm/.gitattributes b/src/Doctrine/Orm/.gitattributes new file mode 100644 index 00000000000..ae3c2e1685a --- /dev/null +++ b/src/Doctrine/Orm/.gitattributes @@ -0,0 +1,2 @@ +/.gitignore export-ignore +/Tests export-ignore diff --git a/src/Doctrine/Orm/.gitignore b/src/Doctrine/Orm/.gitignore new file mode 100644 index 00000000000..2db77de0df4 --- /dev/null +++ b/src/Doctrine/Orm/.gitignore @@ -0,0 +1,5 @@ +/composer.lock +/vendor +/.phpunit.result.cache +/.phpunit.cache +/Tests/var diff --git a/src/Doctrine/Orm/AbstractPaginator.php b/src/Doctrine/Orm/AbstractPaginator.php index 3c3fa42e9ab..33d46fa787f 100644 --- a/src/Doctrine/Orm/AbstractPaginator.php +++ b/src/Doctrine/Orm/AbstractPaginator.php @@ -13,7 +13,7 @@ namespace ApiPlatform\Doctrine\Orm; -use ApiPlatform\Exception\InvalidArgumentException; +use ApiPlatform\Metadata\Exception\InvalidArgumentException; use ApiPlatform\State\Pagination\PartialPaginatorInterface; use Doctrine\ORM\Query; use Doctrine\ORM\Tools\Pagination\Paginator as DoctrinePaginator; diff --git a/src/Doctrine/Orm/Extension/EagerLoadingExtension.php b/src/Doctrine/Orm/Extension/EagerLoadingExtension.php index dc6de300cb0..57f5c7b6591 100644 --- a/src/Doctrine/Orm/Extension/EagerLoadingExtension.php +++ b/src/Doctrine/Orm/Extension/EagerLoadingExtension.php @@ -15,10 +15,10 @@ use ApiPlatform\Doctrine\Orm\Util\QueryBuilderHelper; use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface; -use ApiPlatform\Exception\InvalidArgumentException; -use ApiPlatform\Exception\PropertyNotFoundException; -use ApiPlatform\Exception\ResourceClassNotFoundException; -use ApiPlatform\Exception\RuntimeException; +use ApiPlatform\Metadata\Exception\InvalidArgumentException; +use ApiPlatform\Metadata\Exception\PropertyNotFoundException; +use ApiPlatform\Metadata\Exception\ResourceClassNotFoundException; +use ApiPlatform\Metadata\Exception\RuntimeException; use ApiPlatform\Metadata\Operation; use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface; use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface; diff --git a/src/Doctrine/Orm/Filter/DateFilter.php b/src/Doctrine/Orm/Filter/DateFilter.php index d895cc68cbc..dd42e8ab5c4 100644 --- a/src/Doctrine/Orm/Filter/DateFilter.php +++ b/src/Doctrine/Orm/Filter/DateFilter.php @@ -16,7 +16,7 @@ use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface; use ApiPlatform\Doctrine\Common\Filter\DateFilterTrait; use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface; -use ApiPlatform\Exception\InvalidArgumentException; +use ApiPlatform\Metadata\Exception\InvalidArgumentException; use ApiPlatform\Metadata\Operation; use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\DBAL\Types\Types; diff --git a/src/Doctrine/Orm/Filter/SearchFilter.php b/src/Doctrine/Orm/Filter/SearchFilter.php index 0ea085811d7..4133f33ad91 100644 --- a/src/Doctrine/Orm/Filter/SearchFilter.php +++ b/src/Doctrine/Orm/Filter/SearchFilter.php @@ -19,7 +19,7 @@ use ApiPlatform\Doctrine\Common\Filter\SearchFilterTrait; use ApiPlatform\Doctrine\Orm\Util\QueryBuilderHelper; use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface; -use ApiPlatform\Exception\InvalidArgumentException; +use ApiPlatform\Metadata\Exception\InvalidArgumentException; use ApiPlatform\Metadata\IdentifiersExtractorInterface; use ApiPlatform\Metadata\IriConverterInterface; use ApiPlatform\Metadata\Operation; diff --git a/src/Doctrine/Orm/LICENSE b/src/Doctrine/Orm/LICENSE new file mode 100644 index 00000000000..1ca98eeb824 --- /dev/null +++ b/src/Doctrine/Orm/LICENSE @@ -0,0 +1,21 @@ +The MIT license + +Copyright (c) 2015-present Kévin Dunglas + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/src/Doctrine/Orm/State/CollectionProvider.php b/src/Doctrine/Orm/State/CollectionProvider.php index 94141e5a108..0c0248eee85 100644 --- a/src/Doctrine/Orm/State/CollectionProvider.php +++ b/src/Doctrine/Orm/State/CollectionProvider.php @@ -17,7 +17,7 @@ use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface; use ApiPlatform\Doctrine\Orm\Extension\QueryResultCollectionExtensionInterface; use ApiPlatform\Doctrine\Orm\Util\QueryNameGenerator; -use ApiPlatform\Exception\RuntimeException; +use ApiPlatform\Metadata\Exception\RuntimeException; use ApiPlatform\Metadata\Operation; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\State\ProviderInterface; diff --git a/src/Doctrine/Orm/State/ItemProvider.php b/src/Doctrine/Orm/State/ItemProvider.php index c7235b58e3b..91896e7f685 100644 --- a/src/Doctrine/Orm/State/ItemProvider.php +++ b/src/Doctrine/Orm/State/ItemProvider.php @@ -17,7 +17,7 @@ use ApiPlatform\Doctrine\Orm\Extension\QueryItemExtensionInterface; use ApiPlatform\Doctrine\Orm\Extension\QueryResultItemExtensionInterface; use ApiPlatform\Doctrine\Orm\Util\QueryNameGenerator; -use ApiPlatform\Exception\RuntimeException; +use ApiPlatform\Metadata\Exception\RuntimeException; use ApiPlatform\Metadata\Operation; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\State\ProviderInterface; diff --git a/src/Doctrine/Orm/State/Options.php b/src/Doctrine/Orm/State/Options.php index 50d13f1b7a4..397d2da758a 100644 --- a/src/Doctrine/Orm/State/Options.php +++ b/src/Doctrine/Orm/State/Options.php @@ -13,9 +13,10 @@ namespace ApiPlatform\Doctrine\Orm\State; +use ApiPlatform\Doctrine\Common\State\Options as CommonOptions; use ApiPlatform\State\OptionsInterface; -class Options implements OptionsInterface +class Options extends CommonOptions implements OptionsInterface { /** * @param string|callable $handleLinks experimental callable, typed mixed as we may want a service name in the future @@ -24,8 +25,9 @@ class Options implements OptionsInterface */ public function __construct( protected ?string $entityClass = null, - protected mixed $handleLinks = null, + mixed $handleLinks = null, ) { + parent::__construct(handleLinks: $handleLinks); } public function getEntityClass(): ?string diff --git a/src/Doctrine/Orm/Tests/AppKernel.php b/src/Doctrine/Orm/Tests/AppKernel.php new file mode 100644 index 00000000000..22409c74f2f --- /dev/null +++ b/src/Doctrine/Orm/Tests/AppKernel.php @@ -0,0 +1,89 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Doctrine\Orm\Tests; + +use ApiPlatform\Symfony\Bundle\ApiPlatformBundle; +use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; +use Symfony\Bundle\FrameworkBundle\FrameworkBundle; +use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; +use Symfony\Component\Config\Loader\LoaderInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\HttpKernel\Kernel; + +/** + * AppKernel for tests. + * + * @author Kévin Dunglas + */ +class AppKernel extends Kernel +{ + use MicroKernelTrait; + + public function __construct(string $environment, bool $debug) + { + parent::__construct($environment, $debug); + + // patch for behat/symfony2-extension not supporting %env(APP_ENV)% + $this->environment = $_SERVER['APP_ENV'] ?? $environment; + } + + public function registerBundles(): array + { + return [ + new ApiPlatformBundle(), + new FrameworkBundle(), + new DoctrineBundle(), + new TestBundle(), + ]; + } + + public function getProjectDir(): string + { + return __DIR__; + } + + protected function configureRoutes($routes): void + { + } + + protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader): void + { + $c->setParameter('kernel.project_dir', __DIR__); + + $cookie = ['cookie_secure' => true, 'cookie_samesite' => 'lax', 'handler_id' => 'session.handler.native_file']; + $config = [ + 'secret' => 'dunglas.fr', + 'validation' => ['enable_attributes' => true, 'email_validation_mode' => 'html5'], + 'serializer' => ['enable_attributes' => true], + 'test' => null, + 'session' => ['storage_factory_id' => 'session.storage.factory.mock_file'] + $cookie, + 'profiler' => ['enabled' => false], + 'property_access' => ['enabled' => true], + 'php_errors' => ['log' => true], + 'router' => ['utf8' => true], + 'http_method_override' => false, + 'annotations' => false, + 'handle_all_throwables' => true, + 'uid' => ['default_uuid_version' => 7, 'time_based_uuid_version' => 7], + ]; + + $c->prependExtensionConfig('framework', $config); + + $loader->load(__DIR__.'/config.yml'); + } + + protected function build(ContainerBuilder $container): void + { + } +} diff --git a/src/Test/DoctrineOrmFilterTestCase.php b/src/Doctrine/Orm/Tests/DoctrineOrmFilterTestCase.php similarity index 97% rename from src/Test/DoctrineOrmFilterTestCase.php rename to src/Doctrine/Orm/Tests/DoctrineOrmFilterTestCase.php index ab90ca8107c..f901340ca6b 100644 --- a/src/Test/DoctrineOrmFilterTestCase.php +++ b/src/Doctrine/Orm/Tests/DoctrineOrmFilterTestCase.php @@ -11,11 +11,11 @@ declare(strict_types=1); -namespace ApiPlatform\Test; +namespace ApiPlatform\Doctrine\Orm\Tests; use ApiPlatform\Doctrine\Orm\Filter\FilterInterface; +use ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\Dummy; use ApiPlatform\Doctrine\Orm\Util\QueryNameGenerator; -use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy; use Doctrine\ORM\EntityRepository; use Doctrine\Persistence\ManagerRegistry; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; diff --git a/tests/Doctrine/Orm/Extension/EagerLoadingExtensionTest.php b/src/Doctrine/Orm/Tests/Extension/EagerLoadingExtensionTest.php similarity index 98% rename from tests/Doctrine/Orm/Extension/EagerLoadingExtensionTest.php rename to src/Doctrine/Orm/Tests/Extension/EagerLoadingExtensionTest.php index 922880847a8..0a29d5d1ada 100644 --- a/tests/Doctrine/Orm/Extension/EagerLoadingExtensionTest.php +++ b/src/Doctrine/Orm/Tests/Extension/EagerLoadingExtensionTest.php @@ -11,28 +11,28 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Orm\Extension; +namespace ApiPlatform\Doctrine\Orm\Tests\Extension; use ApiPlatform\Doctrine\Orm\Extension\EagerLoadingExtension; +use ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\AbstractDummy; +use ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\ConcreteDummy; +use ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\Dummy; +use ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\EmbeddableDummy; +use ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\PropertyCollectionIriOnly; +use ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\PropertyCollectionIriOnlyRelation; +use ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\RelatedDummy; +use ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\ThirdLevel; +use ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\UnknownDummy; use ApiPlatform\Doctrine\Orm\Util\QueryNameGenerator; -use ApiPlatform\Exception\PropertyNotFoundException; -use ApiPlatform\Exception\ResourceClassNotFoundException; -use ApiPlatform\Exception\RuntimeException; use ApiPlatform\Metadata\ApiProperty; +use ApiPlatform\Metadata\Exception\PropertyNotFoundException; +use ApiPlatform\Metadata\Exception\ResourceClassNotFoundException; +use ApiPlatform\Metadata\Exception\RuntimeException; use ApiPlatform\Metadata\Get; use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface; use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface; use ApiPlatform\Metadata\Property\PropertyNameCollection; -use ApiPlatform\Tests\Fixtures\TestBundle\Entity\AbstractDummy; -use ApiPlatform\Tests\Fixtures\TestBundle\Entity\ConcreteDummy; -use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy; -use ApiPlatform\Tests\Fixtures\TestBundle\Entity\EmbeddableDummy; -use ApiPlatform\Tests\Fixtures\TestBundle\Entity\PropertyCollectionIriOnly; -use ApiPlatform\Tests\Fixtures\TestBundle\Entity\PropertyCollectionIriOnlyRelation; -use ApiPlatform\Tests\Fixtures\TestBundle\Entity\RelatedDummy; -use ApiPlatform\Tests\Fixtures\TestBundle\Entity\ThirdLevel; -use ApiPlatform\Tests\Fixtures\TestBundle\Entity\UnknownDummy; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataInfo; diff --git a/tests/Doctrine/Orm/Extension/FilterEagerLoadingExtensionTest.php b/src/Doctrine/Orm/Tests/Extension/FilterEagerLoadingExtensionTest.php similarity index 89% rename from tests/Doctrine/Orm/Extension/FilterEagerLoadingExtensionTest.php rename to src/Doctrine/Orm/Tests/Extension/FilterEagerLoadingExtensionTest.php index fbbce89f3ed..7fe4a66002e 100644 --- a/tests/Doctrine/Orm/Extension/FilterEagerLoadingExtensionTest.php +++ b/src/Doctrine/Orm/Tests/Extension/FilterEagerLoadingExtensionTest.php @@ -11,19 +11,19 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Doctrine\Orm\Extension; +namespace ApiPlatform\Doctrine\Orm\Tests\Extension; use ApiPlatform\Doctrine\Orm\Extension\FilterEagerLoadingExtension; +use ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\CompositeItem; +use ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\CompositeLabel; +use ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\CompositeRelation; +use ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\DummyCar; +use ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\DummyTravel; use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface; use ApiPlatform\Metadata\Get; use ApiPlatform\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface; use ApiPlatform\Metadata\Resource\ResourceNameCollection; use ApiPlatform\Metadata\ResourceClassResolver; -use ApiPlatform\Tests\Fixtures\TestBundle\Entity\CompositeItem; -use ApiPlatform\Tests\Fixtures\TestBundle\Entity\CompositeLabel; -use ApiPlatform\Tests\Fixtures\TestBundle\Entity\CompositeRelation; -use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyCar; -use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyTravel; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Query\Expr; @@ -123,7 +123,7 @@ public function testApplyCollection(): void $filterEagerLoadingExtension = new FilterEagerLoadingExtension(true); $filterEagerLoadingExtension->applyToCollection($qb, $queryNameGenerator->reveal(), DummyCar::class, new Get(name: 'get')); - $this->assertSame('SELECT o FROM ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyCar o LEFT JOIN o.colors colors WHERE o IN(SELECT o_2 FROM ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyCar o_2 LEFT JOIN o_2.colors colors_2 WHERE o_2.colors = :foo)', $qb->getDQL()); + $this->assertSame('SELECT o FROM ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\DummyCar o LEFT JOIN o.colors colors WHERE o IN(SELECT o_2 FROM ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\DummyCar o_2 LEFT JOIN o_2.colors colors_2 WHERE o_2.colors = :foo)', $qb->getDQL()); } public function testApplyCollectionWithManualJoin(): void @@ -157,13 +157,13 @@ public function testApplyCollectionWithManualJoin(): void $expected = <<<'SQL' SELECT o -FROM ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyCar o +FROM ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\DummyCar o LEFT JOIN o.colors colors -INNER JOIN ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyTravel t_a3 WITH o.id = t_a3.car AND t_a3.passenger = :user +INNER JOIN ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\DummyTravel t_a3 WITH o.id = t_a3.car AND t_a3.passenger = :user WHERE o IN( - SELECT o_2 FROM ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyCar o_2 + SELECT o_2 FROM ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\DummyCar o_2 LEFT JOIN o_2.colors colors_2 - INNER JOIN ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyTravel t_a3_a20 WITH o_2.id = t_a3_a20.car AND t_a3_a20.passenger = :user + INNER JOIN ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\DummyTravel t_a3_a20 WITH o_2.id = t_a3_a20.car AND t_a3_a20.passenger = :user WHERE o_2.colors = :foo AND t_a3_a20.confirmed = :confirmation ) SQL; @@ -199,10 +199,10 @@ public function testApplyCollectionCorrectlyReplacesJoinCondition(): void $expected = <<<'SQL' SELECT o -FROM ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyCar o +FROM ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\DummyCar o LEFT JOIN o.colors colors ON o.id = colors.car AND colors.id IN (1,2,3) WHERE o IN( - SELECT o_2 FROM ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyCar o_2 + SELECT o_2 FROM ApiPlatform\Doctrine\Orm\Tests\Fixtures\Entity\DummyCar o_2 LEFT JOIN o_2.colors colors_2 ON o_2.id = colors_2.car AND colors_2.id IN (1,2,3) WHERE o_2.colors = :foo AND o_2.info.name = :bar ) @@ -237,10 +237,10 @@ public function testHiddenOrderBy(): void $expected = <<