|
1
|
|
|
<?php declare(strict_types = 1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Simplex\Quickstart\Functional\Test; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use Simplex\Quickstart\Module\Demo\DataFixture\PersonLoader; |
|
7
|
|
|
use Simplex\Quickstart\Shared\Testing\PhpWebServer; |
|
8
|
|
|
use Symfony\Component\Process\Exception\ProcessFailedException; |
|
9
|
|
|
use Symfony\Component\Process\Process; |
|
10
|
|
|
|
|
11
|
|
|
final class WebApplicationTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
use PhpWebServer; |
|
14
|
|
|
|
|
15
|
|
|
private $intervalDuration = 60000; // 60 ms |
|
16
|
|
|
private $numberOfRetries = 34; // max 2.04 seconds |
|
17
|
|
|
|
|
18
|
|
|
public function test_web_application() |
|
19
|
|
|
{ |
|
20
|
|
|
if (getenv('SCRUTINIZER')) { |
|
21
|
|
|
$this->markTestSkipped(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
$acceptHeader = '"Accept: application/json"'; |
|
25
|
|
|
|
|
26
|
|
|
/** @noinspection PhpUndefinedConstantInspection */ |
|
27
|
|
|
$host = PHP_WEBSERVER_HOST; |
|
28
|
|
|
/** @noinspection PhpUndefinedConstantInspection */ |
|
29
|
|
|
$port = PHP_WEBSERVER_PORT; |
|
30
|
|
|
|
|
31
|
|
|
$process = new Process("curl -H $acceptHeader http://$host:$port/"); |
|
32
|
|
|
|
|
33
|
|
|
$this->runProcessWithRetry($process); |
|
34
|
|
|
|
|
35
|
|
|
self::assertContains('"name":"' . PersonLoader::PERSON_1_NAME . '"', $process->getOutput()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
private function runProcessWithRetry(Process $process): void |
|
39
|
|
|
{ |
|
40
|
|
|
for ($i = 0; $i < $this->numberOfRetries; ++$i) { |
|
41
|
|
|
|
|
42
|
|
|
usleep($this->intervalDuration); |
|
43
|
|
|
|
|
44
|
|
|
$process->run(); |
|
45
|
|
|
|
|
46
|
|
|
if ($process->isSuccessful()) { |
|
47
|
|
|
return; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
if (!$process->isSuccessful()) { |
|
52
|
|
|
throw new ProcessFailedException($process); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|