Skip to content

Commit

Permalink
style: apply code styles, adapt test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
helsner committed Jun 28, 2024
1 parent c78aebf commit d8392aa
Show file tree
Hide file tree
Showing 21 changed files with 176 additions and 340 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/backend-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ on: [ push, pull_request ]

jobs:
build:
runs-on: ubuntu-latest
runs-on: self-hosted
strategy:
fail-fast: false
matrix:
php: [ '7.4', '8.1' ]
php: [ '8.1', '8.2' ]
include:
- php: '7.4'
- php: '8.1'

steps:
- name: Checkout Code
Expand Down
2 changes: 1 addition & 1 deletion Classes/Configuration/ConfigurationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace DFAU\ToujouApi\Configuration;

use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Package\PackageInterface;
use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class ConfigurationManager
Expand Down
7 changes: 4 additions & 3 deletions Classes/Database/Query/Restriction/SiteRestriction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression;
use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
use TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionInterface;
use TYPO3\CMS\Core\Database\QueryGenerator;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Site\Entity\Site;

Expand All @@ -17,8 +16,10 @@ class SiteRestriction implements QueryRestrictionInterface
/** @var int[]|null */
private $cachedSitePids;

public function __construct(private readonly PageRepository $pageRepository)
{}
public function __construct(
private readonly PageRepository $pageRepository
) {
}

public function buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder): CompositeExpression
{
Expand Down
2 changes: 1 addition & 1 deletion Classes/Deserializer/JsonApiDeserializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class JsonApiDeserializer implements Deserializer
public function collection(array $data, int $options = 0): array
{
if (isset($data['data']) && \is_array($data['data'])) {
return \array_merge(...\array_map(fn($data) => $this->item(['data' => $data], $options), $data['data']));
return \array_merge(...\array_map(fn ($data) => $this->item(['data' => $data], $options), $data['data']));
}

return [];
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Command/UnitOfWorkTcaResourceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class UnitOfWorkTcaResourceCommand implements UnitOfWorkCommand

public function __construct(array $unitOfWorkCommands)
{
$this->unitOfWorkCommands = \array_map(fn(TcaRecordReferencingCommand $command) => $command, $unitOfWorkCommands);
$this->unitOfWorkCommands = \array_map(fn (TcaRecordReferencingCommand $command) => $command, $unitOfWorkCommands);
}

public function getUnitOfWorkCommands(): array
Expand All @@ -25,7 +25,7 @@ public function getUnitOfWorkCommands(): array
public function withUnitOfWorkCommands(array $unitOfWorkCommands): UnitOfWorkCommand
{
$target = clone $this;
$target->unitOfWorkCommands = \array_map(fn(TcaRecordReferencingCommand $command) => $command, $unitOfWorkCommands);
$target->unitOfWorkCommands = \array_map(fn (TcaRecordReferencingCommand $command) => $command, $unitOfWorkCommands);

return $target;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function addCommandToDataOrCommandMap(TcaRecordReferencingCommand $com

protected function process(array $datamap = [], array $commandmap = []): array
{
if ($datamap === [] && $commandmap === []) {
if ([] === $datamap && [] === $commandmap) {
return [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function findByFiltersWithCursor(array $filters, int $limit, ?string $cur
$result = \array_map($this->createDeduplicator(), $result);
$result = \array_map($this->createOverlayMapper($context), $result);

$nextCursor = $result === [] ? null : \end($result)[$this->identifier];
$nextCursor = [] === $result ? null : \end($result)[$this->identifier];

$result = \array_map($this->createMetaMapper(), $result);

Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Repository/FileReferenceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function findByRelation(string $foreignTableName, string $foreignField, s
{
$fileReferences = $this->coreFileRepository->findByRelation($foreignTableName, $foreignField, $foreignIdentifier);

$fileReferences = \array_map(fn(FileReference $fileReference) => $fileReference->getReferenceProperties(), $fileReferences);
$fileReferences = \array_map(fn (FileReference $fileReference) => $fileReference->getReferenceProperties(), $fileReferences);

return \array_map($this->createMetaMapper(), $fileReferences);
}
Expand Down
4 changes: 2 additions & 2 deletions Classes/IncludeHandler/TcaResourceIncludeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ public function handleInclude(Scope $scope, string $includeName, $data, callable

$relationHandler = GeneralUtility::makeInstance(RelationHandler::class);
$relationHandler->start($fieldValue, $allowedTableName, $mmTableName, $uid, $this->tableName, $columnConfig);
$result = \array_filter($relationHandler->itemArray, fn($item) => $item['table'] === $allowedTableName);
$result = \array_filter($relationHandler->itemArray, fn ($item) => $item['table'] === $allowedTableName);

$resourceType = (isset($columnConfig['maxitems']) && 1 == $columnConfig['maxitems']) || (isset($columnConfig['renderType']) && 'selectSingle' === $columnConfig['renderType']) ? Item::class : Collection::class;

if ($result !== []) {
if ([] !== $result) {
$resourceDefinition = $this->resourceDefinitionsByTableName[$allowedTableName];

// Override any custom Identifier here for our database record identifier
Expand Down
2 changes: 1 addition & 1 deletion Classes/Resource/ResourceOperationToCommandMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ private function loadOperationsToCommandMapFromResourcesConfiguration(): void
return;
}
$resourcesConfiguration = ConfigurationManager::getResourcesConfiguration();
$this->commandsByResourceTypeAndOperation = \array_filter(\array_map(fn($resourceConfiguration) => $resourceConfiguration['operationToCommandMap'] ?? null, $resourcesConfiguration));
$this->commandsByResourceTypeAndOperation = \array_filter(\array_map(fn ($resourceConfiguration) => $resourceConfiguration['operationToCommandMap'] ?? null, $resourcesConfiguration));
}
}
2 changes: 1 addition & 1 deletion Classes/Schema/VisibleColumnsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public function getVisibleColumnsForResource(string $tableName, array $resource)
'databaseRow' => $resource,
]);

return \array_filter($result['columnsToProcess'], fn($columnName) => '-' !== $columnName[0]);
return \array_filter($result['columnsToProcess'], fn ($columnName) => '-' !== $columnName[0]);
}
}
4 changes: 2 additions & 2 deletions Classes/TransformHandler/TcaResourceTransformHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ protected function getVisibleAttributesOfResource(array $resource): array
'databaseRow' => $resource,
]);

$visibleColumns = \array_filter($result['columnsToProcess'], fn($columnName) => !isset($this->excludedColumns[$columnName]) && '-' !== $columnName[0]);
$visibleColumns = \array_filter($result['columnsToProcess'], fn ($columnName) => !isset($this->excludedColumns[$columnName]) && '-' !== $columnName[0]);

return \array_combine($visibleColumns, \array_map(fn($columnName) => $result['databaseRow'][$columnName] ?? null, $visibleColumns));
return \array_combine($visibleColumns, \array_map(fn ($columnName) => $result['databaseRow'][$columnName] ?? null, $visibleColumns));
}
}
16 changes: 8 additions & 8 deletions Classes/Transformer/ComposableTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ class ComposableTransformer extends TransformerAbstract implements ResourceTrans

public function __construct(array $transformHandlers, array $includeHandlers = [])
{
$this->transformHandlerStack = \array_reduce($transformHandlers, fn($next, TransformHandler $transformHandler) => $this->wrapTransformHandler($transformHandler, $next), fn($data, array $transformedData) => $transformedData);
$this->transformHandlerStack = \array_reduce($transformHandlers, fn ($next, TransformHandler $transformHandler) => $this->wrapTransformHandler($transformHandler, $next), fn ($data, array $transformedData) => $transformedData);

$this->availableIncludesStack = \array_reduce($includeHandlers, fn($next, IncludeHandler $includeHandler) => $this->wrapAvailableIncludesHandler($includeHandler, $next), fn($currentIncludes) => \array_unique(\array_merge($currentIncludes, parent::getAvailableIncludes())));
$this->availableIncludesStack = \array_reduce($includeHandlers, fn ($next, IncludeHandler $includeHandler) => $this->wrapAvailableIncludesHandler($includeHandler, $next), fn ($currentIncludes) => \array_unique(\array_merge($currentIncludes, parent::getAvailableIncludes())));

$this->defaultIncludesStack = \array_reduce($includeHandlers, fn($next, IncludeHandler $includeHandler) => $this->wrapDefaultIncludesHandler($includeHandler, $next), fn($currentIncludes) => \array_unique(\array_merge($currentIncludes, parent::getDefaultIncludes())));
$this->defaultIncludesStack = \array_reduce($includeHandlers, fn ($next, IncludeHandler $includeHandler) => $this->wrapDefaultIncludesHandler($includeHandler, $next), fn ($currentIncludes) => \array_unique(\array_merge($currentIncludes, parent::getDefaultIncludes())));

$this->includeHandlerStack = \array_reduce($includeHandlers, fn($next, IncludeHandler $includeHandler) => $this->wrapIncludeHandler($includeHandler, $next), fn(Scope $scope, $includeName, $data) => parent::callIncludeMethod($scope, $includeName, $data));
$this->includeHandlerStack = \array_reduce($includeHandlers, fn ($next, IncludeHandler $includeHandler) => $this->wrapIncludeHandler($includeHandler, $next), fn (Scope $scope, $includeName, $data) => parent::callIncludeMethod($scope, $includeName, $data));
}

public function getAvailableIncludes(): array
Expand All @@ -57,21 +57,21 @@ protected function callIncludeMethod(Scope $scope, $includeName, $data)

protected function wrapTransformHandler(TransformHandler $handler, callable $next): \Closure
{
return fn($data, array $transformedData): array => $handler->handleTransform($data, $transformedData, $next);
return fn ($data, array $transformedData): array => $handler->handleTransform($data, $transformedData, $next);
}

protected function wrapAvailableIncludesHandler(IncludeHandler $handler, callable $next): \Closure
{
return fn(array $currentIncludes): array => $handler->getAvailableIncludes($currentIncludes, $next);
return fn (array $currentIncludes): array => $handler->getAvailableIncludes($currentIncludes, $next);
}

protected function wrapDefaultIncludesHandler(IncludeHandler $handler, callable $next): \Closure
{
return fn(array $currentIncludes): array => $handler->getDefaultIncludes($currentIncludes, $next);
return fn (array $currentIncludes): array => $handler->getDefaultIncludes($currentIncludes, $next);
}

protected function wrapIncludeHandler(IncludeHandler $handler, callable $next): \Closure
{
return fn($scope, $includeName, $data): ?ResourceInterface => $handler->handleInclude($scope, $includeName, $data, $next);
return fn ($scope, $includeName, $data): ?ResourceInterface => $handler->handleInclude($scope, $includeName, $data, $next);
}
}
2 changes: 1 addition & 1 deletion Tests/Unit/JsonApiDeserializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testJsonApiDeserializer(array $result, $expectedResult): void
self::assertEquals($expectedResult, $result);
}

public function provideTestCases(): array
public static function provideTestCases(): array
{
return [
'age-groups test' => [
Expand Down
13 changes: 13 additions & 0 deletions etc/FunctionalTests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" backupGlobals="true" bootstrap="FunctionalTestsBootstrap.php" cacheResult="false" colors="true" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" beStrictAboutTestsThatDoNotTestAnything="false" failOnWarning="true" cacheDirectory=".phpunit.cache" requireCoverageMetadata="false">
<testsuites>
<testsuite name="Functional tests">
<directory>../Tests/Functional/</directory>
</testsuite>
</testsuites>
<php>
<const name="TYPO3_MODE" value="BE"/>
<ini name="display_errors" value="1"/>
<env name="TYPO3_CONTEXT" value="Testing"/>
</php>
</phpunit>
34 changes: 34 additions & 0 deletions etc/FunctionalTestsBootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

use TYPO3\TestingFramework\Core\Testbase;

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* Boilerplate for a functional test phpunit boostrap file.
*
* This file is loosely maintained within TYPO3 testing-framework, extensions
* are encouraged to not use it directly, but to copy it to an own place,
* usually in parallel to a FunctionalTests.xml file.
*
* This file is defined in FunctionalTests.xml and called by phpunit
* before instantiating the test suites.
*/
(static function () {
$testbase = new Testbase();
$testbase->defineOriginalRootPath();
$testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/tests');
$testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/transient');
})();
13 changes: 13 additions & 0 deletions etc/UnitTests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" backupGlobals="true" cacheResult="false" colors="true" processIsolation="false" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" beStrictAboutTestsThatDoNotTestAnything="false" failOnWarning="true" cacheDirectory=".phpunit.cache" requireCoverageMetadata="false">
<testsuites>
<testsuite name="Unit tests">
<directory>../Tests/Unit/</directory>
</testsuite>
</testsuites>
<php>
<const name="TYPO3_MODE" value="BE"/>
<ini name="display_errors" value="1"/>
<env name="TYPO3_CONTEXT" value="Testing"/>
</php>
</phpunit>
4 changes: 2 additions & 2 deletions etc/scripts/checkCodingStandards.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

FILTERED_FOLDERS=`find ./ -mindepth 1 -maxdepth 1 -type d | grep -Ev '.Build|Build|Resources|etc|public|logs|.phpspec|.git|vendor|.idea|var|.ddev'`
FILTERED_FOLDERS=`find ./ -mindepth 1 -maxdepth 1 -type d | grep -Ev '.Build|Build|Resources|etc|public|logs|.phpspec|.git|vendor|.idea|var'`

if [ "0" != "$(echo $?)" ]; then
echo "No php files found to lint. So technically spoken everything's fine, but please check that I haven't missed any files."
Expand All @@ -10,4 +10,4 @@ fi
SEPERATOR=" "
FOLDERS=$(printf "${SEPERATOR}%s" "${FILTERED_FOLDERS[@]}")

.Build/bin/ecs check --no-progress-bar -n -c .Build/vendor/dfau/coding-standard/ecs.php $FOLDERS $@
.Build/bin/ecs check --no-progress-bar -n -c .Build/vendor/dfau/coding-standard/ecs.php $FOLDERS $@
Loading

0 comments on commit d8392aa

Please sign in to comment.