|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the FOSHttpCache package. |
| 5 | + * |
| 6 | + * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace FOS\HttpCache\Test\Legacy; |
| 13 | + |
| 14 | +use FOS\HttpCache\Test\WebServerListenerTrait; |
| 15 | +use PHPUnit\Framework\AssertionFailedError; |
| 16 | +use PHPUnit\Framework\Test; |
| 17 | +use PHPUnit\Framework\TestListener; |
| 18 | +use PHPUnit\Framework\TestSuite; |
| 19 | +use PHPUnit\Framework\Warning; |
| 20 | + |
| 21 | +/** |
| 22 | + * A PHPUnit test listener that starts and stops the PHP built-in web server. |
| 23 | + * |
| 24 | + * This legacy version is for PHPUnit 6.x. |
| 25 | + * |
| 26 | + * This listener is configured with a couple of constants from the phpunit.xml |
| 27 | + * file. To define constants in the phpunit file, use this syntax: |
| 28 | + * <php> |
| 29 | + * <const name="WEB_SERVER_HOSTNAME" value="localhost" /> |
| 30 | + * </php> |
| 31 | + * |
| 32 | + * WEB_SERVER_HOSTNAME host name of the web server (required) |
| 33 | + * WEB_SERVER_PORT port to listen on (required) |
| 34 | + * WEB_SERVER_DOCROOT path to the document root for the server (required) |
| 35 | + */ |
| 36 | +class WebServerListener6 implements TestListener |
| 37 | +{ |
| 38 | + /** @var WebServerListenerTrait */ |
| 39 | + private $trait; |
| 40 | + |
| 41 | + public function __construct() |
| 42 | + { |
| 43 | + $this->trait = new WebServerListenerTrait(); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Make sure the PHP built-in web server is running for tests with group |
| 48 | + * 'webserver'. |
| 49 | + */ |
| 50 | + public function startTestSuite(TestSuite $suite) |
| 51 | + { |
| 52 | + $this->trait->startTestSuite($suite); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * We don't need these. |
| 57 | + */ |
| 58 | + public function endTestSuite(TestSuite $suite) |
| 59 | + { |
| 60 | + } |
| 61 | + |
| 62 | + public function addError(Test $test, \Exception $e, $time) |
| 63 | + { |
| 64 | + } |
| 65 | + |
| 66 | + public function addFailure(Test $test, AssertionFailedError $e, $time) |
| 67 | + { |
| 68 | + } |
| 69 | + |
| 70 | + public function addIncompleteTest(Test $test, \Exception $e, $time) |
| 71 | + { |
| 72 | + } |
| 73 | + |
| 74 | + public function addSkippedTest(Test $test, \Exception $e, $time) |
| 75 | + { |
| 76 | + } |
| 77 | + |
| 78 | + public function startTest(Test $test) |
| 79 | + { |
| 80 | + } |
| 81 | + |
| 82 | + public function endTest(Test $test, $time) |
| 83 | + { |
| 84 | + } |
| 85 | + |
| 86 | + public function addRiskyTest(Test $test, \Exception $e, $time) |
| 87 | + { |
| 88 | + } |
| 89 | + |
| 90 | + public function addWarning(Test $test, Warning $e, $time) |
| 91 | + { |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * Get web server hostname. |
| 96 | + * |
| 97 | + * @throws \Exception |
| 98 | + * |
| 99 | + * @return string |
| 100 | + */ |
| 101 | + protected function getHostName() |
| 102 | + { |
| 103 | + return $this->trait->getHostName(); |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Get web server port. |
| 108 | + * |
| 109 | + * @throws \Exception |
| 110 | + * |
| 111 | + * @return int |
| 112 | + */ |
| 113 | + protected function getPort() |
| 114 | + { |
| 115 | + return $this->trait->getPort(); |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * Get web server port. |
| 120 | + * |
| 121 | + * @throws \Exception |
| 122 | + * |
| 123 | + * @return int |
| 124 | + */ |
| 125 | + protected function getDocRoot() |
| 126 | + { |
| 127 | + return $this->trait->getDocRoot(); |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Start PHP built-in web server. |
| 132 | + * |
| 133 | + * @return int PID |
| 134 | + */ |
| 135 | + protected function startPhpWebServer() |
| 136 | + { |
| 137 | + return $this->trait->startPhpWebServer(); |
| 138 | + } |
| 139 | + |
| 140 | + /** |
| 141 | + * Wait for caching proxy to be started up and reachable. |
| 142 | + * |
| 143 | + * @param string $ip |
| 144 | + * @param int $port |
| 145 | + * @param int $timeout Timeout in milliseconds |
| 146 | + * |
| 147 | + * @throws \RuntimeException If proxy is not reachable within timeout |
| 148 | + */ |
| 149 | + protected function waitFor($ip, $port, $timeout) |
| 150 | + { |
| 151 | + $this->trait->waitFor($ip, $port, $timeout); |
| 152 | + } |
| 153 | +} |
0 commit comments