Skip to content

Commit e5be6e4

Browse files
committed
Merge pull request #226 from FriendsOfSymfony/webserver-listener
Move WebServerListener
2 parents f97980c + 4e60cbe commit e5be6e4

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

doc/testing-your-application.rst

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,40 @@ By having your test classes extend one of the test case classes, you get:
2323
The recommended way to configure the test case is by setting constants
2424
in your ``phpunit.xml``. Alternatively, you can override the getter methods.
2525

26+
Web Server
27+
~~~~~~~~~~
28+
2629
You will need to run a web server to provide the PHP application you want to
27-
test. The test cases only handle running the caching proxy. With PHP 5.4 or
28-
newer, the easiest is to use the PHP built in web server. See the
29-
``WebServerListener`` class in ``tests/Functional`` and how it is registered in
30-
``phpunit.xml.dist``.
30+
test. The test cases only handle running the caching proxy. It’s easiest to
31+
use PHP’s built in web server. Include the WebServerListener in your
32+
``phpunit.xml``:
33+
34+
.. literalinclude:: ../phpunit.xml.dist
35+
:prepend:
36+
<?xml version="1.0" encoding="UTF-8"?>
37+
<phpunit ...>
38+
<listeners>
39+
:language: xml
40+
:start-after: <listeners>
41+
:end-before: </listeners>
42+
:append:
43+
</listeners>
44+
</phpunit>
45+
46+
Then set the ``webserver`` group on your test to start PHP’s web server before
47+
it runs::
48+
49+
class YourTest extends \PHPUnit_Framework_TestCase
50+
{
51+
/**
52+
* @group webserver
53+
*/
54+
public function testYourApp()
55+
{
56+
// The web server will be started before this test code runs and
57+
// shut down again after it finishes.
58+
}
59+
}
3160

3261
Setting Constants
3362
~~~~~~~~~~~~~~~~~

phpunit.xml.dist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
<filter>
1616
<whitelist>
1717
<directory>./src</directory>
18+
<directory>./tests</directory>
1819
</whitelist>
1920
</filter>
2021

2122
<listeners>
2223
<listener class="\Mockery\Adapter\Phpunit\TestListener" />
23-
<listener class="\FOS\HttpCache\Tests\Functional\WebServerListener" />
24+
<listener class="\FOS\HttpCache\Test\WebServerListener" />
2425
</listeners>
2526

2627
<php>

tests/Functional/WebServerListener.php renamed to src/Test/WebServerListener.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace FOS\HttpCache\Tests\Functional;
12+
namespace FOS\HttpCache\Test;
1313

1414
/**
1515
* A PHPUnit test listener that starts and stops the PHP built-in web server
@@ -41,7 +41,7 @@ public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
4141
{
4242
// Only run on PHP >= 5.4 as PHP below that and HHVM don't have a
4343
// built-in web server
44-
if (defined('HHVM_VERSION') || version_compare(PHP_VERSION, '5.4.0', '<')) {
44+
if (defined('HHVM_VERSION')) {
4545
return;
4646
}
4747

@@ -155,17 +155,6 @@ protected function waitFor($ip, $port, $timeout)
155155
usleep(1000);
156156
}
157157

158-
$client = new \Guzzle\Http\Client();
159-
$url = sprintf('http://%s:%d/cache.php', $this->getHostName(), $this->getPort());
160-
for (; $i < $timeout; $i++) {
161-
try {
162-
if ($client->get($url)->send()->isSuccessful()) {
163-
return;
164-
}
165-
} catch (\Exception $e) {
166-
}
167-
}
168-
169158
throw new \RuntimeException(
170159
sprintf(
171160
'Webserver cannot be reached at %s:%s',

0 commit comments

Comments
 (0)