diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 258666f..908027f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,15 +15,10 @@ jobs: strategy: fail-fast: false matrix: - php: ['7.4', '8.0', '8.1'] - symfony: ['~5.4.0'] + php: ['8.3'] + symfony: ['~7.3.0'] phpunit: ['phpunit.xml'] deps: ['normal'] - include: - - php: '7.4' - symfony: '~5.4.0' - phpunit: 'phpunit.xml' - deps: 'low' steps: - uses: actions/checkout@v2 diff --git a/bundle/Command/MigrateCommand.php b/bundle/Command/MigrateCommand.php index d5ffabf..48bd4e5 100644 --- a/bundle/Command/MigrateCommand.php +++ b/bundle/Command/MigrateCommand.php @@ -5,7 +5,7 @@ namespace Netgen\Bundle\EnhancedSelectionBundle\Command; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Driver\Result; +use Doctrine\DBAL\Result; use Netgen\Bundle\EnhancedSelectionBundle\Core\FieldType\EnhancedSelection\Type as EnhancedSelectionType; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -42,7 +42,7 @@ protected function initialize(InputInterface $input, OutputInterface $output): v $this->io = new SymfonyStyle($input, $output); } - protected function execute(InputInterface $input, OutputInterface $output): ?int + protected function execute(InputInterface $input, OutputInterface $output): int { $statement = $this->getFields(); $this->io->progressStart($statement->rowCount()); @@ -80,7 +80,7 @@ private function getFields(): Result ) ->setParameter('data_type_string', $this->typeIdentifier); - return $builder->execute(); + return $builder->executeQuery(); } private function resetFieldData(int $id, int $version): void @@ -96,7 +96,7 @@ private function resetFieldData(int $id, int $version): void ->setParameter('id', $id) ->setParameter('version', $version); - $builder->execute(); + $builder->executeStatement(); } private function removeSelectionDataForField(int $id, int $version): void @@ -111,7 +111,7 @@ private function removeSelectionDataForField(int $id, int $version): void ->setParameter('id', $id) ->setParameter('version', $version); - $builder->execute(); + $builder->executeStatement(); } private function createSelections(int $id, int $version, array $identifiers): void diff --git a/bundle/Core/FieldType/EnhancedSelection/EnhancedSelectionStorage.php b/bundle/Core/FieldType/EnhancedSelection/EnhancedSelectionStorage.php index f0941d2..5a61f25 100644 --- a/bundle/Core/FieldType/EnhancedSelection/EnhancedSelectionStorage.php +++ b/bundle/Core/FieldType/EnhancedSelection/EnhancedSelectionStorage.php @@ -10,7 +10,7 @@ final class EnhancedSelectionStorage extends GatewayBasedStorage { - public function storeFieldData(VersionInfo $versionInfo, Field $field, array $context): ?bool + public function storeFieldData(VersionInfo $versionInfo, Field $field): ?bool { $this->gateway->deleteFieldData($versionInfo, [$field->id]); if (!empty($field->value->externalData)) { @@ -20,12 +20,12 @@ public function storeFieldData(VersionInfo $versionInfo, Field $field, array $co return null; } - public function getFieldData(VersionInfo $versionInfo, Field $field, array $context): void + public function getFieldData(VersionInfo $versionInfo, Field $field): void { $this->gateway->getFieldData($versionInfo, $field); } - public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds, array $context): bool + public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds): bool { $this->gateway->deleteFieldData($versionInfo, $fieldIds); @@ -37,7 +37,7 @@ public function hasFieldData(): bool return true; } - public function getIndexData(VersionInfo $versionInfo, Field $field, array $context) + public function getIndexData(VersionInfo $versionInfo, Field $field): bool { return false; } diff --git a/bundle/Core/FieldType/EnhancedSelection/EnhancedSelectionStorage/Gateway/DoctrineStorage.php b/bundle/Core/FieldType/EnhancedSelection/EnhancedSelectionStorage/Gateway/DoctrineStorage.php index d3a3700..8495ce0 100644 --- a/bundle/Core/FieldType/EnhancedSelection/EnhancedSelectionStorage/Gateway/DoctrineStorage.php +++ b/bundle/Core/FieldType/EnhancedSelection/EnhancedSelectionStorage/Gateway/DoctrineStorage.php @@ -4,6 +4,7 @@ namespace Netgen\Bundle\EnhancedSelectionBundle\Core\FieldType\EnhancedSelection\EnhancedSelectionStorage\Gateway; +use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Types\Types; use Ibexa\Contracts\Core\Persistence\Content\Field; @@ -34,11 +35,11 @@ public function storeFieldData(VersionInfo $versionInfo, Field $field): void 'identifier' => ':identifier', ] ) - ->setParameter(':contentobject_attribute_id', $field->id, Types::INTEGER) - ->setParameter(':contentobject_attribute_version', $versionInfo->versionNo, Types::INTEGER) - ->setParameter(':identifier', $identifier, Types::STRING); + ->setParameter('contentobject_attribute_id', $field->id, Types::INTEGER) + ->setParameter('contentobject_attribute_version', $versionInfo->versionNo, Types::INTEGER) + ->setParameter('identifier', $identifier, Types::STRING); - $insertQuery->execute(); + $insertQuery->executeStatement(); } } @@ -54,14 +55,14 @@ public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds): void ->delete($this->connection->quoteIdentifier('sckenhancedselection')) ->where( $query->expr()->and( - $query->expr()->in('contentobject_attribute_id', [':contentobject_attribute_id']), + $query->expr()->in('contentobject_attribute_id', ':contentobject_attribute_id'), $query->expr()->eq('contentobject_attribute_version', ':contentobject_attribute_version') ) ) - ->setParameter(':contentobject_attribute_id', $fieldIds, Connection::PARAM_INT_ARRAY) - ->setParameter(':contentobject_attribute_version', $versionInfo->versionNo, Types::INTEGER); + ->setParameter('contentobject_attribute_id', $fieldIds, ArrayParameterType::INTEGER) + ->setParameter('contentobject_attribute_version', $versionInfo->versionNo, Types::INTEGER); - $query->execute(); + $query->executeStatement(); } /** @@ -81,12 +82,10 @@ private function loadFieldData(int $fieldId, int $versionNo): array $query->expr()->eq('contentobject_attribute_version', ':contentobject_attribute_version') ) ) - ->setParameter(':contentobject_attribute_id', $fieldId, Types::INTEGER) - ->setParameter(':contentobject_attribute_version', $versionNo, Types::INTEGER); + ->setParameter('contentobject_attribute_id', $fieldId, Types::INTEGER) + ->setParameter('contentobject_attribute_version', $versionNo, Types::INTEGER); - $statement = $query->execute(); - - $rows = $statement->fetchAllAssociative(); + $rows = $query->executeQuery()->fetchAllAssociative(); return array_map( static fn (array $row): string => $row['identifier'], diff --git a/bundle/Core/FieldType/EnhancedSelection/Type.php b/bundle/Core/FieldType/EnhancedSelection/Type.php index 5b94f55..ebbe572 100644 --- a/bundle/Core/FieldType/EnhancedSelection/Type.php +++ b/bundle/Core/FieldType/EnhancedSelection/Type.php @@ -316,9 +316,9 @@ public function validateFieldSettings($fieldSettings): array if ($emptyCount > ($fieldSettings['isMultiple'] ? 0 : 1)) { $validationErrors[] = new ValidationError( - $fieldSettings['isMultiple'] ? - "'%setting%' setting value item's 'identifier' property must have a value" : - "'%setting%' setting value item's 'identifier' property must have only a single empty value", + $fieldSettings['isMultiple'] + ? "'%setting%' setting value item's 'identifier' property must have a value" + : "'%setting%' setting value item's 'identifier' property must have only a single empty value", null, [ '%setting%' => $name, diff --git a/bundle/Core/Search/Legacy/Content/Common/Gateway/CriterionHandler/EnhancedSelection.php b/bundle/Core/Search/Legacy/Content/Common/Gateway/CriterionHandler/EnhancedSelection.php index c560bfb..de4dcb4 100644 --- a/bundle/Core/Search/Legacy/Content/Common/Gateway/CriterionHandler/EnhancedSelection.php +++ b/bundle/Core/Search/Legacy/Content/Common/Gateway/CriterionHandler/EnhancedSelection.php @@ -6,7 +6,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Query\QueryBuilder; -use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; +use Ibexa\Contracts\Core\Repository\Values\Content\Query\CriterionInterface; use Ibexa\Core\Base\Exceptions\InvalidArgumentException; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\FieldBase; @@ -14,13 +14,20 @@ final class EnhancedSelection extends FieldBase { - public function accept(Criterion $criterion): bool + public function accept(CriterionInterface $criterion): bool { return $criterion instanceof EnhancedSelectionCriterion; } - public function handle(CriteriaConverter $converter, QueryBuilder $queryBuilder, Criterion $criterion, array $languageSettings): string - { + /** + * @param \Netgen\Bundle\EnhancedSelectionBundle\API\Repository\Values\Content\Query\Criterion\EnhancedSelection $criterion + */ + public function handle( + CriteriaConverter $converter, + QueryBuilder $queryBuilder, + CriterionInterface $criterion, + array $languageSettings, + ): string { $fieldDefinitionIds = $this->getFieldDefinitionIds($criterion->target); $subSelect = $this->connection->createQueryBuilder(); diff --git a/bundle/Core/Search/Solr/Query/CriterionVisitor/EnhancedSelection.php b/bundle/Core/Search/Solr/Query/CriterionVisitor/EnhancedSelection.php index b450f3c..3771712 100644 --- a/bundle/Core/Search/Solr/Query/CriterionVisitor/EnhancedSelection.php +++ b/bundle/Core/Search/Solr/Query/CriterionVisitor/EnhancedSelection.php @@ -4,7 +4,7 @@ namespace Netgen\Bundle\EnhancedSelectionBundle\Core\Search\Solr\Query\CriterionVisitor; -use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; +use Ibexa\Contracts\Core\Repository\Values\Content\Query\CriterionInterface; use Ibexa\Contracts\Solr\Query\CriterionVisitor; use Ibexa\Core\Base\Exceptions\InvalidArgumentException; use Ibexa\Solr\Query\Common\CriterionVisitor\Field; @@ -14,12 +14,17 @@ final class EnhancedSelection extends Field { - public function canVisit(Criterion $criterion): bool + public function canVisit(CriterionInterface $criterion): bool { return $criterion instanceof EnhancedSelectionCriterion; } - public function visit(Criterion $criterion, ?CriterionVisitor $subVisitor = null): string + /** + * @param \Netgen\Bundle\EnhancedSelectionBundle\API\Repository\Values\Content\Query\Criterion\EnhancedSelection $criterion + * + * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentException + */ + public function visit(CriterionInterface $criterion, ?CriterionVisitor $subVisitor = null): string { $searchFields = $this->getSearchFields($criterion); diff --git a/bundle/Form/Type/FieldType/FieldValueTransformer.php b/bundle/Form/Type/FieldType/FieldValueTransformer.php index 6b758d1..9628734 100644 --- a/bundle/Form/Type/FieldType/FieldValueTransformer.php +++ b/bundle/Form/Type/FieldType/FieldValueTransformer.php @@ -47,9 +47,9 @@ public function reverseTransform($value): Value return $this->fieldType->getEmptyValue(); } - $hash = is_array($value['identifiers']) ? - $value['identifiers'] : - [$value['identifiers']]; + $hash = is_array($value['identifiers']) + ? $value['identifiers'] + : [$value['identifiers']]; return $this->fieldType->fromHash($hash); } diff --git a/composer.json b/composer.json index 16fbd0b..c34901a 100644 --- a/composer.json +++ b/composer.json @@ -16,14 +16,15 @@ } ], "require": { - "ibexa/core": "^4.0", - "ibexa/content-forms": "^4.0", + "ibexa/core": "^5.0", + "ibexa/content-forms": "^5.0", "twig/twig": "^3.0" }, "require-dev": { - "phpunit/phpunit": "^9.0", - "netgen/ibexa-forms-bundle": "^4.0", - "friendsofphp/php-cs-fixer": "^3.3" + "phpunit/phpunit": "^12.0", + "netgen/ibexa-forms-bundle": "^5.0", + "friendsofphp/php-cs-fixer": "^3.3", + "ibexa/solr": "^5.0" }, "minimum-stability": "dev", "prefer-stable": true, diff --git a/phpunit.xml b/phpunit.xml index 752c492..54643ee 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,38 +1,36 @@ - tests - - - bundle - - bundle/DependencyInjection - bundle/Resources - vendor - bundle/Core/Search/Legacy/Content/Common/Gateway/CriterionHandler/EnhancedSelection.php - bundle/Core/FieldType/EnhancedSelection/SearchField.php - bundle/NetgenEnhancedSelectionBundle.php - - - + - - - - + + + + + bundle + + + bundle/DependencyInjection + bundle/Resources + vendor + bundle/Core/Search/Legacy/Content/Common/Gateway/CriterionHandler/EnhancedSelection.php + bundle/Core/FieldType/EnhancedSelection/SearchField.php + bundle/NetgenEnhancedSelectionBundle.php + + diff --git a/tests/Core/FieldType/EnhancedSelection/EnhancedSelectionStorageTest.php b/tests/Core/FieldType/EnhancedSelection/EnhancedSelectionStorageTest.php index 4164fa8..62095e5 100644 --- a/tests/Core/FieldType/EnhancedSelection/EnhancedSelectionStorageTest.php +++ b/tests/Core/FieldType/EnhancedSelection/EnhancedSelectionStorageTest.php @@ -4,10 +4,10 @@ namespace Netgen\Bundle\EnhancedSelectionBundle\Tests\Core\FieldType\EnhancedSelection; +use Ibexa\Contracts\Core\FieldType\StorageGateway; use Ibexa\Contracts\Core\Persistence\Content\Field; use Ibexa\Contracts\Core\Persistence\Content\FieldValue; use Ibexa\Contracts\Core\Persistence\Content\VersionInfo; -use Ibexa\Core\FieldType\StorageGateway; use Netgen\Bundle\EnhancedSelectionBundle\Core\FieldType\EnhancedSelection\EnhancedSelectionStorage; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -43,7 +43,7 @@ public function testGetIndexData(): void ->disableOriginalConstructor() ->getMock(); - self::assertFalse($this->storage->getIndexData($versionInfo, $field, [])); + self::assertFalse($this->storage->getIndexData($versionInfo, $field)); } public function testStoreFieldData(): void @@ -60,7 +60,7 @@ public function testStoreFieldData(): void ] ); - $connection = $this->getMockForAbstractClass(StorageGateway::class); + $connection = $this->createMock(StorageGateway::class); $context = ['identifier' => 'enhancedselection', 'connection' => $connection]; $this->gateway->expects(self::once()) @@ -86,7 +86,7 @@ public function testGetFieldData(): void ] ); - $connection = $this->getMockForAbstractClass(StorageGateway::class); + $connection = $this->createMock(StorageGateway::class); $context = ['identifier' => 'enhancedselection', 'connection' => $connection]; $this->gateway->expects(self::once()) @@ -100,7 +100,7 @@ public function testDeleteFieldData(): void $versionInfo = new VersionInfo(); $fields = ['some_field']; - $connection = $this->getMockForAbstractClass(StorageGateway::class); + $connection = $this->createMock(StorageGateway::class); $context = ['identifier' => 'enhancedselection', 'connection' => $connection]; $this->gateway->expects(self::once()) diff --git a/tests/Core/FieldType/EnhancedSelection/TypeTest.php b/tests/Core/FieldType/EnhancedSelection/TypeTest.php index 953069b..852909f 100644 --- a/tests/Core/FieldType/EnhancedSelection/TypeTest.php +++ b/tests/Core/FieldType/EnhancedSelection/TypeTest.php @@ -375,8 +375,6 @@ public function testAcceptValueWithValueObject(): void { $this->expectException(InvalidArgumentType::class); - $value = new Value([true, true]); - - $this->type->acceptValue($value); + $this->type->acceptValue([true, true]); } } diff --git a/tests/Form/FieldTypeHandler/EnhancedSelectionTest.php b/tests/Form/FieldTypeHandler/EnhancedSelectionTest.php index 7dd1b02..cb311ca 100644 --- a/tests/Form/FieldTypeHandler/EnhancedSelectionTest.php +++ b/tests/Form/FieldTypeHandler/EnhancedSelectionTest.php @@ -108,7 +108,7 @@ public function testBuildFieldCreateForm(): void $fieldDefinition = new FieldDefinition( [ - 'id' => 'id', + 'id' => 11, 'identifier' => 'identifier', 'isRequired' => true, 'descriptions' => ['fre-FR' => 'fre-FR'], diff --git a/tests/Templating/Twig/NetgenEnhancedSelectionRuntimeTest.php b/tests/Templating/Twig/NetgenEnhancedSelectionRuntimeTest.php index 62d7d4b..3346acc 100644 --- a/tests/Templating/Twig/NetgenEnhancedSelectionRuntimeTest.php +++ b/tests/Templating/Twig/NetgenEnhancedSelectionRuntimeTest.php @@ -25,10 +25,7 @@ final class NetgenEnhancedSelectionRuntimeTest extends TestCase protected function setUp(): void { - $this->contentTypeService = $this->getMockBuilder(ContentTypeService::class) - ->disableOriginalConstructor() - ->onlyMethods(['loadContentType']) - ->getMockForAbstractClass(); + $this->contentTypeService = $this->createMock(ContentTypeService::class); $this->runtime = new NetgenEnhancedSelectionRuntime($this->contentTypeService); }