[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / components / testing_framework / core / Build / UnitTestsBootstrap.php
1 <?php
2 /*
3 * This file is part of the TYPO3 CMS project.
4 *
5 * It is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License, either version 2
7 * of the License, or any later version.
8 *
9 * For the full copyright and license information, please read the
10 * LICENSE.txt file that was distributed with this source code.
11 *
12 * The TYPO3 project - inspiring people to share!
13 */
14
15 /**
16 * This file is defined in UnitTests.xml and called by phpunit
17 * before instantiating the test suites, it must also be included
18 * with phpunit parameter --bootstrap if executing single test case classes.
19 *
20 * Run whole core unit test suite, example:
21 * - cd /var/www/t3master/foo # Document root of TYPO3 CMS instance (location of index.php)
22 * - typo3/../bin/phpunit -c components/testing_framework/core/Build/UnitTests.xml
23 *
24 * Run single test case, example:
25 * - cd /var/www/t3master/foo # Document root of TYPO3 CMS instance (location of index.php)
26 * - typo3/../bin/phpunit -c components/testing_framework/core/Build/UnitTests.xml
27 * typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php
28 */
29 call_user_func(function () {
30 $testbase = new \TYPO3\CMS\Components\TestingFramework\Core\Testbase();
31 $testbase->enableDisplayErrors();
32 $testbase->defineBaseConstants();
33 $testbase->defineSitePath();
34 $testbase->defineTypo3ModeBe();
35 $testbase->setTypo3TestingContext();
36 $testbase->createDirectory(PATH_site . 'typo3conf/ext');
37 $testbase->createDirectory(PATH_site . 'typo3temp/assets');
38 $testbase->createDirectory(PATH_site . 'typo3temp/var/tests');
39 $testbase->createDirectory(PATH_site . 'typo3temp/var/transient');
40 $testbase->createDirectory(PATH_site . 'uploads');
41
42 // Retrieve an instance of class loader and inject to core bootstrap
43 $classLoaderFilepath = __DIR__ . '/../../../../vendor/autoload.php';
44 if (!file_exists($classLoaderFilepath)) {
45 die('ClassLoader can\'t be loaded. Please check your path or set an environment variable \'TYPO3_PATH_WEB\' to your root path.');
46 }
47 $classLoader = require $classLoaderFilepath;
48 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()
49 ->initializeClassLoader($classLoader)
50 ->setRequestType(TYPO3_REQUESTTYPE_BE | TYPO3_REQUESTTYPE_CLI)
51 ->baseSetup();
52
53 // Initialize default TYPO3_CONF_VARS
54 $configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager();
55 $GLOBALS['TYPO3_CONF_VARS'] = $configurationManager->getDefaultConfiguration();
56 // Avoid failing tests that rely on HTTP_HOST retrieval
57 $GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] = '.*';
58
59 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()
60 ->disableCoreCache()
61 ->initializeCachingFramework()
62 // Set all packages to active
63 ->initializePackageManagement(\TYPO3\CMS\Core\Package\UnitTestPackageManager::class);
64
65 if (!\TYPO3\CMS\Core\Core\Bootstrap::usesComposerClassLoading()) {
66 // Dump autoload info if in non composer mode
67 \TYPO3\CMS\Core\Core\ClassLoadingInformation::dumpClassLoadingInformation();
68 \TYPO3\CMS\Core\Core\ClassLoadingInformation::registerClassLoadingInformation();
69 }
70 });