Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Toflar committed May 7, 2024
1 parent 3f43eea commit 76389e7
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 46 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
15 changes: 7 additions & 8 deletions src/DcaRelationsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion src/EventListener/DcaDateRangeFilterListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
19 changes: 11 additions & 8 deletions src/EventListener/InsertTagsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}

Expand Down
16 changes: 10 additions & 6 deletions src/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down
17 changes: 16 additions & 1 deletion tests/Fixtures/DataContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,23 @@

declare(strict_types=1);

namespace Codefog\HasteBundle\Tests\Fixtures;
namespace Codefog\Hastebundle\Tests\Fixtures;

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;
}
}
13 changes: 0 additions & 13 deletions tests/Fixtures/System.php

This file was deleted.

9 changes: 8 additions & 1 deletion tests/Form/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
use Codefog\Hastebundle\Tests\Fixtures\FormTextField;
use Contao\Input;
use Contao\PageModel;
use Contao\System;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\RequestStack;

class FormTest extends TestCase
{
Expand Down Expand Up @@ -119,7 +122,7 @@ public function testBoundModelDefaultValues(): void
{
$form = $this->createForm(false);

$pageModel = PageModel::findByPk(13);
$pageModel = PageModel::findById(13);
$pageModel->pageTitle = 'My page';
$pageModel->jumpTo = 11;
$form->setBoundModel($pageModel);
Expand Down Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions tests/StringParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -83,8 +83,8 @@ public function flattenDataProvider()
'foo',
[],
[
'foo_bar' => 'baz',
'foo_bar_baz' => '1',
'foo_bar' => 'baz',
'foo' => '',
],
],
Expand Down
4 changes: 2 additions & 2 deletions tests/UrlParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down Expand Up @@ -121,7 +121,7 @@ public function addQueryStringProvider()
];
}

public function removeQueryStringProvider()
public static function removeQueryStringProvider(): iterable
{
// current request -> query to remove -> expected result
return [
Expand Down

0 comments on commit 76389e7

Please sign in to comment.