mirror of https://github.com/FriendsOfTYPO3/tea.git synced 2024-11-15 15:16:13 +01:00

[TASK] Avoid using testing-framework boilerplate files

typo3/testing-framework provides some template files as kickstart
for project and extension based testing. They are properly marked
to be copied and not used directly from the package. The reason
for this recommendation is, that project should make adjustments
to theire concrete setup, like coverage settings and so on.

This change clonses the corresponding template files from the
testing-framework to folders in this extension, adjusts needed
paths and ensure testing is still working. With that this best
practice example follows the recommendation and best-practice
for typo3/testing-framework usage.

Tasks

* provided cloned unit- and function test configuration and
  bootstrap files in `Build/phpunit/`
* updated cloned phpunit configuration files to be phpunit v9
  compatible, removing old coverage tag as this is done by
  cli options in this repository anyway
* add proper xml namespacing to cloned phpunit configurations
* adjustes config paths in unit and functional testing calls
  provided as composer scripts
* adjusted phpunit configuration files in documentation

Resolves #533
This commit is contained in:
Stefan Bürk 2022-10-15 19:44:09 +02:00
parent 1e8b85e858
commit 41b44c28a4
6 changed files with 217 additions and 6 deletions

View file

@ -0,0 +1,52 @@
<!--
Functional test suite setup
Functional tests should extend \TYPO3\TestingFramework\Core\Tests\FunctionalTestCase,
take a look at this class for further documentation on how to run the suite.
TYPO3 CMS functional test suite also needs phpunit bootstrap code, the
file is located next to this .xml as FunctionalTestsBootstrap.php
-->
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
backupGlobals="true"
bootstrap="FunctionalTestsBootstrap.php"
cacheResult="false"
colors="true"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
convertNoticesToExceptions="true"
convertDeprecationsToExceptions="true"
forceCoversAnnotation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
verbose="false"
beStrictAboutTestsThatDoNotTestAnything="false"
failOnWarning="true"
failOnRisky="true"
>
<testsuites>
<testsuite name="Functional tests">
<!--
This path either needs an adaption in extensions, or an extension's
test location path needs to be given to phpunit.
-->
<directory>../../Tests/Functional/</directory>
</testsuite>
</testsuites>
<php>
<!--
@deprecated: Set this to not suppress warnings, notices and deprecations in functional tests
with TYPO3 core v11 and up.
Will always be done with next major version.
To still suppress warnings, notices and deprecations, do NOT define the constant at all.
-->
<const name="TYPO3_TESTING_FUNCTIONAL_REMOVE_ERROR_HANDLER" value="true" />
<ini name="display_errors" value="1" />
<ini name="error_reporting" value="E_ALL" />
<env name="TYPO3_CONTEXT" value="Testing" />
</php>
</phpunit>

View file

@ -0,0 +1,30 @@
<?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!
*/
/**
* 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 \TYPO3\TestingFramework\Core\Testbase();
$testbase->defineOriginalRootPath();
$testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/tests');
$testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/transient');
})();

View file

@ -0,0 +1,45 @@
<!--
Unit test suite setup.
Unit tests should extend \TYPO3\TestingFramework\Core\Tests\UnitTestCase,
take a look at this class for further documentation on how to run the suite.
TYPO3 CMS unit test suite also needs phpunit bootstrap code, the
file is located next to this .xml as UnitTestsBootstrap.php
-->
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
backupGlobals="true"
bootstrap="UnitTestsBootstrap.php"
cacheResult="false"
colors="true"
convertDeprecationsToExceptions="true"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
convertNoticesToExceptions="true"
forceCoversAnnotation="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
verbose="false"
beStrictAboutTestsThatDoNotTestAnything="true"
failOnWarning="true"
failOnRisky="true"
>
<testsuites>
<testsuite name="Unit tests">
<!--
This path either needs an adaption in extensions, or an extension's
test location path needs to be given to phpunit.
-->
<directory>../../Tests/Unit/</directory>
</testsuite>
</testsuites>
<php>
<ini name="display_errors" value="1" />
<env name="TYPO3_CONTEXT" value="Testing" />
</php>
</phpunit>

View file

@ -0,0 +1,84 @@
<?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!
*/
/**
* Boilerplate for a unit 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 UnitTests.xml file.
*
* This file is defined in UnitTests.xml and called by phpunit
* before instantiating the test suites.
*
* The recommended way to execute the suite is "runTests.sh". See the
* according script within TYPO3 core's Build/Scripts directory and
* adapt to extensions needs.
*/
(static 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\TestingFramework\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 (interface_exists(\TYPO3\CMS\Core\Package\Cache\PackageCacheInterface::class)) {
$packageManager = \TYPO3\CMS\Core\Core\Bootstrap::createPackageManager(\TYPO3\CMS\Core\Package\UnitTestPackageManager::class, \TYPO3\CMS\Core\Core\Bootstrap::createPackageCache($cache));
} else {
// v10 compatibility layer
// @deprecated Will be removed when v10 compat is dropped from testing-framework
$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();
})();

View file

@ -232,7 +232,7 @@ settings so this configuration can serve as a template:
- Directory: use the `Tests/Unit` directory in your project.
- (*) Use alternative configuration file.
- Use `.Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTests.xml`
- Use `.Build/public/typo3conf/tea/Build/phpunit/UnitTests.xml`
in your project folder.
- Add the following environment variables:
@ -258,4 +258,4 @@ settings:
- Directory: use the `Tests/Functional` directory in your project.
- (*) Use alternative configuration file.
- Use
`.Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTests.xml`.
`.Build/public/typo3conf/tea/Build/phpunit/FunctionalTests.xml`.

View file

@ -123,7 +123,7 @@
],
"ci:coverage:functional": [
"@coverage:create-directories",
".Build/vendor/bin/phpunit -c .Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTests.xml --whitelist Classes --coverage-php=.Build/coverage/functional.cov Tests/Functional"
".Build/vendor/bin/phpunit -c .Build/public/typo3conf/ext/tea/Build/phpunit/FunctionalTests.xml --whitelist Classes --coverage-php=.Build/coverage/functional.cov Tests/Functional"
],
"ci:coverage:merge": [
"@coverage:create-directories",
@ -131,7 +131,7 @@
],
"ci:coverage:unit": [
"@coverage:create-directories",
".Build/vendor/bin/phpunit -c .Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTests.xml --whitelist Classes --coverage-php=.Build/coverage/unit.cov Tests/Unit"
".Build/vendor/bin/phpunit -c .Build/public/typo3conf/ext/tea/Build/phpunit/UnitTests.xml --whitelist Classes --coverage-php=.Build/coverage/unit.cov Tests/Unit"
],
"ci:dynamic": [
"@ci:tests"
@ -164,8 +164,8 @@
"@ci:tests:unit",
"@ci:tests:functional"
],
"ci:tests:functional": "find 'Tests/Functional' -wholename '*Test.php' | parallel --gnu 'echo; echo \"Running functional test suite {}\"; .Build/vendor/bin/phpunit -c .Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTests.xml {}';",
"ci:tests:unit": ".Build/vendor/bin/phpunit -c .Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTests.xml Tests/Unit",
"ci:tests:functional": "find 'Tests/Functional' -wholename '*Test.php' | parallel --gnu 'echo; echo \"Running functional test suite {}\"; .Build/vendor/bin/phpunit -c .Build/public/typo3conf/ext/tea/Build/phpunit/FunctionalTests.xml {}';",
"ci:tests:unit": ".Build/vendor/bin/phpunit -c .Build/public/typo3conf/ext/tea/Build/phpunit/UnitTests.xml Tests/Unit",
"ci:ts:lint": "typoscript-lint -c Configuration/TsLint.yml --ansi -n --fail-on-warnings -vvv Configuration/TypoScript",
"ci:yaml:lint": "find . ! -path '*.Build/*' ! -path '*node_modules/*' -regextype egrep -regex '.*.ya?ml$' | xargs -r php ./.Build/vendor/bin/yaml-lint",
"coverage:create-directories": "mkdir -p .Build/logs .Build/coverage",