Skip to content

Commit

Permalink
test: add phpat architecture tests (#207)
Browse files Browse the repository at this point in the history
* test: add phpat architecture tests

* weblink to web-link

* remove psr/container from api-platform package

* remove flex

* provide

* cs
  • Loading branch information
priyadi authored Sep 11, 2024
1 parent 1b2df52 commit 29247fd
Show file tree
Hide file tree
Showing 17 changed files with 340 additions and 39 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

# 0.18.0

* test: add phpat architecture tests

# 0.17.5

* fix: `RekapagerLinkProcessor` was added to the wrong package
Expand Down
35 changes: 20 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "rekalogika/rekapager",
"description": "Pagination library for PHP, supporting both offset-based and keyset-based pagination.",
"homepage": "https://rekalogika.dev/rekapager",
"license": "MIT",
"type": "library",
"authors": [
{
"name": "Priyadi Iman Nurcahyo",
"email": "[email protected]"
}
],
"type": "library",
"homepage": "https://rekalogika.dev/rekapager",
"require": {
"php": "^8.2",
"api-platform/core": "^3.2",
Expand All @@ -27,6 +27,7 @@
"symfony/routing": "^6.4 || ^7.0",
"symfony/serializer": "^6.4 || ^7.0",
"symfony/stimulus-bundle": "^2.16",
"symfony/web-link": "^6.4 || ^7.0",
"twig/twig": "^3.8"
},
"require-dev": {
Expand All @@ -37,6 +38,7 @@
"ekino/phpstan-banned-code": "^1.0 || ^2.0",
"fakerphp/faker": "^1.23",
"graviton/link-header-rel-parser": "^1.0",
"phpat/phpat": "^0.10.18",
"phpstan/phpstan": "^1.10.66 || ^1.11",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpstan/phpstan-phpunit": "^1.3",
Expand Down Expand Up @@ -70,6 +72,20 @@
"vimeo/psalm": "^5.15",
"zenstruck/foundry": "1.37.*"
},
"replace": {
"rekalogika/rekapager-adapter-common": "0.17.5",
"rekalogika/rekapager-api-platform": "0.17.5",
"rekalogika/rekapager-bundle": "0.17.5",
"rekalogika/rekapager-contracts": "0.17.5",
"rekalogika/rekapager-core": "0.17.5",
"rekalogika/rekapager-doctrine-collections-adapter": "0.17.5",
"rekalogika/rekapager-doctrine-dbal-adapter": "0.17.5",
"rekalogika/rekapager-doctrine-orm-adapter": "0.17.5",
"rekalogika/rekapager-keyset-pagination": "0.17.5",
"rekalogika/rekapager-offset-pagination": "0.17.5",
"rekalogika/rekapager-pagerfanta-adapter": "0.17.5",
"rekalogika/rekapager-symfony-bridge": "0.17.5"
},
"autoload": {
"psr-4": {
"Rekalogika\\Contracts\\Rekapager\\": "packages/rekapager-contracts/src/",
Expand Down Expand Up @@ -98,18 +114,7 @@
"symfony/flex": false
}
},
"replace": {
"rekalogika/rekapager-adapter-common": "0.17.5",
"rekalogika/rekapager-api-platform": "0.17.5",
"rekalogika/rekapager-bundle": "0.17.5",
"rekalogika/rekapager-contracts": "0.17.5",
"rekalogika/rekapager-core": "0.17.5",
"rekalogika/rekapager-doctrine-collections-adapter": "0.17.5",
"rekalogika/rekapager-doctrine-dbal-adapter": "0.17.5",
"rekalogika/rekapager-doctrine-orm-adapter": "0.17.5",
"rekalogika/rekapager-keyset-pagination": "0.17.5",
"rekalogika/rekapager-offset-pagination": "0.17.5",
"rekalogika/rekapager-pagerfanta-adapter": "0.17.5",
"rekalogika/rekapager-symfony-bridge": "0.17.5"
"provide": {
"symfony/flex": "*"
}
}
3 changes: 2 additions & 1 deletion packages/rekapager-adapter-common/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"require": {
"php": "^8.2",
"doctrine/collections": "^2.2"
"doctrine/collections": "^2.2",
"rekalogika/rekapager-contracts": "^0.17.5"
}
}
7 changes: 5 additions & 2 deletions packages/rekapager-api-platform/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@
"require": {
"php": "^8.2",
"api-platform/core": "^3.2",
"psr/container": "^2.0",
"rekalogika/rekapager-contracts": "^0.17.5",
"rekalogika/rekapager-core": "^0.17.5",
"rekalogika/rekapager-doctrine-orm-adapter": "^0.17.5",
"rekalogika/rekapager-keyset-pagination": "^0.17.5",
"rekalogika/rekapager-symfony-bridge": "^0.17.5",
"symfony/config": "^6.4 || ^7.0",
"symfony/dependency-injection": "^6.4 || ^7.0",
"symfony/flex": "^2.4",
"symfony/http-foundation": "^6.4 || ^7.0",
"symfony/http-kernel": "^6.4 || ^7.0"
"symfony/http-kernel": "^6.4 || ^7.0",
"symfony/serializer": "^6.4 || ^7.0",
"symfony/web-link": "^6.4 || ^7.0"
}
}
23 changes: 13 additions & 10 deletions packages/rekapager-api-platform/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* that was distributed with this source code.
*/

use Doctrine\ORM\QueryBuilder;
use Rekalogika\Rekapager\ApiPlatform\Implementation\PagerFactory;
use Rekalogika\Rekapager\ApiPlatform\Implementation\PagerNormalizer;
use Rekalogika\Rekapager\ApiPlatform\Implementation\RekapagerExtension;
Expand Down Expand Up @@ -59,14 +60,16 @@
'$collectionNormalizer' => service('.inner'),
]);

$services
->set('rekalogika.rekapager.api_platform.orm.extension')
->class(RekapagerExtension::class)
->args([
'$pagerFactory' => service(PagerFactoryInterface::class),
'$pagination' => service('api_platform.pagination'),
])
->tag('api_platform.doctrine.orm.query_extension.collection', [
'priority' => -48,
]);
if (class_exists(QueryBuilder::class)) {
$services
->set('rekalogika.rekapager.api_platform.orm.extension')
->class(RekapagerExtension::class)
->args([
'$pagerFactory' => service(PagerFactoryInterface::class),
'$pagination' => service('api_platform.pagination'),
])
->tag('api_platform.doctrine.orm.query_extension.collection', [
'priority' => -48,
]);
}
};
1 change: 0 additions & 1 deletion packages/rekapager-bundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"symfony/http-foundation": "^6.4 || ^7.0",
"symfony/http-kernel": "^6.4 || ^7.0",
"symfony/routing": "^6.4 || ^7.0",
"symfony/serializer": "^6.4 || ^7.0",
"symfony/stimulus-bundle": "^2.16"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Rekalogika\Rekapager\Bundle\DependencyInjection;

use Rekalogika\Contracts\Rekapager\Exception\InvalidArgumentException;
use Rekalogika\Contracts\Rekapager\PageIdentifierEncoderInterface;
use Rekalogika\Rekapager\Symfony\RekapagerSymfonyBridge;
use Symfony\Component\AssetMapper\AssetMapperInterface;
Expand Down Expand Up @@ -61,17 +62,17 @@ public function load(array $configs, ContainerBuilder $container): void

$defaultTwigTemplate = $config['default_template'] ?? null;
if (null === $defaultTwigTemplate || !\is_string($defaultTwigTemplate)) {
throw new \InvalidArgumentException('The "default_template" config is required.');
throw new InvalidArgumentException('The "default_template" config is required.');
}

$defaultPageParameterName = $config['default_page_parameter_name'] ?? null;
if (null === $defaultPageParameterName || !\is_string($defaultPageParameterName)) {
throw new \InvalidArgumentException('The "default_page_parameter_name" config is required.');
throw new InvalidArgumentException('The "default_page_parameter_name" config is required.');
}

$defaultProximity = $config['default_proximity'] ?? null;
if (null === $defaultProximity || !\is_int($defaultProximity)) {
throw new \InvalidArgumentException('The "default_proximity" config is required.');
throw new InvalidArgumentException('The "default_proximity" config is required.');
}

$container->setParameter(
Expand Down
5 changes: 3 additions & 2 deletions packages/rekapager-bundle/src/PagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Rekalogika\Rekapager\Bundle;

use Rekalogika\Contracts\Rekapager\Exception\InvalidArgumentException;
use Rekalogika\Contracts\Rekapager\Exception\OutOfBoundsException as ContractsOutOfBoundsException;
use Rekalogika\Contracts\Rekapager\PageableInterface;
use Rekalogika\Rekapager\Bundle\Contracts\PagerFactoryInterface;
Expand Down Expand Up @@ -61,13 +62,13 @@ public function createPager(
// routeName
$routeName = $options?->getRouteName() ?? $request->attributes->get('_route');
if (!\is_string($routeName)) {
throw new \InvalidArgumentException('Cannot determine route name from request.');
throw new InvalidArgumentException('Cannot determine route name from request.');
}

// routeParams
$routeParams = $options?->getRouteParams() ?? $request->attributes->get('_route_params', []);
if (!\is_array($routeParams)) {
throw new \InvalidArgumentException('Cannot determine route parameters from request.');
throw new InvalidArgumentException('Cannot determine route parameters from request.');
}

// urlReferenceType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"php": "^8.2",
"doctrine/collections": "^2.2",
"rekalogika/rekapager-adapter-common": "^0.17.5",
"rekalogika/rekapager-contracts": "^0.17.5",
"rekalogika/rekapager-keyset-pagination": "^0.17.5",
"rekalogika/rekapager-offset-pagination": "^0.17.5"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ class UnsupportedCollectionItemException extends UnexpectedValueException
{
public function __construct(string $type, \Throwable $previous)
{
parent::__construct(\sprintf('Unsupported collection type. The items in the collection must be objects or arrays, an %s was given.', $type), 0, $previous);
parent::__construct(\sprintf('Unsupported collection type. The items in the collection must be objects or arrays, %s was given.', $type), 0, $previous);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Rekalogika\Rekapager\Doctrine\Collections\Internal;

use Doctrine\Common\Collections\Expr\ClosureExpressionVisitor;
use Rekalogika\Contracts\Rekapager\Exception\LogicException;
use Rekalogika\Contracts\Rekapager\Exception\NullBoundaryValueException;
use Rekalogika\Rekapager\Keyset\Contracts\KeysetItemInterface;

Expand Down Expand Up @@ -42,7 +43,7 @@ public function __construct(
private array $boundaryProperties,
) {
if (!\is_object($value) && !\is_array($value)) {
throw new \LogicException('The value must be an object or an array');
throw new LogicException('The value must be an object or an array');
}

$this->objectOrArrayValue = $value;
Expand Down
1 change: 1 addition & 0 deletions packages/rekapager-doctrine-dbal-adapter/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"doctrine/dbal": "^3.8 || ^4.0",
"doctrine/collections": "^2.2",
"rekalogika/rekapager-adapter-common": "^0.17.5",
"rekalogika/rekapager-contracts": "^0.17.5",
"rekalogika/rekapager-keyset-pagination": "^0.17.5",
"rekalogika/rekapager-offset-pagination": "^0.17.5"
}
Expand Down
1 change: 1 addition & 0 deletions packages/rekapager-doctrine-orm-adapter/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"doctrine/orm": "^2.19 || ^3.0",
"doctrine/collections": "^2.2",
"rekalogika/rekapager-adapter-common": "^0.17.5",
"rekalogika/rekapager-contracts": "^0.17.5",
"rekalogika/rekapager-keyset-pagination": "^0.17.5",
"rekalogika/rekapager-offset-pagination": "^0.17.5"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,9 @@ private function detectTypeByHeuristics(object $value): string|null
return Types::DATETIME_MUTABLE;
} elseif ($value instanceof \DateTimeImmutable) {
return Types::DATETIME_IMMUTABLE;
} elseif ($value instanceof Uuid) {
} elseif ($value instanceof Uuid && class_exists(UuidType::class)) {
return UuidType::NAME;
} elseif ($value instanceof Ulid) {
} elseif ($value instanceof Ulid && class_exists(UlidType::class)) {
return UlidType::NAME;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Rekalogika\Rekapager\Symfony\Batch\Internal;

use Rekalogika\Contracts\Rekapager\Exception\LogicException;
use Rekalogika\Contracts\Rekapager\PageInterface;
use Rekalogika\Rekapager\Batch\BatchProcessorDecorator;
use Rekalogika\Rekapager\Batch\BatchProcessorInterface;
Expand Down Expand Up @@ -85,7 +86,7 @@ private function formatTime(\DateTimeInterface $time): string
private function getStartTime(): \DateTimeInterface
{
if ($this->startTime === null) {
throw new \LogicException('Start time is not set');
throw new LogicException('Start time is not set');
}

return $this->startTime;
Expand Down
7 changes: 7 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@ includes:
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
- vendor/bnf/phpstan-psr-container/extension.neon
- vendor/ekino/phpstan-banned-code/extension.neon
- vendor/phpat/phpat/extension.neon
- phar://phpstan.phar/conf/bleedingEdge.neon

services:
-
class: Rekalogika\Rekapager\Tests\ArchitectureTests\ArchitectureTest
tags:
- phpat.test
Loading

0 comments on commit 29247fd

Please sign in to comment.