diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 4cefc92..0c4f495 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -64,7 +64,7 @@ jobs:
fi
- name: Setup problem matchers for PHPUnit
- if: matrix.php-version == '8.1' && matrix.db-type == 'mysql'
+ if: matrix.php-version == '8.2' && matrix.db-type == 'mysql'
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Run PHPUnit
@@ -72,14 +72,14 @@ jobs:
if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:root@127.0.0.1/cakephp?encoding=utf8'; fi
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:postgres@127.0.0.1/postgres'; fi
- if [[ ${{ matrix.php-version }} == '8.1' ]]; then
- export CODECOVERAGE=1 && vendor/bin/phpunit --verbose --coverage-clover=coverage.xml
+ if [[ ${{ matrix.php-version }} == '8.2' ]]; then
+ export CODECOVERAGE=1 && vendor/bin/phpunit --coverage-clover=coverage.xml
else
vendor/bin/phpunit
fi
- name: Submit code coverage
- if: matrix.php-version == '8.1'
+ if: matrix.php-version == '8.2'
uses: codecov/codecov-action@v1
cs-stan:
@@ -92,7 +92,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
- php-version: '8.1'
+ php-version: '8.2'
extensions: mbstring, intl, apcu
coverage: none
diff --git a/README.md b/README.md
index 2b11601..cc404ff 100644
--- a/README.md
+++ b/README.md
@@ -14,6 +14,7 @@ Versions and branches
| ^5.0 | [2.0](https://github.com/cakedc/users/tree/2.next-cake5) | 2.0.0 | stable |
| ^4.5 | [1.0](https://github.com/cakedc/search-filter/tree/1.next-cake4) | 1.0.0 | stable |
+
## Overview
The SearchFilter plugin is a powerful and flexible solution for implementing advanced search functionality in CakePHP applications. It provides a robust set of tools for creating dynamic, user-friendly search interfaces with minimal effort.
@@ -111,7 +112,7 @@ class PostsController extends AppController
]);
$filters = $manager->formatFinders($search);
- $query = $query->find('filters', $filters);
+ $query = $query->find('filters', params: $filters);
}
// Paginate the results
diff --git a/composer.json b/composer.json
index 3dc6bc8..00908dd 100644
--- a/composer.json
+++ b/composer.json
@@ -5,13 +5,12 @@
"license": "MIT",
"require": {
"php": ">=8.1",
- "cakephp/cakephp": "^4.4",
- "skie/cakephp-search": "^4.0"
+ "cakephp/cakephp": "^5.0",
+ "skie/cakephp-search": "^5.0"
},
"require-dev": {
- "cakephp/cakephp-codesniffer": "^4.0",
- "slevomat/coding-standard": "^8.0",
- "phpunit/phpunit": "^9.5"
+ "cakephp/cakephp-codesniffer": "^5.0",
+ "phpunit/phpunit": "^10.0"
},
"scripts": {
"fixcode": [
@@ -29,7 +28,7 @@
"test": "phpunit --stderr",
"coverage-test": "phpunit --stderr --coverage-clover=clover.xml",
"stan": "phpstan.phar analyse --memory-limit=-1 src/",
- "stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:0.12.94 psalm/phar:~4.9.2 && mv composer.backup composer.json",
+ "stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^1.9.0 psalm/phar:^5.1.0 && mv composer.backup composer.json",
"psalm": "psalm.phar --show-info=false",
"stan-rebuild-baseline": "phpstan.phar analyse ./src/ --generate-baseline",
"cs-check": "phpcs -n -p ./src ./tests",
@@ -43,7 +42,7 @@
"autoload-dev": {
"psr-4": {
"CakeDC\\SearchFilter\\Test\\": "tests/",
- "CakeDC\\SearchFilter\\Test\\App\\": "tests/test_app/App/",
+ "CakeDC\\SearchFilter\\Test\\App\\": "tests/test_app/App/",
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/"
}
},
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 57f0d8a..eca6033 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -10,23 +10,17 @@
-
-
- tests/TestCase/
+ ./tests/
-
-
-
+
-
src
-
diff --git a/src/Filter/Exception/MissingFilterException.php b/src/Filter/Exception/MissingFilterException.php
index 21a27b7..ebbfe31 100644
--- a/src/Filter/Exception/MissingFilterException.php
+++ b/src/Filter/Exception/MissingFilterException.php
@@ -18,5 +18,5 @@ class MissingFilterException extends CakeException
/**
* @inheritDoc
*/
- protected $_messageTemplate = 'Filter class %s could not be found.';
+ protected string $_messageTemplate = 'Filter class %s could not be found.';
}
diff --git a/src/Filter/FilterCollection.php b/src/Filter/FilterCollection.php
index 7dd6625..324979c 100644
--- a/src/Filter/FilterCollection.php
+++ b/src/Filter/FilterCollection.php
@@ -13,6 +13,7 @@
use Exception;
use IteratorAggregate;
use Traversable;
+use function Cake\I18n\__;
/**
* FilterCollection class
diff --git a/src/Model/Filter/CriteriaFilter.php b/src/Model/Filter/CriteriaFilter.php
index b89db59..2b8610d 100644
--- a/src/Model/Filter/CriteriaFilter.php
+++ b/src/Model/Filter/CriteriaFilter.php
@@ -8,10 +8,11 @@
namespace CakeDC\SearchFilter\Model\Filter;
-use Cake\ORM\Query;
+use Cake\ORM\Query\SelectQuery;
use PlumSearch\Model\Filter\AbstractFilter;
use PlumSearch\Model\Filter\Exception\MissingFilterException;
use PlumSearch\Model\FilterRegistry;
+use function Cake\I18n\__;
/**
* Class CriteriaFilter
@@ -44,13 +45,15 @@ public function __construct(FilterRegistry $registry, array $config = [])
/**
* Returns query with applied filter
*
- * @param \Cake\ORM\Query<\Cake\Datasource\EntityInterface> $query Query.
+ * @param \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface> $query Query.
* @param string $field Field name.
- * @param array $value Field value.
+ * @param string|array $value Field value.
* @param array $data Filters values.
- * @return \Cake\ORM\Query<\Cake\Datasource\EntityInterface>
+ * @return \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface>
+ * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
+ * @phpstan-param array|string $value
*/
- protected function _buildQuery(Query $query, string $field, $value, array $data = []): Query
+ protected function _buildQuery(SelectQuery $query, string $field, $value, array $data = []): SelectQuery
{
$criteria = $this->getConfig('criteria');
foreach ($value as $name => $values) {
diff --git a/src/Model/Filter/Criterion/AndCriterion.php b/src/Model/Filter/Criterion/AndCriterion.php
index 6445b3c..08570cd 100644
--- a/src/Model/Filter/Criterion/AndCriterion.php
+++ b/src/Model/Filter/Criterion/AndCriterion.php
@@ -9,7 +9,7 @@
namespace CakeDC\SearchFilter\Model\Filter\Criterion;
use Cake\Database\Expression\QueryExpression;
-use Cake\ORM\Query;
+use Cake\ORM\Query\SelectQuery;
class AndCriterion extends BaseCriterion
{
@@ -31,14 +31,14 @@ public function __construct(array $criteria)
/**
* Finder method
*
- * @param \Cake\ORM\Query<\Cake\Datasource\EntityInterface> $query
+ * @param \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface> $query
* @param string $condition
* @param array $values
* @param array $criteria
* @param array $options
- * @return \Cake\ORM\Query<\Cake\Datasource\EntityInterface>
+ * @return \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface>
*/
- public function __invoke(Query $query, string $condition, array $values, array $criteria, array $options): Query
+ public function __invoke(SelectQuery $query, string $condition, array $values, array $criteria, array $options): SelectQuery
{
$filters = $this->buildFilter($condition, $values, $criteria, $options);
if (!empty($filters)) {
diff --git a/src/Model/Filter/Criterion/BaseCriterion.php b/src/Model/Filter/Criterion/BaseCriterion.php
index 3ccf0bb..718c050 100644
--- a/src/Model/Filter/Criterion/BaseCriterion.php
+++ b/src/Model/Filter/Criterion/BaseCriterion.php
@@ -11,8 +11,8 @@
use Cake\Database\Expression\ComparisonExpression;
use Cake\Database\Expression\QueryExpression;
use Cake\Database\ExpressionInterface;
-use Cake\I18n\FrozenDate;
-use Cake\I18n\FrozenTime;
+use Cake\I18n\Date;
+use Cake\I18n\DateTime;
use Cake\Utility\Hash;
use CakeDC\SearchFilter\Filter\AbstractFilter;
@@ -92,9 +92,9 @@ public function buildQueryByCondition(string|QueryExpression $field, string $con
}
if ($condition == AbstractFilter::COND_EQ) {
return function (QueryExpression $expr) use ($field, $value, $type): QueryExpression {
- if ($value instanceof FrozenDate) {
+ if ($value instanceof Date) {
$value = $value->format('Y-m-d');
- } elseif ($value instanceof FrozenTime) {
+ } elseif ($value instanceof DateTime) {
$value = $value->format('Y-m-d H:i');
}
@@ -111,9 +111,9 @@ public function buildQueryByCondition(string|QueryExpression $field, string $con
])
) {
return function (QueryExpression $expr) use ($field, $value, $type, $condition): QueryExpression {
- if ($value instanceof FrozenDate) {
+ if ($value instanceof Date) {
$value = $value->format('Y-m-d');
- } elseif ($value instanceof FrozenTime) {
+ } elseif ($value instanceof DateTime) {
$value = $value->format('Y-m-d H:i');
}
diff --git a/src/Model/Filter/Criterion/BoolCriterion.php b/src/Model/Filter/Criterion/BoolCriterion.php
index d9a8008..bac7123 100644
--- a/src/Model/Filter/Criterion/BoolCriterion.php
+++ b/src/Model/Filter/Criterion/BoolCriterion.php
@@ -9,7 +9,7 @@
namespace CakeDC\SearchFilter\Model\Filter\Criterion;
use Cake\Database\ExpressionInterface;
-use Cake\ORM\Query;
+use Cake\ORM\Query\SelectQuery;
use CakeDC\SearchFilter\Filter\AbstractFilter;
class BoolCriterion extends BaseCriterion
@@ -39,14 +39,14 @@ public function isApplicable(mixed $value, string $condition): bool
/**
* Finder method
*
- * @param \Cake\ORM\Query<\Cake\Datasource\EntityInterface> $query
+ * @param \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface> $query
* @param string|null $condition
* @param array $values
* @param array $criteria
* @param array $options
- * @return \Cake\ORM\Query<\Cake\Datasource\EntityInterface>
+ * @return \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface>
*/
- public function __invoke(Query $query, $condition, array $values, array $criteria, $options): Query
+ public function __invoke(SelectQuery $query, ?string $condition, array $values, array $criteria, array $options): SelectQuery
{
$filter = $this->buildFilter($condition, $values, $criteria, $options);
if (!empty($filter)) {
@@ -59,7 +59,7 @@ public function __invoke(Query $query, $condition, array $values, array $criteri
/**
* @inheritDoc
*/
- public function buildFilter(string $condition, array $values, array $criteria, array $options = []): array|callable|null
+ public function buildFilter(?string $condition, array $values, array $criteria, array $options = []): array|callable|null
{
$value = $this->getValues('value', AbstractFilter::COND_EQ, $values);
diff --git a/src/Model/Filter/Criterion/DateCriterion.php b/src/Model/Filter/Criterion/DateCriterion.php
index 62bd480..b53b234 100644
--- a/src/Model/Filter/Criterion/DateCriterion.php
+++ b/src/Model/Filter/Criterion/DateCriterion.php
@@ -13,8 +13,9 @@
use Cake\Database\Expression\QueryExpression;
use Cake\Database\ExpressionInterface;
use Cake\Database\FunctionsBuilder;
-use Cake\I18n\FrozenDate;
-use Cake\ORM\Query;
+use Cake\I18n\Date;
+use Cake\I18n\DateTime;
+use Cake\ORM\Query\SelectQuery;
use CakeDC\SearchFilter\Filter\AbstractFilter;
class DateCriterion extends BaseCriterion
@@ -61,14 +62,14 @@ public function isApplicable(mixed $value, string $condition): bool
/**
* Finder method
*
- * @param \Cake\ORM\Query<\Cake\Datasource\EntityInterface> $query
+ * @param \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface> $query
* @param string $condition
* @param array $values
* @param array $criteria
* @param array $options
- * @return \Cake\ORM\Query<\Cake\Datasource\EntityInterface>
+ * @return \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface>
*/
- public function __invoke(Query $query, string $condition, array $values, array $criteria, array $options): Query
+ public function __invoke(SelectQuery $query, string $condition, array $values, array $criteria, array $options): SelectQuery
{
$filter = $this->buildFilter($condition, $values, $criteria, $options);
if (!empty($filter)) {
@@ -180,10 +181,10 @@ protected function buildYearWeekExpression(string|ExpressionInterface $value): F
* Create a date/time object from a string
*
* @param string $dateStr
- * @return \DateTimeInterface
+ * @return \Cake\I18n\Date|\Cake\I18n\DateTime
*/
- protected function prepareTime(string $dateStr): \DateTimeInterface
+ protected function prepareTime(string $dateStr): DateTime|Date
{
- return FrozenDate::createFromFormat($this->format, $dateStr);
+ return Date::createFromFormat($this->format, $dateStr);
}
}
diff --git a/src/Model/Filter/Criterion/DateTimeCriterion.php b/src/Model/Filter/Criterion/DateTimeCriterion.php
index 55f8c6f..7315b24 100644
--- a/src/Model/Filter/Criterion/DateTimeCriterion.php
+++ b/src/Model/Filter/Criterion/DateTimeCriterion.php
@@ -9,7 +9,8 @@
namespace CakeDC\SearchFilter\Model\Filter\Criterion;
use Cake\Database\ExpressionInterface;
-use Cake\I18n\FrozenTime;
+use Cake\I18n\Date;
+use Cake\I18n\DateTime;
class DateTimeCriterion extends DateCriterion
{
@@ -29,10 +30,10 @@ public function __construct(string|ExpressionInterface $field, string $format =
* Create a date/time object from a string
*
* @param string $dateStr
- * @return \DateTimeInterface
+ * @return \Cake\I18n\Date|\Cake\I18n\DateTime
*/
- protected function prepareTime(string $dateStr): \DateTimeInterface
+ protected function prepareTime(string $dateStr): DateTime|Date
{
- return FrozenTime::createFromFormat($this->format, $dateStr);
+ return DateTime::createFromFormat($this->format, $dateStr);
}
}
diff --git a/src/Model/Filter/Criterion/InCriterion.php b/src/Model/Filter/Criterion/InCriterion.php
index 24e31af..97e9b99 100644
--- a/src/Model/Filter/Criterion/InCriterion.php
+++ b/src/Model/Filter/Criterion/InCriterion.php
@@ -10,7 +10,7 @@
use Cake\Database\Expression\QueryExpression;
use Cake\Database\ExpressionInterface;
-use Cake\ORM\Query;
+use Cake\ORM\Query\SelectQuery;
use Cake\ORM\Table;
class InCriterion extends BaseCriterion
@@ -44,14 +44,14 @@ public function __construct(string|ExpressionInterface $field, Table $table, Bas
/**
* Finder method
*
- * @param \Cake\ORM\Query<\Cake\Datasource\EntityInterface> $query
+ * @param \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface> $query
* @param string $condition
* @param array $values
* @param array $criteria
* @param array $options
- * @return \Cake\ORM\Query<\Cake\Datasource\EntityInterface>
+ * @return \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface>
*/
- public function __invoke(Query $query, string $condition, array $values, array $criteria, array $options): Query
+ public function __invoke(SelectQuery $query, string $condition, array $values, array $criteria, array $options): SelectQuery
{
$filter = $this->buildFilter($condition, $values, $criteria, $options);
if ($filter !== null) {
diff --git a/src/Model/Filter/Criterion/LookupCriterion.php b/src/Model/Filter/Criterion/LookupCriterion.php
index afddf1f..20f5048 100644
--- a/src/Model/Filter/Criterion/LookupCriterion.php
+++ b/src/Model/Filter/Criterion/LookupCriterion.php
@@ -10,7 +10,7 @@
use Cake\Database\Expression\QueryExpression;
use Cake\Database\ExpressionInterface;
-use Cake\ORM\Query;
+use Cake\ORM\Query\SelectQuery;
use Cake\ORM\Table;
use Cake\Validation\Validation;
use CakeDC\SearchFilter\Filter\AbstractFilter;
@@ -46,14 +46,14 @@ public function __construct(string|ExpressionInterface $field, Table $table, Bas
/**
* Finder method
*
- * @param \Cake\ORM\Query<\Cake\Datasource\EntityInterface> $query
+ * @param \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface> $query
* @param string $condition
* @param array $values
* @param array $criteria
* @param array $options
- * @return \Cake\ORM\Query<\Cake\Datasource\EntityInterface>
+ * @return \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface>
*/
- public function __invoke(Query $query, string $condition, array $values, array $criteria, array $options): Query
+ public function __invoke(SelectQuery $query, string $condition, array $values, array $criteria, array $options): SelectQuery
{
$filter = $this->buildFilter($condition, $values, $criteria, $options);
if (!empty($filter)) {
diff --git a/src/Model/Filter/Criterion/NumericCriterion.php b/src/Model/Filter/Criterion/NumericCriterion.php
index 461f8ef..932c7a9 100644
--- a/src/Model/Filter/Criterion/NumericCriterion.php
+++ b/src/Model/Filter/Criterion/NumericCriterion.php
@@ -10,7 +10,7 @@
use Cake\Database\Expression\QueryExpression;
use Cake\Database\ExpressionInterface;
-use Cake\ORM\Query;
+use Cake\ORM\Query\SelectQuery;
use CakeDC\SearchFilter\Filter\AbstractFilter;
class NumericCriterion extends BaseCriterion
@@ -40,14 +40,14 @@ public function isApplicable(mixed $value, string $condition): bool
/**
* Finder method
*
- * @param \Cake\ORM\Query<\Cake\Datasource\EntityInterface> $query
+ * @param \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface> $query
* @param string $condition
* @param array $values
* @param array $criteria
* @param array $options
- * @return \Cake\ORM\Query<\Cake\Datasource\EntityInterface>
+ * @return \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface>
*/
- public function __invoke(Query $query, string $condition, array $values, array $criteria, array $options): Query
+ public function __invoke(SelectQuery $query, string $condition, array $values, array $criteria, array $options): SelectQuery
{
$filter = $this->buildFilter($condition, $values, $criteria, $options);
if (!empty($filter)) {
@@ -67,7 +67,7 @@ public function buildFilter(string $condition, array $values, array $criteria, a
if ($condition == AbstractFilter::COND_BETWEEN) {
$from = $this->getValues('from', $condition, $values);
$to = $this->getValues('to', $condition, $values);
- if ($this->isApplicable($from, $condition) & $this->isApplicable($to, $condition)) {
+ if ($this->isApplicable($from, $condition) && $this->isApplicable($to, $condition)) {
$filter = function (QueryExpression $exp) use ($fieldName, $from, $to): QueryExpression {
return $exp->between($fieldName, $from, $to, 'integer');
};
diff --git a/src/Model/Filter/Criterion/OrCriterion.php b/src/Model/Filter/Criterion/OrCriterion.php
index b77315d..a6082d7 100644
--- a/src/Model/Filter/Criterion/OrCriterion.php
+++ b/src/Model/Filter/Criterion/OrCriterion.php
@@ -9,7 +9,7 @@
namespace CakeDC\SearchFilter\Model\Filter\Criterion;
use Cake\Database\Expression\QueryExpression;
-use Cake\ORM\Query;
+use Cake\ORM\Query\SelectQuery;
class OrCriterion extends BaseCriterion
{
@@ -31,14 +31,14 @@ public function __construct(array $criteria)
/**
* Finder method
*
- * @param \Cake\ORM\Query<\Cake\Datasource\EntityInterface> $query
+ * @param \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface> $query
* @param string $condition
* @param array $values
* @param array $criteria
* @param array $options
- * @return \Cake\ORM\Query<\Cake\Datasource\EntityInterface>
+ * @return \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface>
*/
- public function __invoke(Query $query, string $condition, array $values, array $criteria, array $options): Query
+ public function __invoke(SelectQuery $query, string $condition, array $values, array $criteria, array $options): SelectQuery
{
$filters = $this->buildFilter($condition, $values, $criteria, $options);
if (!empty($filters)) {
diff --git a/src/Model/Filter/Criterion/StringCriterion.php b/src/Model/Filter/Criterion/StringCriterion.php
index 136a0e7..5898106 100644
--- a/src/Model/Filter/Criterion/StringCriterion.php
+++ b/src/Model/Filter/Criterion/StringCriterion.php
@@ -9,7 +9,7 @@
namespace CakeDC\SearchFilter\Model\Filter\Criterion;
use Cake\Database\ExpressionInterface;
-use Cake\ORM\Query;
+use Cake\ORM\Query\SelectQuery;
class StringCriterion extends BaseCriterion
{
@@ -38,14 +38,14 @@ public function isApplicable(mixed $value, string $condition): bool
/**
* Finder method
*
- * @param \Cake\ORM\Query<\Cake\Datasource\EntityInterface> $query
+ * @param \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface> $query
* @param string $condition
* @param array $values
* @param array $criteria
* @param array $options
- * @return \Cake\ORM\Query<\Cake\Datasource\EntityInterface>
+ * @return \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface>
*/
- public function __invoke(Query $query, string $condition, array $values, array $criteria, array $options): Query
+ public function __invoke(SelectQuery $query, string $condition, array $values, array $criteria, array $options): SelectQuery
{
$filter = $this->buildFilter($condition, $values, $criteria, $options);
if (!empty($filter)) {
diff --git a/tests/Fixture/ArticlesFixture.php b/tests/Fixture/ArticlesFixture.php
index 209416d..37b0069 100644
--- a/tests/Fixture/ArticlesFixture.php
+++ b/tests/Fixture/ArticlesFixture.php
@@ -20,7 +20,7 @@ class ArticlesFixture extends TestFixture
*
* @var array
*/
- public $records = [
+ public array $records = [
['author_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y'],
['author_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y'],
['author_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y'],
diff --git a/tests/Fixture/ArticlesTagsFixture.php b/tests/Fixture/ArticlesTagsFixture.php
index 57ca343..9db6254 100644
--- a/tests/Fixture/ArticlesTagsFixture.php
+++ b/tests/Fixture/ArticlesTagsFixture.php
@@ -20,7 +20,7 @@ class ArticlesTagsFixture extends TestFixture
*
* @var array
*/
- public $records = [
+ public array $records = [
['article_id' => 1, 'tag_id' => 1],
['article_id' => 1, 'tag_id' => 2],
['article_id' => 2, 'tag_id' => 1],
diff --git a/tests/Fixture/AuthorsFixture.php b/tests/Fixture/AuthorsFixture.php
index 6af1287..db5bfec 100644
--- a/tests/Fixture/AuthorsFixture.php
+++ b/tests/Fixture/AuthorsFixture.php
@@ -20,7 +20,7 @@ class AuthorsFixture extends TestFixture
*
* @var array
*/
- public $records = [
+ public array $records = [
['name' => 'evgeny'],
['name' => 'mark'],
['name' => 'larry'],
diff --git a/tests/Fixture/TagsFixture.php b/tests/Fixture/TagsFixture.php
index e1ff9de..d033c95 100644
--- a/tests/Fixture/TagsFixture.php
+++ b/tests/Fixture/TagsFixture.php
@@ -20,7 +20,7 @@ class TagsFixture extends TestFixture
*
* @var array
*/
- public $records = [
+ public array $records = [
['name' => 'tag1'],
['name' => 'tag2'],
['name' => 'tag3'],
diff --git a/tests/TestCase/Controller/ArticlesControllerTest.php b/tests/TestCase/Controller/ArticlesControllerTest.php
index 094f736..131bfd1 100644
--- a/tests/TestCase/Controller/ArticlesControllerTest.php
+++ b/tests/TestCase/Controller/ArticlesControllerTest.php
@@ -10,7 +10,7 @@ class ArticlesControllerTest extends TestCase
{
use IntegrationTestTrait;
- protected $fixtures = [
+ protected array $fixtures = [
'plugin.CakeDC/SearchFilter.Articles',
'plugin.CakeDC/SearchFilter.Authors',
];
diff --git a/tests/TestCase/ManagerTest.php b/tests/TestCase/ManagerTest.php
index c75c007..c4635b3 100644
--- a/tests/TestCase/ManagerTest.php
+++ b/tests/TestCase/ManagerTest.php
@@ -17,6 +17,7 @@
use CakeDC\SearchFilter\Filter\FilterRegistry;
use CakeDC\SearchFilter\Manager;
use CakeDC\SearchFilter\Model\Filter\Criterion\CriteriaBuilder;
+use ReflectionClass;
class ManagerTest extends TestCase
{
@@ -74,7 +75,7 @@ public function testLoadFilter(): void
$mockRegistry = $this->createMock(FilterRegistry::class);
$mockRegistry->method('load')->willReturn($mockFilter);
- $reflectionManager = new \ReflectionClass($this->manager);
+ $reflectionManager = new ReflectionClass($this->manager);
$filtersProperty = $reflectionManager->getProperty('_filters');
$filtersProperty->setAccessible(true);
$filtersProperty->setValue($this->manager, $mockRegistry);
diff --git a/tests/TestCase/Model/Filter/CriteriaFilterTest.php b/tests/TestCase/Model/Filter/CriteriaFilterTest.php
index 2ec74ee..fe1003a 100644
--- a/tests/TestCase/Model/Filter/CriteriaFilterTest.php
+++ b/tests/TestCase/Model/Filter/CriteriaFilterTest.php
@@ -25,7 +25,7 @@ class CriteriaFilterTest extends TestCase
*
* @var array
*/
- protected $fixtures = [
+ protected array $fixtures = [
'plugin.CakeDC/SearchFilter.Articles',
'plugin.CakeDC/SearchFilter.Authors',
];
diff --git a/tests/TestCase/Model/Filter/Criterion/DateCriterionTest.php b/tests/TestCase/Model/Filter/Criterion/DateCriterionTest.php
index 876f482..9bafc45 100644
--- a/tests/TestCase/Model/Filter/Criterion/DateCriterionTest.php
+++ b/tests/TestCase/Model/Filter/Criterion/DateCriterionTest.php
@@ -10,7 +10,7 @@
use Cake\Database\Expression\QueryExpression;
use Cake\Database\ValueBinder;
-use Cake\I18n\FrozenDate;
+use Cake\I18n\Date;
use Cake\TestSuite\TestCase;
use CakeDC\SearchFilter\Filter\AbstractFilter;
use CakeDC\SearchFilter\Model\Filter\Criterion\DateCriterion;
@@ -288,8 +288,8 @@ public function testBuildBetweenFilter(): void
$bindings = $valueBinder->bindings();
$this->assertArrayHasKey(':c0', $bindings);
$this->assertArrayHasKey(':c1', $bindings);
- $this->assertEquals(new FrozenDate('2023-05-01'), $bindings[':c0']['value']);
- $this->assertEquals(new FrozenDate('2023-05-31'), $bindings[':c1']['value']);
+ $this->assertEquals(new Date('2023-05-01'), $bindings[':c0']['value']);
+ $this->assertEquals(new Date('2023-05-31'), $bindings[':c1']['value']);
}
/**
diff --git a/tests/TestCase/Model/Filter/Criterion/DateTimeCriterionTest.php b/tests/TestCase/Model/Filter/Criterion/DateTimeCriterionTest.php
index 9acc3fb..8d3162f 100644
--- a/tests/TestCase/Model/Filter/Criterion/DateTimeCriterionTest.php
+++ b/tests/TestCase/Model/Filter/Criterion/DateTimeCriterionTest.php
@@ -10,7 +10,7 @@
use Cake\Database\Expression\QueryExpression;
use Cake\Database\ValueBinder;
-use Cake\I18n\FrozenDate;
+use Cake\I18n\DateTime;
use Cake\TestSuite\TestCase;
use CakeDC\SearchFilter\Filter\AbstractFilter;
use CakeDC\SearchFilter\Model\Filter\Criterion\DateTimeCriterion;
@@ -181,8 +181,8 @@ public function testBuildBetweenFilter(): void
$sql = $modifiedExpression->sql($valueBinder);
$this->assertStringContainsString('test_datetime BETWEEN :c0 AND :c1', $sql);
- $this->assertEquals(new FrozenDate('2023-05-01 00:00'), $valueBinder->bindings()[':c0']['value']);
- $this->assertEquals(new FrozenDate('2023-05-31 00:00'), $valueBinder->bindings()[':c1']['value']);
+ $this->assertEquals(new DateTime('2023-05-01 00:00'), $valueBinder->bindings()[':c0']['value']);
+ $this->assertEquals(new DateTime('2023-05-31 00:00'), $valueBinder->bindings()[':c1']['value']);
}
/**
diff --git a/tests/TestCase/Model/Filter/Criterion/LookupCriterionTest.php b/tests/TestCase/Model/Filter/Criterion/LookupCriterionTest.php
index b6e30fa..eafd4fb 100644
--- a/tests/TestCase/Model/Filter/Criterion/LookupCriterionTest.php
+++ b/tests/TestCase/Model/Filter/Criterion/LookupCriterionTest.php
@@ -21,7 +21,7 @@ class LookupCriterionTest extends TestCase
*
* @var array
*/
- protected $fixtures = [
+ protected array $fixtures = [
'plugin.CakeDC/SearchFilter.Articles',
'plugin.CakeDC/SearchFilter.Authors',
];
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 1820505..a2477f7 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -1,58 +1,63 @@
'CakeDC\SearchFilter\Test\App',
'encoding' => 'UTF-8',
+ 'debug' => true,
'paths' => [
- 'templates' => [TEST_APP . 'templates' . DS],
+ // 'plugins' => [ROOT . 'Plugin' . DS],
+ 'templates' => [ROOT . 'templates' . DS],
],
]);
+
+Configure::write('App.encoding', 'utf8');
Configure::write('debug', true);
@mkdir(TMP . 'cache/models', 0777);
@@ -84,13 +89,6 @@
'defaults' => 'php',
]);
-Plugin::getCollection()->add(new \CakeDC\SearchFilter\Plugin([
- 'path' => dirname(dirname(__FILE__)) . DS,
- 'routes' => true,
-]));
-
-Configure::write('App.encoding', 'utf8');
-
// Ensure default test connection is defined
if (!getenv('db_dsn')) {
putenv('db_dsn=sqlite:///:memory:');
@@ -101,17 +99,16 @@
'timezone' => 'UTC',
]);
-// Create test database schema
+// Load routes
+// require CONFIG . 'routes.php';
+
+// Load schema
if (env('FIXTURE_SCHEMA_METADATA')) {
$loader = new SchemaLoader();
$loader->loadInternalFile(env('FIXTURE_SCHEMA_METADATA'));
}
-$error = [
- 'errorLevel' => E_ALL,
- 'skipLog' => [],
- 'log' => true,
- 'trace' => true,
- 'ignoredDeprecationPaths' => [],
-];
-(new ErrorTrap($error))->register();
+// Ensure The Plugins are loaded
+Configure::write('Plugin.CakeDC/SearchFilter', [
+ 'path' => dirname(dirname(__FILE__)) . DS,
+]);
diff --git a/tests/test_app/App/Application.php b/tests/test_app/App/Application.php
index cf1d4f8..0f7ea71 100644
--- a/tests/test_app/App/Application.php
+++ b/tests/test_app/App/Application.php
@@ -8,10 +8,14 @@
namespace CakeDC\SearchFilter\Test\App;
+use Cake\Error\Middleware\ErrorHandlerMiddleware;
use Cake\Http\BaseApplication;
use Cake\Http\MiddlewareQueue;
+use Cake\Routing\Middleware\AssetMiddleware;
+use Cake\Routing\Middleware\RoutingMiddleware;
use Cake\Routing\Route\DashedRoute;
use Cake\Routing\RouteBuilder;
+use Cake\Routing\Router;
/**
* Application setup class.
@@ -42,11 +46,11 @@ public function bootstrap(): void
*/
public function middleware(MiddlewareQueue $middleware): MiddlewareQueue
{
- \Cake\Routing\Router::reload();
+ Router::reload();
$middleware
- ->add(new \Cake\Error\Middleware\ErrorHandlerMiddleware())
- ->add(new \Cake\Routing\Middleware\AssetMiddleware())
- ->add(new \Cake\Routing\Middleware\RoutingMiddleware($this));
+ ->add(new ErrorHandlerMiddleware())
+ ->add(new AssetMiddleware())
+ ->add(new RoutingMiddleware($this));
return $middleware;
}
diff --git a/tests/test_app/App/Controller/ArticlesController.php b/tests/test_app/App/Controller/ArticlesController.php
index c83a716..5e1802e 100644
--- a/tests/test_app/App/Controller/ArticlesController.php
+++ b/tests/test_app/App/Controller/ArticlesController.php
@@ -9,6 +9,7 @@
namespace CakeDC\SearchFilter\Test\App\Controller;
use CakeDC\SearchFilter\Manager;
+use stdClass;
/**
* Articles Controller
@@ -56,7 +57,7 @@ public function index()
$collection->add('search', $manager->filters()
->new('string')
- ->setConditions(new \stdClass())
+ ->setConditions(new stdClass())
->setLabel('Search...'));
$collection->add('name', $manager->filters()
@@ -88,7 +89,7 @@ public function index()
]);
$filters = $manager->formatFinders($search);
- $query = $query->find('filters', $filters);
+ $query = $query->find('filters', params: $filters);
}
$query = $this->Filter->prg($query);