Skip to content

Commit

Permalink
Resolve NEXT_MAJOR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Apr 17, 2021
1 parent a81394c commit 8b81d53
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 44 deletions.
20 changes: 1 addition & 19 deletions src/Filter/StringFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,6 @@ public function filter(ProxyQueryInterface $query, string $alias, string $field,

$forceCaseInsensitivity = true === $this->getOption('force_case_insensitivity', false);

// NEXT_MAJOR: Remove the following condition and its body.
if (null !== $this->getOption('case_sensitive')) {
@trigger_error(
'Option "case_sensitive" is deprecated since sonata-project/doctrine-orm-admin-bundle 3.x'
.' and will be removed in version 4.x. Use the "force_case_insensitivity" option instead.',
\E_USER_DEPRECATED
);

if (null === $this->getOption('force_case_insensitivity')) {
$forceCaseInsensitivity = false === $this->getOption('case_sensitive', true);
}
}

if ($forceCaseInsensitivity && '' !== $data['value']) {
$clause = 'LOWER(%s.%s) %s :%s';
} else {
Expand Down Expand Up @@ -122,12 +109,7 @@ public function filter(ProxyQueryInterface $query, string $alias, string $field,
public function getDefaultOptions(): array
{
return [
// NEXT_MAJOR: Remove the "format" option.
'format' => '%%%s%%',
// NEXT_MAJOR: Remove the "case_sensitive" option.
'case_sensitive' => null,
// NEXT_MAJOR: Use `false` as default value for the "force_case_insensitivity" option.
'force_case_insensitivity' => null,
'force_case_insensitivity' => false,
'trim' => self::TRIM_BOTH,
'allow_empty' => false,
];
Expand Down
26 changes: 1 addition & 25 deletions tests/Filter/StringFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,6 @@ public function testEqualsWithValidParentAssociationMappings(): void
}

/**
* NEXT_MAJOR: Remove the "legacy" group annotation.
*
* @group legacy
*
* @dataProvider caseSensitiveDataProvider
*
* @param array<string, mixed> $options
Expand All @@ -282,7 +278,7 @@ public function testCaseSensitive(array $options, int $operatorType, string $exp
}

/**
* @phpstan-return iterable<array{bool, int, string, string}>
* @phpstan-return iterable<array{array{force_case_insensitivity?: bool|null}, int, string, string}>
*/
public function caseSensitiveDataProvider(): iterable
{
Expand All @@ -300,25 +296,5 @@ public function caseSensitiveDataProvider(): iterable
yield [['force_case_insensitivity' => true], StringOperatorType::TYPE_NOT_EQUAL, 'WHERE LOWER(alias.field) <> :field_name_0 OR alias.field IS NULL', 'foobar'];
yield [['force_case_insensitivity' => true], StringOperatorType::TYPE_STARTS_WITH, 'WHERE LOWER(alias.field) LIKE :field_name_0', 'foobar%'];
yield [['force_case_insensitivity' => true], StringOperatorType::TYPE_ENDS_WITH, 'WHERE LOWER(alias.field) LIKE :field_name_0', '%foobar'];

// NEXT_MAJOR: Remove the following test cases.
yield [['force_case_insensitivity' => null, 'case_sensitive' => null], StringOperatorType::TYPE_CONTAINS, 'WHERE alias.field LIKE :field_name_0', '%FooBar%'];
yield [['force_case_insensitivity' => null, 'case_sensitive' => false], StringOperatorType::TYPE_CONTAINS, 'WHERE LOWER(alias.field) LIKE :field_name_0', '%foobar%'];
yield [['force_case_insensitivity' => null, 'case_sensitive' => true], StringOperatorType::TYPE_CONTAINS, 'WHERE alias.field LIKE :field_name_0', '%FooBar%'];
yield [['force_case_insensitivity' => false, 'case_sensitive' => false], StringOperatorType::TYPE_CONTAINS, 'WHERE alias.field LIKE :field_name_0', '%FooBar%'];
yield [['force_case_insensitivity' => true, 'case_sensitive' => true], StringOperatorType::TYPE_CONTAINS, 'WHERE LOWER(alias.field) LIKE :field_name_0', '%foobar%'];

yield [['case_sensitive' => false], StringOperatorType::TYPE_CONTAINS, 'WHERE LOWER(alias.field) LIKE :field_name_0', '%foobar%'];
yield [['case_sensitive' => false], StringOperatorType::TYPE_NOT_CONTAINS, 'WHERE LOWER(alias.field) NOT LIKE :field_name_0 OR alias.field IS NULL', '%foobar%'];
yield [['case_sensitive' => false], StringOperatorType::TYPE_EQUAL, 'WHERE LOWER(alias.field) = :field_name_0', 'foobar'];
yield [['case_sensitive' => false], StringOperatorType::TYPE_NOT_EQUAL, 'WHERE LOWER(alias.field) <> :field_name_0 OR alias.field IS NULL', 'foobar'];
yield [['case_sensitive' => false], StringOperatorType::TYPE_STARTS_WITH, 'WHERE LOWER(alias.field) LIKE :field_name_0', 'foobar%'];
yield [['case_sensitive' => false], StringOperatorType::TYPE_ENDS_WITH, 'WHERE LOWER(alias.field) LIKE :field_name_0', '%foobar'];
yield [['case_sensitive' => true], StringOperatorType::TYPE_CONTAINS, 'WHERE alias.field LIKE :field_name_0', '%FooBar%'];
yield [['case_sensitive' => true], StringOperatorType::TYPE_NOT_CONTAINS, 'WHERE alias.field NOT LIKE :field_name_0 OR alias.field IS NULL', '%FooBar%'];
yield [['case_sensitive' => true], StringOperatorType::TYPE_EQUAL, 'WHERE alias.field = :field_name_0', 'FooBar'];
yield [['case_sensitive' => true], StringOperatorType::TYPE_NOT_EQUAL, 'WHERE alias.field <> :field_name_0 OR alias.field IS NULL', 'FooBar'];
yield [['case_sensitive' => true], StringOperatorType::TYPE_STARTS_WITH, 'WHERE alias.field LIKE :field_name_0', 'FooBar%'];
yield [['case_sensitive' => true], StringOperatorType::TYPE_ENDS_WITH, 'WHERE alias.field LIKE :field_name_0', '%FooBar'];
}
}

0 comments on commit 8b81d53

Please sign in to comment.