|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Panther project. |
| 5 | + * |
| 6 | + * (c) Kévin Dunglas <[email protected]> |
| 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 | +declare(strict_types=1); |
| 13 | + |
| 14 | +namespace Symfony\Component\Panther\Tests; |
| 15 | + |
| 16 | +use PHPUnit\Framework\TestSuite; |
| 17 | +use Symfony\Component\Panther\ServerListener; |
| 18 | + |
| 19 | +class ServerListenerTest extends TestCase |
| 20 | +{ |
| 21 | + private function createTestSuite() |
| 22 | + { |
| 23 | + $suite = $this->createMock(TestSuite::class); |
| 24 | + $suite->expects($this->once())->method('getName')->willReturn('Dummy test suite'); |
| 25 | + |
| 26 | + return $suite; |
| 27 | + } |
| 28 | + |
| 29 | + public function testStartAndStop(): void |
| 30 | + { |
| 31 | + $this->expectOutputString("Starting Panther server for test suite Dummy test suite...\n\nShutting down Panther server...\n"); |
| 32 | + |
| 33 | + $_SERVER['PANTHER_WEB_SERVER_DIR'] = static::$webServerDir; |
| 34 | + |
| 35 | + $streamContext = stream_context_create(['http' => [ |
| 36 | + 'ignore_errors' => true, |
| 37 | + 'protocol_version' => '1.1', |
| 38 | + 'header' => ['Connection: close'], |
| 39 | + 'timeout' => 1, |
| 40 | + ]]); |
| 41 | + |
| 42 | + $healthCheck = function () use ($streamContext) { |
| 43 | + return @file_get_contents('http://127.0.0.1:9000', false, $streamContext); |
| 44 | + }; |
| 45 | + |
| 46 | + $testSuite = $this->createTestSuite(); |
| 47 | + |
| 48 | + $listener = new ServerListener(); |
| 49 | + $listener->startTestSuite($testSuite); |
| 50 | + |
| 51 | + // Means the server rendered a 404, so server is running. |
| 52 | + static::assertContains('<title>404 Not Found</title>', $healthCheck()); |
| 53 | + |
| 54 | + $listener->endTestSuite($testSuite); |
| 55 | + |
| 56 | + // False means that ping failed. |
| 57 | + static::assertFalse($healthCheck()); |
| 58 | + } |
| 59 | +} |
0 commit comments