edb0cd2e044683f6a4fe37f21b2f6d2962f203ba
[Packages/TYPO3.CMS.git] / typo3 / sysext / 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 typo3/sysext/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 typo3/sysext/core/Build/UnitTests.xml
27 * typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php
28 */
29 call_user_func(function () {
30 $testbase = new \TYPO3\CMS\Core\Tests\Testbase();
31 $testbase->enableDisplayErrors();
32 $testbase->defineBaseConstants();
33 $testbase->defineSitePath();
34 $testbase->defineTypo3ModeBe();
35 $testbase->setTypo3TestingContext();
36 $testbase->createDirectory(PATH_site . 'uploads');
37 $testbase->createDirectory(PATH_site . 'typo3temp/var/tests');
38 $testbase->createDirectory(PATH_site . 'typo3temp/var/transient');
39 $testbase->createDirectory(PATH_site . 'typo3conf/ext');
40
41 // Retrieve an instance of class loader and inject to core bootstrap
42 $classLoaderFilepath = __DIR__ . '/../../../../vendor/autoload.php';
43 if (!file_exists($classLoaderFilepath)) {
44 die('ClassLoader can\'t be loaded. Please check your path or set an environment variable \'TYPO3_PATH_WEB\' to your root path.');
45 }
46 $classLoader = require $classLoaderFilepath;
47 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()
48 ->initializeClassLoader($classLoader)
49 ->setRequestType(TYPO3_REQUESTTYPE_BE | TYPO3_REQUESTTYPE_CLI)
50 ->baseSetup();
51
52 // Initialize default TYPO3_CONF_VARS
53 $configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager();
54 $GLOBALS['TYPO3_CONF_VARS'] = $configurationManager->getDefaultConfiguration();
55 // Avoid failing tests that rely on HTTP_HOST retrieval
56 $GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] = '.*';
57
58 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()
59 ->disableCoreCache()
60 ->initializeCachingFramework()
61 // Set all packages to active
62 ->initializePackageManagement(\TYPO3\CMS\Core\Package\UnitTestPackageManager::class)
63 // Find all class names
64 ->ensureClassLoadingInformationExists();
65 });