From c2382db83cb77242f627a12f7ece47397606c39d Mon Sep 17 00:00:00 2001 From: Yanick Witschi Date: Tue, 7 May 2024 13:17:39 +0200 Subject: [PATCH] Fix CI --- .github/workflows/ci.yml | 7 ++++--- composer.json | 5 +++-- src/DcaRelationsManager.php | 15 +++++++-------- .../DcaDateRangeFilterListener.php | 3 ++- src/EventListener/InsertTagsListener.php | 19 +++++++++++-------- src/Form/Form.php | 16 ++++++++++------ tests/CodefogHasteBundleTest.php | 2 +- tests/Fixtures/DataContainer.php | 15 +++++++++++++++ tests/Fixtures/Entity.php | 2 +- tests/Fixtures/Input.php | 2 +- tests/Fixtures/Model.php | 4 ++-- tests/Fixtures/PageModel.php | 2 +- tests/Fixtures/System.php | 13 ------------- tests/Fixtures/Widget.php | 2 +- tests/Form/FormTest.php | 15 +++++++++++---- tests/StringParserTest.php | 6 +++--- tests/UrlParserTest.php | 6 +++--- tests/Util/ArrayPositionTest.php | 2 +- 18 files changed, 77 insertions(+), 59 deletions(-) delete mode 100644 tests/Fixtures/System.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d8259b..bd9795b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,12 +4,13 @@ on: [push] jobs: tests: - name: PHP ${{ matrix.php }} + name: 'PHP ${{ matrix.php }} (Composer Flags: ${{ matrix.composer }})' runs-on: ubuntu-latest strategy: fail-fast: false matrix: - php: [8.1] + php: [8.1, 8.2, 8.3] + composer: ['--prefer-stable', '--prefer-lowest'] steps: - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -22,7 +23,7 @@ jobs: uses: actions/checkout@v3 - name: Install the dependencies - run: composer install --no-interaction --no-progress + run: composer update --no-interaction --no-suggest ${{ matrix.composer }} - name: Run the unit tests run: vendor/bin/phpunit --colors=always diff --git a/composer.json b/composer.json index 29e9b48..dd8098f 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ }, "autoload-dev": { "psr-4": { - "Codefog\\Hastebundle\\Tests\\": "tests/" + "Codefog\\HasteBundle\\Tests\\": "tests/" } }, "extra": { @@ -49,7 +49,8 @@ "allow-plugins": { "contao-components/installer": true, "contao/manager-plugin": true, - "php-http/discovery": false + "php-http/discovery": false, + "terminal42/contao-build-tools": true } }, "scripts": { diff --git a/src/DcaRelationsManager.php b/src/DcaRelationsManager.php index 2e4fa2b..e921e78 100644 --- a/src/DcaRelationsManager.php +++ b/src/DcaRelationsManager.php @@ -36,16 +36,16 @@ class DcaRelationsManager private array $searchableFields = []; /** - * This cache stores the table and record ID that has been already purged. - * It allows you to have multiple fields with the same relation in one DCA - * and prevents the earlier field values to be removed by the last one - * (the helper table is purged only once in this case, for the first field). + * This cache stores the table and record ID that has been already purged. It + * allows you to have multiple fields with the same relation in one DCA and + * prevents the earlier field values to be removed by the last one (the helper + * table is purged only once in this case, for the first field). */ private array $purgeCache = []; /** - * This cache is in fact a hotfix for the "override all" mode. It simply - * does not allow the last record to be double-saved. + * This cache is in fact a hotfix for the "override all" mode. It simply does not + * allow the last record to be double-saved. */ private array $overrideAllCache = []; @@ -848,8 +848,7 @@ public function getRelation(string $table, string $fieldName): array|null /** * Get the relations table name in the following format (sorted alphabetically): - * Parameters: tl_table_one, tl_table_two - * Returned value: tl_table_one_table_two. + * Parameters: tl_table_one, tl_table_two Returned value: tl_table_one_table_two. */ public function getTableName(string $tableOne, string $tableTwo): string { diff --git a/src/EventListener/DcaDateRangeFilterListener.php b/src/EventListener/DcaDateRangeFilterListener.php index 45cee74..1112dd6 100644 --- a/src/EventListener/DcaDateRangeFilterListener.php +++ b/src/EventListener/DcaDateRangeFilterListener.php @@ -118,7 +118,8 @@ public function onPanelCallback(DataContainer $dc): string } /** - * On data container load callback. Filters the records by setting sorting->root if filters are set. + * On data container load callback. Filters the records by setting sorting->root + * if filters are set. */ public function onLoadCallback(DataContainer $dc): void { diff --git a/src/EventListener/InsertTagsListener.php b/src/EventListener/InsertTagsListener.php index 90359dc..de87091 100644 --- a/src/EventListener/InsertTagsListener.php +++ b/src/EventListener/InsertTagsListener.php @@ -43,8 +43,8 @@ public function __invoke(string $tag): mixed * * Description: * - * The source_format and target_format can be any format from php date() - * or "date", "datim" or "time" to take the the format from the root page settings + * The source_format and target_format can be any format from php date() or + * "date", "datim" or "time" to take the the format from the root page settings * (or system settings, in case not defined). * * Possible use cases: @@ -84,11 +84,14 @@ private function replaceConvertedDateFormat(array $chunks): string|false * * {{formatted_datetime::timestamp}} * or - * {{formatted_datetime::timestamp::datim}} - formats a given timestamp with the global date and time (datim) format - * {{formatted_datetime::timestamp::date}} - formats a given timestamp with the global date format - * {{formatted_datetime::timestamp::time}} - formats a given timestamp with the global time format - * {{formatted_datetime::timestamp::Y-m-d H:i}} - formats a given timestamp with the specified format - * {{formatted_datetime::+1 day::Y-m-d H:i}} - formats a given php date/time format (see http://php.net/manual/en/function.strtotime.php) with the specified format + * {{formatted_datetime::timestamp::datim}} - formats a given timestamp with the + * global date and time (datim) format {{formatted_datetime::timestamp::date}} - + * formats a given timestamp with the global date format + * {{formatted_datetime::timestamp::time}} - formats a given timestamp with the + * global time format {{formatted_datetime::timestamp::Y-m-d H:i}} - formats a + * given timestamp with the specified format {{formatted_datetime::+1 day::Y-m-d + * H:i}} - formats a given php date/time format (see + * http://php.net/manual/en/function.strtotime.php) with the specified format */ private function replaceFormattedDateTime(array $chunks): string { @@ -149,7 +152,7 @@ private function replaceOptionsLabel(array $chunks): string { $value = $chunks[2]; - if (null === ($field = FormFieldModel::findByPk($chunks[1]))) { + if (null === ($field = FormFieldModel::findById($chunks[1]))) { return $value; } diff --git a/src/Form/Form.php b/src/Form/Form.php index 03d5242..b259153 100644 --- a/src/Form/Form.php +++ b/src/Form/Form.php @@ -160,7 +160,8 @@ public function getBoundEntity(): object|null } /** - * Binds a Doctrine entity to the form. If there is data, haste form will add the present values as default values. + * Binds a Doctrine entity to the form. If there is data, haste form will add the + * present values as default values. */ public function setBoundEntity(object $boundEntity, PropertyAccessor|null $propertyAccessor = null): self { @@ -176,7 +177,8 @@ public function getBoundModel(): Model|null } /** - * Binds a model instance to the form. If there is data, haste form will add the present values as default values. + * Binds a model instance to the form. If there is data, haste form will add the + * present values as default values. */ public function setBoundModel(Model $boundModel): self { @@ -585,9 +587,10 @@ public function addFieldsFromDca(string $table, callable|null $callback = null): /** * Return true if the field has "inputType" set, false otherwise. * - * This is a default callback that can be used with addFieldsFromDca() method. It prevents from adding fields - * that do not have inputType specified which would result in an exception. The fields you typically would - * like to skip are: id, tstamp, pid, sorting. + * This is a default callback that can be used with addFieldsFromDca() method. It + * prevents from adding fields that do not have inputType specified which would + * result in an exception. The fields you typically would like to skip are: id, + * tstamp, pid, sorting. */ public function skipFieldsWithoutInputType(string $fieldName, array $fieldConfig): bool { @@ -630,7 +633,8 @@ public function addFieldsFromFormGenerator(int $formId, callable|null $callback } /** - * Adds a form field from the form generator without trying to convert a DCA configuration. + * Adds a form field from the form generator without trying to convert a DCA + * configuration. */ public function addFieldFromFormGenerator(string $fieldName, array $fieldConfig, ArrayPosition|null $position = null): self { diff --git a/tests/CodefogHasteBundleTest.php b/tests/CodefogHasteBundleTest.php index 77fff3d..2a836d7 100644 --- a/tests/CodefogHasteBundleTest.php +++ b/tests/CodefogHasteBundleTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Codefog\Hastebundle\Tests; +namespace Codefog\HasteBundle\Tests; use Codefog\HasteBundle\CodefogHasteBundle; use PHPUnit\Framework\TestCase; diff --git a/tests/Fixtures/DataContainer.php b/tests/Fixtures/DataContainer.php index d9907e9..72e7868 100644 --- a/tests/Fixtures/DataContainer.php +++ b/tests/Fixtures/DataContainer.php @@ -6,4 +6,19 @@ class DataContainer { + private array $keys = []; + + public function __construct() + { + } + + public function __set($strKey, $varValue): void + { + $this->keys[$strKey] = $varValue; + } + + public function __get($strKey): mixed + { + return $this->keys[$strKey] ?? null; + } } diff --git a/tests/Fixtures/Entity.php b/tests/Fixtures/Entity.php index b86a31b..58070b8 100644 --- a/tests/Fixtures/Entity.php +++ b/tests/Fixtures/Entity.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Codefog\Hastebundle\Tests\Fixtures; +namespace Codefog\HasteBundle\Tests\Fixtures; class Entity { diff --git a/tests/Fixtures/Input.php b/tests/Fixtures/Input.php index 1ddecf1..3eef97c 100644 --- a/tests/Fixtures/Input.php +++ b/tests/Fixtures/Input.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Codefog\Hastebundle\Tests\Fixtures; +namespace Codefog\HasteBundle\Tests\Fixtures; class Input { diff --git a/tests/Fixtures/Model.php b/tests/Fixtures/Model.php index ab95e93..3c3aa77 100644 --- a/tests/Fixtures/Model.php +++ b/tests/Fixtures/Model.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Codefog\Hastebundle\Tests\Fixtures; +namespace Codefog\HasteBundle\Tests\Fixtures; class Model { @@ -18,7 +18,7 @@ public function __set(string $key, mixed $value): void $this->data[$key] = $value; } - public static function findByPk(int $id): static + public static function findById(int $id): static { $model = new static(); $model->id = $id; diff --git a/tests/Fixtures/PageModel.php b/tests/Fixtures/PageModel.php index 2436f7e..58c3ed8 100644 --- a/tests/Fixtures/PageModel.php +++ b/tests/Fixtures/PageModel.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Codefog\Hastebundle\Tests\Fixtures; +namespace Codefog\HasteBundle\Tests\Fixtures; use Contao\Model; diff --git a/tests/Fixtures/System.php b/tests/Fixtures/System.php deleted file mode 100644 index 2921e70..0000000 --- a/tests/Fixtures/System.php +++ /dev/null @@ -1,13 +0,0 @@ -createForm(false); - $pageModel = PageModel::findByPk(13); + $pageModel = PageModel::findById(13); $pageModel->pageTitle = 'My page'; $pageModel->jumpTo = 11; $form->setBoundModel($pageModel); @@ -148,6 +151,10 @@ private function createForm(bool $isSubmitted = true): Form $GLOBALS['TL_MODELS']['tl_page'] = PageModel::class; $GLOBALS['TL_FFL']['text'] = FormTextField::class; + $container = new Container(); + $container->set('request_stack', new RequestStack()); + System::setContainer($container); + return new Form('my-form-id', 'POST', static fn () => $isSubmitted); } } diff --git a/tests/StringParserTest.php b/tests/StringParserTest.php index 3341a75..2ba0761 100644 --- a/tests/StringParserTest.php +++ b/tests/StringParserTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Codefog\Hastebundle\Tests; +namespace Codefog\HasteBundle\Tests; use Codefog\HasteBundle\StringParser; use PHPUnit\Framework\TestCase; @@ -20,7 +20,7 @@ public function testFlatten(mixed $value, string $key, array $data, array $expec $this->assertSame($expected, $data); } - public function flattenDataProvider() + public static function flattenDataProvider(): iterable { return [ // String input will set key and value @@ -83,8 +83,8 @@ public function flattenDataProvider() 'foo', [], [ - 'foo_bar' => 'baz', 'foo_bar_baz' => '1', + 'foo_bar' => 'baz', 'foo' => '', ], ], diff --git a/tests/UrlParserTest.php b/tests/UrlParserTest.php index 7d733c0..de13417 100644 --- a/tests/UrlParserTest.php +++ b/tests/UrlParserTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Codefog\Hastebundle\Tests; +namespace Codefog\HasteBundle\Tests; use Codefog\HasteBundle\UrlParser; use PHPUnit\Framework\TestCase; @@ -44,7 +44,7 @@ public function testRemoveQueryStringCallback($request, $paramsToRemove, $expect $this->assertSame($expectedResult, $actualResult); } - public function addQueryStringProvider() + public static function addQueryStringProvider(): iterable { // current request -> query to add -> expected result return [ @@ -121,7 +121,7 @@ public function addQueryStringProvider() ]; } - public function removeQueryStringProvider() + public static function removeQueryStringProvider(): iterable { // current request -> query to remove -> expected result return [ diff --git a/tests/Util/ArrayPositionTest.php b/tests/Util/ArrayPositionTest.php index c165be6..4bf40bd 100644 --- a/tests/Util/ArrayPositionTest.php +++ b/tests/Util/ArrayPositionTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Codefog\Hastebundle\Tests\Util; +namespace Codefog\HasteBundle\Tests\Util; use Codefog\HasteBundle\Util\ArrayPosition; use PHPUnit\Framework\TestCase;