From 49ff3856a6a308efeb70de1fc79f11df221fe880 Mon Sep 17 00:00:00 2001 From: Unay Santisteban Date: Thu, 16 Oct 2025 13:44:03 +1000 Subject: [PATCH] Chore/Upgrade dependencies and improve test scripts --- composer.json | 19 +++++++++++-------- src/Criteria.php | 4 ++-- src/Filter.php | 2 +- src/FilterGroup.php | 6 +++--- src/Page.php | 4 ++-- tests/CriteriaTest.php | 13 ++++++++----- tests/Pest.php | 2 -- 7 files changed, 27 insertions(+), 23 deletions(-) diff --git a/composer.json b/composer.json index 783eeb4..2cad463 100644 --- a/composer.json +++ b/composer.json @@ -13,15 +13,16 @@ "require": { "php": "^8.2", "ext-json": "*", - "complex-heart/domain-model": "^4.0.0" + "complex-heart/domain-model": "^5.0.0" }, "require-dev": { "mockery/mockery": "^1.6.0", - "pestphp/pest": "^2.0", - "pestphp/pest-plugin-faker": "^2.0", - "phpstan/phpstan": "^1.12", + "pestphp/pest": "^3.8.4", + "pestphp/pest-plugin-faker": "^3.0.0", + "phpstan/phpstan": "^1.0", "phpstan/extension-installer": "^1.3", - "phpstan/phpstan-mockery": "^1.1" + "phpstan/phpstan-mockery": "^1.1", + "laravel/pint": "^1.25" }, "autoload": { "psr-4": { @@ -34,9 +35,11 @@ } }, "scripts": { - "test": "vendor/bin/pest --configuration=phpunit.xml --coverage-clover=coverage.xml --log-junit=test.xml", - "test-cov": "vendor/bin/pest --configuration=phpunit.xml --coverage-html=coverage", - "analyse": "vendor/bin/phpstan analyse --no-progress" + "test": "vendor/bin/pest --configuration=phpunit.xml --coverage --coverage-clover=coverage.xml --log-junit=test.xml", + "test-cov": "vendor/bin/pest --configuration=phpunit.xml --coverage --coverage-html=coverage", + "analyse": "vendor/bin/phpstan analyse --no-progress --memory-limit=4G", + "pint-test": "vendor/bin/pint --preset=psr12 --test", + "pint": "vendor/bin/pint --preset=psr12" }, "config": { "allow-plugins": { diff --git a/src/Criteria.php b/src/Criteria.php index 32bf587..2c70427 100644 --- a/src/Criteria.php +++ b/src/Criteria.php @@ -87,7 +87,7 @@ public static function fromSource(CriteriaSource $source): self { return self::create( groups: map( - fn(array $g): FilterGroup => FilterGroup::fromArray($g), + fn (array $g): FilterGroup => FilterGroup::fromArray($g), $source->filterGroups() ), order: Order::create($source->orderBy(), OrderType::make($source->orderType())), @@ -230,7 +230,7 @@ public function pageOffset(): int public function __toString(): string { - $groups = join('||', map(fn(FilterGroup $group): string => $group->__toString(), $this->groups)); + $groups = join('||', map(fn (FilterGroup $group): string => $group->__toString(), $this->groups)); $order = $this->order->__toString(); $page = $this->page->__toString(); diff --git a/src/Filter.php b/src/Filter.php index e98e9a2..7ee2869 100644 --- a/src/Filter.php +++ b/src/Filter.php @@ -52,7 +52,7 @@ public static function create(string $field, Operator $operator, bool|float|int| public static function fromArray(array $filter): self { // check if the array is indexed or associative. - $isIndexed = fn($source): bool => ([] !== $source) && array_keys($source) === range(0, count($source) - 1); + $isIndexed = fn ($source): bool => ([] !== $source) && array_keys($source) === range(0, count($source) - 1); return ($isIndexed($filter)) ? self::create( diff --git a/src/FilterGroup.php b/src/FilterGroup.php index 8140189..edf917d 100644 --- a/src/FilterGroup.php +++ b/src/FilterGroup.php @@ -48,7 +48,7 @@ public static function create(Filter ...$filters): self public static function fromArray(array $filters): self { return self::create( - ...map(fn(array $filter): Filter => Filter::fromArray($filter), $filters) + ...map(fn (array $filter): Filter => Filter::fromArray($filter), $filters) ); } @@ -60,7 +60,7 @@ public static function fromArray(array $filters): self */ public function addFilter(Filter $new): self { - if ($this->filter(fn(Filter $filter): bool => $filter->equals($new))->count() > 0) { + if ($this->filter(fn (Filter $filter): bool => $filter->equals($new))->count() > 0) { return $this; } @@ -196,6 +196,6 @@ public function addFilterNotContains(string $field, string $value): self */ public function __toString(): string { - return join('+', map(fn(Filter $filter): string => $filter->__toString(), $this)); + return join('+', map(fn (Filter $filter): string => $filter->__toString(), $this)); } } diff --git a/src/Page.php b/src/Page.php index 953d599..1da6eba 100644 --- a/src/Page.php +++ b/src/Page.php @@ -17,8 +17,8 @@ final class Page implements ValueObject { use IsValueObject; - const DEFAULT_LIMIT = 25; - const DEFAULT_OFFSET = 0; + public const DEFAULT_LIMIT = 25; + public const DEFAULT_OFFSET = 0; /** * Page constructor. diff --git a/tests/CriteriaTest.php b/tests/CriteriaTest.php index b0e6a63..fead0d1 100644 --- a/tests/CriteriaTest.php +++ b/tests/CriteriaTest.php @@ -12,7 +12,7 @@ use ComplexHeart\Domain\Criteria\Page; test('Criteria should be successfully created from source.', function () { - $c = Criteria::fromSource(new class implements CriteriaSource { + $c = Criteria::fromSource(new class () implements CriteriaSource { public function filterGroups(): array { return [ @@ -59,7 +59,7 @@ public function pageNumber(): int test('Criteria should throw exception for invalid filter groups.', function () { try { - Criteria::default()->withFilterGroup(fn() => [1, 2, 3]); + Criteria::default()->withFilterGroup(fn () => [1, 2, 3]); } catch (CriteriaError $e) { expect($e->violations())->toHaveCount(1); } @@ -119,11 +119,13 @@ public function pageNumber(): int test('Criteria should add or filter group to criteria object.', function () { $c = Criteria::default() - ->withFilterGroup(FilterGroup::create() + ->withFilterGroup( + FilterGroup::create() ->addFilterEqual('name', 'Vincent') ->addFilterEqual('status', 'deceased') ) - ->withFilterGroup(FilterGroup::create() + ->withFilterGroup( + FilterGroup::create() ->addFilterEqual('name', 'Jules') ->addFilterEqual('deceased', 'alive') ); @@ -137,7 +139,8 @@ public function pageNumber(): int test('Criteria should be correctly serialized to string.', function () { $c = Criteria::default() - ->withFilterGroup(FilterGroup::create() + ->withFilterGroup( + FilterGroup::create() ->addFilterEqual('name', 'Vincent') ->addFilterGreaterOrEqualThan('age', '35') ) diff --git a/tests/Pest.php b/tests/Pest.php index 5ef07f9..a32dc0c 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -38,5 +38,3 @@ | global functions to help you to reduce the number of lines of code in your test files. | */ - -