diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1bc4074..4a2bfff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,6 @@ on: ["push", "pull_request"] env: COMPOSER_ALLOW_SUPERUSER: '1' - SYMFONY_PHPUNIT_VERSION: 9.5 SYMFONY_DEPRECATIONS_HELPER: max[self]=0 jobs: @@ -12,37 +11,33 @@ jobs: name: Analyze runs-on: ubuntu-latest container: - image: php:7.4-alpine + image: php:8.3-alpine options: >- --tmpfs /tmp:exec --tmpfs /var/tmp:exec steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install Composer run: wget -qO - https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --quiet - name: Get Composer Cache Directory id: composer-cache run: | - echo "::set-output name=dir::$(composer config cache-files-dir)" - - uses: actions/cache@v2 + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + - uses: actions/cache@v3 with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + key: ${{ runner.os }}-composer-8.3-highest-${{ hashFiles('**/composer.json') }} restore-keys: | - ${{ runner.os }}-composer- + ${{ runner.os }}-composer-8.3-highest - name: Validate Composer run: composer validate - - name: Install xsl PHP extension - run: | - apk add $PHPIZE_DEPS libxslt-dev - docker-php-ext-install xsl - name: Install highest dependencies with Composer run: composer update --no-progress --no-suggest --ansi - name: Disable PHP memory limit run: echo 'memory_limit=-1' >> /usr/local/etc/php/php.ini - - name: Analyze - run: vendor/bin/phpqa --execution no-parallel --progress-delay=-1 --ansi + - name: Run CS-Fixer + run: vendor/bin/php-cs-fixer fix --dry-run --diff --format=checkstyle phpunit: name: PHPUnit (PHP ${{ matrix.php }} Deps ${{ matrix.dependencies }}) @@ -55,44 +50,35 @@ jobs: strategy: matrix: php: - - '7.3' - - '7.4' - - '8.0' - '8.1' + - '8.2' + - '8.3' dependencies: + - 'lowest' - 'highest' include: - - php: '7.2' - dependencies: 'lowest' - phpunit-version: 8.5 - - php: '7.3' - phpunit-version: 9.5 - - php: '7.4' - phpunit-version: 9.5 - - php: '8.0' - phpunit-version: 9.5 - php: '8.1' - phpunit-version: 9.5 + phpunit-version: 10 + - php: '8.2' + phpunit-version: 10 + - php: '8.3' + phpunit-version: 10 fail-fast: false steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install Composer run: wget -qO - https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --quiet - name: Get Composer Cache Directory id: composer-cache run: | - echo "::set-output name=dir::$(composer config cache-files-dir)" - - uses: actions/cache@v2 + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + - uses: actions/cache@v3 with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.dependencies }}-${{ hashFiles('**/composer.json') }} restore-keys: | - ${{ runner.os }}-composer- - - name: Install xsl PHP extension - run: | - apk add $PHPIZE_DEPS libxslt-dev - docker-php-ext-install xsl + ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.dependencies }} - name: Install lowest dependencies with Composer if: matrix.dependencies == 'lowest' run: composer update --no-progress --no-suggest --prefer-stable --prefer-lowest --ansi @@ -101,20 +87,20 @@ jobs: run: composer update --no-progress --no-suggest --ansi - name: Run tests with PHPUnit env: - SYMFONY_PHPUNIT_VERSION: ${{ matrix.phpunit-version }} + SYMFONY_MAX_PHPUNIT_VERSION: ${{ matrix.phpunit-version }} run: vendor/bin/simple-phpunit --colors=always coverage: - name: Coverage (PHP ${{ matrix.php }}) + name: Coverage (PHP 8.3) runs-on: ubuntu-latest container: - image: php:7.4-alpine + image: php:8.3-alpine options: >- --tmpfs /tmp:exec --tmpfs /var/tmp:exec steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install pcov PHP extension run: | apk add $PHPIZE_DEPS @@ -125,22 +111,18 @@ jobs: - name: Get Composer Cache Directory id: composer-cache run: | - echo "::set-output name=dir::$(composer config cache-files-dir)" - - uses: actions/cache@v2 + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + - uses: actions/cache@v3 with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + key: ${{ runner.os }}-composer-8.3-highest-${{ hashFiles('**/composer.json') }} restore-keys: | - ${{ runner.os }}-composer- - - name: Install xsl PHP extension - run: | - apk add $PHPIZE_DEPS libxslt-dev - docker-php-ext-install xsl + ${{ runner.os }}-composer-8.3-highest - name: Install highest dependencies with Composer run: composer update --no-progress --no-suggest --ansi - name: Run coverage with PHPUnit run: vendor/bin/simple-phpunit --coverage-clover ./coverage.xml --colors=always - name: Send code coverage report to Codecov.io - uses: codecov/codecov-action@v1.0.3 # 1.0.4+ uncompatible alpine :/ + uses: codecov/codecov-action@v3 with: token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index fbe9694..7b8eb43 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -9,33 +9,43 @@ file that was distributed with this source code. HEADER; + +$finder = (new PhpCsFixer\Finder()) + ->in(['src', 'tests']) +; + return (new PhpCsFixer\Config()) ->setRiskyAllowed(true) + ->registerCustomFixers(new PhpCsFixerCustomFixers\Fixers()) ->setRules([ - '@DoctrineAnnotation' => true, - '@PHP70Migration' => true, - '@PHP70Migration:risky' => true, - '@PHP71Migration' => true, - '@PHP71Migration:risky' => true, - '@PHP73Migration' => true, - '@PHPUnit75Migration:risky' => true, + '@PHP82Migration' => true, '@PhpCsFixer' => true, '@PhpCsFixer:risky' => true, - '@Symfony' => true, - '@Symfony:risky' => true, - 'array_syntax' => ['syntax' => 'short'], - 'date_time_immutable' => true, - 'header_comment' => ['header' => $header], - 'general_phpdoc_annotation_remove' => true, + + // From https://github.com/symfony/demo/blob/main/.php-cs-fixer.dist.php 'linebreak_after_opening_tag' => true, - 'list_syntax' => ['syntax' => 'short'], - 'no_superfluous_phpdoc_tags' => true, + // 'mb_str_functions' => true, + 'no_php4_constructor' => true, + 'no_unreachable_default_argument_value' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, 'php_unit_strict' => false, + 'php_unit_internal_class' => false, 'php_unit_test_class_requires_covers' => false, + 'phpdoc_order' => true, + 'strict_comparison' => true, + 'strict_param' => true, + 'trailing_comma_in_multiline' => ['after_heredoc' => true, 'elements' => ['arrays', 'parameters']], + 'statement_indentation' => true, + 'method_chaining_indentation' => true, + 'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline', 'attribute_placement' => 'ignore'], + + PhpCsFixerCustomFixers\Fixer\ConstructorEmptyBracesFixer::name() => true, + PhpCsFixerCustomFixers\Fixer\MultilineCommentOpeningClosingAloneFixer::name() => true, + PhpCsFixerCustomFixers\Fixer\MultilinePromotedPropertiesFixer::name() => true, + PhpCsFixerCustomFixers\Fixer\NoDuplicatedImportsFixer::name() => true, + PhpCsFixerCustomFixers\Fixer\NoImportFromGlobalNamespaceFixer::name() => true, + PhpCsFixerCustomFixers\Fixer\PhpdocSingleLineVarFixer::name() => true, ]) - ->setFinder( - (new PhpCsFixer\Finder()) - ->exclude(['vendor']) - ->in(['src', 'tests']) - ) + ->setFinder($finder) ; diff --git a/.phpqa.yml b/.phpqa.yml deleted file mode 100644 index 77c34e6..0000000 --- a/.phpqa.yml +++ /dev/null @@ -1,15 +0,0 @@ -phpqa: - tools: - - php-cs-fixer:0 - - phpunit:0 - - psalm - output: cli - -phpunit: - binary: ./vendor/bin/simple-phpunit - -php-cs-fixer: - config: .php-cs-fixer.dist.php - -psalm: - config: psalm.xml diff --git a/composer.json b/composer.json index d4b916b..be58dc4 100644 --- a/composer.json +++ b/composer.json @@ -16,23 +16,24 @@ } ], "require": { - "php": ">=7.2.5", - "symfony/config": "^3.4.30|^4.3|^5.0|^6.0", - "symfony/dependency-injection": "^3.4.30|^4.3|^5.0|^6.0", - "symfony/doctrine-bridge": "^3.4.30|^4.3|^5.0|^6.0", - "symfony/form": "^3.4.30|^4.3|^5.0|^6.0", - "symfony/http-kernel": "^3.4.30|^4.3|^5.0|^6.0", - "doctrine/persistence": "^1.3|^2.0|^3.0" + "php": "^8.1", + "doctrine/persistence": "^1.3|^2.0|^3.0", + "symfony/config": "^5.4.30|^6.3.10|^7.0", + "symfony/dependency-injection": "^5.4.30|^6.3.10|^7.0", + "symfony/doctrine-bridge": "^5.4.30|^6.3.10|^7.0", + "symfony/form": "^5.4.30|^6.3.10|^7.0", + "symfony/http-kernel": "^5.4.30|^6.3.10|^7.0" }, "require-dev": { - "doctrine/orm": "^2.7", - "edgedesign/phpqa": "^1.25", - "friendsofphp/php-cs-fixer": "^3.4.0", - "phpstan/phpstan": "^1.2.0", - "symfony/cache": "^5.4", - "symfony/phpunit-bridge": "^6.0", - "symfony/validator": "^3.4.30|^4.3|^5.0|^6.0", - "vimeo/psalm": "^4.15" + "doctrine/orm": "^2.15", + "friendsofphp/php-cs-fixer": "^3.45", + "kubawerlos/php-cs-fixer-custom-fixers": "^3.18", + "phpstan/phpstan": "^1.10", + "rector/rector": "^0.18", + "symfony/cache": "^5.4.30|^6.3.10|^7.0", + "symfony/phpunit-bridge": "^5.4.30|^6.3.10|^7.0", + "symfony/validator": "^5.4.30|^6.3.10|^7.0", + "vimeo/psalm": "^5.18" }, "suggest": { "a2lix/translation-form-bundle": "For translation form" @@ -45,7 +46,7 @@ "psalm" ], "phpunit": [ - "SYMFONY_PHPUNIT_VERSION=9.5 SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT=1 simple-phpunit" + "SYMFONY_DEPRECATIONS_HELPER=max[self]=0 simple-phpunit" ] }, "config": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 56957f8..b1de987 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,14 +2,13 @@ - diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..e6244a4 --- /dev/null +++ b/rector.php @@ -0,0 +1,37 @@ +parallel(); + $rectorConfig->paths([ + __DIR__.'/src', + __DIR__.'/tests', + ]); + $rectorConfig->importNames(); + $rectorConfig->importShortClasses(false); + + $rectorConfig->phpVersion(PhpVersion::PHP_82); + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_82, + + DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES, + // DoctrineSetList::DOCTRINE_CODE_QUALITY, + DoctrineSetList::DOCTRINE_ORM_214, + DoctrineSetList::DOCTRINE_DBAL_30, + + PHPUnitLevelSetList::UP_TO_PHPUNIT_91, + // PHPUnitSetList::PHPUNIT_CODE_QUALITY, + // PHPUnitSetList::PHPUNIT_YIELD_DATA_PROVIDER, + ]); +}; diff --git a/src/A2lixAutoFormBundle.php b/src/A2lixAutoFormBundle.php index f444206..9a1c442 100644 --- a/src/A2lixAutoFormBundle.php +++ b/src/A2lixAutoFormBundle.php @@ -15,6 +15,4 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; -class A2lixAutoFormBundle extends Bundle -{ -} +class A2lixAutoFormBundle extends Bundle {} diff --git a/src/DependencyInjection/A2lixAutoFormExtension.php b/src/DependencyInjection/A2lixAutoFormExtension.php index 56b552b..4dddffd 100644 --- a/src/DependencyInjection/A2lixAutoFormExtension.php +++ b/src/DependencyInjection/A2lixAutoFormExtension.php @@ -16,7 +16,7 @@ use Symfony\Component\Config\Definition\Processor; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Loader; +use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\HttpKernel\DependencyInjection\Extension; class A2lixAutoFormExtension extends Extension @@ -26,7 +26,7 @@ public function load(array $configs, ContainerBuilder $container): void $processor = new Processor(); $config = $processor->processConfiguration(new Configuration(), $configs); - $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('a2lix_form.xml'); $loader->load('object_info.xml'); diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 2f058a3..ef33d2d 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -29,9 +29,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->defaultValue(['id', 'locale', 'translatable']) ->beforeNormalization() ->ifString() - ->then(function ($v) { - return preg_split('/\s*,\s*/', $v); - }) + ->then(static fn ($v) => preg_split('/\s*,\s*/', (string) $v)) ->end() ->prototype('scalar') ->info('Global list of fields to exclude from form generation. (Default: id, locale, translatable)')->end() diff --git a/src/Form/EventListener/AutoFormListener.php b/src/Form/EventListener/AutoFormListener.php index db2f4cd..9ca6134 100644 --- a/src/Form/EventListener/AutoFormListener.php +++ b/src/Form/EventListener/AutoFormListener.php @@ -20,13 +20,9 @@ class AutoFormListener implements EventSubscriberInterface { - /** @var FormManipulatorInterface */ - private $formManipulator; - - public function __construct(FormManipulatorInterface $formManipulator) - { - $this->formManipulator = $formManipulator; - } + public function __construct( + private readonly FormManipulatorInterface $formManipulator, + ) {} public static function getSubscribedEvents(): array { diff --git a/src/Form/Manipulator/DoctrineORMManipulator.php b/src/Form/Manipulator/DoctrineORMManipulator.php index 2554fd8..0fb0dc2 100644 --- a/src/Form/Manipulator/DoctrineORMManipulator.php +++ b/src/Form/Manipulator/DoctrineORMManipulator.php @@ -18,16 +18,10 @@ class DoctrineORMManipulator implements FormManipulatorInterface { - /** @var DoctrineORMInfo */ - private $doctrineORMInfo; - /** @var array */ - private $globalExcludedFields; - - public function __construct(DoctrineORMInfo $doctrineORMInfo, array $globalExcludedFields = []) - { - $this->doctrineORMInfo = $doctrineORMInfo; - $this->globalExcludedFields = $globalExcludedFields; - } + public function __construct( + private readonly DoctrineORMInfo $doctrineORMInfo, + private readonly array $globalExcludedFields = [], + ) {} public function getFieldsConfig(FormInterface $form): array { @@ -71,17 +65,18 @@ private function getDataClass(FormInterface $form): string { // Simple case, data_class from current form (with ORM Proxy management) if (null !== $dataClass = $form->getConfig()->getDataClass()) { - if (false === $pos = strrpos($dataClass, '\\__CG__\\')) { + if (false === $pos = strrpos((string) $dataClass, '\\__CG__\\')) { return $dataClass; } - return substr($dataClass, $pos + 8); + return substr((string) $dataClass, $pos + 8); } // Advanced case, loop parent form to get closest fill data_class while (null !== $formParent = $form->getParent()) { if (null === $dataClass = $formParent->getConfig()->getDataClass()) { $form = $formParent; + continue; } diff --git a/src/Form/Type/AutoFormType.php b/src/Form/Type/AutoFormType.php index e48a0f6..c565f95 100644 --- a/src/Form/Type/AutoFormType.php +++ b/src/Form/Type/AutoFormType.php @@ -21,13 +21,9 @@ class AutoFormType extends AbstractType { - /** @var AutoFormListener */ - private $autoFormListener; - - public function __construct(AutoFormListener $autoFormListener) - { - $this->autoFormListener = $autoFormListener; - } + public function __construct( + private readonly AutoFormListener $autoFormListener, + ) {} public function buildForm(FormBuilderInterface $builder, array $options): void { @@ -41,7 +37,7 @@ public function configureOptions(OptionsResolver $resolver): void 'excluded_fields' => [], ]); - $resolver->setNormalizer('data_class', function (Options $options, $value): string { + $resolver->setNormalizer('data_class', static function (Options $options, $value): string { if (empty($value)) { throw new \RuntimeException('Missing "data_class" option of "AutoFormType".'); } diff --git a/src/ObjectInfo/DoctrineORMInfo.php b/src/ObjectInfo/DoctrineORMInfo.php index 331da50..cb24946 100644 --- a/src/ObjectInfo/DoctrineORMInfo.php +++ b/src/ObjectInfo/DoctrineORMInfo.php @@ -20,13 +20,9 @@ class DoctrineORMInfo { - /** @var ClassMetadataFactory */ - private $classMetadataFactory; - - public function __construct(ClassMetadataFactory $classMetadataFactory) - { - $this->classMetadataFactory = $classMetadataFactory; - } + public function __construct( + private readonly ClassMetadataFactory $classMetadataFactory, + ) {} public function getFieldsConfig(string $class): array { @@ -65,6 +61,7 @@ private function getAssocsConfig(ClassMetadata $metadata, array $assocNames): ar if (isset($associationMapping['inversedBy'])) { $assocsConfigs[$assocName] = []; + continue; } diff --git a/tests/Fixtures/Entity/Media.php b/tests/Fixtures/Entity/Media.php index 361bf13..5b70b99 100644 --- a/tests/Fixtures/Entity/Media.php +++ b/tests/Fixtures/Entity/Media.php @@ -15,32 +15,22 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class Media { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue(strategy="AUTO") - */ - protected $id; - - /** - * @ORM\ManyToOne(targetEntity="Product", inversedBy="medias") - */ - protected $product; - - /** - * @ORM\Column(nullable=true) - */ - protected $url; - - /** - * @ORM\Column(nullable=true) - */ - protected $description; + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue(strategy: 'AUTO')] + private ?int $id = null; + + #[ORM\ManyToOne(targetEntity: Product::class, inversedBy: 'medias')] + private Product $product; + + #[ORM\Column(nullable: true)] + private ?string $url = null; + + #[ORM\Column(nullable: true)] + private ?string $description = null; public function getId(): ?int { diff --git a/tests/Fixtures/Entity/Product.php b/tests/Fixtures/Entity/Product.php index 49a39b9..898dcdb 100644 --- a/tests/Fixtures/Entity/Product.php +++ b/tests/Fixtures/Entity/Product.php @@ -17,42 +17,28 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class Product { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue(strategy="AUTO") - */ - protected $id; - - /** - * @ORM\Column(nullable=true) - */ - protected $title; - - /** - * @ORM\Column(type="text", nullable=true) - */ - protected $description; - - /** - * @ORM\Column(nullable=true) - */ - protected $url; - - /** - * @ORM\ManyToOne(targetEntity="Media") - */ - protected $mainMedia; - - /** - * @ORM\OneToMany(targetEntity="Media", mappedBy="product", cascade={"all"}, orphanRemoval=true) - */ - protected $medias; + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue(strategy: 'AUTO')] + private ?int $id = null; + + #[ORM\Column(nullable: true)] + private ?string $title = null; + + #[ORM\Column(type: 'text', nullable: true)] + private ?string $description = null; + + #[ORM\Column(nullable: true)] + private ?string $url = null; + + #[ORM\ManyToOne(targetEntity: Media::class)] + private Media $mainMedia; + + #[ORM\OneToMany(targetEntity: Media::class, mappedBy: 'product', cascade: ['all'], orphanRemoval: true)] + private ArrayCollection $medias; public function __construct() { diff --git a/tests/Form/Type/AutoFormTypeAdvancedTest.php b/tests/Form/Type/AutoFormTypeAdvancedTest.php index 12acad8..2685e59 100755 --- a/tests/Form/Type/AutoFormTypeAdvancedTest.php +++ b/tests/Form/Type/AutoFormTypeAdvancedTest.php @@ -81,9 +81,9 @@ public function testCreationFormWithOverriddenFieldsLabel(): Product ]; $form->submit($formData); - static::assertTrue($form->isSynchronized()); - static::assertEquals($product, $form->getData()); - static::assertEquals('URL/URI', $form->get('url')->getConfig()->getOptions()['label']); + self::assertTrue($form->isSynchronized()); + self::assertEquals($product, $form->getData()); + self::assertEquals('URL/URI', $form->get('url')->getConfig()->getOptions()['label']); return $product; } @@ -132,9 +132,9 @@ public function testCreationFormWithOverriddenFieldsMappedFalse(): Product ]; $form->submit($formData); - static::assertTrue($form->isSynchronized()); - static::assertEquals($product, $form->getData()); - static::assertEquals('blue', $form->get('color')->getData()); + self::assertTrue($form->isSynchronized()); + self::assertEquals($product, $form->getData()); + self::assertEquals('blue', $form->get('color')->getData()); return $product; } diff --git a/tests/Form/Type/AutoFormTypeSimpleTest.php b/tests/Form/Type/AutoFormTypeSimpleTest.php index 8714133..2d9767b 100755 --- a/tests/Form/Type/AutoFormTypeSimpleTest.php +++ b/tests/Form/Type/AutoFormTypeSimpleTest.php @@ -32,11 +32,11 @@ public function testEmptyForm(): void ->getForm() ; - static::assertEquals(['create', 'title', 'description', 'url', 'mainMedia', 'medias'], array_keys($form->all()), 'Fields should matches Product fields'); + self::assertEquals(['create', 'title', 'description', 'url', 'mainMedia', 'medias'], array_keys($form->all()), 'Fields should matches Product fields'); $mediasFormOptions = $form->get('medias')->getConfig()->getOptions(); - static::assertEquals(AutoFormType::class, $mediasFormOptions['entry_type'], 'Media type should be an AutoType'); - static::assertEquals(Media::class, $mediasFormOptions['entry_options']['data_class'], 'Media should have its right data_class'); + self::assertEquals(AutoFormType::class, $mediasFormOptions['entry_type'], 'Media type should be an AutoType'); + self::assertEquals(Media::class, $mediasFormOptions['entry_options']['data_class'], 'Media should have its right data_class'); } public function testCreationForm(): Product @@ -76,8 +76,8 @@ public function testCreationForm(): Product ]; $form->submit($formData); - static::assertTrue($form->isSynchronized()); - static::assertEquals($product, $form->getData()); + self::assertTrue($form->isSynchronized()); + self::assertEquals($product, $form->getData()); return $product; } @@ -110,14 +110,14 @@ public function testEditionForm(Product $product): void ; $form->submit($formData); - static::assertTrue($form->isSynchronized()); - static::assertEquals($product, $form->getData()); + self::assertTrue($form->isSynchronized()); + self::assertEquals($product, $form->getData()); $view = $form->createView(); $children = $view->children; foreach (array_keys($formData) as $key) { - static::assertArrayHasKey($key, $children); + self::assertArrayHasKey($key, $children); } } diff --git a/tests/Form/TypeTestCase.php b/tests/Form/TypeTestCase.php index b178938..f83e385 100755 --- a/tests/Form/TypeTestCase.php +++ b/tests/Form/TypeTestCase.php @@ -17,8 +17,9 @@ use A2lix\AutoFormBundle\Form\Manipulator\DoctrineORMManipulator; use A2lix\AutoFormBundle\Form\Type\AutoFormType; use A2lix\AutoFormBundle\ObjectInfo\DoctrineORMInfo; +use Doctrine\DBAL\DriverManager; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Tools\Setup; +use Doctrine\ORM\ORMSetup; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Form\Extension\Validator\Type\FormTypeValidatorExtension; use Symfony\Component\Form\Extension\Validator\ValidatorTypeGuesser; @@ -30,7 +31,7 @@ abstract class TypeTestCase extends BaseTypeTestCase { - protected $doctrineORMManipulator; + protected ?DoctrineORMManipulator $doctrineORMManipulator = null; protected function setUp(): void { @@ -45,9 +46,7 @@ protected function setUp(): void new FormTypeValidatorExtension($validator) ) ->addTypeGuesser( - $this->getMockBuilder(ValidatorTypeGuesser::class) - ->disableOriginalConstructor() - ->getMock() + $this->createMock(ValidatorTypeGuesser::class) ) ->getFormFactory() ; @@ -62,8 +61,9 @@ protected function getDoctrineORMManipulator(): DoctrineORMManipulator return $this->doctrineORMManipulator; } - $config = Setup::createAnnotationMetadataConfiguration([__DIR__.'/../Fixtures/Entity'], true, null, null, false); - $entityManager = EntityManager::create(['driver' => 'pdo_sqlite'], $config); + $config = ORMSetup::createAttributeMetadataConfiguration([__DIR__.'/../Fixtures/Entity'], true); + $connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true], $config); + $entityManager = new EntityManager($connection, $config); $doctrineORMInfo = new DoctrineORMInfo($entityManager->getMetadataFactory()); return $this->doctrineORMManipulator = new DoctrineORMManipulator($doctrineORMInfo, ['id', 'locale', 'translatable']);