From fa057ce10cb27190601d6c6586581c132caa66e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Fri, 10 May 2019 12:53:15 +0200 Subject: [PATCH 01/13] Compatiblity with Symfony 4.3 --- src/Bridge/Symfony/Messenger/DataPersister.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bridge/Symfony/Messenger/DataPersister.php b/src/Bridge/Symfony/Messenger/DataPersister.php index fb059983eb5..0c3d0d9f957 100644 --- a/src/Bridge/Symfony/Messenger/DataPersister.php +++ b/src/Bridge/Symfony/Messenger/DataPersister.php @@ -88,6 +88,6 @@ public function persist($data, array $context = []) */ public function remove($data, array $context = []) { - $this->messageBus->dispatch(new Envelope($data, new RemoveStamp())); + $this->messageBus->dispatch(new Envelope($data, [new RemoveStamp()])); } } From 9f65b2b73b5c89999ea4251290f0db173221b89c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Wed, 15 May 2019 22:44:35 +0200 Subject: [PATCH 02/13] Fix all broken unit tests --- tests/Bridge/Symfony/Messenger/DataPersisterTest.php | 2 +- tests/Security/EventListener/DenyAccessListenerTest.php | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/Bridge/Symfony/Messenger/DataPersisterTest.php b/tests/Bridge/Symfony/Messenger/DataPersisterTest.php index fc7bef5ffdb..0ee7becbbf9 100644 --- a/tests/Bridge/Symfony/Messenger/DataPersisterTest.php +++ b/tests/Bridge/Symfony/Messenger/DataPersisterTest.php @@ -80,7 +80,7 @@ public function testHandle() $dummy = new Dummy(); $messageBus = $this->prophesize(MessageBusInterface::class); - $messageBus->dispatch($dummy)->willReturn(new Envelope($dummy, new HandledStamp($dummy, 'DummyHandler::__invoke')))->shouldBeCalled(); + $messageBus->dispatch($dummy)->willReturn(new Envelope($dummy, [new HandledStamp($dummy, 'DummyHandler::__invoke')]))->shouldBeCalled(); $dataPersister = new DataPersister($this->prophesize(ResourceMetadataFactoryInterface::class)->reveal(), $messageBus->reveal()); $this->assertSame($dummy, $dataPersister->persist($dummy)); diff --git a/tests/Security/EventListener/DenyAccessListenerTest.php b/tests/Security/EventListener/DenyAccessListenerTest.php index 9ff418728dd..09854f2391d 100644 --- a/tests/Security/EventListener/DenyAccessListenerTest.php +++ b/tests/Security/EventListener/DenyAccessListenerTest.php @@ -29,7 +29,6 @@ use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\Security\Core\Role\RoleHierarchy; -use Symfony\Component\Security\Core\Role\RoleHierarchyInterface; /** * @author Kévin Dunglas @@ -270,8 +269,8 @@ private function getLegacyListener(ResourceMetadataFactoryInterface $resourceMet { $authenticationTrustResolverProphecy = $this->prophesize(AuthenticationTrustResolverInterface::class); - $roleHierarchyInterfaceProphecy = $this->prophesize(RoleHierarchyInterface::class); - $roleHierarchyInterfaceProphecy->{method_exists(RoleHierarchy::class, 'getReachableRoleNames') ? 'getReachableRoleNames' : 'getReachableRoles'}(Argument::type('array'))->willReturn([]); + $roleHierarchyInterfaceProphecy = $this->prophesize(RoleHierarchy::class); + $roleHierarchyInterfaceProphecy->getReachableRoles(Argument::type('array'))->willReturn([]); $tokenProphecy = $this->prophesize(AbstractToken::class); $tokenProphecy->getUser()->willReturn('anon.'); From 6e236ddb89fd5ddb1a4c95641aa65ae69d0ca8e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Wed, 15 May 2019 22:58:44 +0200 Subject: [PATCH 03/13] Fix some deprecations --- .travis.yml | 4 ++-- composer.json | 6 +++--- .../config/doctrine_orm_mercure_publisher.xml | 2 +- .../Symfony/Bundle/Resources/config/messenger.xml | 2 +- .../Resources/views/DataCollector/request.html.twig | 12 +++++++----- src/Serializer/AbstractItemNormalizer.php | 8 ++++---- .../DependencyInjection/ApiPlatformExtensionTest.php | 4 ++-- tests/Fixtures/app/AppKernel.php | 6 ++++-- tests/Fixtures/app/config/config_common.yml | 2 -- 9 files changed, 24 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9ead294b1bd..b85854e77eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -209,7 +209,7 @@ jobs: - *validate-openapi-v3-yaml - php: '7.3' - env: SYMFONY_DEPRECATIONS_HELPER=0 + env: SYMFONY_DEPRECATIONS_HELPER=max[total]=0 before_install: - *install-mongodb-php-extension - *disable-xdebug-php-extension @@ -229,5 +229,5 @@ jobs: - *validate-openapi-v3-yaml allow_failures: - - env: SYMFONY_DEPRECATIONS_HELPER=0 + - env: SYMFONY_DEPRECATIONS_HELPER=max[total]=0 fast_finish: true diff --git a/composer.json b/composer.json index c79f0a187bf..a8c1b963460 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "symfony/http-kernel": "^3.4 || ^4.0", "symfony/property-access": "^3.4 || ^4.0", "symfony/property-info": "^3.4 || ^4.0", - "symfony/serializer": "^4.2.6", + "symfony/serializer": "^4.3", "symfony/web-link": "^4.1", "willdurand/negotiation": "^2.0.3" }, @@ -44,7 +44,7 @@ "guzzlehttp/guzzle": "^6.0", "jangregor/phpstan-prophecy": "^0.3", "justinrainbow/json-schema": "^5.0", - "nelmio/api-doc-bundle": "^2.13.3", + "nelmio/api-doc-bundle": "^2.13.4", "phpdocumentor/reflection-docblock": "^3.0 || ^4.0", "phpdocumentor/type-resolver": "^0.3 || ^0.4", "phpspec/prophecy": "^1.8", @@ -71,7 +71,7 @@ "symfony/expression-language": "^3.4 || ^4.0", "symfony/finder": "^3.4 || ^4.0", "symfony/form": "^3.4 || ^4.0", - "symfony/framework-bundle": "^4.2", + "symfony/framework-bundle": "^4.3", "symfony/mercure-bundle": "*", "symfony/messenger": "^4.2", "symfony/phpunit-bridge": "^4.3", diff --git a/src/Bridge/Symfony/Bundle/Resources/config/doctrine_orm_mercure_publisher.xml b/src/Bridge/Symfony/Bundle/Resources/config/doctrine_orm_mercure_publisher.xml index 0b4c6e1bdad..54f4f4d1b79 100644 --- a/src/Bridge/Symfony/Bundle/Resources/config/doctrine_orm_mercure_publisher.xml +++ b/src/Bridge/Symfony/Bundle/Resources/config/doctrine_orm_mercure_publisher.xml @@ -14,7 +14,7 @@ %api_platform.formats% - + diff --git a/src/Bridge/Symfony/Bundle/Resources/config/messenger.xml b/src/Bridge/Symfony/Bundle/Resources/config/messenger.xml index 5117f5e9d41..d50ec0e3d69 100644 --- a/src/Bridge/Symfony/Bundle/Resources/config/messenger.xml +++ b/src/Bridge/Symfony/Bundle/Resources/config/messenger.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - + diff --git a/src/Bridge/Symfony/Bundle/Resources/views/DataCollector/request.html.twig b/src/Bridge/Symfony/Bundle/Resources/views/DataCollector/request.html.twig index e5983280b4e..79d78a25bf2 100644 --- a/src/Bridge/Symfony/Bundle/Resources/views/DataCollector/request.html.twig +++ b/src/Bridge/Symfony/Bundle/Resources/views/DataCollector/request.html.twig @@ -164,11 +164,13 @@ - {% for key, value in collector.resourceMetadata.attributes if key != 'filters' %} - - {{ key }} - {{- profiler_dump(value, 2) -}} - + {% for key, value in collector.resourceMetadata.attributes %} + {% if key != 'filters' %} + + {{ key }} + {{- profiler_dump(value, 2) -}} + + {% endif %} {% endfor %} diff --git a/src/Serializer/AbstractItemNormalizer.php b/src/Serializer/AbstractItemNormalizer.php index b11ee52a5af..c0bf199ef41 100644 --- a/src/Serializer/AbstractItemNormalizer.php +++ b/src/Serializer/AbstractItemNormalizer.php @@ -396,7 +396,7 @@ protected function denormalizeCollection(string $attribute, PropertyMetadata $pr ); } - $values[$index] = $this->denormalizeRelation($attribute, $propertyMetadata, $className, $obj, $format, $this->createChildContext($context, $attribute)); + $values[$index] = $this->denormalizeRelation($attribute, $propertyMetadata, $className, $obj, $format, $this->createChildContext($context, $attribute, $format)); } return $values; @@ -531,7 +531,7 @@ protected function getAttributeValue($object, $attribute, $format = null, array $this->resourceClassResolver->isResourceClass($className) ) { $resourceClass = $this->resourceClassResolver->getResourceClass($attributeValue, $className); - $childContext = $this->createChildContext($context, $attribute); + $childContext = $this->createChildContext($context, $attribute, $format); $childContext['resource_class'] = $resourceClass; return $this->normalizeCollectionOfRelations($propertyMetadata, $attributeValue, $resourceClass, $format, $childContext); @@ -543,7 +543,7 @@ protected function getAttributeValue($object, $attribute, $format = null, array $this->resourceClassResolver->isResourceClass($className) ) { $resourceClass = $this->resourceClassResolver->getResourceClass($attributeValue, $className, true); - $childContext = $this->createChildContext($context, $attribute); + $childContext = $this->createChildContext($context, $attribute, $format); $childContext['resource_class'] = $resourceClass; return $this->normalizeRelation($propertyMetadata, $attributeValue, $resourceClass, $format, $childContext); @@ -660,7 +660,7 @@ private function createAttributeValue($attribute, $value, $format = null, array $this->resourceClassResolver->isResourceClass($className) ) { $resourceClass = $this->resourceClassResolver->getResourceClass(null, $className); - $childContext = $this->createChildContext($context, $attribute); + $childContext = $this->createChildContext($context, $attribute, $format); $childContext['resource_class'] = $resourceClass; return $this->denormalizeRelation($attribute, $propertyMetadata, $resourceClass, $value, $format, $childContext); diff --git a/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php b/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php index d2361c1d782..c6a401fae48 100644 --- a/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php +++ b/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php @@ -518,7 +518,7 @@ public function testDisabledSwaggerUIAndRedoc() public function testDisabledMessenger() { $containerBuilderProphecy = $this->getBaseContainerBuilderProphecy(); - $containerBuilderProphecy->setAlias('api_platform.message_bus', 'message_bus')->shouldNotBeCalled(); + $containerBuilderProphecy->setAlias('api_platform.message_bus', 'messenger.default_bus')->shouldNotBeCalled(); $containerBuilderProphecy->setDefinition('api_platform.messenger.data_persister', Argument::type(Definition::class))->shouldNotBeCalled(); $containerBuilderProphecy->setDefinition('api_platform.messenger.data_transformer', Argument::type(Definition::class))->shouldNotBeCalled(); $containerBuilder = $containerBuilderProphecy->reveal(); @@ -1194,7 +1194,7 @@ private function getBaseContainerBuilderProphecy(array $doctrineIntegrationsToLo $aliases = [ 'api_platform.http_cache.purger' => 'api_platform.http_cache.purger.varnish', - 'api_platform.message_bus' => 'message_bus', + 'api_platform.message_bus' => 'messenger.default_bus', EagerLoadingExtension::class => 'api_platform.doctrine.orm.query_extension.eager_loading', FilterExtension::class => 'api_platform.doctrine.orm.query_extension.filter', FilterEagerLoadingExtension::class => 'api_platform.doctrine.orm.query_extension.filter_eager_loading', diff --git a/tests/Fixtures/app/AppKernel.php b/tests/Fixtures/app/AppKernel.php index f7e09ae561b..d10be21e349 100644 --- a/tests/Fixtures/app/AppKernel.php +++ b/tests/Fixtures/app/AppKernel.php @@ -29,6 +29,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Routing\RouteCollectionBuilder; +use Symfony\Component\Security\Core\Encoder\SodiumPasswordEncoder; use Symfony\Component\Security\Core\User\UserInterface; /** @@ -96,10 +97,11 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load $loader->load(__DIR__."/config/config_{$this->getEnvironment()}.yml"); + $alg = class_exists(SodiumPasswordEncoder::class) ? 'auto' : 'bcrypt'; $securityConfig = [ 'encoders' => [ - User::class => 'bcrypt', - UserDocument::class => 'bcrypt', + User::class => $alg, + UserDocument::class => $alg, // Don't use plaintext in production! UserInterface::class => 'plaintext', ], diff --git a/tests/Fixtures/app/config/config_common.yml b/tests/Fixtures/app/config/config_common.yml index 23eb8cda1f2..147ab132550 100644 --- a/tests/Fixtures/app/config/config_common.yml +++ b/tests/Fixtures/app/config/config_common.yml @@ -8,8 +8,6 @@ framework: session: storage_id: 'session.storage.mock_file' form: ~ # For FOSUser - templating: - engines: ['twig'] # For Swagger UI profiler: enabled: true collect: false From d93b4e2daf7b4909756ca51ae836a0a1bd369cae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Thu, 16 May 2019 09:34:10 +0200 Subject: [PATCH 04/13] Remove @final from ItemNormalizer --- src/Serializer/ItemNormalizer.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Serializer/ItemNormalizer.php b/src/Serializer/ItemNormalizer.php index f1e18b6d24d..68a7c4679a1 100644 --- a/src/Serializer/ItemNormalizer.php +++ b/src/Serializer/ItemNormalizer.php @@ -30,8 +30,6 @@ /** * Generic item normalizer. * - * @final - * * @author Kévin Dunglas */ class ItemNormalizer extends AbstractItemNormalizer From f7a432071c99950dc4c8d84a0c52a735486ccafa Mon Sep 17 00:00:00 2001 From: Alan Poulain Date: Sat, 1 Jun 2019 17:22:37 +0200 Subject: [PATCH 05/13] Fix Behat tests --- features/bootstrap/HydraContext.php | 2 +- features/graphql/mutation.feature | 2 +- features/hydra/docs.feature | 2 - features/jsonld/context.feature | 1 - .../PropertyInfo/DoctrineExtractor.php | 45 ++++++++++++++++--- .../PropertyInfo/DoctrineExtractorTest.php | 10 +++++ .../Fixtures/DoctrineGeneratedValue.php | 37 +++++++++++++++ 7 files changed, 87 insertions(+), 12 deletions(-) create mode 100644 tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/Fixtures/DoctrineGeneratedValue.php diff --git a/features/bootstrap/HydraContext.php b/features/bootstrap/HydraContext.php index 84edc9ff52b..9b995f7c359 100644 --- a/features/bootstrap/HydraContext.php +++ b/features/bootstrap/HydraContext.php @@ -230,7 +230,7 @@ private function getPropertyInfo(string $propertyName, string $className): stdCl } } - throw new \InvalidArgumentException(sprintf('Property "%s" of class "%s" does\'nt exist', $propertyName, $className)); + throw new \InvalidArgumentException(sprintf('Property "%s" of class "%s" doesn\'t exist', $propertyName, $className)); } /** diff --git a/features/graphql/mutation.feature b/features/graphql/mutation.feature index 449cf421fba..10036262caf 100644 --- a/features/graphql/mutation.feature +++ b/features/graphql/mutation.feature @@ -324,7 +324,7 @@ Feature: GraphQL mutation support When I send the following GraphQL request: """ mutation { - createDummy(input: {_id: 12, name: "", foo: [], clientMutationId: "myId"}) { + createDummy(input: {name: "", foo: [], clientMutationId: "myId"}) { clientMutationId } } diff --git a/features/hydra/docs.feature b/features/hydra/docs.feature index e77d86b4769..9b8fa98f57c 100644 --- a/features/hydra/docs.feature +++ b/features/hydra/docs.feature @@ -56,8 +56,6 @@ Feature: Documentation support And the value of the node "hydra:title" of the Hydra class "Dummy" is "Dummy" And the value of the node "hydra:description" of the Hydra class "Dummy" is "Dummy." # Properties - And "id" property is readable for Hydra class "Dummy" - And "id" property is writable for Hydra class "Dummy" And "name" property is readable for Hydra class "Dummy" And "name" property is writable for Hydra class "Dummy" And "name" property is required for Hydra class "Dummy" diff --git a/features/jsonld/context.feature b/features/jsonld/context.feature index 42bacdca557..45f324a742f 100644 --- a/features/jsonld/context.feature +++ b/features/jsonld/context.feature @@ -41,7 +41,6 @@ Feature: JSON-LD contexts generation "jsonData": "Dummy/jsonData", "arrayData": "Dummy/arrayData", "nameConverted": "Dummy/nameConverted", - "id": "Dummy/id", "name": "http://schema.org/name", "alias": "https://schema.org/alternateName", "foo": "Dummy/foo" diff --git a/src/Bridge/Doctrine/MongoDbOdm/PropertyInfo/DoctrineExtractor.php b/src/Bridge/Doctrine/MongoDbOdm/PropertyInfo/DoctrineExtractor.php index e9fdac022a3..2d37e04c560 100644 --- a/src/Bridge/Doctrine/MongoDbOdm/PropertyInfo/DoctrineExtractor.php +++ b/src/Bridge/Doctrine/MongoDbOdm/PropertyInfo/DoctrineExtractor.php @@ -16,7 +16,9 @@ use Doctrine\Common\Collections\Collection; use Doctrine\Common\Persistence\Mapping\MappingException; use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; use Doctrine\ODM\MongoDB\Types\Type as MongoDbType; +use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface; use Symfony\Component\PropertyInfo\PropertyListExtractorInterface; use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface; use Symfony\Component\PropertyInfo\Type; @@ -29,7 +31,7 @@ * @author Kévin Dunglas * @author Alan Poulain */ -final class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeExtractorInterface +final class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeExtractorInterface, PropertyAccessExtractorInterface { private $objectManager; @@ -43,9 +45,7 @@ public function __construct(ObjectManager $objectManager) */ public function getProperties($class, array $context = []) { - try { - $metadata = $this->objectManager->getClassMetadata($class); - } catch (MappingException $exception) { + if (null === $metadata = $this->getMetadata($class)) { return null; } @@ -57,9 +57,7 @@ public function getProperties($class, array $context = []) */ public function getTypes($class, $property, array $context = []) { - try { - $metadata = $this->objectManager->getClassMetadata($class); - } catch (MappingException $exception) { + if (null === $metadata = $this->getMetadata($class)) { return null; } @@ -111,6 +109,39 @@ public function getTypes($class, $property, array $context = []) } } + /** + * {@inheritdoc} + */ + public function isReadable($class, $property, array $context = []): ?bool + { + return null; + } + + /** + * {@inheritdoc} + */ + public function isWritable($class, $property, array $context = []): ?bool + { + if ( + null === ($metadata = $this->getMetadata($class)) + || ClassMetadata::GENERATOR_TYPE_NONE === $metadata->generatorType + || !\in_array($property, $metadata->getIdentifierFieldNames(), true) + ) { + return null; + } + + return false; + } + + private function getMetadata(string $class): ?ClassMetadata + { + try { + return $this->objectManager->getClassMetadata($class); + } catch (MappingException $exception) { + return null; + } + } + /** * Gets the corresponding built-in PHP type. */ diff --git a/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/DoctrineExtractorTest.php b/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/DoctrineExtractorTest.php index 2106410577a..2bf5c361644 100644 --- a/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/DoctrineExtractorTest.php +++ b/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/DoctrineExtractorTest.php @@ -18,6 +18,7 @@ use ApiPlatform\Core\Tests\Bridge\Doctrine\MongoDbOdm\PropertyInfo\Fixtures\DoctrineDummy; use ApiPlatform\Core\Tests\Bridge\Doctrine\MongoDbOdm\PropertyInfo\Fixtures\DoctrineEmbeddable; use ApiPlatform\Core\Tests\Bridge\Doctrine\MongoDbOdm\PropertyInfo\Fixtures\DoctrineFooType; +use ApiPlatform\Core\Tests\Bridge\Doctrine\MongoDbOdm\PropertyInfo\Fixtures\DoctrineGeneratedValue; use ApiPlatform\Core\Tests\Bridge\Doctrine\MongoDbOdm\PropertyInfo\Fixtures\DoctrineRelation; use ApiPlatform\Core\Tests\Bridge\Doctrine\MongoDbOdm\PropertyInfo\Fixtures\DoctrineWithEmbedded; use Doctrine\Common\Collections\Collection; @@ -193,6 +194,15 @@ public function testGetTypesCatchException(): void $this->assertNull($this->createExtractor()->getTypes('Not\Exist', 'baz')); } + public function testGeneratedValueNotWritable() + { + $extractor = $this->createExtractor(); + $this->assertFalse($extractor->isWritable(DoctrineGeneratedValue::class, 'id')); + $this->assertNull($extractor->isReadable(DoctrineGeneratedValue::class, 'id')); + $this->assertNull($extractor->isWritable(DoctrineGeneratedValue::class, 'foo')); + $this->assertNull($extractor->isReadable(DoctrineGeneratedValue::class, 'foo')); + } + private function createExtractor(): DoctrineExtractor { $config = DoctrineMongoDbOdmSetup::createAnnotationMetadataConfiguration([__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'], true); diff --git a/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/Fixtures/DoctrineGeneratedValue.php b/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/Fixtures/DoctrineGeneratedValue.php new file mode 100644 index 00000000000..46ece808957 --- /dev/null +++ b/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/Fixtures/DoctrineGeneratedValue.php @@ -0,0 +1,37 @@ + + * + * 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\Core\Tests\Bridge\Doctrine\MongoDbOdm\PropertyInfo\Fixtures; + +use Doctrine\ODM\MongoDB\Mapping\Annotations\Document; +use Doctrine\ODM\MongoDB\Mapping\Annotations\Field; +use Doctrine\ODM\MongoDB\Mapping\Annotations\Id; + +/** + * @Document + * + * @author Kévin Dunglas + * @author Alan Poulain + */ +class DoctrineGeneratedValue +{ + /** + * @Id(strategy="INCREMENT", type="integer") + */ + public $id; + + /** + * @Field + */ + public $foo; +} From 7b99246912f25a4982d73b287cadf6e41b0b1e68 Mon Sep 17 00:00:00 2001 From: soyuka Date: Tue, 4 Jun 2019 17:48:24 +0200 Subject: [PATCH 06/13] Use composition for the Exception Listener --- src/EventListener/ExceptionListener.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/EventListener/ExceptionListener.php b/src/EventListener/ExceptionListener.php index 61a2b2984e0..2f5c577bc1a 100644 --- a/src/EventListener/ExceptionListener.php +++ b/src/EventListener/ExceptionListener.php @@ -14,6 +14,7 @@ namespace ApiPlatform\Core\EventListener; use ApiPlatform\Core\Util\RequestAttributesExtractor; +use Psr\Log\LoggerInterface; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpKernel\EventListener\ExceptionListener as BaseExceptionListener; @@ -23,8 +24,15 @@ * @author Samuel ROZE * @author Kévin Dunglas */ -final class ExceptionListener extends BaseExceptionListener +final class ExceptionListener { + private $exceptionListener; + + public function __construct($controller, LoggerInterface $logger = null) + { + $this->exceptionListener = new BaseExceptionListener($controller, $logger); + } + public function onKernelException(GetResponseForExceptionEvent $event): void { $request = $event->getRequest(); @@ -36,6 +44,6 @@ public function onKernelException(GetResponseForExceptionEvent $event): void return; } - parent::onKernelException($event); + $this->exceptionListener->onKernelException($event); } } From 795192b307fd529b4c2b4d0e8937189157813394 Mon Sep 17 00:00:00 2001 From: soyuka Date: Tue, 4 Jun 2019 17:48:29 +0200 Subject: [PATCH 07/13] Fix default firewall logout_on_user_change deprecation --- tests/Fixtures/app/AppKernel.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Fixtures/app/AppKernel.php b/tests/Fixtures/app/AppKernel.php index d10be21e349..ef2c873bc4d 100644 --- a/tests/Fixtures/app/AppKernel.php +++ b/tests/Fixtures/app/AppKernel.php @@ -127,6 +127,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load 'security' => false, ], 'default' => [ + 'logout_on_user_change' => true, 'provider' => 'chain_provider', 'http_basic' => null, 'anonymous' => null, From 17d17d388eb5321a9e069fa80612e314e246e4b4 Mon Sep 17 00:00:00 2001 From: soyuka Date: Fri, 14 Jun 2019 15:58:04 +0200 Subject: [PATCH 08/13] Make sure that sodium is supported --- tests/Fixtures/app/AppKernel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Fixtures/app/AppKernel.php b/tests/Fixtures/app/AppKernel.php index ef2c873bc4d..d90f7c3f133 100644 --- a/tests/Fixtures/app/AppKernel.php +++ b/tests/Fixtures/app/AppKernel.php @@ -97,7 +97,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load $loader->load(__DIR__."/config/config_{$this->getEnvironment()}.yml"); - $alg = class_exists(SodiumPasswordEncoder::class) ? 'auto' : 'bcrypt'; + $alg = class_exists(SodiumPasswordEncoder::class) && SodiumPasswordEncoder::isSupported() ? 'auto' : 'bcrypt'; $securityConfig = [ 'encoders' => [ User::class => $alg, From 2260d05a755eba1a728d4854e6bd5dd59b6c9d9d Mon Sep 17 00:00:00 2001 From: soyuka Date: Fri, 14 Jun 2019 16:55:46 +0200 Subject: [PATCH 09/13] Fix composer and tests --- composer.json | 7 +++---- tests/Security/EventListener/DenyAccessListenerTest.php | 5 +++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index a8c1b963460..7d87a1e2d37 100644 --- a/composer.json +++ b/composer.json @@ -73,8 +73,8 @@ "symfony/form": "^3.4 || ^4.0", "symfony/framework-bundle": "^4.3", "symfony/mercure-bundle": "*", - "symfony/messenger": "^4.2", - "symfony/phpunit-bridge": "^4.3", + "symfony/messenger": "^4.3", + "symfony/phpunit-bridge": "^4.3.1", "symfony/routing": "^3.4 || ^4.0", "symfony/security-bundle": "^3.4 || ^4.0", "symfony/security-core": "^3.4 || ^4.0", @@ -86,8 +86,7 @@ }, "conflict": { "doctrine/common": "<2.7", - "doctrine/mongodb-odm": "<2.0", - "symfony/messenger": ">=4.3" + "doctrine/mongodb-odm": "<2.0" }, "suggest": { "doctrine/mongodb-odm-bundle": "To support MongoDB. Only versions 4.0 and later are supported.", diff --git a/tests/Security/EventListener/DenyAccessListenerTest.php b/tests/Security/EventListener/DenyAccessListenerTest.php index 09854f2391d..6845607d0ae 100644 --- a/tests/Security/EventListener/DenyAccessListenerTest.php +++ b/tests/Security/EventListener/DenyAccessListenerTest.php @@ -29,6 +29,7 @@ use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\Security\Core\Role\RoleHierarchy; +use Symfony\Component\Security\Core\Role\RoleHierarchyInterface; /** * @author Kévin Dunglas @@ -269,8 +270,8 @@ private function getLegacyListener(ResourceMetadataFactoryInterface $resourceMet { $authenticationTrustResolverProphecy = $this->prophesize(AuthenticationTrustResolverInterface::class); - $roleHierarchyInterfaceProphecy = $this->prophesize(RoleHierarchy::class); - $roleHierarchyInterfaceProphecy->getReachableRoles(Argument::type('array'))->willReturn([]); + $roleHierarchyInterfaceProphecy = $this->prophesize(RoleHierarchyInterface::class); + $roleHierarchyInterfaceProphecy->{method_exists(RoleHierarchy::class, 'getReachableRoleNames') ? 'getReachableRoleNames' : 'getReachableRoles'}(Argument::type('array'))->willReturn([]); $tokenProphecy = $this->prophesize(AbstractToken::class); $tokenProphecy->getUser()->willReturn('anon.'); From d902ea86b96936a99d6303fd073f4027c2170dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sat, 15 Jun 2019 10:54:07 +0200 Subject: [PATCH 10/13] Fix PHPStan config and CS --- phpstan.neon.dist | 4 ++-- tests/Security/EventListener/DenyAccessListenerTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index acf3d7eb68d..60efa0cd90f 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -34,10 +34,10 @@ parameters: - '#Call to an undefined method Doctrine\\Common\\Persistence\\ObjectManager::getConnection\(\)#' # https://github.com/symfony/symfony/pull/31903 - - message: '#Access to an undefined property object::\$headers\.#' + message: '#Access to property \$headers on an unknown class Symfony\\Component\\HttpKernel\\Response\.#' path: %currentWorkingDirectory%/tests/Bridge/Symfony/Bundle/Twig/ApiPlatformProfilerPanelTest.php - - message: '#Call to an undefined method object::getStatusCode\(\)\.#' + message: '#Call to method getStatusCode\(\) on an unknown class Symfony\\Component\\HttpKernel\\Response\.#' path: %currentWorkingDirectory%/tests/Bridge/Symfony/Bundle/Twig/ApiPlatformProfilerPanelTest.php - '#Parameter \#1 \$function of function call_user_func expects callable\(\): mixed, .+ given\.#' - '#Parameter \#1 \$exception of static method Symfony\\Component\\Debug\\Exception\\FlattenException::create\(\) expects Exception, Symfony\\Component\\Serializer\\Exception\\ExceptionInterface given\.#' diff --git a/tests/Security/EventListener/DenyAccessListenerTest.php b/tests/Security/EventListener/DenyAccessListenerTest.php index 6845607d0ae..9ff418728dd 100644 --- a/tests/Security/EventListener/DenyAccessListenerTest.php +++ b/tests/Security/EventListener/DenyAccessListenerTest.php @@ -270,7 +270,7 @@ private function getLegacyListener(ResourceMetadataFactoryInterface $resourceMet { $authenticationTrustResolverProphecy = $this->prophesize(AuthenticationTrustResolverInterface::class); - $roleHierarchyInterfaceProphecy = $this->prophesize(RoleHierarchyInterface::class); + $roleHierarchyInterfaceProphecy = $this->prophesize(RoleHierarchyInterface::class); $roleHierarchyInterfaceProphecy->{method_exists(RoleHierarchy::class, 'getReachableRoleNames') ? 'getReachableRoleNames' : 'getReachableRoles'}(Argument::type('array'))->willReturn([]); $tokenProphecy = $this->prophesize(AbstractToken::class); From 830d2fc0ef532260de36017ee18465c3fe0617f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sat, 15 Jun 2019 11:26:02 +0200 Subject: [PATCH 11/13] Remove deprecated option --- tests/Fixtures/app/AppKernel.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Fixtures/app/AppKernel.php b/tests/Fixtures/app/AppKernel.php index d90f7c3f133..feb981f694c 100644 --- a/tests/Fixtures/app/AppKernel.php +++ b/tests/Fixtures/app/AppKernel.php @@ -127,7 +127,6 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load 'security' => false, ], 'default' => [ - 'logout_on_user_change' => true, 'provider' => 'chain_provider', 'http_basic' => null, 'anonymous' => null, From 22e953c8b8b32651127028ee376088158ddaf5a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sat, 15 Jun 2019 11:51:49 +0200 Subject: [PATCH 12/13] Fix MongoDB --- tests/Fixtures/app/config/config_common.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Fixtures/app/config/config_common.yml b/tests/Fixtures/app/config/config_common.yml index 147ab132550..c922767e2f3 100644 --- a/tests/Fixtures/app/config/config_common.yml +++ b/tests/Fixtures/app/config/config_common.yml @@ -28,6 +28,13 @@ doctrine: auto_generate_proxy_classes: '%kernel.debug%' auto_mapping: true +doctrine_mongodb: + connections: + default: ~ + document_managers: + default: + auto_mapping: true + twig: strict_variables: '%kernel.debug%' From 9f3d6bd3c0aae97bd937f76913ac18bbdbae6070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sun, 16 Jun 2019 08:05:28 +0200 Subject: [PATCH 13/13] Fix rebase --- tests/Fixtures/app/config/config_common.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Fixtures/app/config/config_common.yml b/tests/Fixtures/app/config/config_common.yml index c922767e2f3..147ab132550 100644 --- a/tests/Fixtures/app/config/config_common.yml +++ b/tests/Fixtures/app/config/config_common.yml @@ -28,13 +28,6 @@ doctrine: auto_generate_proxy_classes: '%kernel.debug%' auto_mapping: true -doctrine_mongodb: - connections: - default: ~ - document_managers: - default: - auto_mapping: true - twig: strict_variables: '%kernel.debug%'