2 namespace TYPO3\CMS\Core\Build
;
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Core\Tests\BaseTestCase
;
20 * This file is defined in FunctionalTests.xml and called by phpunit
21 * before instantiating the test suites, it must also be included
22 * with phpunit parameter --bootstrap if executing single test case classes.
24 class FunctionalTestsBootstrap
{
26 * Bootstraps the system for unit tests.
30 public function bootstrapSystem() {
31 $this->enableDisplayErrors()
33 ->defineOriginalRootPath()
34 ->createNecessaryDirectoriesInDocumentRoot();
38 * Makes sure error messages during the tests get displayed no matter what is set in php.ini.
40 * @return FunctionalTestsBootstrap fluent interface
42 protected function enableDisplayErrors() {
43 @ini_set
('display_errors', 1);
48 * Requires classes the functional test classes extend from or use for further bootstrap.
49 * Only files required for "new TestCaseClass" are required here and a general exception
50 * that is thrown by setUp() code.
52 * @return FunctionalTestsBootstrap fluent interface
54 protected function loadClassFiles() {
55 if (!class_exists('PHPUnit_Framework_TestCase')) {
56 die('PHPUnit wasn\'t found. Please check your settings and command.');
58 if (!class_exists(BaseTestCase
::class)) {
59 // PHPUnit is invoked globally, so we need to include the project autoload file
60 require_once __DIR__
. '/../../../../vendor/autoload.php';
67 * Defines the constant ORIGINAL_ROOT for the path to the original TYPO3 document root.
69 * If ORIGINAL_ROOT already is defined, this method is a no-op.
71 * @return FunctionalTestsBootstrap fluent interface
73 protected function defineOriginalRootPath() {
74 if (!defined('ORIGINAL_ROOT')) {
76 define('ORIGINAL_ROOT', $this->getWebRoot());
83 * Creates the following directories in the TYPO3 core:
86 * @return FunctionalTestsBootstrap fluent interface
88 protected function createNecessaryDirectoriesInDocumentRoot() {
89 $this->createDirectory(ORIGINAL_ROOT
. 'typo3temp');
95 * Creates the directory $directory (recursively if required).
97 * If $directory already exists, this method is a no-op.
99 * @param string $directory absolute path of the directory to be created
101 * @throws \RuntimeException
103 protected function createDirectory($directory) {
104 if (is_dir($directory)) {
107 @mkdir
($directory, 0777, TRUE);
109 if (!is_dir($directory)) {
110 throw new \
RuntimeException('Directory "' . $directory . '" could not be created', 1404038665);
115 * Returns the absolute path the TYPO3 document root.
117 * @return string the TYPO3 document root using Unix path separators
119 protected function getWebRoot() {
120 if (getenv('TYPO3_PATH_WEB')) {
121 $webRoot = getenv('TYPO3_PATH_WEB');
125 return rtrim(strtr($webRoot, '\\', '/'), '/') . '/';
129 if (PHP_SAPI
!== 'cli') {
130 die('This script supports command line usage only. Please check your command.');
132 $bootstrap = new FunctionalTestsBootstrap();
133 $bootstrap->bootstrapSystem();