TYPO3 CMS  TYPO3_7-6
FunctionalTestsBootstrap.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
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.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
18 
25 {
31  public function bootstrapSystem()
32  {
33  $this->enableDisplayErrors()
34  ->loadClassFiles()
35  ->defineOriginalRootPath()
36  ->createNecessaryDirectoriesInDocumentRoot();
37  }
38 
44  protected function enableDisplayErrors()
45  {
46  @ini_set('display_errors', 1);
47  return $this;
48  }
49 
57  protected function loadClassFiles()
58  {
59  if (!class_exists('PHPUnit_Framework_TestCase')) {
60  $this->exitWithMessage('PHPUnit wasn\'t found. Please check your settings and command.');
61  }
62  if (!class_exists(BaseTestCase::class)) {
63  // PHPUnit is invoked globally, so we need to include the project autoload file
64  require_once __DIR__ . '/../../../../vendor/autoload.php';
65  }
66 
67  return $this;
68  }
69 
77  protected function defineOriginalRootPath()
78  {
79  if (!defined('ORIGINAL_ROOT')) {
81  define('ORIGINAL_ROOT', $this->getWebRoot());
82  }
83 
84  if (!file_exists(ORIGINAL_ROOT . 'typo3/cli_dispatch.phpsh')) {
85  $this->exitWithMessage('Unable to determine path to entry script. Please check your path or set an environment variable \'TYPO3_PATH_WEB\' to your root path.');
86  }
87 
88  return $this;
89  }
90 
98  {
99  $this->createDirectory(ORIGINAL_ROOT . 'typo3temp');
100 
101  return $this;
102  }
103 
113  protected function createDirectory($directory)
114  {
115  if (is_dir($directory)) {
116  return;
117  }
118  @mkdir($directory, 0777, true);
119  clearstatcache();
120  if (!is_dir($directory)) {
121  throw new \RuntimeException('Directory "' . $directory . '" could not be created', 1404038665);
122  }
123  }
124 
130  protected function getWebRoot()
131  {
132  if (getenv('TYPO3_PATH_WEB')) {
133  $webRoot = getenv('TYPO3_PATH_WEB');
134  } else {
135  $webRoot = getcwd();
136  }
137  return rtrim(strtr($webRoot, '\\', '/'), '/') . '/';
138  }
139 
145  protected function exitWithMessage($message)
146  {
147  echo $message . chr(10);
148  exit(1);
149  }
150 }
151 
152 if (PHP_SAPI !== 'cli') {
153  die('This script supports command line usage only. Please check your command.');
154 }
156 $bootstrap->bootstrapSystem();
157 unset($bootstrap);
if(PHP_SAPI !=='cli') $bootstrap