Skip to content

Commit

Permalink
[TASK] Add testing for T3v13
Browse files Browse the repository at this point in the history
- bump dev-packages
- align code style with latest from typo3/coding-standards
  • Loading branch information
twoldanski committed Sep 20, 2024
1 parent eccba3a commit 4906fbe
Show file tree
Hide file tree
Showing 28 changed files with 190 additions and 62 deletions.
74 changes: 69 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,69 @@ jobs:
- "php:cs-fixer"
php-version:
- 8.2
tests:
testV12:
runs-on: ubuntu-latest
strategy:
max-parallel: 2
matrix:
php-versions: [8.1]
php-versions: [ 8.1, 8.2 ]
typo3-versions:
- {typo3: 12, testing: ^7.0@dev}
- { typo3: 12, testing: ^7.0, phpunit: ^9, yaml: ^6, phpcov: ^8 }

name: "Run tests with PHP ${{ matrix.php-versions }}
using TYPO3 ${{ matrix.typo3-versions.typo3 }}
with testing framework version ${{ matrix.typo3-versions.testing }}"
steps:
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: intl, mbstring, pdo_sqlite

- name: "Cache composer dependencies"
uses: actions/cache@v4
with:
path: ~/.composer/cache
key: php-${{ matrix.php-versions }}
-typo3-${{ matrix.typo3-versions.typo3 }}
-phpunit-${{ matrix.typo3-versions.phpunit }}
-phpcov-${{ matrix.typo3-versions.phpcov }}
-yaml-${{ matrix.typo3-versions.yaml }}
-testing-${{ matrix.typo3-versions.testing }}
-composer-${{ hashFiles('composer.json') }}
restore-keys: |
php-${{ matrix.php-versions }}
-typo3-${{ matrix.typo3-versions.typo3 }}
-phpunit-${{ matrix.typo3-versions.phpunit }}
-phpcov-${{ matrix.typo3-versions.phpcov }}
-yaml-${{ matrix.typo3-versions.yaml }}
-testing-${{ matrix.typo3-versions.testing }}composer-
php-${{ matrix.php-versions }}-typo3-
- name: "Install composer dependencies"
run: composer require typo3/minimal
"^${{ matrix.typo3-versions.typo3 }}"
typo3/testing-framework "${{ matrix.typo3-versions.testing }}"
phpunit/phpunit "${{ matrix.typo3-versions.phpunit }}"
phpunit/phpcov "${{ matrix.typo3-versions.phpcov }}"
symfony/yaml "${{ matrix.typo3-versions.yaml }}"
--prefer-dist --no-progress --no-suggest

- name: "Run Unit tests"
run: composer ci:test:unit

- name: "Functional tests"
run: composer ci:test:functional

testsV13:
runs-on: ubuntu-latest
strategy:
max-parallel: 2
matrix:
php-versions: [8.2, 8.3]
typo3-versions:
- {typo3: 13, testing: ^8.0, phpunit: ^10, yaml: ^7, phpcov: ^9 }

name: "Run tests with PHP ${{ matrix.php-versions }}
using TYPO3 ${{ matrix.typo3-versions.typo3 }}
Expand All @@ -89,19 +144,28 @@ jobs:
path: ~/.composer/cache
key: php-${{ matrix.php-versions }}
-typo3-${{ matrix.typo3-versions.typo3 }}
-phpunit-${{ matrix.typo3-versions.phpunit }}
-phpcov-${{ matrix.typo3-versions.phpcov }}
-yaml-${{ matrix.typo3-versions.yaml }}
-testing-${{ matrix.typo3-versions.testing }}
-composer-${{ hashFiles('composer.json') }}
restore-keys: |
php-${{ matrix.php-versions }}
-typo3-${{ matrix.typo3-versions.typo3 }}
-phpunit-${{ matrix.typo3-versions.phpunit }}
-phpcov-${{ matrix.typo3-versions.phpcov }}
-yaml-${{ matrix.typo3-versions.yaml }}
-testing-${{ matrix.typo3-versions.testing }}composer-
php-${{ matrix.php-versions }}-typo3-
- name: "Install composer dependencies"
run: composer require typo3/minimal
run: composer remove php-coveralls/php-coveralls --no-progress && composer require typo3/minimal
"^${{ matrix.typo3-versions.typo3 }}"
typo3/testing-framework "${{ matrix.typo3-versions.testing }}"
--prefer-dist --no-progress --no-suggest
phpunit/phpunit "${{ matrix.typo3-versions.phpunit }}"
phpunit/phpcov "${{ matrix.typo3-versions.phpcov }}"
symfony/yaml "${{ matrix.typo3-versions.yaml }}"
--prefer-dist --no-progress

- name: "Run Unit tests"
run: composer ci:test:unit
Expand Down
3 changes: 2 additions & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
$config = \TYPO3\CodingStandards\CsFixerConfig::create();
$config->getFinder()->in('Classes')->in('Configuration')->in('Tests');
$rules = $config->getRules();
$rules['global_namespace_import'] = ['import_classes' => true, 'import_constants' => true, 'import_functions' => true];
$rules['ordered_imports'] = [
'imports_order' => [
'class',
Expand All @@ -26,4 +27,4 @@
];

$config->setRules($rules);
return $config;
return $config;
6 changes: 4 additions & 2 deletions Classes/DataProcessing/DatabaseQueryProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;

use function json_decode;

/**
* Fetch records from the database, using the default .select syntax from TypoScript.
*
Expand Down Expand Up @@ -109,13 +111,13 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
$objConf = $this->typoScriptService->convertPlainArrayToTypoScriptArray(['fields' => $fields, '_typoScriptNodeValue' => 'JSON']);
}

$processedRecordVariables[$key] = $objConf !== [] ? \json_decode($recordContentObjectRenderer->cObjGetSingle($objName, $objConf), true) : $record;
$processedRecordVariables[$key] = $objConf !== [] ? json_decode($recordContentObjectRenderer->cObjGetSingle($objName, $objConf), true) : $record;
$processedRecordVariables[$key] = $this->contentDataProcessor->process($recordContentObjectRenderer, $processorConfiguration, $processedRecordVariables[$key]);

if (isset($processorConfiguration['overrideFields.'])) {
$overrideFields = $this->typoScriptService->convertTypoScriptArrayToPlainArray($processorConfiguration['overrideFields.']);
$jsonCE = $this->typoScriptService->convertPlainArrayToTypoScriptArray(['fields' => $overrideFields, '_typoScriptNodeValue' => 'JSON']);
$record = \json_decode($recordContentObjectRenderer->cObjGetSingle('JSON', $jsonCE), true);
$record = json_decode($recordContentObjectRenderer->cObjGetSingle('JSON', $jsonCE), true);

foreach ($record as $fieldName => $overrideData) {
$processedRecordVariables[$key][$fieldName] = $overrideData;
Expand Down
5 changes: 3 additions & 2 deletions Classes/DataProcessing/ExtractPropertyProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FriendsOfTYPO3\Headless\DataProcessing;

use Exception;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
Expand Down Expand Up @@ -49,11 +50,11 @@ public function process(
array $processedData
) {
if (empty($processorConfiguration['as'])) {
throw new \Exception('Please specify property \'as\'');
throw new Exception('Please specify property \'as\'');
}

if (empty($processorConfiguration['key'])) {
throw new \Exception('Please specify property \'key\'');
throw new Exception('Please specify property \'key\'');
}

$targetFieldName = (string)$cObj->stdWrapValue(
Expand Down
10 changes: 7 additions & 3 deletions Classes/DataProcessing/FlexFormProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;

use function is_array;
use function is_string;
use function json_decode;

/**
* Basic TypoScript configuration:
* Processing the field pi_flexform and overrides the values stored in data
Expand Down Expand Up @@ -106,9 +110,9 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
// processing the flexform data
$originalValue = $processedData['data'][$fieldName] ?? $processedData[$fieldName];

if (\is_array($originalValue)) {
if (is_array($originalValue)) {
$flexformData = $originalValue;
} elseif (\is_string($originalValue)) {
} elseif (is_string($originalValue)) {
$flexformData = $this->flexFormService->convertFlexFormContentToArray($originalValue);
} else {
return $processedData;
Expand Down Expand Up @@ -149,7 +153,7 @@ public function processOverrideFields(array $data, array $flexformData, array $p
$typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
$overrideFields = $typoScriptService->convertTypoScriptArrayToPlainArray($processorConfiguration['overrideFields.']);
$jsonCE = $typoScriptService->convertPlainArrayToTypoScriptArray(['fields' => $overrideFields, '_typoScriptNodeValue' => 'JSON']);
$record = \json_decode($recordContentObjectRenderer->cObjGetSingle('JSON', $jsonCE), true);
$record = json_decode($recordContentObjectRenderer->cObjGetSingle('JSON', $jsonCE), true);

foreach ($record as $fieldName => $overrideData) {
$flexformData[$fieldName] = $overrideData;
Expand Down
6 changes: 4 additions & 2 deletions Classes/DataProcessing/MenuProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;

use function is_array;

/**
* This menu processor utilizes HMENU to generate a json encoded menu
* string that will be decoded again and assigned to JSON as
Expand Down Expand Up @@ -143,15 +145,15 @@ public function buildConfiguration()
{
// Before rendering the actual menu via HMENU we want to update $this->menuLevelConfig
$overwriteMenuLevelConfig = $this->getConfigurationValue('overwriteMenuLevelConfig.');
if (\is_array($overwriteMenuLevelConfig)) {
if (is_array($overwriteMenuLevelConfig)) {
ArrayUtility::mergeRecursiveWithOverrule($this->menuLevelConfig, $overwriteMenuLevelConfig);
}

parent::buildConfiguration();

// override built configuration
$overwriteMenuConfig = $this->getConfigurationValue('overwriteMenuConfig.');
if (\is_array($overwriteMenuConfig)) {
if (is_array($overwriteMenuConfig)) {
ArrayUtility::mergeRecursiveWithOverrule($this->menuConfig, $overwriteMenuConfig);
}
}
Expand Down
7 changes: 5 additions & 2 deletions Classes/DataProcessing/RootSiteProcessing/SiteProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@
namespace FriendsOfTYPO3\Headless\DataProcessing\RootSiteProcessing;

use Doctrine\DBAL\Driver\Exception;
use InvalidArgumentException;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Site\SiteFinder;

use TYPO3\CMS\Core\Utility\GeneralUtility;

use function array_filter;
use function array_map;
use function array_values;
use function count;
use function in_array;
use function is_a;
use function usort;

class SiteProvider implements SiteProviderInterface
Expand Down Expand Up @@ -84,8 +87,8 @@ public function prepare(array $config, int $siteUid): self
$pages = $this->fetchPageData($sites, $config);

if ($customSorting !== null) {
if (!\is_a($customSorting, SiteSortingInterface::class, true)) {
throw new \InvalidArgumentException('Invalid implementation of SiteSortingInterface');
if (!is_a($customSorting, SiteSortingInterface::class, true)) {
throw new InvalidArgumentException('Invalid implementation of SiteSortingInterface');
}
/**
* @var SiteSortingInterface $sorting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
use FriendsOfTYPO3\Headless\Seo\MetaHandler;
use FriendsOfTYPO3\Headless\Utility\HeadlessMode;
use FriendsOfTYPO3\Headless\Utility\HeadlessUserInt;
use Throwable;
use TYPO3\CMS\Core\Utility\GeneralUtility;

use TYPO3\CMS\Frontend\Event\AfterCacheableContentIsGeneratedEvent;

use function json_decode;
Expand Down Expand Up @@ -51,7 +53,7 @@ public function __invoke(AfterCacheableContentIsGeneratedEvent $event)
$content = $this->metaHandler->process($event->getRequest(), $event->getController(), $content);

$event->getController()->content = $this->encoder->encode($content);
} catch (\Throwable $e) {
} catch (Throwable $e) {
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FriendsOfTYPO3\Headless\Event\Listener;

use Exception;
use FriendsOfTYPO3\Headless\Event\RedirectUrlEvent;
use FriendsOfTYPO3\Headless\Utility\HeadlessFrontendUrlInterface;
use Psr\Log\LoggerAwareInterface;
Expand All @@ -22,6 +23,7 @@
use TYPO3\CMS\Core\Resource\Folder;
use TYPO3\CMS\Core\Routing\PageRouter;
use TYPO3\CMS\Core\Site\Entity\Site;

use TYPO3\CMS\Core\Utility\GeneralUtility;

use function parse_str;
Expand Down Expand Up @@ -82,7 +84,7 @@ public function __invoke(RedirectUrlEvent $event): void
);

$event->setTargetUrl($frontendUrl);
} catch (\Exception $exception) {
} catch (Exception $exception) {
$this->logError(
'Error during action redirect',
['record' => $event->getRedirectRecord(), 'uri' => $url]
Expand Down
3 changes: 2 additions & 1 deletion Classes/Seo/MetaHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FriendsOfTYPO3\Headless\Seo;

use InvalidArgumentException;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry;
Expand Down Expand Up @@ -121,7 +122,7 @@ private function setMetaTag(string $type, string $name, string $content, array $
$type = strtolower($type);
$name = strtolower($name);
if (!in_array($type, ['property', 'name', 'http-equiv'], true)) {
throw new \InvalidArgumentException(
throw new InvalidArgumentException(
'When setting a meta tag the only types allowed are property, name or http-equiv. "' . $type . '" given.',
1496402460
);
Expand Down
6 changes: 5 additions & 1 deletion Classes/Utility/FileUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
use FriendsOfTYPO3\Headless\Event\EnrichFileDataEvent;
use FriendsOfTYPO3\Headless\Event\FileDataAfterCropVariantProcessingEvent;
use FriendsOfTYPO3\Headless\Utility\File\ProcessingConfiguration;
use InvalidArgumentException;
use Psr\EventDispatcher\EventDispatcherInterface;
use RuntimeException;
use Throwable;
use TYPO3\CMS\Core\Configuration\Features;
use TYPO3\CMS\Core\Http\NormalizedParams;
Expand All @@ -26,8 +28,10 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Service\ImageService;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Typolink\LinkResultInterface;
use UnexpectedValueException;

use function array_key_exists;
use function array_merge;
Expand Down Expand Up @@ -309,7 +313,7 @@ public function processImageFile(
}

return $this->imageService->applyProcessingInstructions($fileReference, $instructions);
} catch (\UnexpectedValueException|\RuntimeException|\InvalidArgumentException $e) {
} catch (UnexpectedValueException|RuntimeException|InvalidArgumentException $e) {
$type = lcfirst(get_class($fileReference));
$status = get_class($e);
$this->errors['processImageFile'][$type . '-' . $fileReference->getUid()] = $status;
Expand Down
3 changes: 2 additions & 1 deletion Classes/ViewHelpers/DomainViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FriendsOfTYPO3\Headless\ViewHelpers;

use Closure;
use FriendsOfTYPO3\Headless\Utility\UrlUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
Expand All @@ -25,7 +26,7 @@ public function initializeArguments()

public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
$urlUtility = GeneralUtility::makeInstance(UrlUtility::class);
Expand Down
3 changes: 2 additions & 1 deletion Classes/ViewHelpers/Form/RegisterFieldViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FriendsOfTYPO3\Headless\ViewHelpers\Form;

use Traversable;
use TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;

Expand Down Expand Up @@ -59,7 +60,7 @@ public function render()
$propertyValue = $this->getPropertyValue();
}

if ($propertyValue instanceof \Traversable) {
if ($propertyValue instanceof Traversable) {
$propertyValue = iterator_to_array($propertyValue);
}
if (is_array($propertyValue)) {
Expand Down
3 changes: 2 additions & 1 deletion Classes/ViewHelpers/Format/Json/DecodeViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace FriendsOfTYPO3\Headless\ViewHelpers\Format\Json;

use Exception;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

/**
Expand Down Expand Up @@ -45,7 +46,7 @@ public function render()
return $object;
}
if ($GLOBALS['TYPO3_CONF_VARS']['FE']['debug'] ?? false) {
throw new \Exception(sprintf(
throw new Exception(sprintf(
'Failure "%s" occured when running json_decode() for string: %s',
json_last_error_msg(),
$json
Expand Down
Loading

0 comments on commit 4906fbe

Please sign in to comment.