TYPO3 CMS  TYPO3_6-2
UnitTestsBootstrap.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Build;
3 
18 
44  public function bootstrapSystem() {
45  $this->enableDisplayErrors()
46  ->checkForCliDispatch()
47  ->defineSitePath()
48  ->setTypo3Context()
49  ->createNecessaryDirectoriesInDocumentRoot()
50  ->includeAndStartCoreBootstrap()
51  ->initializeConfiguration()
52  ->finishCoreBootstrap();
53  }
54 
60  protected function enableDisplayErrors() {
61  @ini_set('display_errors', 1);
62  return $this;
63  }
64 
71  protected function checkForCliDispatch() {
72  if (!defined('TYPO3_MODE')) {
73  return $this;
74  }
75 
76  array_shift($_SERVER['argv']);
77  $flatArguments = implode(' ', $_SERVER['argv']);
78  echo 'Please run the unit tests using the following command:' . chr(10) .
79  sprintf('typo3conf/ext/phpunit/Composer/vendor/bin/phpunit %s', $flatArguments) . chr(10) .
80  chr(10);
81 
82  exit(1);
83  }
84 
90  protected function defineSitePath() {
92  define('PATH_site', $this->getWebRoot());
94  define('PATH_thisScript', PATH_site . 'typo3/cli_dispatch.phpsh');
95  $_SERVER['SCRIPT_NAME'] = PATH_thisScript;
96 
97  return $this;
98  }
99 
105  protected function getWebRoot() {
106  if (getenv('TYPO3_PATH_WEB')) {
107  $webRoot = getenv('TYPO3_PATH_WEB') . '/';
108  } else {
109  $webRoot = getcwd() . '/';
110  }
111 
112  return strtr($webRoot, '\\', '/');
113  }
114 
120  protected function setTypo3Context() {
122  define('TYPO3_MODE', 'BE');
124  define('TYPO3_cliMode', TRUE);
125  putenv('TYPO3_CONTEXT=Testing');
126 
127  return $this;
128  }
129 
140  $this->createDirectory(PATH_site . 'uploads');
141  $this->createDirectory(PATH_site . 'typo3temp');
142  $this->createDirectory(PATH_site . 'typo3conf/ext');
143 
144  return $this;
145  }
146 
158  protected function createDirectory($directory) {
159  if (is_dir($directory)) {
160  return;
161  }
162 
163  if (!mkdir($directory, 0777, TRUE)) {
164  throw new \RuntimeException('Directory "' . $directory . '" could not be created', 1423043755);
165  }
166  }
167 
173  protected function includeAndStartCoreBootstrap() {
174  $bootstrapPath = PATH_site . '/typo3/sysext/core/Classes/Core/Bootstrap.php';
175  if (!file_exists($bootstrapPath)) {
176  die('Bootstrap can\'t be loaded. Please check your path or set an environment variable \'TYPO3_PATH_WEB\' to your root path.');
177  }
178  require_once $bootstrapPath;
179 
181  ->baseSetup()
182  ->initializeClassLoader();
183 
184  return $this;
185  }
186 
192  protected function initializeConfiguration() {
193  $configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager();
194  $GLOBALS['TYPO3_CONF_VARS'] = $configurationManager->getDefaultConfiguration();
195 
196  // avoid failing tests that rely on HTTP_HOST retrieval
197  $GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] = '.*';
198 
199  return $this;
200  }
201 
207  protected function finishCoreBootstrap() {
209  ->disableCoreAndClassesCache()
210  ->initializeCachingFramework()
211  ->initializeClassLoaderCaches()
212  ->initializePackageManagement('TYPO3\\CMS\\Core\\Package\\UnitTestPackageManager');
213 
214  return $this;
215  }
216 }
217 
218 if (PHP_SAPI !== 'cli') {
219  die('This script supports command line usage only. Please check your command.');
220 }
221 
223 $bootstrap->bootstrapSystem();
224 unset($bootstrap);
if(PHP_SAPI !=='cli') $bootstrap
die
Definition: index.php:6
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]