|
10 | 10 |
|
11 | 11 | final class RedmineInstance |
12 | 12 | { |
13 | | - /** |
14 | | - * Make sure that supported versions have a service in /docker-composer.yml |
15 | | - * and are configured in /tests/Behat/behat.yml |
16 | | - */ |
17 | | - public static function getSupportedVersions(): array |
18 | | - { |
19 | | - return [ |
20 | | - RedmineVersion::V5_1_3, |
21 | | - RedmineVersion::V5_0_9, |
22 | | - RedmineVersion::V4_2_10, |
23 | | - ]; |
24 | | - } |
25 | | - |
26 | 13 | /** |
27 | 14 | * @param InstanceRegistration $tracer Required to ensure that RedmineInstance is created while Test Runner is running |
28 | 15 | */ |
29 | 16 | public static function create(InstanceRegistration $tracer, RedmineVersion $version): void |
30 | 17 | { |
31 | | - if (! in_array($version, static::getSupportedVersions())) { |
32 | | - throw new InvalidArgumentException('Redmine ' . $version->asString() . ' is not supported.'); |
33 | | - } |
34 | | - |
35 | 18 | $tracer->registerInstance(new self($tracer, $version)); |
36 | 19 | } |
37 | 20 |
|
@@ -77,6 +60,8 @@ private function __construct(InstanceRegistration $tracer, RedmineVersion $versi |
77 | 60 | $this->redmineUrl = 'http://redmine-' . $versionId . ':3000'; |
78 | 61 | $this->apiKey = sha1($versionId . (string) time()); |
79 | 62 |
|
| 63 | + $this->runHealthChecks($version); |
| 64 | + |
80 | 65 | $this->createDatabaseBackup(); |
81 | 66 | $this->createFilesBackup(); |
82 | 67 | $this->runDatabaseMigration(); |
@@ -104,6 +89,33 @@ public function getApiKey(): string |
104 | 89 | return $this->apiKey; |
105 | 90 | } |
106 | 91 |
|
| 92 | + private function runHealthChecks(RedmineVersion $version): void |
| 93 | + { |
| 94 | + $ch = curl_init($this->redmineUrl); |
| 95 | + curl_setopt($ch, CURLOPT_TIMEOUT, 5); |
| 96 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); |
| 97 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 98 | + $data = curl_exec($ch); |
| 99 | + $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| 100 | + curl_close($ch); |
| 101 | + |
| 102 | + if ($data === false || $statusCode !== 200) { |
| 103 | + throw new InvalidArgumentException(sprintf( |
| 104 | + 'Could not connect to Redmine server at %s, please make sure that Redmine %s has a docker service in /docker-composer.yml and is correctly configured in /tests/Behat/behat.yml.', |
| 105 | + $this->redmineUrl, |
| 106 | + $version->asString(), |
| 107 | + )); |
| 108 | + } |
| 109 | + |
| 110 | + if (! file_exists($this->rootPath . $this->workingDB)) { |
| 111 | + throw new InvalidArgumentException(sprintf( |
| 112 | + 'Could not find database file in %s, please make sure that Redmine %s has a docker service in /docker-composer.yml and is correctly configured in /tests/Behat/behat.yml.', |
| 113 | + $this->rootPath . $this->workingDB, |
| 114 | + $version->asString(), |
| 115 | + )); |
| 116 | + } |
| 117 | + } |
| 118 | + |
107 | 119 | public function reset(InstanceRegistration $tracer): void |
108 | 120 | { |
109 | 121 | if ($tracer !== $this->tracer) { |
|
0 commit comments