-
-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathUnitTestsBootstrap.php
More file actions
97 lines (84 loc) · 4.1 KB
/
UnitTestsBootstrap.php
File metadata and controls
97 lines (84 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
use TYPO3\CMS\Core\Cache\Backend\NullBackend;
use TYPO3\CMS\Core\Cache\Frontend\PhpFrontend;
use TYPO3\CMS\Core\Configuration\ConfigurationManager;
use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
use TYPO3\CMS\Core\Package\Cache\PackageCacheInterface;
use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3\CMS\Core\Package\UnitTestPackageManager;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\TestingFramework\Core\Testbase;
/*
* 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 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 = SystemEnvironmentBuilder::REQUESTTYPE_BE | SystemEnvironmentBuilder::REQUESTTYPE_CLI;
\TYPO3\TestingFramework\Core\SystemEnvironmentBuilder::run(0, $requestType);
$testbase->createDirectory(Environment::getPublicPath() . '/typo3conf/ext');
$testbase->createDirectory(Environment::getPublicPath() . '/typo3temp/assets');
$testbase->createDirectory(Environment::getPublicPath() . '/typo3temp/var/tests');
$testbase->createDirectory(Environment::getPublicPath() . '/typo3temp/var/transient');
// Retrieve an instance of class loader and inject to core bootstrap
$classLoader = require $testbase->getPackagesPath() . '/autoload.php';
Bootstrap::initializeClassLoader($classLoader);
// Initialize default TYPO3_CONF_VARS
$configurationManager = new ConfigurationManager();
$GLOBALS['TYPO3_CONF_VARS'] = $configurationManager->getDefaultConfiguration();
$cache = new PhpFrontend(
'core',
new NullBackend('production', [])
);
// Set all packages to active
if (interface_exists(PackageCacheInterface::class)) {
$packageManager = Bootstrap::createPackageManager(UnitTestPackageManager::class, Bootstrap::createPackageCache($cache));
} else {
// v10 compatibility layer
// @deprecated Will be removed when v10 compat is dropped from testing-framework
$packageManager = Bootstrap::createPackageManager(UnitTestPackageManager::class, $cache);
}
GeneralUtility::setSingletonInstance(PackageManager::class, $packageManager);
ExtensionManagementUtility::setPackageManager($packageManager);
$testbase->dumpClassLoadingInformation();
GeneralUtility::purgeInstances();
})();