diff --git a/.github/workflows/run-test.yml b/.github/workflows/run-test.yml index 04732cf..3e70a87 100644 --- a/.github/workflows/run-test.yml +++ b/.github/workflows/run-test.yml @@ -36,7 +36,7 @@ jobs: - name: Install Dependencies run: composer install --no-scripts --no-ansi --no-interaction --no-progress - name: Run PHPUnit tests - run: vendor/bin/phpunit -v --whitelist ./src --coverage-clover ./build/logs/clover.xml src/Test + run: vendor/bin/phpunit -v --bootstrap=tests/bootstrap.php --whitelist ./src --coverage-clover ./build/logs/clover.xml tests/ - name: Run PHP Code Sniffer run: vendor/bin/phpcs -p ./src - name: Run PHPStan diff --git a/.gitignore b/.gitignore index f47660e..77a54b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# +# Roadiz +# +/pimple.json # Ignore Google webmaster tool verification /google*.html diff --git a/LICENSE.md b/LICENSE.md index 8e18fa6..d4d8a00 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright © 2024 Ambroise Maupate +Copyright © 2023 Ambroise Maupate Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/Makefile b/Makefile index 7e2ca6b..b90c2a5 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ test: - vendor/bin/phpunit -v --whitelist ./src --coverage-clover ./build/logs/clover.xml src/Test + vendor/bin/phpunit -v --bootstrap=tests/bootstrap.php --whitelist ./src --coverage-clover ./build/logs/clover.xml tests/ vendor/bin/phpcbf -p ./src vendor/bin/phpstan analyse -c phpstan.neon diff --git a/composer.json b/composer.json index caa964e..780e31a 100644 --- a/composer.json +++ b/composer.json @@ -19,13 +19,13 @@ ], "require": { "php": ">=8.1", - "doctrine/orm": "~2.19.0", + "doctrine/orm": "~2.17.0", "jms/serializer": "^3.9.0", - "symfony/string": "6.4.*", - "symfony/translation-contracts": "^3.0", - "symfony/http-foundation": "6.4.*", - "symfony/serializer": "6.4.*", - "symfony/validator": "6.4.*" + "symfony/string": "5.4.*", + "symfony/translation-contracts": "^2.3", + "symfony/http-foundation": "5.4.*", + "symfony/serializer": "5.4.*", + "symfony/validator": "5.4.*" }, "require-dev": { "phpunit/phpunit": "^9.5", @@ -46,8 +46,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3.x-dev", - "dev-develop": "2.4.x-dev" + "dev-master": "2.2.x-dev", + "dev-develop": "2.3.x-dev" } } } diff --git a/phpstan.neon b/phpstan.neon index 6b1b04b..5f1941e 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 7 + level: max paths: - src excludePaths: @@ -7,9 +7,9 @@ parameters: - */bower_components/* - */static/* ignoreErrors: - - identifier: missingType.iterableValue - - identifier: missingType.generics - '#unknown class Parsedown(Extra)?#' - '#Instantiated class Memcached not found#' - '#Instantiated class Redis not found#' reportUnmatchedIgnoredErrors: false + checkGenericClassInNonGenericObjectType: false + checkMissingIterableValueType: false diff --git a/src/Bag/LazyParameterBag.php b/src/Bag/LazyParameterBag.php index a258d5b..4e9d6cd 100644 --- a/src/Bag/LazyParameterBag.php +++ b/src/Bag/LazyParameterBag.php @@ -23,7 +23,7 @@ public function __construct() * @param mixed|null $default * @return mixed|null */ - public function get(string $key, $default = null): mixed + public function get(string $key, $default = null) { if (!$this->ready) { $this->populateParameters(); @@ -50,7 +50,7 @@ public function all(string $key = null): array * * @return bool */ - public function has(string $key): bool + public function has(string $key) { if (!$this->ready) { $this->populateParameters(); @@ -62,7 +62,7 @@ public function has(string $key): bool /** * @return array */ - public function keys(): array + public function keys() { if (!$this->ready) { $this->populateParameters(); @@ -75,7 +75,7 @@ public function keys(): array * @return \ArrayIterator */ #[\ReturnTypeWillChange] - public function getIterator(): \ArrayIterator + public function getIterator() { if (!$this->ready) { $this->populateParameters(); @@ -88,7 +88,7 @@ public function getIterator(): \ArrayIterator * @return int */ #[\ReturnTypeWillChange] - public function count(): int + public function count() { if (!$this->ready) { $this->populateParameters(); @@ -105,7 +105,7 @@ public function count(): int * * @return mixed */ - public function filter(string $key, $default = null, int $filter = \FILTER_DEFAULT, $options = []): mixed + public function filter(string $key, $default = null, int $filter = \FILTER_DEFAULT, $options = []) { if (!$this->ready) { $this->populateParameters(); diff --git a/src/Core/AbstractEntities/AbstractDateTimedPositioned.php b/src/Core/AbstractEntities/AbstractDateTimedPositioned.php new file mode 100644 index 0000000..afb2623 --- /dev/null +++ b/src/Core/AbstractEntities/AbstractDateTimedPositioned.php @@ -0,0 +1,39 @@ + - */ public function getChildren(): Collection { return $this->children; diff --git a/src/Core/Handlers/AbstractHandler.php b/src/Core/Handlers/AbstractHandler.php index d7e1fbb..fa5a708 100644 --- a/src/Core/Handlers/AbstractHandler.php +++ b/src/Core/Handlers/AbstractHandler.php @@ -8,6 +8,8 @@ abstract class AbstractHandler { + protected ObjectManager $objectManager; + /** * @return ObjectManager */ @@ -16,9 +18,22 @@ public function getObjectManager(): ObjectManager return $this->objectManager; } - public function __construct( - protected readonly ObjectManager $objectManager - ) { + /** + * @param ObjectManager $objectManager + * @return static + */ + public function setObjectManager(ObjectManager $objectManager) + { + $this->objectManager = $objectManager; + return $this; + } + + /** + * @param ObjectManager $objectManager + */ + public function __construct(ObjectManager $objectManager) + { + $this->objectManager = $objectManager; } /** diff --git a/src/Core/Handlers/HandlerFactoryInterface.php b/src/Core/Handlers/HandlerFactoryInterface.php index 0f9745b..2b0e53b 100644 --- a/src/Core/Handlers/HandlerFactoryInterface.php +++ b/src/Core/Handlers/HandlerFactoryInterface.php @@ -8,5 +8,9 @@ interface HandlerFactoryInterface { + /** + * @param AbstractEntity $entity + * @return AbstractHandler + */ public function getHandler(AbstractEntity $entity): AbstractHandler; } diff --git a/src/Test/StringHandlerTest.php b/tests/Utils/StringHandlerTest.php similarity index 71% rename from src/Test/StringHandlerTest.php rename to tests/Utils/StringHandlerTest.php index 5e15ded..1490e26 100644 --- a/src/Test/StringHandlerTest.php +++ b/tests/Utils/StringHandlerTest.php @@ -1,21 +1,52 @@ + */ use PHPUnit\Framework\TestCase; use RZ\Roadiz\Utils\StringHandler; +/** + * Class StringHandlerTest + */ class StringHandlerTest extends TestCase { + /** * @dataProvider cleanForFilenameProvider + * @param $input + * @param $expected */ - public function testCleanForFilename(string $input, string $expected): void + public function testCleanForFilename($input, $expected) { $this->assertEquals($expected, StringHandler::cleanForFilename($input)); } - public function cleanForFilenameProvider(): array + public function cleanForFilenameProvider() { return [ [ @@ -43,13 +74,16 @@ public function cleanForFilenameProvider(): array /** * @dataProvider endsWithProvider + * @param $input + * @param $wanted + * @param $expected */ - public function testEndsWith(string $input, string $wanted, bool $expected): void + public function testEndsWith($input, $wanted, $expected) { $this->assertEquals($expected, StringHandler::endsWith($input, $wanted)); } - public function endsWithProvider(): array + public function endsWithProvider() { return [ [" ", "Locale", false], @@ -69,8 +103,11 @@ public function endsWithProvider(): array /** * @dataProvider replaceLastProvider + * @param $input + * @param $wanted + * @param $expected */ - public function testReplaceLast(string $input, string $wanted, string $expected): void + public function testReplaceLast($input, $wanted, $expected) { $this->assertEquals($expected, StringHandler::replaceLast($wanted, "", $input)); } @@ -78,7 +115,7 @@ public function testReplaceLast(string $input, string $wanted, string $expected) /** * @return array */ - public function replaceLastProvider(): array + public function replaceLastProvider() { return [ ["testPage", "Locale", "testPage"], @@ -94,8 +131,10 @@ public function replaceLastProvider(): array /** * @dataProvider removeDiacriticsProvider + * @param $input + * @param $expected */ - public function testRemoveDiacritics(string $input, string $expected): void + public function testRemoveDiacritics($input, $expected) { // Assert $this->assertEquals($expected, StringHandler::removeDiacritics($input)); @@ -104,7 +143,7 @@ public function testRemoveDiacritics(string $input, string $expected): void /** * @return array */ - public function removeDiacriticsProvider(): array + public function removeDiacriticsProvider() { return [ ["à", "a"], @@ -124,8 +163,10 @@ public function removeDiacriticsProvider(): array /** * @dataProvider variablizeProvider + * @param $input + * @param $expected */ - public function testVariablize(string $input, string $expected): void + public function testVariablize($input, $expected) { // Assert $this->assertEquals($expected, StringHandler::variablize($input)); @@ -134,7 +175,7 @@ public function testVariablize(string $input, string $expected): void /** * @return array */ - public function variablizeProvider(): array + public function variablizeProvider() { return [ ["à", "a"], @@ -159,8 +200,10 @@ public function variablizeProvider(): array /** * @dataProvider classifyProvider + * @param $input + * @param $expected */ - public function testClassify(string $input, string $expected): void + public function testClassify($input, $expected) { // Assert $this->assertEquals($expected, StringHandler::classify($input)); @@ -169,7 +212,7 @@ public function testClassify(string $input, string $expected): void /** * @return array */ - public function classifyProvider(): array + public function classifyProvider() { return [ ["Ligula $* _--Egestas Mattis Nullam", "LigulaEgestasMattisNullam"], @@ -182,8 +225,10 @@ public function classifyProvider(): array /** * @dataProvider camelCaseProvider + * @param $input + * @param $expected */ - public function testCamelCase(string $input, string $expected): void + public function testCamelCase($input, $expected) { // Assert $this->assertEquals($expected, StringHandler::camelcase($input)); @@ -192,7 +237,7 @@ public function testCamelCase(string $input, string $expected): void /** * @return array */ - public function camelCaseProvider(): array + public function camelCaseProvider() { return [ ["Ligula $* _--Egestas Mattis Nullam", "ligulaEgestasMattisNullam"], @@ -205,8 +250,10 @@ public function camelCaseProvider(): array /** * @dataProvider slugifyProvider + * @param $input + * @param $expected */ - public function testSlugify(string $input, string $expected): void + public function testSlugify($input, $expected) { // Assert $this->assertEquals($expected, StringHandler::slugify($input)); @@ -215,7 +262,7 @@ public function testSlugify(string $input, string $expected): void /** * @return array */ - public function slugifyProvider(): array + public function slugifyProvider() { return [ ["Ligula $* _--Egestas Mattis Nullam$* _ ", "ligula-egestas-mattis-nullam"], @@ -239,8 +286,10 @@ public function slugifyProvider(): array /** * @dataProvider encodeWithSecretProvider + * @param $input + * @param $secret */ - public function testEncodeWithSecret(string $input, string $secret): void + public function testEncodeWithSecret($input, $secret) { $code = StringHandler::encodeWithSecret($input, $secret); @@ -251,7 +300,7 @@ public function testEncodeWithSecret(string $input, string $secret): void /** * @return array */ - public function encodeWithSecretProvider(): array + public function encodeWithSecretProvider() { return [ ["Ligula $* _--Egestas Mattis Nullam", "Commodo Pellentesque Sem Fusce Quam"], @@ -264,8 +313,10 @@ public function encodeWithSecretProvider(): array /** * @dataProvider encodeWithSecretNoSaltProvider + * @param $input + * @param $secret */ - public function testEncodeWithSecretNoSalt(string $input, string $secret): void + public function testEncodeWithSecretNoSalt($input, $secret) { $this->expectException('\\InvalidArgumentException'); @@ -278,7 +329,7 @@ public function testEncodeWithSecretNoSalt(string $input, string $secret): void /** * @return array */ - public function encodeWithSecretNoSaltProvider(): array + public function encodeWithSecretNoSaltProvider() { return [ ["Ligula $* _--Egestas Mattis Nullam", ""], diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..2e59cdf --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,36 @@ +