Skip to content

Commit

Permalink
!!! [TASK] change requirements
Browse files Browse the repository at this point in the history
* drop TYPO3 10 Support
* add TYPO3 13 Support
* use CI
  • Loading branch information
achimfritz-b13 committed May 23, 2024
1 parent 1161b69 commit 01e5857
Show file tree
Hide file tree
Showing 21 changed files with 244 additions and 50 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: CI

on: [push, pull_request]

jobs:
testsuite:

runs-on: ubuntu-latest
strategy:
matrix:
TYPO3: [ '11' , '12', '13']

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up PHP Version
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
tools: composer:v2

- name: Start MySQL
run: sudo /etc/init.d/mysql start

- name: Validate composer.json and composer.lock
run: composer validate

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache
key: dependencies-composer-${{ hashFiles('composer.json') }}

- name: Install composer dependencies TYPO3 13
if: matrix.TYPO3 == '13'
run: |
composer install --no-progress --no-interaction
- name: Install composer dependencies TYPO3 12
if: matrix.TYPO3 == '12'
run: |
composer require typo3/cms-core:^12.4 --no-progress --no-interaction --dev -W
- name: Install composer dependencies TYPO3 11
if: matrix.TYPO3 == '11'
run: |
composer require typo3/cms-core:^11.5 --no-progress --no-interaction --dev -W
- name: Phpstan 12/13
if: matrix.TYPO3 != '11'
run: .Build/bin/phpstan analyze -c Build/phpstan.neon
- name: Phpstan 11
if: matrix.TYPO3 == '11'
run: .Build/bin/phpstan analyze -c Build/phpstan11.neon
- name: Phpcsfix
run: .Build/bin/php-cs-fixer fix --config=Build/php-cs-fixer.php --dry-run --stop-on-violation --using-cache=no
- name: Unit Tests
run: .Build/bin/phpunit -c Build/phpunit/UnitTests.xml Tests/Unit
- name: Functional Tests
run: |
export typo3DatabaseName="typo3";
export typo3DatabaseHost="127.0.0.1";
export typo3DatabaseUsername="root";
export typo3DatabasePassword="root";
.Build/bin/phpunit -c Build/phpunit/FunctionalTests.xml Tests/Functional
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/build/
/composer.lock
/.php_cs.cache
/public/
/Build/phpunit/.phpunit.*
/public/
/.Build/
5 changes: 5 additions & 0 deletions Build/php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

$config = \TYPO3\CodingStandards\CsFixerConfig::create();
$config->getFinder()->exclude(['var'])->in(__DIR__ . '/..');
return $config;
6 changes: 6 additions & 0 deletions Build/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
includes:
- ../.Build/vendor/saschaegerer/phpstan-typo3/extension.neon
parameters:
level: 5
paths:
- %currentWorkingDirectory%/Classes
8 changes: 8 additions & 0 deletions Build/phpstan11.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
includes:
- ../.Build/vendor/saschaegerer/phpstan-typo3/extension.neon
parameters:
level: 5
paths:
- %currentWorkingDirectory%/Classes
excludePaths:
- %currentWorkingDirectory%/Classes/Listener/AfterCacheableContentIsGenerated.php
12 changes: 12 additions & 0 deletions Build/phpunit/FunctionalTests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" backupGlobals="true" bootstrap="FunctionalTestsBootstrap.php" 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>
<ini name="display_errors" value="1"/>
<env name="TYPO3_CONTEXT" value="Testing"/>
</php>
</phpunit>
20 changes: 20 additions & 0 deletions Build/phpunit/FunctionalTestsBootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/*
* 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!
*/

call_user_func(function () {
$testbase = new \TYPO3\TestingFramework\Core\Testbase();
$testbase->defineOriginalRootPath();
$testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/tests');
$testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/transient');
});
12 changes: 12 additions & 0 deletions Build/phpunit/UnitTests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?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="UnitTestsBootstrap.php" 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>
<ini name="display_errors" value="1"/>
<env name="TYPO3_CONTEXT" value="Testing"/>
</php>
</phpunit>
74 changes: 74 additions & 0 deletions Build/phpunit/UnitTestsBootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/*
* 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!
*/

use TYPO3\CMS\Core\Information\Typo3Version;

call_user_func(function () {
$testbase = new \TYPO3\TestingFramework\Core\Testbase();

// These if's are for core testing (package typo3/cms) only. cms-composer-installer does
// not create the autoload-include.php file that sets these env vars and sets composer
// mode to true. testing-framework can not be used without composer anyway, so it is safe
// to do this here. This way it does not matter if 'bin/phpunit' or 'vendor/phpunit/phpunit/phpunit'
// is called to run the tests since the 'relative to entry script' path calculation within
// SystemEnvironmentBuilder is not used. However, the binary must be called from the document
// root since getWebRoot() uses 'getcwd()'.
if (!getenv('TYPO3_PATH_ROOT')) {
putenv('TYPO3_PATH_ROOT=' . rtrim($testbase->getWebRoot(), '/'));
}
if (!getenv('TYPO3_PATH_WEB')) {
putenv('TYPO3_PATH_WEB=' . rtrim($testbase->getWebRoot(), '/'));
}

$testbase->defineSitePath();

$requestType = \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_BE | \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_CLI;
\TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::run(0, $requestType);

$testbase->createDirectory(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/typo3conf/ext');
$testbase->createDirectory(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/typo3temp/assets');
$testbase->createDirectory(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/typo3temp/var/tests');
$testbase->createDirectory(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/typo3temp/var/transient');

// Retrieve an instance of class loader and inject to core bootstrap
$classLoader = require $testbase->getPackagesPath() . '/autoload.php';
\TYPO3\CMS\Core\Core\Bootstrap::initializeClassLoader($classLoader);

// Initialize default TYPO3_CONF_VARS
$configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager();
$GLOBALS['TYPO3_CONF_VARS'] = $configurationManager->getDefaultConfiguration();

$cache = new \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend(
'core',
new \TYPO3\CMS\Core\Cache\Backend\NullBackend('production', [])
);
// Set all packages to active
if (version_compare((new Typo3Version())->getVersion(), '11.3.0', '>')) {
$packageManager = \TYPO3\CMS\Core\Core\Bootstrap::createPackageManager(
\TYPO3\CMS\Core\Package\UnitTestPackageManager::class,
\TYPO3\CMS\Core\Core\Bootstrap::createPackageCache($cache)
);
} else {
$packageManager = \TYPO3\CMS\Core\Core\Bootstrap::createPackageManager(
\TYPO3\CMS\Core\Package\UnitTestPackageManager::class,
$cache
);
}
\TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Package\PackageManager::class, $packageManager);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::setPackageManager($packageManager);

$testbase->dumpClassLoadingInformation();

\TYPO3\CMS\Core\Utility\GeneralUtility::purgeInstances();
});
4 changes: 3 additions & 1 deletion Classes/AssetCollector.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

namespace B13\Assetcollector;

/*
Expand Down Expand Up @@ -137,6 +138,7 @@ public function buildInlineCssTag(): string

protected function cssContentWithResolvedPaths(string $cssFile): string
{
$content = '';
$absoluteFile = GeneralUtility::getFileAbsFileName($cssFile);
if (file_exists($absoluteFile)) {
$content = $this->removeUtf8Bom(file_get_contents($absoluteFile));
Expand Down Expand Up @@ -183,7 +185,7 @@ public function buildJavaScriptIncludes(): string
$attributeCode[] = htmlspecialchars($name);
}
}
$webPath = (strpos($file['fileName'], 'EXT:') === 0)
$webPath = (str_starts_with($file['fileName'], 'EXT:'))
? PathUtility::getAbsoluteWebPath(GeneralUtility::getFileAbsFileName(($file['fileName'])))
: $file['fileName'];
$includes .= '<script src="' . htmlspecialchars($webPath) . '"' . (!empty($attributeCode) ? ' ' . implode(' ', $attributeCode) : '') . '></script>';
Expand Down
1 change: 1 addition & 0 deletions Classes/Hooks/AssetRenderer.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

namespace B13\Assetcollector\Hooks;

/*
Expand Down
3 changes: 2 additions & 1 deletion Classes/Middleware/InlineSvgInjector.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

namespace B13\Assetcollector\Middleware;

/*
Expand Down Expand Up @@ -35,7 +36,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$body = $response->getBody();
$body->rewind();
$contents = $response->getBody()->getContents();
if (strpos($contents, '</body>') !== false) {
if (str_contains($contents, '</body>')) {
$content = str_ireplace(
'</body>',
$svgAsset . '</body>',
Expand Down
1 change: 1 addition & 0 deletions Classes/Resource/ResourceCompressor.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

namespace B13\Assetcollector\Resource;

/*
Expand Down
1 change: 1 addition & 0 deletions Classes/ViewHelpers/CssViewHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

namespace B13\Assetcollector\ViewHelpers;

/*
Expand Down
1 change: 1 addition & 0 deletions Classes/ViewHelpers/JsViewHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

namespace B13\Assetcollector\ViewHelpers;

/*
Expand Down
1 change: 1 addition & 0 deletions Classes/ViewHelpers/SvgViewHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

namespace B13\Assetcollector\ViewHelpers;

/*
Expand Down
1 change: 0 additions & 1 deletion Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ services:
tags:
- name: event.listener
identifier: 'b13-assetcollector-after-cacheable-content-is-generated'
event: TYPO3\CMS\Frontend\Event\AfterCacheableContentIsGeneratedEvent
33 changes: 0 additions & 33 deletions Tests/Functional/Frontend/AbstractFrontendTest.php

This file was deleted.

11 changes: 8 additions & 3 deletions Tests/Functional/Frontend/InlineCssTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@
*/

use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

class InlineCssTest extends AbstractFrontendTest
class InlineCssTest extends FunctionalTestCase
{
protected array $testExtensionsToLoad = ['typo3conf/ext/assetcollector'];
protected array $coreExtensionsToLoad = ['core', 'frontend'];
protected array $pathsToLinkInTestInstance = ['typo3conf/ext/assetcollector/Build/sites' => 'typo3conf/sites'];

/**
* @test
*/
public function scriptTagForInlineCssIsRendered(): void
{
$this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/assetcollector/Tests/Functional/Frontend/Fixtures/inline_css.csv');
$response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/'));
$this->importCSVDataSet(__DIR__ . '/Fixtures/inline_css.csv');
$response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/'));
$expected = '<style class="tx_assetcollector">h1{color:red;}';
$body = (string)$response->getBody();
self::assertStringContainsString($expected, $body);
Expand Down
Loading

0 comments on commit 01e5857

Please sign in to comment.