b48f354cd28915da14360a93ee1e8be6433cf2fb
[yaffs-website] / PHP / Template / TestCaseMethod.tpl.dist
1 <?php
2 if (!defined('STDOUT')) {
3     // php://stdout does not obey output buffering. Any output would break
4     // unserialization of child process results in the parent process.
5     define('STDOUT', fopen('php://temp', 'w+b'));
6     define('STDERR', fopen('php://stderr', 'wb'));
7 }
8
9 {iniSettings}
10 ini_set('display_errors', 'stderr');
11 set_include_path('{include_path}');
12
13 $composerAutoload = {composerAutoload};
14 $phar             = {phar};
15
16 ob_start();
17
18 if ($composerAutoload) {
19     require_once $composerAutoload;
20     define('PHPUNIT_COMPOSER_INSTALL', $composerAutoload);
21 } else if ($phar) {
22     require $phar;
23 }
24
25 function __phpunit_run_isolated_test()
26 {
27     if (!class_exists('{className}')) {
28         require_once '{filename}';
29     }
30
31     $result = new PHPUnit_Framework_TestResult;
32
33     if ({collectCodeCoverageInformation}) {
34         $result->setCodeCoverage(
35             new PHP_CodeCoverage(
36                 null,
37                 unserialize('{codeCoverageFilter}')
38             )
39         );
40     }
41
42     $result->beStrictAboutTestsThatDoNotTestAnything({isStrictAboutTestsThatDoNotTestAnything});
43     $result->beStrictAboutOutputDuringTests({isStrictAboutOutputDuringTests});
44     $result->beStrictAboutTestSize({isStrictAboutTestSize});
45     $result->beStrictAboutTodoAnnotatedTests({isStrictAboutTodoAnnotatedTests});
46
47     $test = new {className}('{methodName}', unserialize('{data}'), '{dataName}');
48     $test->setDependencyInput(unserialize('{dependencyInput}'));
49     $test->setInIsolation(TRUE);
50
51     ob_end_clean();
52     $test->run($result);
53     $output = '';
54     if (!$test->hasExpectationOnOutput()) {
55         $output = $test->getActualOutput();
56     }
57
58     @rewind(STDOUT); /* @ as not every STDOUT target stream is rewindable */
59     if ($stdout = stream_get_contents(STDOUT)) {
60         $output = $stdout . $output;
61     }
62
63     print serialize(
64       array(
65         'testResult'    => $test->getResult(),
66         'numAssertions' => $test->getNumAssertions(),
67         'result'        => $result,
68         'output'        => $output
69       )
70     );
71 }
72
73 $configurationFilePath = '{configurationFilePath}';
74
75 if ('' !== $configurationFilePath) {
76     $configuration = PHPUnit_Util_Configuration::getInstance($configurationFilePath);
77     $configuration->handlePHPConfiguration();
78     unset($configuration);
79 }
80
81 function __phpunit_error_handler($errno, $errstr, $errfile, $errline, $errcontext)
82 {
83    return true;
84 }
85
86 set_error_handler("__phpunit_error_handler");
87
88 {constants}
89 {included_files}
90 {globals}
91
92 restore_error_handler();
93
94 if (isset($GLOBALS['__PHPUNIT_BOOTSTRAP'])) {
95     require_once $GLOBALS['__PHPUNIT_BOOTSTRAP'];
96     unset($GLOBALS['__PHPUNIT_BOOTSTRAP']);
97 }
98
99 __phpunit_run_isolated_test();