From f63b9c07dcd28235029a5c00aaf8cc300e79a2d0 Mon Sep 17 00:00:00 2001 From: Maxence Date: Thu, 30 May 2024 22:21:56 +0200 Subject: [PATCH] init symfony 7 support apply suggested change for Prophecy trait usage update dependencies switch to xml mapping to avoid annotation/attribute retrocompatibility issues add sqlite extension to ci add missing behat test to makefile command set minimum php version requirement to 8.0 bump dependencies to versions supporting php 8.0 use attribute mapping update readme --- .github/workflows/ci.yml | 9 +++-- .gitignore | 1 + Makefile | 2 +- README.md | 5 +++ composer.json | 39 ++++++++++++------- src/Crud/Controller/BaseCrudController.php | 2 +- src/Crud/Controller/Create.php | 2 +- src/Crud/Controller/Delete.php | 2 +- src/Crud/Controller/Get.php | 2 +- src/Crud/Controller/GetAll.php | 2 +- src/Crud/Controller/Update.php | 2 +- src/Crud/Event/CrudEvent.php | 6 --- src/Crud/FilterCollectionInterface.php | 2 - .../Pagination/PaginationRequestFactory.php | 3 -- src/Crud/Persistence/DataStoreInterface.php | 2 +- src/DependencyInjection/Configuration.php | 2 +- src/Doctrine/DoctrineDataStore.php | 2 +- src/EventListener/ExceptionListener.php | 2 +- src/Form/ApiRequestHandler.php | 4 +- src/Form/DomainObjectDataMapperInterface.php | 5 +-- src/Form/DomainObjectsDataMapper.php | 5 +-- src/Form/Type/ApiType.php | 2 +- src/Form/Type/CollectionType.php | 6 --- src/Form/Type/DateTimeType.php | 6 --- src/MelodiiaBundle.php | 3 -- src/MelodiiaConfiguration.php | 3 -- src/Response/Created.php | 2 +- src/Response/OkContent.php | 4 -- src/Serialization/Json/CreatedNormalizer.php | 4 +- src/Serialization/Json/ErrorNormalizer.php | 2 +- .../Json/ExceptionNormalizer.php | 2 +- .../Json/OkContentNormalizer.php | 7 +--- tests/Behat/Context/BasicsContext.php | 4 +- tests/Melodiia/Crud/Controller/CreateTest.php | 2 + tests/Melodiia/Crud/Controller/DeleteTest.php | 2 + tests/Melodiia/Crud/Controller/GetAllTest.php | 27 ++++++------- tests/Melodiia/Crud/Controller/GetTest.php | 3 ++ tests/Melodiia/Crud/Controller/UpdateTest.php | 2 + .../Crud/Event/CustomResponseEventTest.php | 3 ++ .../Crud/FilterCollectionFactoryTest.php | 3 ++ tests/Melodiia/Crud/FilterCollectionTest.php | 3 ++ .../PaginationRequestFactoryTest.php | 21 +++++----- .../Crud/Tools/SimpleIdResolverTest.php | 3 ++ .../Doctrine/DoctrineDataStoreTest.php | 5 ++- .../Controller/SwaggerUiControllerTest.php | 3 ++ tests/Melodiia/Error/OnErrorTest.php | 3 ++ .../EventListener/ExceptionListenerTest.php | 7 +++- tests/Melodiia/Form/ApiRequestHandlerTest.php | 7 +++- tests/Melodiia/Form/ApiTypeTest.php | 2 +- .../Form/DomainObjectsDataMapperTest.php | 12 ++---- ...orderDataToMatchCollectionListenerTest.php | 4 +- tests/Melodiia/MelodiiaConfigurationTest.php | 3 ++ .../Response/FormErrorResponseTest.php | 21 ++-------- .../Listener/SerializeOnKernelViewTest.php | 9 +++-- .../Context/ContextBuilderFactoryTest.php | 3 ++ .../Json/ExceptionNormalizerTest.php | 3 ++ .../Json/OkContentNormalizerTest.php | 3 ++ tests/TestApplication/config/bundles.php | 2 +- tests/TestApplication/config/config.yaml | 25 ++++++++++-- tests/TestApplication/src/Entity/Todo.php | 20 +++------- tests/TestApplication/src/Kernel.php | 4 +- 61 files changed, 185 insertions(+), 166 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5453f0a..6483566 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,11 +37,11 @@ jobs: name: Unit tests strategy: matrix: - php: [ 8.0, 8.1, 8.2 ] + php: [ 8.1, 8.2 ] os: [ ubuntu-latest ] include: - os: [ ubuntu-latest ] - php: 7.4 + php: 8.0 composer-flag: "'--prefer-lowest'" runs-on: ${{ matrix.os }} @@ -72,11 +72,11 @@ jobs: name: Functionnal tests strategy: matrix: - php: [ 8.0, 8.1, 8.2 ] + php: [ 8.1, 8.2 ] os: [ ubuntu-latest ] include: - os: [ ubuntu-latest ] - php: 7.4 + php: 8.0 composer-flag: "'--prefer-lowest'" runs-on: ${{ matrix.os }} @@ -87,6 +87,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} + extensions: sqlite3 - uses: actions/cache@v2 id: cache-composer diff --git a/.gitignore b/.gitignore index ae3a03f..e69d10d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ vendor tests/TestApplication/var .couscous .phpunit.result.cache +.idea diff --git a/Makefile b/Makefile index d5c8f98..a2399b2 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ clean: ## Stop the project and remove generated files # ------- # -test: test.composer test.phpcs test.phpunit ## Run all tests +test: test.composer test.phpcs test.phpunit test.behat ## Run all tests .PHONY: test test.composer: ## Validate composer.json diff --git a/README.md b/README.md index 9f62a6c..ad39c3a 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,11 @@ Features Learn more in the [complete documentation](https://melodiia.swag.industries). +Requirements +------- +Melodiia requires PHP 8.0 or higher. For php 7.4 you can still use this tag +https://github.com/swagindustries/Melodiia/releases/tag/0.10.2 + Install ------- diff --git a/composer.json b/composer.json index 9382b15..a7e6a57 100644 --- a/composer.json +++ b/composer.json @@ -8,30 +8,43 @@ "post-install-cmd": "make hooks.install" }, "require": { - "php": ">=7.3", + "php": ">=8.0", "nekland/tools": "^2.5.1", - "symfony/event-dispatcher": "^5.3 || ^6.0", + "symfony/event-dispatcher": "^5.3 || ^6.0 || 7.0.8", "pagerfanta/pagerfanta": "^2.0.1 || ^3.0.0", - "symfony/yaml": "^5.3 || ^6.0", - "symfony/serializer": "^5.3 || ^6.0", + "symfony/yaml": "^5.3 || ^6.0 || 7.0.8", + "symfony/serializer": "^5.3.12 || ^6.0 || 7.0.8", "pagerfanta/doctrine-orm-adapter": "^3.5" }, "require-dev": { + "roave/security-advisories": "dev-latest", "psr/container": "^v1.1.1 || ^2.0", - "phpunit/phpunit": "^8.5", - "friendsofphp/php-cs-fixer": "^v3.3.2", + "phpunit/phpunit": "^9.6 || ^10.0.0 || ^11.1.3", + "friendsofphp/php-cs-fixer": "3.58.0", "phpspec/prophecy": "^1.8", - "twig/twig": "^2.5", - "symfony/symfony": "^5.3 || ^6.0", - "doctrine/orm": "^v2.6.6", + "twig/twig": "^2.5 || ^3.10", + "doctrine/orm": "^2.6.6 || ^2.17.0", "justinrainbow/json-schema": "^5.2", - "doctrine/annotations": "^1.8", - "doctrine/doctrine-bundle": "^2.1", - "behat/behat": "3.10.0", + "doctrine/doctrine-bundle": "^2.12.0", + "behat/behat": "3.14.0", "friends-of-behat/symfony-extension": "^2.3.0", "fakerphp/faker": "^1.12.1", "monolog/monolog": "^3.4 || ^2.9", - "masterminds/html5": "^2.8" + "masterminds/html5": "^2.8", + "phpspec/prophecy-phpunit": "^2.0.0", + "symfony/dotenv": "^5.3 || ^6.0 || 7.0.8", + "symfony/security-bundle": "^5.4.20 || ^6.2.6 || 7.0.8", + "symfony/twig-bundle": "^5.3 || ^6.0 || 7.0.8", + "symfony/web-profiler-bundle": "^5.3 || ^6.0 || 7.0.8", + "symfony/asset": "^5.3 || ^6.0 || 7.0.8", + "symfony/form": "^5.3 || ^6.0 || 7.0.8", + "symfony/validator": "^5.3 || ^6.0 || 7.0.8", + "symfony/framework-bundle": "^5.3 || ^6.0 || 7.0.8", + "symfony/dependency-injection": "^5.3 || ^6.0 || 7.0.8", + "symfony/config": "^5.3 || ^6.0 || 7.0.8", + "symfony/proxy-manager-bridge": "^5.3 || ^6.4", + "symfony/browser-kit": "^5.3 || ^6.0 || 7.0.8", + "symfony/doctrine-bridge": "^5.3 || ^6.0 || 7.0.8" }, "autoload": { "psr-4": { diff --git a/src/Crud/Controller/BaseCrudController.php b/src/Crud/Controller/BaseCrudController.php index 3513bd9..8f18148 100644 --- a/src/Crud/Controller/BaseCrudController.php +++ b/src/Crud/Controller/BaseCrudController.php @@ -25,7 +25,7 @@ public function __construct(EventDispatcherInterface $eventDispatcher) /** * @return ApiResponse|FormInterface */ - protected function decodeInputData(FormFactoryInterface $formFactory, string $form, Request $request, bool $clearMissing = null, object $data = null) + protected function decodeInputData(FormFactoryInterface $formFactory, string $form, Request $request, ?bool $clearMissing = null, ?object $data = null) { $form = $formFactory->createNamed('', $form, $data, ['clear_missing' => $clearMissing]); $form->handleRequest($request); diff --git a/src/Crud/Controller/Create.php b/src/Crud/Controller/Create.php index f4fd0ab..37b8f5d 100644 --- a/src/Crud/Controller/Create.php +++ b/src/Crud/Controller/Create.php @@ -34,7 +34,7 @@ final class Create extends BaseCrudController /** @var AuthorizationCheckerInterface|null */ private $checker; - public function __construct(DataStoreInterface $dataStore, FormFactoryInterface $formFactory, EventDispatcherInterface $dispatcher, AuthorizationCheckerInterface $checker = null) + public function __construct(DataStoreInterface $dataStore, FormFactoryInterface $formFactory, EventDispatcherInterface $dispatcher, ?AuthorizationCheckerInterface $checker = null) { parent::__construct($dispatcher); $this->dataStore = $dataStore; diff --git a/src/Crud/Controller/Delete.php b/src/Crud/Controller/Delete.php index 179526b..3f813ae 100644 --- a/src/Crud/Controller/Delete.php +++ b/src/Crud/Controller/Delete.php @@ -33,7 +33,7 @@ final class Delete extends BaseCrudController implements CrudControllerInterface /** @var IdResolverInterface */ private $idResolver; - public function __construct(DataStoreInterface $dataStore, EventDispatcherInterface $dispatcher, IdResolverInterface $idResolver = null, AuthorizationCheckerInterface $checker = null) + public function __construct(DataStoreInterface $dataStore, EventDispatcherInterface $dispatcher, ?IdResolverInterface $idResolver = null, ?AuthorizationCheckerInterface $checker = null) { parent::__construct($dispatcher); $this->dataStore = $dataStore; diff --git a/src/Crud/Controller/Get.php b/src/Crud/Controller/Get.php index af9ba42..4f97d3f 100644 --- a/src/Crud/Controller/Get.php +++ b/src/Crud/Controller/Get.php @@ -29,7 +29,7 @@ final class Get implements CrudControllerInterface /** @var IdResolverInterface */ private $idResolver; - public function __construct(DataStoreInterface $dataStore, IdResolverInterface $idResolver = null, AuthorizationCheckerInterface $checker = null) + public function __construct(DataStoreInterface $dataStore, ?IdResolverInterface $idResolver = null, ?AuthorizationCheckerInterface $checker = null) { $this->dataStore = $dataStore; $this->idResolver = $idResolver ?? new SimpleIdResolver(); diff --git a/src/Crud/Controller/GetAll.php b/src/Crud/Controller/GetAll.php index a98bb73..8d7b9de 100644 --- a/src/Crud/Controller/GetAll.php +++ b/src/Crud/Controller/GetAll.php @@ -33,7 +33,7 @@ public function __construct( DataStoreInterface $dataStore, FilterCollectionFactoryInterface $collectionFactory, PaginationRequestFactoryInterface $pagesRequestFactory, - AuthorizationCheckerInterface $checker = null + ?AuthorizationCheckerInterface $checker = null ) { $this->dataStore = $dataStore; $this->checker = $checker; diff --git a/src/Crud/Controller/Update.php b/src/Crud/Controller/Update.php index d803440..6d25c4d 100644 --- a/src/Crud/Controller/Update.php +++ b/src/Crud/Controller/Update.php @@ -41,7 +41,7 @@ final class Update extends BaseCrudController /** @var IdResolverInterface */ private $idResolver; - public function __construct(DataStoreInterface $dataStore, FormFactoryInterface $formFactory, EventDispatcherInterface $dispatcher, IdResolverInterface $idResolver = null, AuthorizationCheckerInterface $checker = null) + public function __construct(DataStoreInterface $dataStore, FormFactoryInterface $formFactory, EventDispatcherInterface $dispatcher, ?IdResolverInterface $idResolver = null, ?AuthorizationCheckerInterface $checker = null) { parent::__construct($dispatcher); $this->dataStore = $dataStore; diff --git a/src/Crud/Event/CrudEvent.php b/src/Crud/Event/CrudEvent.php index 77af330..8eda616 100644 --- a/src/Crud/Event/CrudEvent.php +++ b/src/Crud/Event/CrudEvent.php @@ -8,14 +8,8 @@ class CrudEvent extends Event { - /** - * @var mixed - */ private $data; - /** - * @param mixed $data - */ public function __construct($data) { $this->data = $data; diff --git a/src/Crud/FilterCollectionInterface.php b/src/Crud/FilterCollectionInterface.php index 78343df..65375d8 100644 --- a/src/Crud/FilterCollectionInterface.php +++ b/src/Crud/FilterCollectionInterface.php @@ -16,8 +16,6 @@ public function add(FilterInterface $filter): void; /** * Executes filters against a query. - * - * @param mixed $query */ public function filter($query): void; diff --git a/src/Crud/Pagination/PaginationRequestFactory.php b/src/Crud/Pagination/PaginationRequestFactory.php index 7f89d19..04651d1 100644 --- a/src/Crud/Pagination/PaginationRequestFactory.php +++ b/src/Crud/Pagination/PaginationRequestFactory.php @@ -22,9 +22,6 @@ public function __construct(MelodiiaConfigurationInterface $configuration) $this->configuration = $configuration; } - /** - * {@inheritdoc} - */ public function createPaginationRequest(Request $request): PaginationRequest { $page = $request->query->getInt('page', self::DEFAULT_PAGE); diff --git a/src/Crud/Persistence/DataStoreInterface.php b/src/Crud/Persistence/DataStoreInterface.php index 07780d9..2d19467 100644 --- a/src/Crud/Persistence/DataStoreInterface.php +++ b/src/Crud/Persistence/DataStoreInterface.php @@ -21,5 +21,5 @@ public function find(string $type, $id): ?object; /** * @param int $maxPerPage */ - public function getPaginated(string $type, int $page, FilterCollectionInterface $filters, $maxPerPage = 30): PagerFanta; + public function getPaginated(string $type, int $page, FilterCollectionInterface $filters, $maxPerPage = 30): Pagerfanta; } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 9ad2907..453a9a9 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -10,7 +10,7 @@ class Configuration implements ConfigurationInterface { - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('melodiia'); diff --git a/src/Doctrine/DoctrineDataStore.php b/src/Doctrine/DoctrineDataStore.php index 687fa6b..d2ca20d 100644 --- a/src/Doctrine/DoctrineDataStore.php +++ b/src/Doctrine/DoctrineDataStore.php @@ -34,7 +34,7 @@ public function find(string $type, $id): ?object return $this->getEntityManager()->getRepository($type)->find($id); } - public function getPaginated(string $type, int $page, FilterCollectionInterface $filters, $maxPerPage = 30): PagerFanta + public function getPaginated(string $type, int $page, FilterCollectionInterface $filters, $maxPerPage = 30): Pagerfanta { $doctrineRepository = $this->getEntityManager()->getRepository($type); diff --git a/src/EventListener/ExceptionListener.php b/src/EventListener/ExceptionListener.php index 734d142..0a212d7 100644 --- a/src/EventListener/ExceptionListener.php +++ b/src/EventListener/ExceptionListener.php @@ -21,7 +21,7 @@ public function __construct( MelodiiaConfigurationInterface $config, OnError $controller, bool $debug, - ErrorListener $errorListener = null + ?ErrorListener $errorListener = null ) { $this->errorListener = $errorListener ?? new ErrorListener($controller, null, $debug); $this->config = $config; diff --git a/src/Form/ApiRequestHandler.php b/src/Form/ApiRequestHandler.php index 7fadb14..e197748 100644 --- a/src/Form/ApiRequestHandler.php +++ b/src/Form/ApiRequestHandler.php @@ -13,7 +13,7 @@ class ApiRequestHandler implements RequestHandlerInterface { - public function handleRequest(FormInterface $form, $request = null) + public function handleRequest(FormInterface $form, $request = null): void { if (!$request instanceof Request) { throw new UnexpectedTypeException($request, 'Symfony\Component\HttpFoundation\Request'); @@ -44,8 +44,6 @@ public function handleRequest(FormInterface $form, $request = null) /** * Notice: this impacts allow_file_upload field. - * - * @param mixed $data */ public function isFileUpload($data): bool { diff --git a/src/Form/DomainObjectDataMapperInterface.php b/src/Form/DomainObjectDataMapperInterface.php index 9c7540a..7aeaad3 100644 --- a/src/Form/DomainObjectDataMapperInterface.php +++ b/src/Form/DomainObjectDataMapperInterface.php @@ -8,8 +8,5 @@ interface DomainObjectDataMapperInterface extends DataMapperInterface { - /** - * @return mixed - */ - public function createObject(iterable $form, string $dataClass = null); + public function createObject(iterable $form, ?string $dataClass = null); } diff --git a/src/Form/DomainObjectsDataMapper.php b/src/Form/DomainObjectsDataMapper.php index 19093d9..a2d161f 100644 --- a/src/Form/DomainObjectsDataMapper.php +++ b/src/Form/DomainObjectsDataMapper.php @@ -15,10 +15,7 @@ */ class DomainObjectsDataMapperBase extends DataMapper implements DomainObjectDataMapperInterface { - /** - * {@inheritdoc} - */ - public function createObject(iterable $form, string $dataClass = null) + public function createObject(iterable $form, ?string $dataClass = null) { if (null === $dataClass && $form instanceof FormInterface) { $dataClass = $form->getConfig()->getOption('data_class'); diff --git a/src/Form/Type/ApiType.php b/src/Form/Type/ApiType.php index f2263b6..69ef2c6 100644 --- a/src/Form/Type/ApiType.php +++ b/src/Form/Type/ApiType.php @@ -20,7 +20,7 @@ class ApiType extends AbstractType /** @var DataMapperInterface */ private $dataMapper; - public function __construct(DataMapperInterface $dataMapper = null) + public function __construct(?DataMapperInterface $dataMapper = null) { $this->dataMapper = $dataMapper ?? new DomainObjectsDataMapper(); } diff --git a/src/Form/Type/CollectionType.php b/src/Form/Type/CollectionType.php index 73592bc..f3471df 100644 --- a/src/Form/Type/CollectionType.php +++ b/src/Form/Type/CollectionType.php @@ -13,9 +13,6 @@ class CollectionType extends AbstractType { - /** - * {@inheritdoc} - */ public function buildForm(FormBuilderInterface $builder, array $options) { $resizeListener = new ResizeFormListener( @@ -32,9 +29,6 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->addEventSubscriber($reorderInputDataListener); } - /** - * {@inheritdoc} - */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ diff --git a/src/Form/Type/DateTimeType.php b/src/Form/Type/DateTimeType.php index 48f59b4..b81e460 100644 --- a/src/Form/Type/DateTimeType.php +++ b/src/Form/Type/DateTimeType.php @@ -10,9 +10,6 @@ class DateTimeType extends AbstractType { - /** - * {@inheritdoc} - */ public function configureOptions(OptionsResolver $resolver) { $resolver @@ -24,9 +21,6 @@ public function configureOptions(OptionsResolver $resolver) ; } - /** - * {@inheritdoc} - */ public function getParent() { return OriginalDateTimeType::class; diff --git a/src/MelodiiaBundle.php b/src/MelodiiaBundle.php index 2a85b97..513be40 100644 --- a/src/MelodiiaBundle.php +++ b/src/MelodiiaBundle.php @@ -10,9 +10,6 @@ class MelodiiaBundle extends Bundle { - /** - * {@inheritdoc} - */ public function getContainerExtension(): ?ExtensionInterface { return new MelodiiaExtension(); diff --git a/src/MelodiiaConfiguration.php b/src/MelodiiaConfiguration.php index d25a666..3e1fa87 100644 --- a/src/MelodiiaConfiguration.php +++ b/src/MelodiiaConfiguration.php @@ -21,9 +21,6 @@ public function __construct(array $config) $this->config = $config; } - /** - * {@inheritdoc} - */ public function getApiEndpoints(): array { $endpoints = []; diff --git a/src/Response/Created.php b/src/Response/Created.php index 9a36db4..e98e2c0 100644 --- a/src/Response/Created.php +++ b/src/Response/Created.php @@ -12,7 +12,7 @@ class Created implements ApiResponse /** @var string|null */ private $resourceId; - public function __construct($id, string $resourceId = null) + public function __construct($id, ?string $resourceId = null) { $this->id = $id; $this->resourceId = $resourceId; diff --git a/src/Response/OkContent.php b/src/Response/OkContent.php index 083523e..fdf2a4a 100644 --- a/src/Response/OkContent.php +++ b/src/Response/OkContent.php @@ -10,7 +10,6 @@ class OkContent implements ApiResponse, SerializationContextAwareInterface { use SerializationContextAwareTrait; - /** @var mixed */ private $content; public function __construct($content, $serializationGroups = []) @@ -19,9 +18,6 @@ public function __construct($content, $serializationGroups = []) $this->serializationContext = new SerializationContext($serializationGroups); } - /** - * @return mixed - */ public function getContent() { return $this->content; diff --git a/src/Serialization/Json/CreatedNormalizer.php b/src/Serialization/Json/CreatedNormalizer.php index d29fcd5..4e85b71 100644 --- a/src/Serialization/Json/CreatedNormalizer.php +++ b/src/Serialization/Json/CreatedNormalizer.php @@ -9,7 +9,7 @@ class CreatedNormalizer implements NormalizerInterface { - public function normalize($object, string $format = null, array $context = []): array + public function normalize($object, ?string $format = null, array $context = []): array { $res = []; $resource = $object->getResourceId(); @@ -22,7 +22,7 @@ public function normalize($object, string $format = null, array $context = []): return $res; } - public function supportsNormalization($data, string $format = null): bool + public function supportsNormalization($data, ?string $format = null, array $context = []): bool { return is_object($data) && $data instanceof Created; } diff --git a/src/Serialization/Json/ErrorNormalizer.php b/src/Serialization/Json/ErrorNormalizer.php index 22066db..0c5f21c 100644 --- a/src/Serialization/Json/ErrorNormalizer.php +++ b/src/Serialization/Json/ErrorNormalizer.php @@ -26,7 +26,7 @@ public function normalize($object, $format = null, array $context = []): array return $res; } - public function supportsNormalization($data, $format = null): bool + public function supportsNormalization($data, $format = null, array $context = []): bool { return is_object($data) && $data instanceof AbstractUserDataErrorResponse; } diff --git a/src/Serialization/Json/ExceptionNormalizer.php b/src/Serialization/Json/ExceptionNormalizer.php index 60e4778..04d9041 100644 --- a/src/Serialization/Json/ExceptionNormalizer.php +++ b/src/Serialization/Json/ExceptionNormalizer.php @@ -33,7 +33,7 @@ public function normalize($object, $format = null, array $context = []): array return $data; } - public function supportsNormalization($data, $format = null): bool + public function supportsNormalization($data, $format = null, array $context = []): bool { if (class_exists(FlattenException::class)) { return $data instanceof \Exception || $data instanceof FlattenException; diff --git a/src/Serialization/Json/OkContentNormalizer.php b/src/Serialization/Json/OkContentNormalizer.php index ade9415..d2cf8df 100644 --- a/src/Serialization/Json/OkContentNormalizer.php +++ b/src/Serialization/Json/OkContentNormalizer.php @@ -36,7 +36,7 @@ public function __construct(RequestStack $requestStack) * * @return array|bool|float|int|string */ - public function normalize($object, $format = null, array $context = []) + public function normalize($object, $format = null, array $context = []): float|int|bool|\ArrayObject|array|string|null { $groups = $object->getSerializationContext()->getGroups(); if (!empty($context['groups'])) { @@ -106,10 +106,7 @@ public function normalize($object, $format = null, array $context = []) return $result; } - /** - * {@inheritdoc} - */ - public function supportsNormalization($data, $format = null): bool + public function supportsNormalization($data, $format = null, array $context = []): bool { return is_object($data) && $data instanceof OkContent; } diff --git a/tests/Behat/Context/BasicsContext.php b/tests/Behat/Context/BasicsContext.php index e010c7b..9fe92c9 100644 --- a/tests/Behat/Context/BasicsContext.php +++ b/tests/Behat/Context/BasicsContext.php @@ -12,9 +12,10 @@ class BasicsContext extends AbstractContext { /** * @When I make a GET request on :uri + * * @Given I make a :verb request on :uri with the content: */ - public function iMakeARequestOn($uri, $verb = 'GET', PyStringNode $content = null) + public function iMakeARequestOn($uri, $verb = 'GET', ?PyStringNode $content = null) { $this->request($uri, $verb, (string) $content); } @@ -29,6 +30,7 @@ public function theStatusCodeIs($statusCode) /** * @Then I should retrieve: + * * @Given the last response contains: */ public function iShouldRetrieve(PyStringNode $string) diff --git a/tests/Melodiia/Crud/Controller/CreateTest.php b/tests/Melodiia/Crud/Controller/CreateTest.php index 1cddf50..4d10664 100644 --- a/tests/Melodiia/Crud/Controller/CreateTest.php +++ b/tests/Melodiia/Crud/Controller/CreateTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use SwagIndustries\Melodiia\Crud\Controller\Create; use SwagIndustries\Melodiia\Crud\CrudControllerInterface; @@ -29,6 +30,7 @@ class CreateTest extends TestCase { use MockDispatcherTrait; + use ProphecyTrait; /** @var FormFactoryInterface|ObjectProphecy */ private $formFactory; diff --git a/tests/Melodiia/Crud/Controller/DeleteTest.php b/tests/Melodiia/Crud/Controller/DeleteTest.php index 0bfc148..0a8df6d 100644 --- a/tests/Melodiia/Crud/Controller/DeleteTest.php +++ b/tests/Melodiia/Crud/Controller/DeleteTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Promise\CallbackPromise; use Prophecy\Prophecy\ObjectProphecy; use SwagIndustries\Melodiia\Crud\Controller\Delete; @@ -31,6 +32,7 @@ class DeleteTest extends TestCase { use MockDispatcherTrait; + use ProphecyTrait; /** @var Request|ObjectProphecy */ private $request; diff --git a/tests/Melodiia/Crud/Controller/GetAllTest.php b/tests/Melodiia/Crud/Controller/GetAllTest.php index 0b57af6..bb9d8a6 100644 --- a/tests/Melodiia/Crud/Controller/GetAllTest.php +++ b/tests/Melodiia/Crud/Controller/GetAllTest.php @@ -8,6 +8,7 @@ use Pagerfanta\Pagerfanta; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use SwagIndustries\Melodiia\Crud\Controller\GetAll; use SwagIndustries\Melodiia\Crud\CrudControllerInterface; @@ -20,6 +21,7 @@ use SwagIndustries\Melodiia\Response\OkContent; use SwagIndustries\Melodiia\Test\TestFixtures\FakeMelodiiaModel; use Symfony\Component\Form\FormInterface; +use Symfony\Component\HttpFoundation\InputBag; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; @@ -27,6 +29,8 @@ class GetAllTest extends TestCase { + use ProphecyTrait; + /** @var DataStoreInterface|ObjectProphecy */ private $dataStore; @@ -68,11 +72,9 @@ public function setUp(): void $this->attributes->get(CrudControllerInterface::MAX_PER_PAGE_ATTRIBUTE, 30)->willReturn(30); $this->attributes->getInt(CrudControllerInterface::MAX_PER_PAGE_ALLOWED, 250)->willReturn(30); $this->attributes->getBoolean(CrudControllerInterface::ALLOW_USER_DEFINE_MAX_PAGE, false)->willReturn(false); - $this->queries = $this->prophesize(ParameterBag::class); - $this->queries->getInt('page', Argument::cetera())->willReturn(1); - $this->request = $this->prophesize(Request::class); + $this->request = new Request(); $this->request->attributes = $this->attributes->reveal(); - $this->request->query = $this->queries->reveal(); + $this->request->query = new InputBag(['page' => 1]); $this->form = $this->prophesize(FormInterface::class); $this->form->handleRequest(Argument::any())->willReturn($this->form->reveal()); @@ -87,7 +89,7 @@ public function setUp(): void $this->paginationRequest->getPage()->willReturn(1); $paginationFactory = $this->prophesize(PaginationRequestFactoryInterface::class); - $paginationFactory->createPaginationRequest($this->request->reveal())->willReturn($this->paginationRequest->reveal()); + $paginationFactory->createPaginationRequest($this->request)->willReturn($this->paginationRequest->reveal()); $this->controller = new GetAll( $this->dataStore->reveal(), @@ -106,7 +108,7 @@ public function testItReturnResourceFromDataStoreInsideOkContent() { $this->dataStore->getPaginated(FakeMelodiiaModel::class, 1, $this->filtersCollection->reveal(), 250)->willReturn(new Pagerfanta(new ArrayAdapter([new \stdClass()])))->shouldBeCalled(); - $res = ($this->controller)($this->request->reveal()); + $res = ($this->controller)($this->request); $this->assertInstanceOf(OkContent::class, $res); $this->assertTrue($res->isCollection()); @@ -117,31 +119,30 @@ public function testItStillReturn200OkOnEmptyPaginated() { $this->dataStore->getPaginated(FakeMelodiiaModel::class, 1, $this->filtersCollection->reveal(), 250)->willReturn(new Pagerfanta(new ArrayAdapter([])))->shouldBeCalled(); - $res = ($this->controller)($this->request->reveal()); + $res = ($this->controller)($this->request); $this->assertInstanceOf(OkContent::class, $res); } - public function testItCheckAccessToResourceIfSpecifiedInConfiguration() + public function testItCheckAccessToResourceIfSpecifiedInConfiguration(): void { $this->expectException(AccessDeniedException::class); $this->attributes->get(CrudControllerInterface::SECURITY_CHECK, null)->willReturn('view'); $this->authorizationChecker->isGranted('view', Argument::any())->willReturn(false); - ($this->controller)($this->request->reveal(), 'id'); + ($this->controller)($this->request, 'id'); } - public function testItReturnsErrorFromFilters() + public function testItReturnsErrorFromFilters(): void { - $request = $this->request->reveal(); - $this->form->handleRequest($request)->shouldBeCalled()->willReturn($this->form->reveal()); + $this->form->handleRequest($this->request)->shouldBeCalled()->willReturn($this->form->reveal()); $this->form->isSubmitted()->willReturn(true); $this->form->isValid()->willReturn(false); $this->dataStore->getPaginated(Argument::cetera())->shouldNotBeCalled(); - $res = ($this->controller)($request); + $res = ($this->controller)($this->request); $this->assertInstanceOf(FormErrorResponse::class, $res); } diff --git a/tests/Melodiia/Crud/Controller/GetTest.php b/tests/Melodiia/Crud/Controller/GetTest.php index f93aacd..1e289d9 100644 --- a/tests/Melodiia/Crud/Controller/GetTest.php +++ b/tests/Melodiia/Crud/Controller/GetTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use SwagIndustries\Melodiia\Crud\Controller\Get; use SwagIndustries\Melodiia\Crud\CrudControllerInterface; @@ -21,6 +22,8 @@ class GetTest extends TestCase { + use ProphecyTrait; + /** @var DataStoreInterface|ObjectProphecy */ private $dataStore; diff --git a/tests/Melodiia/Crud/Controller/UpdateTest.php b/tests/Melodiia/Crud/Controller/UpdateTest.php index 181ef97..8b0eaed 100644 --- a/tests/Melodiia/Crud/Controller/UpdateTest.php +++ b/tests/Melodiia/Crud/Controller/UpdateTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use SwagIndustries\Melodiia\Crud\Controller\Update; use SwagIndustries\Melodiia\Crud\CrudControllerInterface; @@ -30,6 +31,7 @@ class UpdateTest extends TestCase { use MockDispatcherTrait; + use ProphecyTrait; /** @var FormFactoryInterface|ObjectProphecy */ private $formFactory; diff --git a/tests/Melodiia/Crud/Event/CustomResponseEventTest.php b/tests/Melodiia/Crud/Event/CustomResponseEventTest.php index b64b190..b89d619 100644 --- a/tests/Melodiia/Crud/Event/CustomResponseEventTest.php +++ b/tests/Melodiia/Crud/Event/CustomResponseEventTest.php @@ -5,12 +5,15 @@ namespace SwagIndustries\Melodiia\Test\Crud\Event; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use SwagIndustries\Melodiia\Crud\Event\CrudEvent; use SwagIndustries\Melodiia\Crud\Event\CustomResponseEvent; use SwagIndustries\Melodiia\Response\ApiResponse; class CustomResponseEventTest extends TestCase { + use ProphecyTrait; + public function testItImplementsCrudEvent() { $event = new CustomResponseEvent(new \stdClass()); diff --git a/tests/Melodiia/Crud/FilterCollectionFactoryTest.php b/tests/Melodiia/Crud/FilterCollectionFactoryTest.php index a790d5e..92832b8 100644 --- a/tests/Melodiia/Crud/FilterCollectionFactoryTest.php +++ b/tests/Melodiia/Crud/FilterCollectionFactoryTest.php @@ -5,6 +5,7 @@ namespace SwagIndustries\Melodiia\Test\Crud\Controller; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use SwagIndustries\Melodiia\Crud\FilterCollection; use SwagIndustries\Melodiia\Crud\FilterCollectionFactory; @@ -16,6 +17,8 @@ class FilterCollectionFactoryTest extends TestCase { + use ProphecyTrait; + /** @var FormFactoryInterface|ObjectProphecy */ private $formFactory; diff --git a/tests/Melodiia/Crud/FilterCollectionTest.php b/tests/Melodiia/Crud/FilterCollectionTest.php index a853f7b..efa5118 100644 --- a/tests/Melodiia/Crud/FilterCollectionTest.php +++ b/tests/Melodiia/Crud/FilterCollectionTest.php @@ -7,6 +7,7 @@ use Doctrine\ORM\QueryBuilder; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use SwagIndustries\Melodiia\Crud\FilterCollection; use SwagIndustries\Melodiia\Crud\FilterInterface; @@ -17,6 +18,8 @@ class FilterCollectionTest extends TestCase { + use ProphecyTrait; + /** @var FormFactoryInterface|ObjectProphecy */ private $formFactory; diff --git a/tests/Melodiia/Crud/Pagination/PaginationRequestFactoryTest.php b/tests/Melodiia/Crud/Pagination/PaginationRequestFactoryTest.php index a0558d5..b183fef 100644 --- a/tests/Melodiia/Crud/Pagination/PaginationRequestFactoryTest.php +++ b/tests/Melodiia/Crud/Pagination/PaginationRequestFactoryTest.php @@ -5,24 +5,24 @@ namespace SwagIndustries\Melodiia\Crud\Pagination; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use SwagIndustries\Melodiia\Crud\CrudControllerInterface; use SwagIndustries\Melodiia\MelodiiaConfigurationInterface; +use Symfony\Component\HttpFoundation\InputBag; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; class PaginationRequestFactoryTest extends TestCase { + use ProphecyTrait; + /** @var MelodiiaConfigurationInterface|ObjectProphecy */ private $configuration; /** @var Request|ObjectProphecy */ private $request; - /** @var ParameterBag */ - private $queryBag; - /** @var ParameterBag */ private $attributesBag; @@ -33,25 +33,22 @@ protected function setUp(): void { $this->configuration = $this->prophesize(MelodiiaConfigurationInterface::class); $this->request = $this->prophesize(Request::class); - $this->queryBag = $this->prophesize(ParameterBag::class); $this->attributesBag = $this->prophesize(ParameterBag::class); $this->attributesBag->getInt(CrudControllerInterface::MAX_PER_PAGE_ATTRIBUTE, PaginationRequestFactory::DEFAULT_ITEMS_PER_PAGE)->willReturn(PaginationRequestFactory::DEFAULT_ITEMS_PER_PAGE); $this->attributesBag->get(PaginationRequestFactory::DEFAULT_MAX_PER_PAGE_ATTRIBUTE, PaginationRequestFactory::DEFAULT_MAX_PER_PAGE_ATTRIBUTE)->willReturn(PaginationRequestFactory::DEFAULT_MAX_PER_PAGE_ATTRIBUTE); $this->attributesBag->getInt(CrudControllerInterface::MAX_PER_PAGE_ALLOWED, 250)->willReturn(30); $this->attributesBag->getBoolean(CrudControllerInterface::ALLOW_USER_DEFINE_MAX_PAGE, false)->willReturn(false); - $this->queryBag->getInt('page', Argument::any())->willReturn(1); $this->request->attributes = $this->attributesBag->reveal(); - $this->request->query = $this->queryBag->reveal(); + $this->request->query = new InputBag(['page' => 1]); $this->subject = new PaginationRequestFactory($this->configuration->reveal()); } public function testItDoesNotAllowUserToAskForALimitIfNotConfigured() { $this->attributesBag->getBoolean(CrudControllerInterface::ALLOW_USER_DEFINE_MAX_PAGE, false)->willReturn(false); - $this->queryBag->getInt('page', PaginationRequestFactory::DEFAULT_PAGE)->willReturn(PaginationRequestFactory::DEFAULT_PAGE); - $this->queryBag->getInt('max_per_page', 0)->shouldNotBeCalled(); + $this->request->query = new InputBag(['page' => 1]); $this->configuration->getApiConfigFor($this->request->reveal())->willReturn($this->configApi())->shouldBeCalled(); @@ -61,7 +58,7 @@ public function testItDoesNotAllowUserToAskForALimitIfNotConfigured() public function testItDoAllowUserToAskForALimitIfConfigured() { $this->attributesBag->getBoolean(CrudControllerInterface::ALLOW_USER_DEFINE_MAX_PAGE, false)->willReturn(true); - $this->queryBag->getInt(PaginationRequestFactory::DEFAULT_MAX_PER_PAGE_ATTRIBUTE, 0)->willReturn(15)->shouldBeCalled(); + $this->request->query = new InputBag([PaginationRequestFactory::DEFAULT_MAX_PER_PAGE_ATTRIBUTE => 15]); $paginationRequest = $this->subject->createPaginationRequest($this->request->reveal()); $this->assertEquals(1, $paginationRequest->getPage()); @@ -72,7 +69,7 @@ public function testThatNoUserRequestCanSurpassTheConfiguredLimitPerPage() { $this->attributesBag->getBoolean(CrudControllerInterface::ALLOW_USER_DEFINE_MAX_PAGE, false)->willReturn(true); $this->attributesBag->getInt(CrudControllerInterface::MAX_PER_PAGE_ALLOWED, 250)->willReturn(555); - $this->queryBag->getInt(PaginationRequestFactory::DEFAULT_MAX_PER_PAGE_ATTRIBUTE, 0)->willReturn(666 * 666 * 666)->shouldBeCalled(); + $this->request->query = new InputBag([PaginationRequestFactory::DEFAULT_MAX_PER_PAGE_ATTRIBUTE => 666 * 666 * 666]); $paginationRequest = $this->subject->createPaginationRequest($this->request->reveal()); $this->assertEquals(1, $paginationRequest->getPage()); @@ -86,7 +83,7 @@ public function testItRetrieveLimitPerPageAtSpecifiedLocationInAttributes() $this->configuration->getApiConfigFor($this->request->reveal())->willReturn($config); $this->attributesBag->getBoolean(CrudControllerInterface::ALLOW_USER_DEFINE_MAX_PAGE, false)->willReturn(true); $this->attributesBag->getInt(CrudControllerInterface::MAX_PER_PAGE_ALLOWED, 250)->willReturn(555); - $this->queryBag->getInt('size', 0)->willReturn(12)->shouldBeCalled(); + $this->request->query = new InputBag(['size' => 12]); $paginationRequest = $this->subject->createPaginationRequest($this->request->reveal()); $this->assertEquals(1, $paginationRequest->getPage()); diff --git a/tests/Melodiia/Crud/Tools/SimpleIdResolverTest.php b/tests/Melodiia/Crud/Tools/SimpleIdResolverTest.php index 279a753..0515332 100644 --- a/tests/Melodiia/Crud/Tools/SimpleIdResolverTest.php +++ b/tests/Melodiia/Crud/Tools/SimpleIdResolverTest.php @@ -5,6 +5,7 @@ namespace SwagIndustries\Melodiia\Test\Crud\Tools; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use SwagIndustries\Melodiia\Crud\Tools\IdResolverInterface; use SwagIndustries\Melodiia\Crud\Tools\SimpleIdResolver; use SwagIndustries\Melodiia\Exception\IdMissingException; @@ -13,6 +14,8 @@ class SimpleIdResolverTest extends TestCase { + use ProphecyTrait; + private $subject; protected function setUp(): void diff --git a/tests/Melodiia/Doctrine/DoctrineDataStoreTest.php b/tests/Melodiia/Doctrine/DoctrineDataStoreTest.php index b524cdc..77db857 100644 --- a/tests/Melodiia/Doctrine/DoctrineDataStoreTest.php +++ b/tests/Melodiia/Doctrine/DoctrineDataStoreTest.php @@ -11,13 +11,16 @@ use Pagerfanta\Pagerfanta; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use SwagIndustries\Melodiia\Crud\FilterCollection; use SwagIndustries\Melodiia\Crud\Persistence\DataStoreInterface; use SwagIndustries\Melodiia\Doctrine\DoctrineDataStore; class DoctrineDataStoreTest extends TestCase { - public function testItIsAMelodiiaDataStore() + use ProphecyTrait; + + public function testItIsAMelodiiaDataStore(): void { $datastore = new DoctrineDataStore($this->prophesize(ManagerRegistry::class)->reveal()); diff --git a/tests/Melodiia/Documentation/Controller/SwaggerUiControllerTest.php b/tests/Melodiia/Documentation/Controller/SwaggerUiControllerTest.php index 26aa7c4..b573a55 100644 --- a/tests/Melodiia/Documentation/Controller/SwaggerUiControllerTest.php +++ b/tests/Melodiia/Documentation/Controller/SwaggerUiControllerTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use SwagIndustries\Melodiia\Documentation\Controller\SwaggerUiController; use SwagIndustries\Melodiia\MelodiiaConfiguration; @@ -17,6 +18,8 @@ class SwaggerUiControllerTest extends TestCase { + use ProphecyTrait; + /** @var SwaggerUiController */ private $controller; diff --git a/tests/Melodiia/Error/OnErrorTest.php b/tests/Melodiia/Error/OnErrorTest.php index dc6c135..5830dac 100644 --- a/tests/Melodiia/Error/OnErrorTest.php +++ b/tests/Melodiia/Error/OnErrorTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use SwagIndustries\Melodiia\Error\OnError; use SwagIndustries\Melodiia\Exception\MelodiiaRuntimeException; @@ -16,6 +17,8 @@ class OnErrorTest extends TestCase { + use ProphecyTrait; + /** @var SerializerInterface|ObjectProphecy */ private $serializer; diff --git a/tests/Melodiia/EventListener/ExceptionListenerTest.php b/tests/Melodiia/EventListener/ExceptionListenerTest.php index 5bfdef2..a839696 100644 --- a/tests/Melodiia/EventListener/ExceptionListenerTest.php +++ b/tests/Melodiia/EventListener/ExceptionListenerTest.php @@ -5,6 +5,7 @@ namespace SwagIndustries\Melodiia\Test\EventListener; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use SwagIndustries\Melodiia\Error\OnError; use SwagIndustries\Melodiia\EventListener\ExceptionListener; @@ -17,6 +18,8 @@ class ExceptionListenerTest extends TestCase { + use ProphecyTrait; + public function testItDoesNothingIfNotMelodiiaRoute() { /** @var Request|ObjectProphecy $request */ @@ -72,12 +75,12 @@ public function __construct() parent::__construct(''); } - public function onKernelException($event) + public function onKernelException($event): void { $this->isCalled = true; } - public function hasBeenCalled() + public function hasBeenCalled(): bool { return $this->isCalled; } diff --git a/tests/Melodiia/Form/ApiRequestHandlerTest.php b/tests/Melodiia/Form/ApiRequestHandlerTest.php index 15e0028..2575ef8 100644 --- a/tests/Melodiia/Form/ApiRequestHandlerTest.php +++ b/tests/Melodiia/Form/ApiRequestHandlerTest.php @@ -6,16 +6,19 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use SwagIndustries\Melodiia\Form\ApiRequestHandler; use SwagIndustries\Melodiia\Form\Type\ApiType; use Symfony\Component\Form\FormConfigInterface; use Symfony\Component\Form\FormError; use Symfony\Component\Form\FormInterface; -use Symfony\Component\HttpFoundation\ParameterBag; +use Symfony\Component\HttpFoundation\InputBag; use Symfony\Component\HttpFoundation\Request; class ApiRequestHandlerTest extends TestCase { + use ProphecyTrait; + /** @var ApiRequestHandler */ private $subject; @@ -85,7 +88,7 @@ public function testICanChangeClearMissingOption() public function testItSupportsGetRequests() { - $query = new ParameterBag(['hello' => 'foo']); + $query = new InputBag(['hello' => 'foo']); $this->form->submit(['hello' => 'foo'])->willReturn($this->form->reveal())->shouldBeCalled(); $this->request->getMethod()->willReturn('GET'); $this->request->query = $query; diff --git a/tests/Melodiia/Form/ApiTypeTest.php b/tests/Melodiia/Form/ApiTypeTest.php index e0f71d9..b3ac33f 100644 --- a/tests/Melodiia/Form/ApiTypeTest.php +++ b/tests/Melodiia/Form/ApiTypeTest.php @@ -42,7 +42,7 @@ public function testItSupportsCustomDataMapper() $customDataMapper = new class() extends DomainObjectsDataMapper { private $hasBeenCalled = false; - public function createObject(iterable $form, string $dataClass = null) + public function createObject(iterable $form, ?string $dataClass = null) { $this->hasBeenCalled = true; diff --git a/tests/Melodiia/Form/DomainObjectsDataMapperTest.php b/tests/Melodiia/Form/DomainObjectsDataMapperTest.php index 2d11e47..d64d8b2 100644 --- a/tests/Melodiia/Form/DomainObjectsDataMapperTest.php +++ b/tests/Melodiia/Form/DomainObjectsDataMapperTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use SwagIndustries\Melodiia\Form\DomainObjectsDataMapper; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Form\DataMapperInterface; @@ -15,6 +16,8 @@ class DomainObjectsDataMapperTest extends TestCase { + use ProphecyTrait; + public function testItIsInstanceOfDataMapper() { $this->assertInstanceOf(DataMapperInterface::class, new DomainObjectsDataMapper()); @@ -48,9 +51,6 @@ class FakeValueObject /** * FakeValueObject constructor. - * - * @param $hello - * @param $foo */ public function __construct($hello, $foo) { @@ -58,17 +58,11 @@ public function __construct($hello, $foo) $this->foo = $foo; } - /** - * @return mixed - */ public function getHello() { return $this->hello; } - /** - * @return mixed - */ public function getFoo() { return $this->foo; diff --git a/tests/Melodiia/Form/Listener/ReorderDataToMatchCollectionListenerTest.php b/tests/Melodiia/Form/Listener/ReorderDataToMatchCollectionListenerTest.php index b094843..f4e4aa9 100644 --- a/tests/Melodiia/Form/Listener/ReorderDataToMatchCollectionListenerTest.php +++ b/tests/Melodiia/Form/Listener/ReorderDataToMatchCollectionListenerTest.php @@ -4,6 +4,7 @@ namespace SwagIndustries\Melodiia\Test\Form\Listener; +use Prophecy\PhpUnit\ProphecyTrait; use SwagIndustries\Melodiia\Crud\MelodiiaModel; use SwagIndustries\Melodiia\Form\Listener\ReorderDataToMatchCollectionListener; use Symfony\Component\EventDispatcher\EventDispatcher; @@ -19,6 +20,8 @@ class ReorderDataToMatchCollectionListenerTest extends FormIntegrationTestCase { + use ProphecyTrait; + private $subject; protected function setUp(): void @@ -31,7 +34,6 @@ protected function setUp(): void protected function tearDown(): void { parent::tearDown(); - $this->factory = null; $this->subject = null; } diff --git a/tests/Melodiia/MelodiiaConfigurationTest.php b/tests/Melodiia/MelodiiaConfigurationTest.php index 39c4c1e..67deae9 100644 --- a/tests/Melodiia/MelodiiaConfigurationTest.php +++ b/tests/Melodiia/MelodiiaConfigurationTest.php @@ -5,6 +5,7 @@ namespace SwagIndustries\Melodiia\Test; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use SwagIndustries\Melodiia\MelodiiaConfiguration; use SwagIndustries\Melodiia\MelodiiaConfigurationInterface; use Symfony\Component\HttpFoundation\Request; @@ -12,6 +13,8 @@ class MelodiiaConfigurationTest extends TestCase { + use ProphecyTrait; + /** @var RouterInterface */ private $router; diff --git a/tests/Melodiia/Response/FormErrorResponseTest.php b/tests/Melodiia/Response/FormErrorResponseTest.php index 4a3a270..155c79f 100644 --- a/tests/Melodiia/Response/FormErrorResponseTest.php +++ b/tests/Melodiia/Response/FormErrorResponseTest.php @@ -211,18 +211,12 @@ class DummyData /** @var OtherDummy */ private $bar; - /** - * @return string - */ public function getFoo(): ?string { return $this->foo; } - /** - * @param string $foo - */ - public function setFoo(string $foo = null): void + public function setFoo(?string $foo = null): void { $this->foo = $foo; } @@ -235,10 +229,7 @@ public function getBar(): ?OtherDummy return $this->bar; } - /** - * @param OtherDummy $bar - */ - public function setBar(OtherDummy $bar = null): void + public function setBar(?OtherDummy $bar = null): void { $this->bar = $bar; } @@ -249,18 +240,12 @@ class OtherDummy /** @var string */ private $baz; - /** - * @return string - */ public function getBaz(): ?string { return $this->baz; } - /** - * @param string $baz - */ - public function setBaz(string $baz = null): void + public function setBaz(?string $baz = null): void { $this->baz = $baz; } diff --git a/tests/Melodiia/Response/Listener/SerializeOnKernelViewTest.php b/tests/Melodiia/Response/Listener/SerializeOnKernelViewTest.php index 6c445c6..472902a 100644 --- a/tests/Melodiia/Response/Listener/SerializeOnKernelViewTest.php +++ b/tests/Melodiia/Response/Listener/SerializeOnKernelViewTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use SwagIndustries\Melodiia\Response\ApiResponse; use SwagIndustries\Melodiia\Response\Listener\SerializeOnKernelView; @@ -21,6 +22,8 @@ class SerializeOnKernelViewTest extends TestCase { + use ProphecyTrait; + /** @var SerializerInterface|ObjectProphecy */ private $serializer; @@ -72,7 +75,7 @@ public function testItTransformApiResponse() $event = new ViewEvent( $this->prophesize(HttpKernelInterface::class)->reveal(), $this->prophesize(Request::class)->reveal(), - HttpKernelInterface::MASTER_REQUEST, + HttpKernelInterface::MAIN_REQUEST, $this->dummyResponse ); @@ -87,7 +90,7 @@ public function testItDoesNotTransformSymfonyResponse() $event = new ViewEvent( $this->prophesize(HttpKernelInterface::class)->reveal(), $this->prophesize(Request::class)->reveal(), - HttpKernelInterface::MASTER_REQUEST, + HttpKernelInterface::MAIN_REQUEST, $response ); $this->listener->onKernelView($event); @@ -100,7 +103,7 @@ public function testItSendsTheRightContentType() $event = new ViewEvent( $this->prophesize(HttpKernelInterface::class)->reveal(), $this->prophesize(Request::class)->reveal(), - HttpKernelInterface::MASTER_REQUEST, + HttpKernelInterface::MAIN_REQUEST, $this->dummyResponse ); diff --git a/tests/Melodiia/Serialization/Context/ContextBuilderFactoryTest.php b/tests/Melodiia/Serialization/Context/ContextBuilderFactoryTest.php index 2d6942f..397eb88 100644 --- a/tests/Melodiia/Serialization/Context/ContextBuilderFactoryTest.php +++ b/tests/Melodiia/Serialization/Context/ContextBuilderFactoryTest.php @@ -5,12 +5,15 @@ namespace Melodiia\Serialization\Context; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use SwagIndustries\Melodiia\Response\ApiResponse; use SwagIndustries\Melodiia\Serialization\Context\ContextBuilderChain; use SwagIndustries\Melodiia\Serialization\Context\ContextBuilderInterface; class ContextBuilderFactoryTest extends TestCase { + use ProphecyTrait; + public function testItBuildContextUsingGivenBuilders() { $builder1 = new class() implements ContextBuilderInterface { diff --git a/tests/Melodiia/Serialization/Json/ExceptionNormalizerTest.php b/tests/Melodiia/Serialization/Json/ExceptionNormalizerTest.php index 3722ebf..74fef6e 100644 --- a/tests/Melodiia/Serialization/Json/ExceptionNormalizerTest.php +++ b/tests/Melodiia/Serialization/Json/ExceptionNormalizerTest.php @@ -5,12 +5,15 @@ namespace SwagIndustries\Melodiia\Test\Serialization\Json; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use SwagIndustries\Melodiia\Serialization\Json\ExceptionNormalizer; use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException; use Symfony\Component\ErrorHandler\Exception\FlattenException; class ExceptionNormalizerTest extends TestCase { + use ProphecyTrait; + public function testItSupportsExceptionAndFlattenException() { $normalizer = new ExceptionNormalizer(); diff --git a/tests/Melodiia/Serialization/Json/OkContentNormalizerTest.php b/tests/Melodiia/Serialization/Json/OkContentNormalizerTest.php index 4cb161e..91d714a 100644 --- a/tests/Melodiia/Serialization/Json/OkContentNormalizerTest.php +++ b/tests/Melodiia/Serialization/Json/OkContentNormalizerTest.php @@ -8,6 +8,7 @@ use Pagerfanta\Pagerfanta; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use SwagIndustries\Melodiia\Response\Model\Collection; use SwagIndustries\Melodiia\Response\OkContent; @@ -19,6 +20,8 @@ class OkContentNormalizerTest extends TestCase { + use ProphecyTrait; + /** @var NormalizerInterface|ObjectProphecy */ private $mainNormalizer; diff --git a/tests/TestApplication/config/bundles.php b/tests/TestApplication/config/bundles.php index a4ea923..8d32667 100644 --- a/tests/TestApplication/config/bundles.php +++ b/tests/TestApplication/config/bundles.php @@ -9,5 +9,5 @@ Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true], FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true], - \SwagIndustries\Melodiia\MelodiiaBundle::class => ['all' => true], + SwagIndustries\Melodiia\MelodiiaBundle::class => ['all' => true], ]; diff --git a/tests/TestApplication/config/config.yaml b/tests/TestApplication/config/config.yaml index ee9a120..6581c29 100644 --- a/tests/TestApplication/config/config.yaml +++ b/tests/TestApplication/config/config.yaml @@ -7,13 +7,28 @@ parameters: framework: serializer: ~ form: ~ - test: ~ - annotations: ~ + test: true assets: ~ +security: + providers: + in_memory: + memory: ~ + + firewalls: + dev: + pattern: ^/(_(profiler|wdt)|css|images|js)/ + security: false + + test: + pattern: ^/ + security: false + doctrine: dbal: url: '%env(resolve:DATABASE_URL)%' + driver: 'pdo_sqlite' + charset: UTF8 # IMPORTANT: You MUST configure your server version, # either here or in the DATABASE_URL env var (see .env file) @@ -25,7 +40,6 @@ doctrine: mappings: TestApplication: is_bundle: false - type: annotation dir: '%kernel.project_dir%/src/Entity' prefix: 'TestApplication\Entity' alias: App @@ -43,3 +57,8 @@ services: TestApplication\Filters\TodoContainFilter: autoconfigure: true + + test.client: + class: Symfony\Bundle\FrameworkBundle\KernelBrowser + arguments: ['@kernel'] + public: true diff --git a/tests/TestApplication/src/Entity/Todo.php b/tests/TestApplication/src/Entity/Todo.php index 0465efe..6a8b682 100644 --- a/tests/TestApplication/src/Entity/Todo.php +++ b/tests/TestApplication/src/Entity/Todo.php @@ -7,26 +7,18 @@ use Doctrine\ORM\Mapping as ORM; use SwagIndustries\Melodiia\Crud\MelodiiaModel; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class Todo implements MelodiiaModel { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] private $id; - /** - * @ORM\Column(type="text") - */ + #[ORM\Column(type: 'text')] private $content; - /** - * @ORM\Column(type="datetime_immutable") - */ + #[ORM\Column(type: 'datetime_immutable')] private $publishDate; public function getId(): ?int diff --git a/tests/TestApplication/src/Kernel.php b/tests/TestApplication/src/Kernel.php index 711f032..358b47d 100644 --- a/tests/TestApplication/src/Kernel.php +++ b/tests/TestApplication/src/Kernel.php @@ -15,8 +15,8 @@ class Kernel extends BaseKernel protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void { -// $container->import('../config/config.yaml'); -// $container->import('../config/melodiia.yaml'); + // $container->import('../config/config.yaml'); + // $container->import('../config/melodiia.yaml'); $loader->load(__DIR__ . '/../config/config.yaml'); $loader->load(__DIR__ . '/../config/melodiia.yaml'); }