diff --git a/.gitignore b/.gitignore index 27210ae..fcd145e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ composer.lock bin/ var/ !bin/update-constraints-to-lowest.php + +.phpunit.result.cache diff --git a/CHANGELOG.md b/CHANGELOG.md index 081cd95..e134d17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.7.0] +### Added +- Support for Symfony 6.4 + +### Changed +- Fixed code style +- Fixed tests + ## [1.6.0] ### Added - Allow library to work with various version of `paysera/lib-object-wrapper` from `0.1.0` diff --git a/composer.json b/composer.json index fd5b2b6..402e4ca 100644 --- a/composer.json +++ b/composer.json @@ -17,23 +17,24 @@ "require": { "php": "^7.1 || ^8.0", "ext-json": "*", - "symfony/framework-bundle": "^3.4.34|^4.3|^5.4", - "symfony/security-bundle": "^3.4.34|^4.3|^5.4", - "symfony/validator": "^3.4.34|^4.3|^5.4", + "symfony/framework-bundle": "^3.4.34|^4.3|^5.4|^6.0", + "symfony/security-bundle": "^3.4.34|^4.3|^5.4|^6.0", + "symfony/validator": "^3.4.34|^4.3|^5.4|^6.0", "paysera/lib-normalization-bundle": "^1.1.0", "paysera/lib-normalization": "^1.2", "paysera/lib-object-wrapper": "~0.1", "paysera/lib-pagination": "^1.0", "paysera/lib-dependency-injection": "^1.3.0", "psr/log": "^1.0|^2.0", - "doctrine/persistence": "^1.3.8 || ^2.0.1" + "doctrine/persistence": "^1.3.8 || ^2.0.1 || ^3.0", + "doctrine/annotations": "^v1.14" }, "require-dev": { - "phpunit/phpunit": "^6.5 || ^9.0", - "mockery/mockery": "^1.2.4", - "symfony/yaml": "^3.4.34|^4.3|^5.4", - "doctrine/doctrine-bundle": "^1.4|^2.0", - "doctrine/orm": "^2.5.14|^2.6" + "phpunit/phpunit": "^7.5 || ^9.5", + "mockery/mockery": "^1.3.6", + "symfony/yaml": "^3.4.34|^4.3|^5.4|^6.0", + "doctrine/doctrine-bundle": "^1.12.0|^2.1", + "doctrine/orm": "^2.5.14" }, "config": { "bin-dir": "bin" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index bde7395..ec7f0ef 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,16 +1,10 @@ - - + diff --git a/src/DependencyInjection/PayseraApiExtension.php b/src/DependencyInjection/PayseraApiExtension.php index 1eee814..d157b41 100644 --- a/src/DependencyInjection/PayseraApiExtension.php +++ b/src/DependencyInjection/PayseraApiExtension.php @@ -6,6 +6,7 @@ use Doctrine\Persistence\ObjectRepository; use Paysera\Bundle\ApiBundle\Service\PathAttributeResolver\DoctrinePathAttributeResolver; use RuntimeException; +use Symfony\Bundle\FrameworkBundle\Routing\AttributeRouteControllerLoader; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Definition; @@ -23,6 +24,13 @@ public function load(array $configs, ContainerBuilder $container) $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.xml'); + $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config/services')); + if (class_exists(AttributeRouteControllerLoader::class)) { + $loader->load('annotations.xml'); + } else { + $loader->load('annotations_legacy.xml'); + } + $container->setParameter('paysera_api.locales', $config['locales']); if (count($config['locales']) === 0) { $container->removeDefinition('paysera_api.listener.locale'); diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index bb957b9..d282980 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -5,7 +5,6 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - diff --git a/src/Resources/config/services/annotations.xml b/src/Resources/config/services/annotations.xml index 06531f1..bfd252d 100644 --- a/src/Resources/config/services/annotations.xml +++ b/src/Resources/config/services/annotations.xml @@ -5,9 +5,9 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - diff --git a/src/Resources/config/services/annotations_legacy.xml b/src/Resources/config/services/annotations_legacy.xml new file mode 100644 index 0000000..06531f1 --- /dev/null +++ b/src/Resources/config/services/annotations_legacy.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + diff --git a/tests/Functional/Fixtures/FixtureTestBundle/DependencyInjection/PayseraFixtureTestExtension.php b/tests/Functional/Fixtures/FixtureTestBundle/DependencyInjection/PayseraFixtureTestExtension.php index f1e4612..0fd5676 100644 --- a/tests/Functional/Fixtures/FixtureTestBundle/DependencyInjection/PayseraFixtureTestExtension.php +++ b/tests/Functional/Fixtures/FixtureTestBundle/DependencyInjection/PayseraFixtureTestExtension.php @@ -7,6 +7,7 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\Loader; +use Symfony\Component\HttpKernel\Kernel; /** * This is the class that loads and manages your bundle configuration. @@ -24,7 +25,8 @@ public function load(array $configs, ContainerBuilder $container) $config = $this->processConfiguration($configuration, $configs); $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); - $loader->load('services.xml'); + $prefix = Kernel::MAJOR_VERSION <= 4 ? 'legacy_' : ''; + $loader->load($prefix . 'services.xml'); } } diff --git a/tests/Functional/Fixtures/FixtureTestBundle/Resources/config/legacy_routing.xml b/tests/Functional/Fixtures/FixtureTestBundle/Resources/config/legacy_routing.xml new file mode 100644 index 0000000..60c538f --- /dev/null +++ b/tests/Functional/Fixtures/FixtureTestBundle/Resources/config/legacy_routing.xml @@ -0,0 +1,43 @@ + + + + + + + + PayseraFixtureTestBundle:Default:action1 + + + PayseraFixtureTestBundle:Default:action1b + + + Paysera\Bundle\ApiBundle\Tests\Functional\Fixtures\FixtureTestBundle\Controller\DefaultController::action2 + + + paysera_fixture_test.controller.default_controller:action3 + + + paysera_fixture_test.controller.default_controller:action4 + + + Paysera\Bundle\ApiBundle\Tests\Functional\Fixtures\FixtureTestBundle\Controller\DefaultController::action5 + + + + paysera_fixture_test.controller.default_controller:action + + + paysera_fixture_test.controller.default_controller:actionWithReturn + + + paysera_fixture_test.controller.default_controller:action + + + paysera_fixture_test.controller.default_controller:actionWithMultipleParameters + + + paysera_fixture_test.controller.default_controller:actionWithMultipleParameters + + diff --git a/tests/Functional/Fixtures/FixtureTestBundle/Resources/config/legacy_services.xml b/tests/Functional/Fixtures/FixtureTestBundle/Resources/config/legacy_services.xml new file mode 100644 index 0000000..33b3915 --- /dev/null +++ b/tests/Functional/Fixtures/FixtureTestBundle/Resources/config/legacy_services.xml @@ -0,0 +1,102 @@ + + + + + + + + + + parameter + + + + parameter_custom + + + + key + + + + key_custom + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + extract:parameter + + + parameter + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/Functional/Fixtures/FixtureTestBundle/Resources/config/routing.xml b/tests/Functional/Fixtures/FixtureTestBundle/Resources/config/routing.xml index fbd3eae..705905f 100644 --- a/tests/Functional/Fixtures/FixtureTestBundle/Resources/config/routing.xml +++ b/tests/Functional/Fixtures/FixtureTestBundle/Resources/config/routing.xml @@ -1,43 +1,51 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - PayseraFixtureTestBundle:Default:action1 + Paysera\Bundle\ApiBundle\Tests\Functional\Fixtures\FixtureTestBundle\Controller\DefaultController::action1Action - PayseraFixtureTestBundle:Default:action1b + + Paysera\Bundle\ApiBundle\Tests\Functional\Fixtures\FixtureTestBundle\Controller\DefaultController::action1bAction + - Paysera\Bundle\ApiBundle\Tests\Functional\Fixtures\FixtureTestBundle\Controller\DefaultController::action2 + + Paysera\Bundle\ApiBundle\Tests\Functional\Fixtures\FixtureTestBundle\Controller\DefaultController::action2 + - paysera_fixture_test.controller.default_controller:action3 + paysera_fixture_test.controller.default_controller::action3 - paysera_fixture_test.controller.default_controller:action4 + paysera_fixture_test.controller.default_controller::action4 - Paysera\Bundle\ApiBundle\Tests\Functional\Fixtures\FixtureTestBundle\Controller\DefaultController::action5 + + Paysera\Bundle\ApiBundle\Tests\Functional\Fixtures\FixtureTestBundle\Controller\DefaultController::action5 + - paysera_fixture_test.controller.default_controller:action + paysera_fixture_test.controller.default_controller::action - paysera_fixture_test.controller.default_controller:actionWithReturn + paysera_fixture_test.controller.default_controller::actionWithReturn - paysera_fixture_test.controller.default_controller:action + + Paysera\Bundle\ApiBundle\Tests\Functional\Fixtures\FixtureTestBundle\Controller\DefaultController::action + - paysera_fixture_test.controller.default_controller:actionWithMultipleParameters + paysera_fixture_test.controller.default_controller::actionWithMultipleParameters - paysera_fixture_test.controller.default_controller:actionWithMultipleParameters + paysera_fixture_test.controller.default_controller::actionWithMultipleParameters diff --git a/tests/Functional/Fixtures/FixtureTestBundle/Resources/config/services.xml b/tests/Functional/Fixtures/FixtureTestBundle/Resources/config/services.xml index a31e7de..b4ada44 100644 --- a/tests/Functional/Fixtures/FixtureTestBundle/Resources/config/services.xml +++ b/tests/Functional/Fixtures/FixtureTestBundle/Resources/config/services.xml @@ -57,10 +57,10 @@ controller="Paysera\Bundle\ApiBundle\Tests\Functional\Fixtures\FixtureTestBundle\Controller\DefaultController::action1bAction"/> - + - + diff --git a/tests/Functional/Fixtures/TestKernel.php b/tests/Functional/Fixtures/TestKernel.php index a793fb4..28ae475 100644 --- a/tests/Functional/Fixtures/TestKernel.php +++ b/tests/Functional/Fixtures/TestKernel.php @@ -24,7 +24,7 @@ public function __construct($testCase, $commonFile = 'common.yml') $this->commonFile = $commonFile; } - public function registerBundles() + public function registerBundles(): array { return [ new FrameworkBundle(), diff --git a/tests/Functional/Fixtures/config/common.yml b/tests/Functional/Fixtures/config/common.yml index 86a4ce7..6ebbeab 100644 --- a/tests/Functional/Fixtures/config/common.yml +++ b/tests/Functional/Fixtures/config/common.yml @@ -1,10 +1,11 @@ framework: secret: 'secret' router: - resource: '%kernel.root_dir%/config/routing.yml' + resource: '%kernel.project_dir%/tests/Functional/Fixtures/config/routing.yml' validation: ~ security: + enable_authenticator_manager: true providers: in_memory: memory: @@ -16,12 +17,15 @@ security: password: pass roles: ['ROLE_USER', 'ROLE_ADMIN'] firewalls: + config: + pattern: ^/(config)/ + security: false main: - anonymous: true http_basic: ~ stateless: true - encoders: - Symfony\Component\Security\Core\User\User: plaintext + password_hashers: + Symfony\Component\Security\Core\User\InMemoryUser: + algorithm: plaintext doctrine: orm: @@ -33,7 +37,7 @@ doctrine: services: logger: - class: Symfony\Component\Debug\BufferingLogger + class: Symfony\Component\ErrorHandler\BufferingLogger public: true rest_registry: alias: paysera_api.rest_request_options_registry diff --git a/tests/Functional/Fixtures/config/legacy_common.yml b/tests/Functional/Fixtures/config/legacy_common.yml new file mode 100644 index 0000000..e684ada --- /dev/null +++ b/tests/Functional/Fixtures/config/legacy_common.yml @@ -0,0 +1,46 @@ +framework: + secret: 'secret' + router: + resource: '%kernel.root_dir%/config/legacy_routing.yml' + validation: ~ + +security: + providers: + in_memory: + memory: + users: + user: + password: pass + roles: 'ROLE_USER' + admin: + password: pass + roles: ['ROLE_USER', 'ROLE_ADMIN'] + firewalls: + main: + anonymous: true + http_basic: ~ + stateless: true + encoders: + Symfony\Component\Security\Core\User\User: plaintext + +doctrine: + orm: + auto_mapping: true + dbal: + driver: pdo_sqlite + memory: true + charset: UTF8 + +services: + logger: + class: Symfony\Component\Debug\BufferingLogger + public: true + rest_registry: + alias: paysera_api.rest_request_options_registry + public: true + +paysera_api: + path_attribute_resolvers: + Paysera\Bundle\ApiBundle\Tests\Functional\Fixtures\FixtureTestBundle\Entity\PersistedEntity: + field: someField + Paysera\Bundle\ApiBundle\Tests\Functional\Fixtures\FixtureTestBundle\Entity\SimplePersistedEntity: ~ diff --git a/tests/Functional/Fixtures/config/legacy_routing.yml b/tests/Functional/Fixtures/config/legacy_routing.yml new file mode 100644 index 0000000..0df4919 --- /dev/null +++ b/tests/Functional/Fixtures/config/legacy_routing.yml @@ -0,0 +1,3 @@ +paysera_fixture_test: + resource: "@PayseraFixtureTestBundle/Resources/config/legacy_routing.xml" + prefix: / diff --git a/tests/Functional/FunctionalRestBundleTest.php b/tests/Functional/FunctionalRestBundleTest.php index 86bfe27..c5ab1d3 100644 --- a/tests/Functional/FunctionalRestBundleTest.php +++ b/tests/Functional/FunctionalRestBundleTest.php @@ -47,7 +47,7 @@ public function restRequestsConfigurationProvider() new Response('default'), $this->createRequest('GET', '/config/by-full-controller?parameter=works'), ], - 'config works by full class name when using bundle notation routing (Bundle:Controller:action)' => [ + 'config works by full class name' => [ new Response('works'), $this->createRequest('GET', '/config/by-full-controller-and-class-name?parameter=works'), ], diff --git a/tests/Functional/FunctionalTestCase.php b/tests/Functional/FunctionalTestCase.php index d11436f..199f425 100644 --- a/tests/Functional/FunctionalTestCase.php +++ b/tests/Functional/FunctionalTestCase.php @@ -9,6 +9,8 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ResettableContainerInterface; +use Symfony\Component\HttpKernel\Kernel; +use Symfony\Contracts\Service\ResetInterface; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -28,7 +30,8 @@ abstract class FunctionalTestCase extends TestCase */ protected function setUpContainer($testCase, $commonFile = 'common.yml') { - $this->kernel = new TestKernel($testCase, $commonFile); + $prefix = Kernel::MAJOR_VERSION <= 4 ? 'legacy_' : ''; + $this->kernel = new TestKernel($testCase, $prefix . $commonFile); $this->kernel->boot(); return $this->kernel->getContainer(); } @@ -37,7 +40,7 @@ protected function tearDown(): void { $container = $this->kernel->getContainer(); $this->kernel->shutdown(); - if ($container instanceof ResettableContainerInterface) { + if ($container instanceof ResettableContainerInterface || $container instanceof ResetInterface) { $container->reset(); } diff --git a/tests/Unit/Helper/HttpKernelHelper.php b/tests/Unit/Helper/HttpKernelHelper.php new file mode 100644 index 0000000..67a50b0 --- /dev/null +++ b/tests/Unit/Helper/HttpKernelHelper.php @@ -0,0 +1,19 @@ +shouldReceive('isRestRequest')->with($request)->andReturn($rest); if (class_exists('Symfony\Component\HttpKernel\Event\RequestEvent')) { - $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($kernel, $request, HttpKernelHelper::getMainRequestConstValue()); } else { - $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); + $event = new GetResponseEvent($kernel, $request, HttpKernelHelper::getMainRequestConstValue()); } $listener->onKernelRequest($event); diff --git a/tests/Unit/Listener/RestExceptionListenerTest.php b/tests/Unit/Listener/RestExceptionListenerTest.php index 1c5b20d..3bdc879 100644 --- a/tests/Unit/Listener/RestExceptionListenerTest.php +++ b/tests/Unit/Listener/RestExceptionListenerTest.php @@ -11,6 +11,7 @@ use Paysera\Bundle\ApiBundle\Service\ErrorBuilderInterface; use Paysera\Bundle\ApiBundle\Service\ResponseBuilder; use Paysera\Bundle\ApiBundle\Service\RestRequestHelper; +use Paysera\Bundle\ApiBundle\Tests\Unit\Helper\HttpKernelHelper; use Paysera\Component\Normalization\CoreNormalizer; use Psr\Log\LoggerInterface; use Symfony\Component\HttpFoundation\Request; @@ -51,14 +52,14 @@ public function testOnKernelException(bool $restRequest, int $statusCode = 400, $event = new ExceptionEvent( $kernel, $request, - HttpKernelInterface::MASTER_REQUEST, + HttpKernelHelper::getMainRequestConstValue(), $exception ); } else { $event = new GetResponseForExceptionEvent( $kernel, $request, - HttpKernelInterface::MASTER_REQUEST, + HttpKernelHelper::getMainRequestConstValue(), $exception ); } diff --git a/tests/Unit/Service/ResponseBuilderTest.php b/tests/Unit/Service/ResponseBuilderTest.php index 74c9be0..1f6a4b3 100644 --- a/tests/Unit/Service/ResponseBuilderTest.php +++ b/tests/Unit/Service/ResponseBuilderTest.php @@ -44,6 +44,7 @@ public function testBuildResponseWithJsonSerializable() $this->expectException(RuntimeException::class); $this->expectExceptionMessage('expected'); $builder->buildResponse(new class() implements JsonSerializable { + #[\ReturnTypeWillChange] public function jsonSerialize() { throw new RuntimeException('expected'); diff --git a/tests/Unit/Service/Validation/EntityValidatorTest.php b/tests/Unit/Service/Validation/EntityValidatorTest.php index 55ed763..6f53884 100644 --- a/tests/Unit/Service/Validation/EntityValidatorTest.php +++ b/tests/Unit/Service/Validation/EntityValidatorTest.php @@ -67,6 +67,7 @@ public function testValidate($expectedException, ValidationOptions $validationOp if ($expectedException !== null) { $this->fail('Expected exception'); } + $this->expectNotToPerformAssertions(); } catch (ApiException $exception) { $this->assertEquals($expectedException, $exception); }