Skip to content

Commit

Permalink
Merge branch 'main' into task/docker-composer-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
achimfritz committed Aug 1, 2024
2 parents e9dc7bd + 3f32491 commit 68b3d21
Show file tree
Hide file tree
Showing 71 changed files with 1,235 additions and 502 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '7.4', '7.3', '7.2' ]
TYPO3: [ '10' ]
php: [ '7.4', '8.0', '8.1' ]
TYPO3: [ '11' ]
include:
- TYPO3: '11'
- TYPO3: '12'
php: '8.1'
- TYPO3: '11'
php: '8.0'
- TYPO3: '11'
php: '7.4'
- TYPO3: '13'
php: '8.3'
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
14 changes: 0 additions & 14 deletions Build/phpstan10.neon

This file was deleted.

15 changes: 8 additions & 7 deletions Build/phpstan11.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ parameters:
paths:
- %currentWorkingDirectory%/Classes
- %currentWorkingDirectory%/Tests

excludePaths:
- %currentWorkingDirectory%/Tests/Unit/Domain/Repository/MenuRepositoryTest.php
ignoreErrors:
-
message: '#.*TYPO3\\CMS\\Frontend\\Page\\PageRepository.*#'
path: %currentWorkingDirectory%/Classes/Domain/Repository/MenuRepository.php
message: '#Cannot call method getLanguageCode\(\) on string.#'
path: %currentWorkingDirectory%/Classes/Compiler/LanguageMenuCompiler.php
-
message: '#Constant ORIGINAL_ROOT not found.#'
path: %currentWorkingDirectory%/Tests
message: '#Class TYPO3\\CMS\\Frontend\\Cache\\CacheLifetimeCalculator not found.#'
path: %currentWorkingDirectory%/Classes/CacheHelper.php
-
message: '#Call to an undefined method Prophecy\\Prophecy\\ObjectProphecy::.*#'
path: %currentWorkingDirectory%/Tests
message: '#.*unknown class TYPO3\\CMS\\Core\\TypoScript\\FrontendTypoScript.#'
path: %currentWorkingDirectory%/Classes/CacheHelper.php
18 changes: 18 additions & 0 deletions Build/phpstan12.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
parameters:
level: 5

paths:
- %currentWorkingDirectory%/Classes
- %currentWorkingDirectory%/Tests
excludePaths:
- %currentWorkingDirectory%/Tests/Unit/Domain/Repository/MenuRepositoryTest.php
ignoreErrors:
-
message: '#Call to an undefined static method TYPO3\\CMS\\Frontend\\ContentObject\\AbstractContentObject::__construct\(\).#'
path: %currentWorkingDirectory%/Classes/ContentObject/*
-
message: '#Property TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController::\$id \(int\) does not accept string.#'
path: %currentWorkingDirectory%/Tests/Functional/Compiler/LanguageMenuCompilerTest.php
-
message: '#Call to an undefined method TYPO3\\CMS\\Core\\TypoScript\\FrontendTypoScript::getConfigArray\(\).#'
path: %currentWorkingDirectory%/Classes/CacheHelper.php
27 changes: 27 additions & 0 deletions Build/phpstan13.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
parameters:
level: 5

paths:
- %currentWorkingDirectory%/Classes
- %currentWorkingDirectory%/Tests
excludePaths:
- %currentWorkingDirectory%/Tests/Unit/Domain/Repository/MenuRepositoryTest.php
ignoreErrors:
-
message: '#Call to an undefined method TYPO3\\CMS\\Core\\Site\\Entity\\SiteLanguage::getTwoLetterIsoCode\(\).#'
path: %currentWorkingDirectory%/Classes/Compiler/LanguageMenuCompiler.php
-
message: '#Access to undefined constant TYPO3\\CMS\\Core\\Domain\\Repository\\PageRepository::DOKTYPE_RECYCLER.#'
path: %currentWorkingDirectory%/Classes/Domain/Repository/MenuRepository.php
-
message: '#Access to undefined constant TYPO3\\CMS\\Core\\Domain\\Repository\\PageRepository::DOKTYPE_RECYCLER.#'
path: %currentWorkingDirectory%/Tests/Unit/Domain/Repository/MenuRepositoryTest.php
-
message: '#.*get_cache_timeout\(\).*#'
path: %currentWorkingDirectory%/Classes/CacheHelper.php
-
message: '#Call to an undefined static method TYPO3\\CMS\\Frontend\\ContentObject\\AbstractContentObject::__construct\(\).#'
path: %currentWorkingDirectory%/Classes/ContentObject/*
-
message: '#Property TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController::\$id \(int\) does not accept string.#'
path: %currentWorkingDirectory%/Tests/Functional/Compiler/LanguageMenuCompilerTest.php
1 change: 0 additions & 1 deletion Build/phpunit/FunctionalTests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@
<const name="TYPO3_MODE" value="BE" />
<ini name="display_errors" value="1" />
<env name="TYPO3_CONTEXT" value="Testing" />
<const name="TYPO3_TESTING_FUNCTIONAL_REMOVE_ERROR_HANDLER" value="true" />
</php>
</phpunit>
34 changes: 4 additions & 30 deletions Build/phpunit/UnitTestsBootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,9 @@
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\CMS\Core\Information\Typo3Version;

call_user_func(function () {
if (!class_exists(\TYPO3\CMS\Frontend\Page\PageRepository::class)) {
class_alias(\TYPO3\CMS\Core\Domain\Repository\PageRepository::class, \TYPO3\CMS\Frontend\Page\PageRepository::class);
}
$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;
Expand All @@ -57,17 +38,10 @@ class_alias(\TYPO3\CMS\Core\Domain\Repository\PageRepository::class, \TYPO3\CMS\
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
);
}
$packageManager = \TYPO3\CMS\Core\Core\Bootstrap::createPackageManager(
\TYPO3\CMS\Core\Package\UnitTestPackageManager::class,
\TYPO3\CMS\Core\Core\Bootstrap::createPackageCache($cache)
);
\TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Package\PackageManager::class, $packageManager);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::setPackageManager($packageManager);

Expand Down
23 changes: 14 additions & 9 deletions Build/testing-docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,15 @@ services:
set -x
fi
php -v | grep '^PHP';
if [ ${TYPO3} -eq 10 ]; then
composer install --no-progress --no-interaction;
if [ ${TYPO3} -eq 11 ]; then
composer require typo3/cms-install:^11.5 typo3/cms-fluid-styled-content:^11.5 --dev -W --no-progress --no-interaction
composer prepare-tests
elif [ ${TYPO3} -eq 12 ]; then
composer require typo3/cms-install:^12.4 typo3/cms-fluid-styled-content:^12.4 --dev -W --no-progress --no-interaction
composer prepare-tests
else
composer remove typo3/cms* --dev --no-progress --no-interaction && composer require typo3/cms-install:^11.5 typo3/cms-fluid-styled-content:^11.5 --dev -W --no-progress --no-interaction
composer install --no-progress --no-interaction
composer prepare-tests
fi
"
Expand Down Expand Up @@ -122,7 +127,7 @@ services:
typo3DatabaseUsername: root
typo3DatabasePassword: funcp
typo3DatabaseHost: mariadb10
working_dir: ${ROOT_DIR}/.Build
working_dir: ${ROOT_DIR}
command: >
/bin/sh -c "
if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
Expand All @@ -136,13 +141,13 @@ services:
php -v | grep '^PHP';
if [ ${PHP_XDEBUG_ON} -eq 0 ]; then
export XDEBUG_MODE=\"off\"
bin/phpunit -c Web/typo3conf/ext/menus/Build/phpunit/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
.Build/bin/phpunit -c Build/phpunit/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
else
DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'`
export XDEBUG_MODE=\"debug,develop\" \
XDEBUG_TRIGGER=\"foo\" \
XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\"
bin/phpunit -c Web/typo3conf/ext/menus/Build/phpunit/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
.Build/bin/phpunit -c Build/phpunit/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
fi
"
lint:
Expand Down Expand Up @@ -188,7 +193,7 @@ services:
- ${HOST_HOME}:${HOST_HOME}
- /etc/passwd:/etc/passwd:ro
- /etc/group:/etc/group:ro
working_dir: ${ROOT_DIR}/.Build
working_dir: ${ROOT_DIR}
command: >
/bin/sh -c "
if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
Expand All @@ -197,12 +202,12 @@ services:
php -v | grep '^PHP';
if [ ${PHP_XDEBUG_ON} -eq 0 ]; then
XDEBUG_MODE=\"off\" \
bin/phpunit -c Web/typo3conf/ext/menus/Build/phpunit/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
.Build/bin/phpunit -c Build/phpunit/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
else
DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'`
XDEBUG_MODE=\"debug,develop\" \
XDEBUG_TRIGGER=\"foo\" \
XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\" \
bin/phpunit -c Web/typo3conf/ext/menus/Build/phpunit/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
.Build/bin/phpunit -c menus/Build/phpunit/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
fi
"
87 changes: 61 additions & 26 deletions Classes/CacheHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
* of the License, or any later version.
*/

use TYPO3\CMS\Core\Cache\CacheManager;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\TypoScript\FrontendTypoScript;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Cache\CacheLifetimeCalculator;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

/**
Expand All @@ -28,23 +30,14 @@
*/
class CacheHelper implements SingletonInterface
{
/**
* @var FrontendInterface
*/
protected $cache;

protected $disableCaching = false;
protected FrontendInterface $cache;
protected bool $disableCaching = false;
protected Context $context;

public function __construct(FrontendInterface $cache = null, Context $context = null)
public function __construct(FrontendInterface $cache, Context $context)
{
if ((new Typo3Version())->getMajorVersion() < 10) {
$this->cache = $cache ?? GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_hash');
} else {
$this->cache = $cache ?? GeneralUtility::makeInstance(CacheManager::class)->getCache('hash');
}
if ($context === null) {
$context = GeneralUtility::makeInstance(Context::class);
}
$this->context = $context;
$this->cache = $cache;
try {
$this->disableCaching = $context->getPropertyFromAspect('workspace', 'id', 0) > 0;
} catch (AspectNotFoundException $e) {
Expand All @@ -60,10 +53,6 @@ public function __construct(FrontendInterface $cache = null, Context $context =
/**
* Looks up the items inside the cache, if it exists, takes the cached entry, otherwise computes the data
* via the $loader().
*
* @param string $cacheIdentifier
* @param callable $loader
* @return array
*/
public function get(string $cacheIdentifier, callable $loader): array
{
Expand All @@ -81,7 +70,8 @@ public function get(string $cacheIdentifier, callable $loader): array

// Calculate tags + lifetime
$tags = $this->buildTagsAndAddThemToPageCache($pages);
$maximumLifeTime = $this->getMaxLifetimeOfPages($pages, $this->getFrontendController()->get_cache_timeout());
$defaultMaxLifeTime = $this->getDefaultMaxLifeTime();
$maximumLifeTime = $this->getMaxLifetimeOfPages($pages, $defaultMaxLifeTime);
$this->cache->set($cacheIdentifier, $pages, $tags, $maximumLifeTime);
return $pages;
}
Expand Down Expand Up @@ -126,15 +116,58 @@ protected function getAllPageIdsFromItems(array $pages): array
return $pageIds;
}

protected function getDefaultMaxLifeTime(): int
{
if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 13) {
$maxLifetime = (int)$this->getFrontendController()->get_cache_timeout();
} else {
$request = $this->getServerRequest();
$pageInformation = $request->getAttribute('frontend.page.information');
/** @var ?FrontendTypoScript $typoScript */
$typoScript = $request->getAttribute('frontend.typoscript');
if ($typoScript === null || $pageInformation === null) {
return 0;
}
$typoScriptConfigArray = $typoScript->getConfigArray();
$maxLifetime = GeneralUtility::makeInstance(CacheLifetimeCalculator::class)
->calculateLifetimeForPage(
$pageInformation->getId(),
$pageInformation->getPageRecord(),
$typoScriptConfigArray,
0,
$this->context
);
}
return $maxLifetime;
}

/**
* pages.cache_timeout is not used here, as this is supposed to be relevant for content of a page, not the
* metadata.
*/
protected function getMaxLifetimeOfPages(array $pages, int $maxLifetime = null): ?int
protected function getMaxLifetimeOfPages(array $pages, int $maxLifetime): int
{
foreach ($pages as $page) {
if (!empty($page['endtime'])) {
$maxLifetimeOfPage = $page['endtime'] - $GLOBALS['EXEC_TIME'];
$maxLifetimeOfPage = (int)$page['endtime'] - $GLOBALS['EXEC_TIME'];
if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() === 13) {
$request = $this->getServerRequest();
/** @var ?FrontendTypoScript $typoScript */
$typoScript = $request->getAttribute('frontend.typoscript');
if ($typoScript === null) {
$typoScriptConfigArray = [];
} else {
$typoScriptConfigArray = $typoScript->getConfigArray();
}
$maxLifetimeOfPage = GeneralUtility::makeInstance(CacheLifetimeCalculator::class)
->calculateLifetimeForPage(
$page['uid'],
$page,
$typoScriptConfigArray,
0,
$this->context
);
}
if ($maxLifetimeOfPage < $maxLifetime) {
$maxLifetime = $maxLifetimeOfPage;
}
Expand All @@ -146,9 +179,11 @@ protected function getMaxLifetimeOfPages(array $pages, int $maxLifetime = null):
return $maxLifetime;
}

/**
* @return TypoScriptFrontendController
*/
protected function getServerRequest(): ServerRequestInterface
{
return $GLOBALS['TYPO3_REQUEST'];
}

protected function getFrontendController(): TypoScriptFrontendController
{
return $GLOBALS['TSFE'];
Expand Down
Loading

0 comments on commit 68b3d21

Please sign in to comment.