|
3 | 3 | namespace FOS\HttpCache\Tests\Functional;
|
4 | 4 |
|
5 | 5 | /**
|
6 |
| - * A PHPUnit test listener that starts and stops the PHP built-in web server |
| 6 | + * A PHPUnit test listener that starts and stops the PHP/HHVM built-in web |
| 7 | + * server |
7 | 8 | *
|
8 | 9 | * This listener is configured with a couple of constants from the phpunit.xml
|
9 | 10 | * file. To define constants in the phpunit file, use this syntax:
|
@@ -34,15 +35,13 @@ public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
|
34 | 35 | return;
|
35 | 36 | }
|
36 | 37 |
|
37 |
| - $command = sprintf( |
38 |
| - 'php -S %s:%d -t %s >/dev/null 2>&1 & echo $!', |
39 |
| - $this->getHostName(), |
40 |
| - $this->getPort(), |
41 |
| - $this->getDocRoot() |
42 |
| - ); |
| 38 | + if (defined('HHVM_VERSION')) { |
| 39 | + $pid = $this->startHhvmWebServer(); |
| 40 | + } else { |
| 41 | + $pid = $this->startPhpWebServer(); |
| 42 | + } |
43 | 43 |
|
44 |
| - exec($command, $output); |
45 |
| - $this->pid = $pid = $output[0]; |
| 44 | + $this->pid = $pid; |
46 | 45 |
|
47 | 46 | register_shutdown_function(function () use ($pid) {
|
48 | 47 | exec('kill ' . $pid);
|
@@ -107,4 +106,41 @@ protected function getDocRoot()
|
107 | 106 |
|
108 | 107 | return WEB_SERVER_DOCROOT;
|
109 | 108 | }
|
| 109 | + |
| 110 | + /** |
| 111 | + * Start HHVM built-in web server |
| 112 | + * |
| 113 | + * @return int PID |
| 114 | + */ |
| 115 | + protected function startHhvmWebServer() |
| 116 | + { |
| 117 | + $cur = getcwd(); |
| 118 | + chdir($this->getDocRoot()); |
| 119 | + $command = sprintf( |
| 120 | + 'hhvm -m server -p %d >/dev/null 2>&1 & echo $!', |
| 121 | + $this->getPort() |
| 122 | + ); |
| 123 | + exec($command, $output); |
| 124 | + chdir($cur); |
| 125 | + |
| 126 | + return $output[0]; |
| 127 | + } |
| 128 | + |
| 129 | + /** |
| 130 | + * Start PHP built-in web server |
| 131 | + * |
| 132 | + * @return int PID |
| 133 | + */ |
| 134 | + protected function startPhpWebServer() |
| 135 | + { |
| 136 | + $command = sprintf( |
| 137 | + 'php -S %s:%d -t %s >/dev/null 2>&1 & echo $!', |
| 138 | + $this->getHostName(), |
| 139 | + $this->getPort(), |
| 140 | + $this->getDocRoot() |
| 141 | + ); |
| 142 | + exec($command, $output); |
| 143 | + |
| 144 | + return $output[0]; |
| 145 | + } |
110 | 146 | }
|
0 commit comments