Skip to content

Commit

Permalink
[TASK] Update tests to run without fluidtypo3/development
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessCoder committed Nov 24, 2022
1 parent 59514ae commit f76456a
Show file tree
Hide file tree
Showing 275 changed files with 2,223 additions and 1,468 deletions.
63 changes: 25 additions & 38 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ on:
branches: [ master, development, '[0-9]+.[0-9]', '[0-9]+.[0-9]+.[0-9]+' ]

jobs:
build:
phpstan:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
name: "PHP ${{ matrix.php-versions }} Test (deps: ${{ matrix.dependencies }})"

continue-on-error: ${{ matrix.experimental }}
name: "PHPStan, PHP ${{ matrix.php }} TYPO3 ${{ matrix.typo3 }}"

strategy:
fail-fast: false
matrix:
php-versions: ['7.4']
dependencies: ['highest']
composer-arguments: [''] # to run --ignore-platform-reqs in experimental builds
typo3-version: ['^9.5', '^8.7']
experimental: [false]
include:
- php: "7.4"
typo3: "^8.7"
- php: "7.4"
typo3: "^9.5"
- php: "7.4"
typo3: "^10.4"
- php: "8.0"
typo3: "^11.5"
- php: "8.1"
typo3: "^11.5"

runs-on: ubuntu-latest

Expand All @@ -31,33 +35,28 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
php-version: ${{ matrix.php }}
extensions: mbstring, json
ini-values: date.timezone="Europe/Copenhagen", opcache.fast_shutdown=0
tools: composer:v2.2

- name: Select TYPO3 version
run: "composer require typo3/cms-core:${{ matrix.typo3-version }}"
run: "composer require typo3/cms-core:${{ matrix.typo3 }} -W --no-update"

- name: Composer install
uses: ramsey/composer-install@v2
with:
dependency-versions: ${{ matrix.dependencies }}
composer-options: ${{ matrix.composer-arguments }}

- name: Run tests
run: vendor/bin/phpunit
- name: Run phpstan
run: vendor/bin/phpstan analyze

phpstan:
build:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
name: "PHPStan, PHP ${{ matrix.php }} TYPO3 ${{ matrix.typo3 }}"
name: "PHPUnit, PHP ${{ matrix.php }} TYPO3 ${{ matrix.typo3 }}"

strategy:
fail-fast: false
matrix:
include:
- php: "7.4"
typo3: "^8.7"
- php: "7.4"
typo3: "^9.5"
- php: "7.4"
Expand All @@ -82,13 +81,13 @@ jobs:
tools: composer:v2.2

- name: Select TYPO3 version
run: "composer require typo3/cms-core:${{ matrix.typo3 }} -W --no-update"
run: "composer require typo3/cms-core:${{ matrix.typo3 }} --no-update"

- name: Composer install
uses: ramsey/composer-install@v2

- name: Run phpstan
run: vendor/bin/phpstan analyze
- name: Run tests
run: vendor/bin/phpunit

coverage:
runs-on: ubuntu-latest
Expand All @@ -103,14 +102,14 @@ jobs:
with:
php-version: "7.4"
extensions: mbstring, json
coverage: xdebug #optional
coverage: xdebug
ini-values: date.timezone="Europe/Copenhagen", opcache.fast_shutdown=0

- name: Select TYPO3 version 9.5
run: "composer require typo3/cms-core:^9.5"
run: "composer require typo3/cms-core:^9.5 --no-update"

- name: Composer install
uses: ramsey/composer-install@v1
uses: ramsey/composer-install@v2

- name: Run tests
run: vendor/bin/phpunit --coverage-clover=build/logs/clover.xml
Expand All @@ -119,15 +118,3 @@ jobs:
run: vendor/bin/php-coveralls -vvv
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Use this step to configure a required build pass via gh branch protection rules (currently makes experimental builds unusable due to https://github.com/actions/toolkit/issues/581)
#buildall:
# if: "!contains(github.event.head_commit.message, '[skip ci]')"
# runs-on: ubuntu-latest
# name: CI build (matrix)
# needs: build
# steps:
# - name: Check build matrix status
# if: ${{ needs.build.result != 'success' }}
# run: exit 1

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
vendor
.idea
.phpunit.result.cache
composer.lock
/build
/Documentation-GENERATED-temp/
/index.php
/typo3
/typo3_src
/public
7 changes: 6 additions & 1 deletion Classes/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,12 @@ public function getSettings()
}
$settings = (array) self::$settingsCache;
$properties = get_class_vars(get_class($this));
foreach (array_keys($properties) as $propertyName) {
$skipProperties = ['settingsCache', 'configurationManager'];
foreach (array_keys($properties) as $index => $propertyName) {
if (in_array($propertyName, $skipProperties, true)) {
unset($properties[$propertyName]);
continue;
}
$properties[$propertyName] = $this->$propertyName;
}

Expand Down
13 changes: 9 additions & 4 deletions Classes/Service/AssetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ protected function writeCachedMergedFileAndReturnTag($assets, $type)
}
}
$fileRelativePathAndFilename = $this->getTempPath() . 'vhs-assets-' . $assetName . '.' . $type;
$fileAbsolutePathAndFilename = GeneralUtility::getFileAbsFileName($fileRelativePathAndFilename);
$fileAbsolutePathAndFilename = $this->resolveAbsolutePathForFile($fileRelativePathAndFilename);
if (false === file_exists($fileAbsolutePathAndFilename)
|| 0 === filemtime($fileAbsolutePathAndFilename)
|| true === isset($GLOBALS['BE_USER'])
Expand Down Expand Up @@ -596,10 +596,10 @@ protected function renderAssetAsFluidTemplate($asset)
protected function prefixPath($fileRelativePathAndFilename)
{
$settings = $this->getSettings();
$prefixPath = $settings['prependPath'];
if (false === empty($GLOBALS['TSFE']->absRefPrefix) && true === empty($prefixPath)) {
$prefixPath = $settings['prependPath'] ?? '';
if (!empty($GLOBALS['TSFE']->absRefPrefix) && empty($prefixPath)) {
$fileRelativePathAndFilename = $GLOBALS['TSFE']->absRefPrefix . $fileRelativePathAndFilename;
} elseif (false === empty($prefixPath)) {
} elseif (!empty($prefixPath)) {
$fileRelativePathAndFilename = $prefixPath . $fileRelativePathAndFilename;
}
return $fileRelativePathAndFilename;
Expand Down Expand Up @@ -875,4 +875,9 @@ private function getTempPath()
{
return 'typo3temp/assets/';
}

protected function resolveAbsolutePathForFile(string $filename): string
{
return GeneralUtility::getFileAbsFileName($filename);
}
}
2 changes: 1 addition & 1 deletion Classes/Traits/ArrayConsumingViewHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3\CMS\Fluid\Core\ViewHelper\Exception;
use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;

/**
* Class ArrayConsumingViewHelperTrait
Expand Down
34 changes: 0 additions & 34 deletions Classes/Utility/ViewHelperUtility.php

This file was deleted.

15 changes: 7 additions & 8 deletions Classes/View/UncacheTemplateView.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@
* LICENSE.md file that was distributed with this source code.
*/

use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
use TYPO3\CMS\Fluid\Compatibility\TemplateParserBuilder;
use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
use TYPO3Fluid\Fluid\Core\Parser\TemplateParser;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
use TYPO3\CMS\Fluid\View\TemplateView;
use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
use TYPO3Fluid\Fluid\Core\Parser\TemplateParser;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;

/**
Expand Down Expand Up @@ -77,9 +76,9 @@ public function injectObjectManager(ObjectManagerInterface $objectManager)
*/
public function callUserFunction($postUserFunc, $conf, $content)
{
$partial = $conf['partial'];
$section = $conf['section'];
$arguments = true === is_array($conf['arguments']) ? $conf['arguments'] : [];
$partial = $conf['partial'] ?? '';
$section = $conf['section'] ?? '';
$arguments = $conf['arguments'] ?? [];
/** @var ControllerContext $controllerContext */
$controllerContext = $this->objectManager->get(ControllerContext::class);
/** @var Request $request */
Expand All @@ -91,7 +90,7 @@ public function callUserFunction($postUserFunc, $conf, $content)
$uriBuilder->setRequest($request);
$controllerContext->setUriBuilder($uriBuilder);

if ($conf['controllerContext']) {
if ($conf['controllerContext'] ?? false) {
$request->setControllerActionName($conf['controllerContext']['actionName']);
$request->setControllerExtensionName($conf['controllerContext']['extensionName']);
$request->setControllerName($conf['controllerContext']['controllerName']);
Expand All @@ -100,7 +99,7 @@ public function callUserFunction($postUserFunc, $conf, $content)
$request->setFormat($conf['controllerContext']['format']);
}

if (true === empty($partial)) {
if (empty($partial)) {
return '';
}

Expand Down
63 changes: 30 additions & 33 deletions Classes/ViewHelpers/Condition/Form/HasValidatorViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
* LICENSE.md file that was distributed with this source code.
*/

use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
use TYPO3\CMS\Extbase\Reflection\ReflectionService;
use TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
Expand Down Expand Up @@ -73,51 +74,47 @@ protected static function evaluateCondition($arguments = null)
return false;
}

if (static::$staticReflectionService === null) {
/** @var ObjectManager $objectManager */
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var ReflectionService $reflectionService */
$reflectionService = $objectManager->get(ReflectionService::class);
static::$staticReflectionService = $reflectionService;
}
/** @var ObjectManager $objectManager */
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var ReflectionService $reflectionService */
$reflectionService = $objectManager->get(ReflectionService::class);

$property = $arguments['property'];
$validatorName = $arguments['validatorName'] ?? null;
$object = $arguments['object'] ?? null;

$className = get_class($object);
if (false !== strpos($property, '.')) {
$pathSegments = explode('.', $property);
foreach ($pathSegments as $property) {
if (true === ctype_digit($property)) {
continue;
}
$annotations = static::$staticReflectionService->getPropertyTagValues((string) $className, $property, 'var');
$possibleClassName = array_pop($annotations);
if (false !== strpos($possibleClassName, '<')) {
$parts = explode('<', trim($possibleClassName, '>'));
$className = array_pop($parts);
} elseif (true === class_exists($possibleClassName)) {
$className = $possibleClassName;
$path = null;
if (strpos($property, '.') !== false) {
$parts = explode('.', $property);
$property = array_pop($parts);
$path = implode('.', $parts);
$object = ObjectAccess::getPropertyPath($object, $path);
}

if (!is_object($object)) {
return false;
}

if (!method_exists($reflectionService, 'getPropertyTagValues')) {
// TYPO3 version no longer contains the raw property tag value extractor. Instead, we can check for a given
// validator by extracting the validators and analysing those.
$validators = $reflectionService->getClassSchema($object)->getProperty($property)->getValidators();
foreach ($validators as $validatorConfiguration) {
if ($validatorConfiguration['name'] === $validatorName) {
return true;
}
}
return false;
}

// If we are on TYPO3 9.3 or above, the old validator ID is no longer possible to use and we must use the new one.
$fluidCoreVersion = ExtensionManagementUtility::getExtensionVersion('fluid');
if (version_compare($fluidCoreVersion, '9.3', '>=')) {
$annotationName = 'Extbase\\Validate';
} else {
$annotationName = 'validate';
}
$annotations = static::$staticReflectionService->getPropertyTagValues((string) $className, $property, $annotationName);
if (empty($annotations) && $annotationName === 'validate' && version_compare($fluidCoreVersion, '9.1', '>=')) {
$className = get_class($object);
$annotations = $reflectionService->getPropertyTagValues($className, $property, 'validate');
if (empty($annotations)) {
// We tried looking for the legacy validator name but found none. Retry with the new way. We have to do this
// as a retry, because we cannot assume that any site using TYPO3 9.1+ will also be using the modern
// annotations. Hence we cannot change the validator name until we've also looked for the legacy ones (which
// will take priority if found).
$annotationName = 'Extbase\\Validate';
$annotations = static::$staticReflectionService->getPropertyTagValues((string) $className, $property, $annotationName);
$annotations = $reflectionService->getPropertyTagValues($className, $property, 'Extbase\\Validate');
}
return (count($annotations) && (!$validatorName || in_array($validatorName, $annotations)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\LanguageAspect;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper;

Expand Down
2 changes: 0 additions & 2 deletions Classes/ViewHelpers/Condition/Variable/IssetViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
* LICENSE.md file that was distributed with this source code.
*/

use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper;

/**
Expand Down
Loading

0 comments on commit f76456a

Please sign in to comment.