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