[CLEANUP] Wrap the tests bootstrap code into classes
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Build / FunctionalTestsBootstrap.php
1 <?php
2 namespace TYPO3\CMS\Core\Build;
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
17 /**
18 * This file is defined in FunctionalTests.xml and called by phpunit
19 * before instantiating the test suites, it must also be included
20 * with phpunit parameter --bootstrap if executing single test case classes.
21 */
22 class FunctionalTestsBootstrap {
23 /**
24 * Bootstraps the system for unit tests.
25 *
26 * @return void
27 */
28 public function bootstrapSystem() {
29 $this->enableDisplayErrors()
30 ->loadClassFiles()
31 ->defineOriginalRootPath();
32 }
33
34 /**
35 * Makes sure error messages during the tests get displayed no matter what is set in php.ini.
36 *
37 * @return FunctionalTestsBootstrap fluent interface
38 */
39 protected function enableDisplayErrors() {
40 @ini_set('display_errors', 1);
41 return $this;
42 }
43
44 /**
45 * Requires classes the functional test classes extend from or use for further bootstrap.
46 * Only files required for "new TestCaseClass" are required here and a general exception
47 * that is thrown by setUp() code.
48 *
49 * @return FunctionalTestsBootstrap fluent interface
50 */
51 protected function loadClassFiles() {
52 $testsDirectory = __DIR__ . '/../Tests/';
53 require_once($testsDirectory . 'BaseTestCase.php');
54 require_once($testsDirectory . 'FunctionalTestCase.php');
55 require_once($testsDirectory . 'FunctionalTestCaseBootstrapUtility.php');
56 require_once($testsDirectory . 'Exception.php');
57
58 return $this;
59 }
60
61 /**
62 * Defines the constant ORIGINAL_ROOT for the path to the original TYPO3 document root.
63 *
64 * If ORIGINAL_ROOT already is defined, this method is a no-op.
65 *
66 * @return FunctionalTestsBootstrap fluent interface
67 */
68 protected function defineOriginalRootPath() {
69 if (!defined('ORIGINAL_ROOT')) {
70 /** @var string */
71 define('ORIGINAL_ROOT', $this->getWebRoot());
72 }
73
74 return $this;
75 }
76
77 /**
78 * Returns the absolute path the TYPO3 document root.
79 *
80 * @return string the TYPO3 document root using Unix path separators
81 *
82 * @throws \RuntimeException
83 */
84 protected function getWebRoot() {
85 if (getenv('TYPO3_PATH_WEB')) {
86 $webRoot = getenv('TYPO3_PATH_WEB') . '/';
87 } else {
88 $webRoot = getcwd() . '/';
89 }
90
91 return strtr($webRoot, '\\', '/');
92 }
93 }
94
95 $bootstrap = new FunctionalTestsBootstrap();
96 $bootstrap->bootstrapSystem();
97 unset($bootstrap);