Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions bundle/Command/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);

Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}

Expand All @@ -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();
}

/**
Expand All @@ -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'],
Expand Down
6 changes: 3 additions & 3 deletions bundle/Core/FieldType/EnhancedSelection/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,28 @@

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;
use Netgen\Bundle\EnhancedSelectionBundle\API\Repository\Values\Content\Query\Criterion\EnhancedSelection as EnhancedSelectionCriterion;

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
{
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

superflous PHPDoc. This method does not throw anything and all @param and @return are already declared in method signature itself.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at the method declaration in the abstract class, it has a PHPDoc which says that it throws an InvalidArgumentException. Also, in the method itself, the $this->getFieldDefinitionIds() method is called, which throws an InvalidArgumentException.

I added the PHPDoc first and foremost to say that the CriterionInterface param is actually EnhancedSelectionCriterion class. If that's alright with you, I would just keep this info in PHPDoc and remove everything else.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine.

As for @throws, we should not specify those if the method does not directly throw. Otherwise, we might put every throw on every method ever :D

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

795f61f
Removed the @throws and left only the param for CriterionInterface, which I've put to be FQCN.

* @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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions bundle/Form/Type/FieldType/FieldValueTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
44 changes: 21 additions & 23 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
colors="true"
verbose="true"
processIsolation="false"
stopOnFailure="false"
beStrictAboutTestsThatDoNotTestAnything="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.4/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<testsuites>
<testsuite name="Netgen\EnhancedSelectionBundle\Tests">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">bundle</directory>
<exclude>
<directory>bundle/DependencyInjection</directory>
<directory>bundle/Resources</directory>
<directory>vendor</directory>
<file>bundle/Core/Search/Legacy/Content/Common/Gateway/CriterionHandler/EnhancedSelection.php</file>
<file>bundle/Core/FieldType/EnhancedSelection/SearchField.php</file>
<file>bundle/NetgenEnhancedSelectionBundle.php</file>
</exclude>
</whitelist>
</filter>

<logging>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<junit outputFile="build/report.junit.xml"/>
</logging>

<source>
<include>
<directory suffix=".php">bundle</directory>
</include>
<exclude>
<directory>bundle/DependencyInjection</directory>
<directory>bundle/Resources</directory>
<directory>vendor</directory>
<file>bundle/Core/Search/Legacy/Content/Common/Gateway/CriterionHandler/EnhancedSelection.php</file>
<file>bundle/Core/FieldType/EnhancedSelection/SearchField.php</file>
<file>bundle/NetgenEnhancedSelectionBundle.php</file>
</exclude>
</source>
</phpunit>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand Down
4 changes: 1 addition & 3 deletions tests/Core/FieldType/EnhancedSelection/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
2 changes: 1 addition & 1 deletion tests/Form/FieldTypeHandler/EnhancedSelectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function testBuildFieldCreateForm(): void

$fieldDefinition = new FieldDefinition(
[
'id' => 'id',
'id' => 11,
'identifier' => 'identifier',
'isRequired' => true,
'descriptions' => ['fre-FR' => 'fre-FR'],
Expand Down
Loading