From 2aa3e32a3a841c77d1dbf499f3f0a1673a058005 Mon Sep 17 00:00:00 2001 From: tuutti Date: Thu, 25 Apr 2024 16:04:01 +0300 Subject: [PATCH 01/11] UHF-9833: Removed support for environment specific metadata, removed azure devops link from project metadata --- documentation/environment-resolver.md | 4 - fixtures/environments.json | 135 +++--------------- src/Environment/Environment.php | 13 -- src/Environment/EnvironmentMetadata.php | 64 --------- src/Environment/EnvironmentResolver.php | 1 - src/Environment/ProjectMetadata.php | 17 +-- .../Environment/EnvironmentMetadataTest.php | 53 ------- .../Environment/EnvironmentResolverTest.php | 16 --- .../src/Unit/Environment/EnvironmentTest.php | 10 +- .../Unit/Environment/ProjectMetadataTest.php | 5 +- tests/src/Unit/Environment/ProjectTest.php | 9 +- 11 files changed, 27 insertions(+), 300 deletions(-) delete mode 100644 src/Environment/EnvironmentMetadata.php delete mode 100644 tests/src/Unit/Environment/EnvironmentMetadataTest.php diff --git a/documentation/environment-resolver.md b/documentation/environment-resolver.md index 7c7fc242..67f33f54 100644 --- a/documentation/environment-resolver.md +++ b/documentation/environment-resolver.md @@ -15,8 +15,6 @@ $resolver = \Drupal::service('helfi_api_base.environment_resolver'); $project = $resolver->getProject($projectName); /** @var \Drupal\helfi_api_base\Environment\ProjectMetadata $projectMetadata */ $projectMetadata = $project->getMetadata(); -// A link to the Azure DevOps service. -$projectMetadata->getAzureDevopsLink(); // 'https://dev.azure.com/City-of-Helsinki/asuminen'. // A link to the Git repository. $projectMetadata->getRepositoryUrl(); // 'https://github.com/City-of-Helsinki/drupal-helfi-asuminen'. @@ -31,8 +29,6 @@ $domain = $environment->getDomain(); // 'nginx-asuminen-dev.agw.arodevtest.hel.f $baseUrl = $environment->getBaseUrl(); // 'https://nginx-asuminen-dev.agw.arodevtest.hel.fi' /** @var \Drupal\helfi_api_base\Environment\EnvironmentMetadata $environmentMetadata */ $environmentMetadata = $environment->getMetadata(); -// A link to the OpenShift service. -$environmentMetadata->getOpenshiftConsoleLink(); // 'https://console-openshift-console.apps.arodevtest.hel.fi/k8s/cluster/projects/hki-kanslia-asuminen-test' ``` ### Active environment diff --git a/fixtures/environments.json b/fixtures/environments.json index bd1161eb..6e4e813c 100644 --- a/fixtures/environments.json +++ b/fixtures/environments.json @@ -1,8 +1,7 @@ { "asuminen": { "meta": { - "repository": "City-of-Helsinki/drupal-helfi-asuminen", - "azure_devops_link": "https://dev.azure.com/City-of-Helsinki/asuminen" + "repository": "City-of-Helsinki/drupal-helfi-asuminen" }, "environments": { "local": { @@ -19,8 +18,7 @@ "protocol": "http", "domain": "helfi-asuminen", "port": 8080 - }, - "meta": {} + } }, "test": { "path": { @@ -35,9 +33,6 @@ "internal_address": { "protocol": "https", "domain": "nginx-asuminen-test.apps.arodevtest.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.arodevtest.hel.fi/k8s/cluster/projects/hki-kanslia-asuminen-test" } }, "stage": { @@ -53,9 +48,6 @@ "internal_address": { "protocol": "https", "domain": "nginx-asuminen-staging.apps.platta.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.platta.hel.fi/k8s/cluster/projects/hki-kanslia-asuminen-staging" } }, "prod": { @@ -71,17 +63,13 @@ "internal_address": { "protocol": "https", "domain": "nginx-asuminen-prod.apps.platta.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.platta.hel.fi/k8s/cluster/projects/hki-kanslia-asuminen-prod" } } } }, "etusivu": { "meta": { - "repository": "City-of-Helsinki/drupal-helfi-etusivu", - "azure_devops_link": "https://dev.azure.com/City-of-Helsinki/helfi-etusivu" + "repository": "City-of-Helsinki/drupal-helfi-etusivu" }, "environments": { "local": { @@ -98,8 +86,7 @@ "protocol": "http", "domain": "helfi-etusivu", "port": 8080 - }, - "meta": {} + } }, "test": { "path": { @@ -114,9 +101,6 @@ "internal_address": { "protocol": "https", "domain": "nginx-etusivu-test.apps.arodevtest.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.arodevtest.hel.fi/k8s/cluster/projects/hki-kanslia-helfi-etusivu-test" } }, "stage": { @@ -132,9 +116,6 @@ "internal_address": { "protocol": "https", "domain": "nginx-etusivu-staging.apps.platta.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.platta.hel.fi/k8s/cluster/projects/hki-kanslia-helfi-etusivu-staging" } }, "prod": { @@ -150,17 +131,13 @@ "internal_address": { "protocol": "https", "domain": "nginx-etusivu-prod.apps.platta.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.platta.hel.fi/k8s/cluster/projects/hki-kanslia-helfi-etusivu-prod" } } } }, "kasvatus-koulutus": { "meta": { - "repository": "City-of-Helsinki/drupal-helfi-kasvatus-koulutus", - "azure_devops_link": "https://dev.azure.com/City-of-Helsinki/kasvatus-koulutus" + "repository": "City-of-Helsinki/drupal-helfi-kasvatus-koulutus" }, "environments": { "local": { @@ -177,8 +154,7 @@ "protocol": "http", "domain": "helfi-kasko", "port": 8080 - }, - "meta": {} + } }, "test": { "path": { @@ -193,9 +169,6 @@ "internal_address": { "protocol": "https", "domain": "nginx-kasvatus-koulutus-test.apps.arodevtest.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.arodevtest.hel.fi/k8s/cluster/projects/hki-kasko-kasvatus-koulutus-test" } }, "stage": { @@ -211,9 +184,6 @@ "internal_address": { "protocol": "https", "domain": "nginx-kasvatus-koulutus-staging.apps.platta.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.platta.hel.fi/k8s/cluster/projects/hki-kasko-kasvatus-koulutus-staging" } }, "prod": { @@ -229,17 +199,13 @@ "internal_address": { "protocol": "https", "domain": "nginx-kasvatus-koulutus-prod.apps.platta.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.platta.hel.fi/k8s/cluster/projects/hki-kasko-kasvatus-koulutus-prod" } } } }, "kuva": { "meta": { - "repository": "City-of-Helsinki/drupal-helfi-kuva", - "azure_devops_link": "https://dev.azure.com/City-of-Helsinki/helfi-kuva" + "repository": "City-of-Helsinki/drupal-helfi-kuva" }, "environments": { "local": { @@ -256,8 +222,7 @@ "protocol": "http", "domain": "helfi-kuva", "port": 8080 - }, - "meta": {} + } }, "test": { "path": { @@ -272,9 +237,6 @@ "internal_address": { "protocol": "https", "domain": "nginx-kuva-test.apps.arodevtest.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.arodevtest.hel.fi/k8s/cluster/projects/hki-kuva-helfi-kuva-test" } }, "stage": { @@ -290,9 +252,6 @@ "internal_address": { "protocol": "https", "domain": "nginx-kuva-staging.apps.platta.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.platta.hel.fi/k8s/cluster/projects/hki-kuva-helfi-kuva-staging" } }, "prod": { @@ -308,17 +267,13 @@ "internal_address": { "protocol": "https", "domain": "nginx-kuva-prod.apps.platta.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.platta.hel.fi/k8s/cluster/projects/hki-kuva-helfi-kuva-prod" } } } }, "liikenne": { "meta": { - "repository": "City-of-Helsinki/drupal-helfi-kymp", - "azure_devops_link": "https://dev.azure.com/City-of-Helsinki/liikenne" + "repository": "City-of-Helsinki/drupal-helfi-kymp" }, "environments": { "local": { @@ -335,8 +290,7 @@ "protocol": "http", "domain": "helfi-kymp", "port": 8080 - }, - "meta": {} + } }, "test": { "path": { @@ -351,9 +305,6 @@ "internal_address": { "protocol": "https", "domain": "nginx-liikenne-test.apps.arodevtest.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.arodevtest.hel.fi/k8s/cluster/projects/hki-kanslia-liikenne-test" } }, "stage": { @@ -369,9 +320,6 @@ "internal_address": { "protocol": "https", "domain": "nginx-liikenne-staging.apps.platta.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.platta.hel.fi/k8s/cluster/projects/hki-kanslia-liikenne-staging" } }, "prod": { @@ -387,17 +335,13 @@ "internal_address": { "protocol": "https", "domain": "nginx-liikenne-prod.apps.platta.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.platta.hel.fi/k8s/cluster/projects/hki-kanslia-liikenne-prod" } } } }, "rekry": { "meta": { - "repository": "City-of-Helsinki/drupal-helfi-rekry", - "azure_devops_link": "https://dev.azure.com/City-of-Helsinki/helfi-rekry" + "repository": "City-of-Helsinki/drupal-helfi-rekry" }, "environments": { "local": { @@ -414,8 +358,7 @@ "protocol": "http", "domain": "helfi-rekry", "port": 8080 - }, - "meta": {} + } }, "test": { "path": { @@ -430,9 +373,6 @@ "internal_address": { "protocol": "https", "domain": "nginx-rekry-test.apps.arodevtest.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.arodevtest.hel.fi/k8s/cluster/projects/hki-kanslia-helfi-rekry-test" } }, "stage": { @@ -448,9 +388,6 @@ "internal_address": { "protocol": "https", "domain": "nginx-rekry-staging.apps.platta.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.platta.hel.fi/k8s/cluster/projects/hki-kanslia-helfi-rekry-staging" } }, "prod": { @@ -466,17 +403,13 @@ "internal_address": { "protocol": "https", "domain": "nginx-rekry-prod.apps.platta.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.platta.hel.fi/k8s/cluster/projects/hki-kanslia-helfi-rekry-prod" } } } }, "strategia": { "meta": { - "repository": "City-of-Helsinki/drupal-helfi-strategia", - "azure_devops_link": "https://dev.azure.com/City-of-Helsinki/strategia-talous" + "repository": "City-of-Helsinki/drupal-helfi-strategia" }, "environments": { "local": { @@ -493,8 +426,7 @@ "protocol": "http", "domain": "strategia", "port": 8080 - }, - "meta": {} + } }, "test": { "path": { @@ -509,9 +441,6 @@ "internal_address": { "protocol": "https", "domain": "nginx-strategia-talous-test.apps.arodevtest.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.arodevtest.hel.fi/k8s/cluster/projects/hki-kanslia-strategia-talous-test" } }, "stage": { @@ -527,9 +456,6 @@ "internal_address": { "protocol": "https", "domain": "nginx-strategia-talous-staging.apps.platta.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.platta.hel.fi/k8s/cluster/projects/hki-kanslia-strategia-talous-staging" } }, "prod": { @@ -545,17 +471,13 @@ "internal_address": { "protocol": "https", "domain": "nginx-strategia-talous-prod.apps.platta.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.platta.hel.fi/k8s/cluster/projects/hki-kanslia-strategia-talous-prod" } } } }, "terveys": { "meta": { - "repository": "City-of-Helsinki/drupal-helfi-sote", - "azure_devops_link": "https://dev.azure.com/City-of-Helsinki/terveys" + "repository": "City-of-Helsinki/drupal-helfi-sote" }, "environments": { "local": { @@ -572,8 +494,7 @@ "protocol": "http", "domain": "helfi-sote", "port": 8080 - }, - "meta": {} + } }, "test": { "path": { @@ -588,9 +509,6 @@ "internal_address": { "protocol": "https", "domain": "nginx-terveys-test.apps.arodevtest.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.arodevtest.hel.fi/k8s/cluster/projects/hki-kanslia-terveys-test" } }, "stage": { @@ -606,9 +524,6 @@ "internal_address": { "protocol": "https", "domain": "nginx-terveys-staging.apps.platta.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.platta.hel.fi/k8s/cluster/projects/hki-kanslia-terveys-staging" } }, "prod": { @@ -624,17 +539,13 @@ "internal_address": { "protocol": "https", "domain": "nginx-terveys-prod.apps.platta.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.platta.hel.fi/k8s/cluster/projects/hki-kanslia-terveys-prod" } } } }, "tyo-yrittaminen": { "meta": { - "repository": "City-of-Helsinki/drupal-helfi-tyo-yrittaminen", - "azure_devops_link": "https://dev.azure.com/City-of-Helsinki/tyo-yrittaminen" + "repository": "City-of-Helsinki/drupal-helfi-tyo-yrittaminen" }, "environments": { "local": { @@ -651,8 +562,7 @@ "protocol": "http", "domain": "helfi-elo", "port": 8080 - }, - "meta": {} + } }, "test": { "path": { @@ -667,9 +577,6 @@ "internal_address": { "protocol": "https", "domain": "nginx-tyo-yrittaminen-test.apps.arodevtest.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.arodevtest.hel.fi/k8s/cluster/projects/hki-kanslia-tyo-yrittaminen-test" } }, "stage": { @@ -685,9 +592,6 @@ "internal_address": { "protocol": "https", "domain": "nginx-tyo-yrittaminen-staging.apps.platta.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.platta.hel.fi/k8s/cluster/projects/hki-kanslia-tyo-yrittaminen-staging" } }, "prod": { @@ -703,9 +607,6 @@ "internal_address": { "protocol": "https", "domain": "nginx-tyo-yrittaminen-prod.apps.platta.hel.fi" - }, - "meta": { - "openshift_console_link": "https://console-openshift-console.apps.platta.hel.fi/k8s/cluster/projects/hki-kanslia-tyo-yrittaminen-prod" } } } diff --git a/src/Environment/Environment.php b/src/Environment/Environment.php index 5e0bf9b9..83b49fb0 100644 --- a/src/Environment/Environment.php +++ b/src/Environment/Environment.php @@ -22,8 +22,6 @@ final class Environment { * Environment resolver identifier for the project. * @param \Drupal\helfi_api_base\Environment\EnvironmentEnum $environment * The environment name. - * @param \Drupal\helfi_api_base\Environment\EnvironmentMetadata|null $metadata - * The environment specific metadata. */ public function __construct( private readonly Address $address, @@ -31,7 +29,6 @@ public function __construct( private readonly array $paths, private readonly string $id, private readonly EnvironmentEnum $environment, - private readonly ?EnvironmentMetadata $metadata, ) { } @@ -129,14 +126,4 @@ public function getEnvironment() : EnvironmentEnum { return $this->environment; } - /** - * Gets the environment metadata. - * - * @return \Drupal\helfi_api_base\Environment\EnvironmentMetadata|null - * The metadata. - */ - public function getMetadata(): ?EnvironmentMetadata { - return $this->metadata; - } - } diff --git a/src/Environment/EnvironmentMetadata.php b/src/Environment/EnvironmentMetadata.php deleted file mode 100644 index 19f63fd1..00000000 --- a/src/Environment/EnvironmentMetadata.php +++ /dev/null @@ -1,64 +0,0 @@ - $openShiftConsoleLink, - ] = $data; - - return new self($openShiftConsoleLink); - } - - /** - * Gets the link to OpenShift console. - * - * @return string - * The OpenShift console link. - */ - public function getOpenshiftConsoleLink(): string { - return $this->openshiftConsoleLink; - } - -} diff --git a/src/Environment/EnvironmentResolver.php b/src/Environment/EnvironmentResolver.php index c2d95949..62eda82b 100644 --- a/src/Environment/EnvironmentResolver.php +++ b/src/Environment/EnvironmentResolver.php @@ -100,7 +100,6 @@ private function populateEnvironments(string $pathOrJson) : void { $settings['path'], $id, EnvironmentEnum::tryFrom($environment), - EnvironmentMetadata::createFromArray($settings['meta'] ?? []) )); } $this->projects[$id] = $project; diff --git a/src/Environment/ProjectMetadata.php b/src/Environment/ProjectMetadata.php index 3928d347..7681fa45 100644 --- a/src/Environment/ProjectMetadata.php +++ b/src/Environment/ProjectMetadata.php @@ -14,12 +14,9 @@ final class ProjectMetadata { * * @param string $repository * The repository. - * @param string $azureDevopsLink - * The azure devops link. */ public function __construct( private readonly string $repository, - private readonly string $azureDevopsLink, ) { } @@ -35,7 +32,6 @@ public function __construct( public static function createFromArray(array $data) : self { $required = [ 'repository', - 'azure_devops_link', ]; foreach ($required as $key) { @@ -46,20 +42,9 @@ public static function createFromArray(array $data) : self { [ 'repository' => $repository, - 'azure_devops_link' => $devopsLink, ] = $data; - return new self($repository, $devopsLink); - } - - /** - * Gets the Azure DevOps link. - * - * @return string - * The azure_devops_link link. - */ - public function getAzureDevopsLink() : string { - return $this->azureDevopsLink; + return new self($repository); } /** diff --git a/tests/src/Unit/Environment/EnvironmentMetadataTest.php b/tests/src/Unit/Environment/EnvironmentMetadataTest.php deleted file mode 100644 index daa99636..00000000 --- a/tests/src/Unit/Environment/EnvironmentMetadataTest.php +++ /dev/null @@ -1,53 +0,0 @@ - 'dsa']); - } - catch (\InvalidArgumentException $e) { - $this->assertMatchesRegularExpression('/Missing required/', $e->getMessage()); - $caught = TRUE; - } - $this->assertTrue($caught); - } - - /** - * @covers ::createFromArray - */ - public function testNull() : void { - $sut = EnvironmentMetadata::createFromArray([]); - $this->assertNull($sut); - } - - /** - * @covers ::__construct - * @covers ::createFromArray - * @covers ::getOpenshiftConsoleLink - */ - public function testGetters() : void { - $sut = EnvironmentMetadata::createFromArray([ - 'openshift_console_link' => 'https://example.com', - ]); - $this->assertEquals('https://example.com', $sut->getOpenshiftConsoleLink()); - } - -} diff --git a/tests/src/Unit/Environment/EnvironmentResolverTest.php b/tests/src/Unit/Environment/EnvironmentResolverTest.php index c105a287..e9a179aa 100644 --- a/tests/src/Unit/Environment/EnvironmentResolverTest.php +++ b/tests/src/Unit/Environment/EnvironmentResolverTest.php @@ -40,8 +40,6 @@ class EnvironmentResolverTest extends UnitTestCase { * @covers \Drupal\helfi_api_base\Environment\EnvironmentTrait::normalizeEnvironmentName * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::__construct * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::createFromArray - * @covers \Drupal\helfi_api_base\Environment\EnvironmentMetadata::createFromArray - * @covers \Drupal\helfi_api_base\Environment\EnvironmentMetadata::__construct */ public function testProjectConstant() : void { $constants = new \ReflectionClass(Project::class); @@ -119,8 +117,6 @@ public function populateEnvironmentsExceptionsData() : array { * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::__construct * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::createFromArray * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::getNormalizedRepository - * @covers \Drupal\helfi_api_base\Environment\EnvironmentMetadata::createFromArray - * @covers \Drupal\helfi_api_base\Environment\EnvironmentMetadata::__construct * @dataProvider resolveEnvironmentExceptionData */ public function testGetEnvironmentException( @@ -164,8 +160,6 @@ public function resolveEnvironmentExceptionData() : array { * @covers \Drupal\helfi_api_base\Environment\EnvironmentTrait::normalizeEnvironmentName * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::__construct * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::createFromArray - * @covers \Drupal\helfi_api_base\Environment\EnvironmentMetadata::createFromArray - * @covers \Drupal\helfi_api_base\Environment\EnvironmentMetadata::__construct * @dataProvider environmentMapData */ public function testEnvironmentMap(string $envName, string $expected) : void { @@ -203,8 +197,6 @@ public function environmentMapData() : array { * @covers \Drupal\helfi_api_base\Environment\Project::addEnvironment * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::__construct * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::createFromArray - * @covers \Drupal\helfi_api_base\Environment\EnvironmentMetadata::createFromArray - * @covers \Drupal\helfi_api_base\Environment\EnvironmentMetadata::__construct * @dataProvider activeProjectExceptionData */ public function testGetActiveProjectException(mixed $value) : void { @@ -252,8 +244,6 @@ public function activeProjectExceptionData() : array { * @covers \Drupal\helfi_api_base\Environment\EnvironmentResolver::getProject * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::__construct * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::createFromArray - * @covers \Drupal\helfi_api_base\Environment\EnvironmentMetadata::createFromArray - * @covers \Drupal\helfi_api_base\Environment\EnvironmentMetadata::__construct */ public function testGetActiveProject() : void { $sut = $this->getEnvironmentResolver(Project::ASUMINEN, 'dev'); @@ -278,8 +268,6 @@ public function testGetActiveProject() : void { * @covers \Drupal\helfi_api_base\Environment\Project::addEnvironment * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::__construct * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::createFromArray - * @covers \Drupal\helfi_api_base\Environment\EnvironmentMetadata::createFromArray - * @covers \Drupal\helfi_api_base\Environment\EnvironmentMetadata::__construct */ public function testGetActiveEnvironmentException() : void { putenv('APP_ENV='); @@ -299,8 +287,6 @@ public function testGetActiveEnvironmentException() : void { * @covers \Drupal\helfi_api_base\Environment\EnvironmentTrait::normalizeEnvironmentName * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::__construct * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::createFromArray - * @covers \Drupal\helfi_api_base\Environment\EnvironmentMetadata::createFromArray - * @covers \Drupal\helfi_api_base\Environment\EnvironmentMetadata::__construct */ public function testGetActiveEnvironmentFallback() : void { // Make sure environment resolver fallbacks to APP_ENV env variable when @@ -329,8 +315,6 @@ public function testGetActiveEnvironmentFallback() : void { * @covers \Drupal\helfi_api_base\Environment\EnvironmentTrait::normalizeEnvironmentName * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::__construct * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::createFromArray - * @covers \Drupal\helfi_api_base\Environment\EnvironmentMetadata::createFromArray - * @covers \Drupal\helfi_api_base\Environment\EnvironmentMetadata::__construct */ public function testGetActiveEnvironment() : void { $sut = $this->getEnvironmentResolver(Project::ASUMINEN, 'test'); diff --git a/tests/src/Unit/Environment/EnvironmentTest.php b/tests/src/Unit/Environment/EnvironmentTest.php index ca7530af..aa066619 100644 --- a/tests/src/Unit/Environment/EnvironmentTest.php +++ b/tests/src/Unit/Environment/EnvironmentTest.php @@ -7,7 +7,6 @@ use Drupal\helfi_api_base\Environment\Address; use Drupal\helfi_api_base\Environment\Environment; use Drupal\helfi_api_base\Environment\EnvironmentEnum; -use Drupal\helfi_api_base\Environment\EnvironmentMetadata; use Drupal\Tests\UnitTestCase; /** @@ -27,8 +26,6 @@ class EnvironmentTest extends UnitTestCase { * @covers ::getBaseUrl * @cove * @covers ::getMetadata - * @covers \Drupal\helfi_api_base\Environment\EnvironmentMetadata::__construct - * @covers \Drupal\helfi_api_base\Environment\EnvironmentMetadata::getOpenshiftConsoleLink */ public function testSimpleGetters() : void { $sut = new Environment( @@ -37,13 +34,12 @@ public function testSimpleGetters() : void { [], 'test', EnvironmentEnum::Test, - new EnvironmentMetadata('https://localhost')); + ); $this->assertEquals('test', $sut->getId()); $this->assertEquals(EnvironmentEnum::Test, $sut->getEnvironment()); $this->assertEquals(EnvironmentEnum::Test->value, $sut->getEnvironmentName()); $this->assertEquals('https://www.hel.fi', $sut->getBaseUrl()); $this->assertEquals('http://internal-address.local:8080', $sut->getInternalBaseUrl()); - $this->assertEquals('https://localhost', $sut->getMetadata()->getOpenshiftConsoleLink()); } /** @@ -59,7 +55,7 @@ public function testGetUrl() : void { ['fi' => 'test-path'], 'test', EnvironmentEnum::Local, - NULL); + ); $this->assertEquals('https://www.hel.fi/test-path', $sut->getUrl('fi')); $this->assertEquals('http://www.hel.fi/test-path', $sut->getInternalAddress('fi')); @@ -79,7 +75,7 @@ public function testGetUrl() : void { ['fi' => 'test-path'], 'test', EnvironmentEnum::Local, - NULL); + ); $this->assertEquals('https://www.hel.fi/test-path', $sut->getUrl('fi')); $this->assertEquals('https://www.hel.fi:8080/test-path', $sut->getInternalAddress('fi')); } diff --git a/tests/src/Unit/Environment/ProjectMetadataTest.php b/tests/src/Unit/Environment/ProjectMetadataTest.php index 3e29a9b8..9833428a 100644 --- a/tests/src/Unit/Environment/ProjectMetadataTest.php +++ b/tests/src/Unit/Environment/ProjectMetadataTest.php @@ -21,7 +21,7 @@ class ProjectMetadataTest extends UnitTestCase { public function testRequiredValueException() : void { $caught = FALSE; try { - ProjectMetadata::createFromArray(['repository' => 'test']); + ProjectMetadata::createFromArray(['dsad' => 'test']); } catch (\InvalidArgumentException $e) { $this->assertMatchesRegularExpression('/Missing required/', $e->getMessage()); @@ -33,7 +33,6 @@ public function testRequiredValueException() : void { /** * @covers ::__construct * @covers ::createFromArray - * @covers ::getAzureDevopsLink * @covers ::getRepository * @covers ::getRepositoryUrl * @covers ::getNormalizedRepository @@ -41,12 +40,10 @@ public function testRequiredValueException() : void { public function testGetters() : void { $sut = ProjectMetadata::createFromArray([ 'repository' => 'City-of-Helsinki/test', - 'azure_devops_link' => 'https://example.com/2', ]); $this->assertEquals('City-of-Helsinki/test', $sut->getRepository()); $this->assertEquals('city-of-helsinki/test', $sut->getNormalizedRepository()); $this->assertEquals('https://github.com/City-of-Helsinki/test', $sut->getRepositoryUrl()); - $this->assertEquals('https://example.com/2', $sut->getAzureDevopsLink()); } } diff --git a/tests/src/Unit/Environment/ProjectTest.php b/tests/src/Unit/Environment/ProjectTest.php index b0e78a53..012d0297 100644 --- a/tests/src/Unit/Environment/ProjectTest.php +++ b/tests/src/Unit/Environment/ProjectTest.php @@ -28,7 +28,7 @@ public function testConstructorException() : void { $caught = FALSE; try { // Make sure $environments parameter must be an Environment object. - new Project(Project::ASUMINEN, new ProjectMetadata('', ''), ['invalid env']); + new Project(Project::ASUMINEN, new ProjectMetadata(''), ['invalid env']); } catch (\InvalidArgumentException $e) { $caught = TRUE; @@ -45,14 +45,13 @@ public function testConstructorException() : void { * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::__construct */ public function testGetters() : void { - $sut = new Project(Project::ASUMINEN, new ProjectMetadata('', ''), [ + $sut = new Project(Project::ASUMINEN, new ProjectMetadata(''), [ new Environment( new Address('www.hel.fi'), new Address('www.hel.fi'), [], Project::ASUMINEN, EnvironmentEnum::Local, - NULL ), ]); $this->assertEquals(Project::ASUMINEN, $sut->getName()); @@ -69,7 +68,7 @@ public function testGetters() : void { */ public function testGetEnvironmentException() : void { $caught = FALSE; - $sut = new Project(Project::ASUMINEN, new ProjectMetadata('', '')); + $sut = new Project(Project::ASUMINEN, new ProjectMetadata('')); try { $sut->getEnvironment('local'); } @@ -90,7 +89,7 @@ public function testLabel() : void { $found = 0; foreach ($constants->getConstants() as $value) { $found++; - $sut = new Project($value, new ProjectMetadata('', '')); + $sut = new Project($value, new ProjectMetadata('')); $this->assertInstanceOf(TranslatableMarkup::class, $sut->label()); } $this->assertTrue($found > 0); From b34e9a8f4cc1dc7bca1f6e17a2e52d048a5cab52 Mon Sep 17 00:00:00 2001 From: tuutti Date: Thu, 25 Apr 2024 16:23:45 +0300 Subject: [PATCH 02/11] UHF-9833: Added services metadata --- fixtures/environments.json | 20 +++++-- src/Environment/Environment.php | 3 + src/Environment/EnvironmentMetadata.php | 78 +++++++++++++++++++++++++ src/Environment/EnvironmentResolver.php | 3 + 4 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 src/Environment/EnvironmentMetadata.php diff --git a/fixtures/environments.json b/fixtures/environments.json index 6e4e813c..86647a1f 100644 --- a/fixtures/environments.json +++ b/fixtures/environments.json @@ -18,7 +18,8 @@ "protocol": "http", "domain": "helfi-asuminen", "port": 8080 - } + }, + "meta": {} }, "test": { "path": { @@ -33,7 +34,8 @@ "internal_address": { "protocol": "https", "domain": "nginx-asuminen-test.apps.arodevtest.hel.fi" - } + }, + "meta": {} }, "stage": { "path": { @@ -48,7 +50,8 @@ "internal_address": { "protocol": "https", "domain": "nginx-asuminen-staging.apps.platta.hel.fi" - } + }, + "meta": {} }, "prod": { "path": { @@ -63,7 +66,8 @@ "internal_address": { "protocol": "https", "domain": "nginx-asuminen-prod.apps.platta.hel.fi" - } + }, + "meta": {} } } }, @@ -86,6 +90,14 @@ "protocol": "http", "domain": "helfi-etusivu", "port": 8080 + }, + "meta": { + "services": { + "elastic-proxy": { + "protocol": "http", + "domain": "helfi-etusivu-elastic" + } + } } }, "test": { diff --git a/src/Environment/Environment.php b/src/Environment/Environment.php index 83b49fb0..4bfc571a 100644 --- a/src/Environment/Environment.php +++ b/src/Environment/Environment.php @@ -22,6 +22,8 @@ final class Environment { * Environment resolver identifier for the project. * @param \Drupal\helfi_api_base\Environment\EnvironmentEnum $environment * The environment name. + * @param \Drupal\helfi_api_base\Environment\EnvironmentMetadata|null $environmentMetadata + * The environment metadata. */ public function __construct( private readonly Address $address, @@ -29,6 +31,7 @@ public function __construct( private readonly array $paths, private readonly string $id, private readonly EnvironmentEnum $environment, + private readonly ?EnvironmentMetadata $environmentMetadata = NULL, ) { } diff --git a/src/Environment/EnvironmentMetadata.php b/src/Environment/EnvironmentMetadata.php new file mode 100644 index 00000000..1323f655 --- /dev/null +++ b/src/Environment/EnvironmentMetadata.php @@ -0,0 +1,78 @@ + $value) { + if (!isset($value['domain'])) { + throw new \InvalidArgumentException("$name missing required domain."); + } + $services[$name] = new Address(...$value); + } + + return new self($services); + } + + /** + * Gets the services. + * + * @return array + * The services. + */ + public function getServices(): array { + return $this->services; + } + + /** + * Gets the given service. + * + * @param string $name + * The service name. + * + * @return \Drupal\helfi_api_base\Environment\Address|null + * The service. + */ + public function getService(string $name) : ?Address { + return $this->services[$name] ?? NULL; + } + +} diff --git a/src/Environment/EnvironmentResolver.php b/src/Environment/EnvironmentResolver.php index 62eda82b..18dd5e4f 100644 --- a/src/Environment/EnvironmentResolver.php +++ b/src/Environment/EnvironmentResolver.php @@ -94,12 +94,15 @@ private function populateEnvironments(string $pathOrJson) : void { throw new \InvalidArgumentException('Project missing "address", "internal_address" or "paths" setting.'); } + $environmentMeta = !empty($settings['meta']) ? EnvironmentMetadata::createFromArray($settings['meta']) : NULL; + $project->addEnvironment($environment, new Environment( new Address(...$settings['address']), new Address(...$settings['internal_address']), $settings['path'], $id, EnvironmentEnum::tryFrom($environment), + $environmentMeta, )); } $this->projects[$id] = $project; From ca8d0fb608008683af0c07bb0928d72d601ab2f2 Mon Sep 17 00:00:00 2001 From: tuutti Date: Thu, 25 Apr 2024 16:26:20 +0300 Subject: [PATCH 03/11] UHF-9833: Added support for services --- documentation/environment-resolver.md | 3 ++- fixtures/environments.json | 22 +++++++------------ src/Environment/Environment.php | 6 ++--- src/Environment/EnvironmentResolver.php | 4 +--- .../{EnvironmentMetadata.php => Services.php} | 4 ++-- 5 files changed, 16 insertions(+), 23 deletions(-) rename src/Environment/{EnvironmentMetadata.php => Services.php} (93%) diff --git a/documentation/environment-resolver.md b/documentation/environment-resolver.md index 67f33f54..91e2cab4 100644 --- a/documentation/environment-resolver.md +++ b/documentation/environment-resolver.md @@ -6,6 +6,7 @@ ## Usage ### Environment resolver + ```php // See \Drupal\helfi_api_base\Environment\Project for all available project constants. $projectName = \Drupal\helfi_api_base\Environment\Project::ASUMINEN; @@ -27,7 +28,7 @@ $internalUrl = $environment->getInternalAddress('fi'); // 'https://helfi-asumine $path = $environment->getPath('fi'); // '/fi/dev-asuminen'. $domain = $environment->getDomain(); // 'nginx-asuminen-dev.agw.arodevtest.hel.fi'. $baseUrl = $environment->getBaseUrl(); // 'https://nginx-asuminen-dev.agw.arodevtest.hel.fi' -/** @var \Drupal\helfi_api_base\Environment\EnvironmentMetadata $environmentMetadata */ +/** @var \Drupal\helfi_api_base\Environment\Services $environmentMetadata */ $environmentMetadata = $environment->getMetadata(); ``` diff --git a/fixtures/environments.json b/fixtures/environments.json index 86647a1f..7f7fb587 100644 --- a/fixtures/environments.json +++ b/fixtures/environments.json @@ -18,8 +18,7 @@ "protocol": "http", "domain": "helfi-asuminen", "port": 8080 - }, - "meta": {} + } }, "test": { "path": { @@ -34,8 +33,7 @@ "internal_address": { "protocol": "https", "domain": "nginx-asuminen-test.apps.arodevtest.hel.fi" - }, - "meta": {} + } }, "stage": { "path": { @@ -50,8 +48,7 @@ "internal_address": { "protocol": "https", "domain": "nginx-asuminen-staging.apps.platta.hel.fi" - }, - "meta": {} + } }, "prod": { "path": { @@ -66,8 +63,7 @@ "internal_address": { "protocol": "https", "domain": "nginx-asuminen-prod.apps.platta.hel.fi" - }, - "meta": {} + } } } }, @@ -91,12 +87,10 @@ "domain": "helfi-etusivu", "port": 8080 }, - "meta": { - "services": { - "elastic-proxy": { - "protocol": "http", - "domain": "helfi-etusivu-elastic" - } + "services": { + "elastic-proxy": { + "protocol": "http", + "domain": "helfi-etusivu-elastic" } } }, diff --git a/src/Environment/Environment.php b/src/Environment/Environment.php index 4bfc571a..fbe5c450 100644 --- a/src/Environment/Environment.php +++ b/src/Environment/Environment.php @@ -22,8 +22,8 @@ final class Environment { * Environment resolver identifier for the project. * @param \Drupal\helfi_api_base\Environment\EnvironmentEnum $environment * The environment name. - * @param \Drupal\helfi_api_base\Environment\EnvironmentMetadata|null $environmentMetadata - * The environment metadata. + * @param \Drupal\helfi_api_base\Environment\Services|null $services + * The environment services. */ public function __construct( private readonly Address $address, @@ -31,7 +31,7 @@ public function __construct( private readonly array $paths, private readonly string $id, private readonly EnvironmentEnum $environment, - private readonly ?EnvironmentMetadata $environmentMetadata = NULL, + private readonly ?Services $services = NULL, ) { } diff --git a/src/Environment/EnvironmentResolver.php b/src/Environment/EnvironmentResolver.php index 18dd5e4f..769f93bb 100644 --- a/src/Environment/EnvironmentResolver.php +++ b/src/Environment/EnvironmentResolver.php @@ -94,15 +94,13 @@ private function populateEnvironments(string $pathOrJson) : void { throw new \InvalidArgumentException('Project missing "address", "internal_address" or "paths" setting.'); } - $environmentMeta = !empty($settings['meta']) ? EnvironmentMetadata::createFromArray($settings['meta']) : NULL; - $project->addEnvironment($environment, new Environment( new Address(...$settings['address']), new Address(...$settings['internal_address']), $settings['path'], $id, EnvironmentEnum::tryFrom($environment), - $environmentMeta, + Services::createFromArray($services['services'] ?? []), )); } $this->projects[$id] = $project; diff --git a/src/Environment/EnvironmentMetadata.php b/src/Environment/Services.php similarity index 93% rename from src/Environment/EnvironmentMetadata.php rename to src/Environment/Services.php index 1323f655..fc97b04b 100644 --- a/src/Environment/EnvironmentMetadata.php +++ b/src/Environment/Services.php @@ -7,7 +7,7 @@ /** * A value object to store environment metadata. */ -final class EnvironmentMetadata { +final class Services { /** * Constructs a new instance. @@ -23,7 +23,7 @@ private function __construct( * @param array $data * The data. * - * @return \Drupal\helfi_api_base\Environment\EnvironmentMetadata|null + * @return \Drupal\helfi_api_base\Environment\Services|null * The self or null. */ public static function createFromArray(array $data) : ? self { From 6881c01bacb58786cd78261f4e2de86c51e10971 Mon Sep 17 00:00:00 2001 From: tuutti Date: Thu, 25 Apr 2024 16:43:01 +0300 Subject: [PATCH 04/11] UHF-9833: Better structure --- documentation/environment-resolver.md | 2 +- fixtures/environments.json | 6 +- src/Environment/Environment.php | 14 ++--- src/Environment/EnvironmentResolver.php | 10 +++- src/Environment/Project.php | 4 +- src/Environment/Service.php | 21 +++++++ src/Environment/Services.php | 78 ------------------------- 7 files changed, 44 insertions(+), 91 deletions(-) create mode 100644 src/Environment/Service.php delete mode 100644 src/Environment/Services.php diff --git a/documentation/environment-resolver.md b/documentation/environment-resolver.md index 91e2cab4..eef8f2d9 100644 --- a/documentation/environment-resolver.md +++ b/documentation/environment-resolver.md @@ -28,7 +28,7 @@ $internalUrl = $environment->getInternalAddress('fi'); // 'https://helfi-asumine $path = $environment->getPath('fi'); // '/fi/dev-asuminen'. $domain = $environment->getDomain(); // 'nginx-asuminen-dev.agw.arodevtest.hel.fi'. $baseUrl = $environment->getBaseUrl(); // 'https://nginx-asuminen-dev.agw.arodevtest.hel.fi' -/** @var \Drupal\helfi_api_base\Environment\Services $environmentMetadata */ +/** @var \Drupal\helfi_api_base\Environment\Service $environmentMetadata */ $environmentMetadata = $environment->getMetadata(); ``` diff --git a/fixtures/environments.json b/fixtures/environments.json index 7f7fb587..7abda1a6 100644 --- a/fixtures/environments.json +++ b/fixtures/environments.json @@ -89,8 +89,10 @@ }, "services": { "elastic-proxy": { - "protocol": "http", - "domain": "helfi-etusivu-elastic" + "address": { + "protocol": "http", + "domain": "helfi-etusivu-elastic" + } } } }, diff --git a/src/Environment/Environment.php b/src/Environment/Environment.php index fbe5c450..89664888 100644 --- a/src/Environment/Environment.php +++ b/src/Environment/Environment.php @@ -22,16 +22,16 @@ final class Environment { * Environment resolver identifier for the project. * @param \Drupal\helfi_api_base\Environment\EnvironmentEnum $environment * The environment name. - * @param \Drupal\helfi_api_base\Environment\Services|null $services + * @param \Drupal\helfi_api_base\Environment\Service|null $services * The environment services. */ public function __construct( - private readonly Address $address, - private readonly Address $internalAddress, - private readonly array $paths, - private readonly string $id, - private readonly EnvironmentEnum $environment, - private readonly ?Services $services = NULL, + public readonly Address $address, + public readonly Address $internalAddress, + public readonly array $paths, + public readonly string $id, + public readonly EnvironmentEnum $environment, + public readonly array $services = [], ) { } diff --git a/src/Environment/EnvironmentResolver.php b/src/Environment/EnvironmentResolver.php index 769f93bb..f1e9f30d 100644 --- a/src/Environment/EnvironmentResolver.php +++ b/src/Environment/EnvironmentResolver.php @@ -94,13 +94,21 @@ private function populateEnvironments(string $pathOrJson) : void { throw new \InvalidArgumentException('Project missing "address", "internal_address" or "paths" setting.'); } + $services = []; + foreach ($settings['services'] ?? [] as $name => $service) { + if (!isset($service['address'])) { + throw new \InvalidArgumentException('Service is missing "address".'); + } + $services[$name] = new Service($name, new Address(...$service['address'])); + } + $project->addEnvironment($environment, new Environment( new Address(...$settings['address']), new Address(...$settings['internal_address']), $settings['path'], $id, EnvironmentEnum::tryFrom($environment), - Services::createFromArray($services['services'] ?? []), + $services, )); } $this->projects[$id] = $project; diff --git a/src/Environment/Project.php b/src/Environment/Project.php index 66328dcf..2ba8b4f6 100644 --- a/src/Environment/Project.php +++ b/src/Environment/Project.php @@ -42,8 +42,8 @@ final class Project { * The environments. */ public function __construct( - private readonly string $name, - private readonly ProjectMetadata $metadata, + public readonly string $name, + public readonly ProjectMetadata $metadata, array $environments = [], ) { Assert::allIsInstanceOf($environments, Environment::class); diff --git a/src/Environment/Service.php b/src/Environment/Service.php new file mode 100644 index 00000000..c3514f48 --- /dev/null +++ b/src/Environment/Service.php @@ -0,0 +1,21 @@ + $value) { - if (!isset($value['domain'])) { - throw new \InvalidArgumentException("$name missing required domain."); - } - $services[$name] = new Address(...$value); - } - - return new self($services); - } - - /** - * Gets the services. - * - * @return array - * The services. - */ - public function getServices(): array { - return $this->services; - } - - /** - * Gets the given service. - * - * @param string $name - * The service name. - * - * @return \Drupal\helfi_api_base\Environment\Address|null - * The service. - */ - public function getService(string $name) : ?Address { - return $this->services[$name] ?? NULL; - } - -} From b531912af9e0cf84e0ee3e712e73e33fbbffe2b5 Mon Sep 17 00:00:00 2001 From: tuutti Date: Fri, 26 Apr 2024 09:29:57 +0300 Subject: [PATCH 05/11] UHF-9833: Initialize projects and environments in code rather than json --- documentation/environment-resolver.md | 9 +- fixtures/environments.json | 622 ------------------ helfi_api_base.services.yml | 3 +- src/Environment/Environment.php | 52 +- src/Environment/EnvironmentResolver.php | 389 +++++++++-- src/Environment/EnvironmentTrait.php | 1 + src/Environment/Project.php | 21 +- src/Environment/ProjectMetadata.php | 42 +- .../EnvironmentResponseSubscriber.php | 10 +- tests/fixtures/environments.json | 78 --- tests/src/Traits/EnvironmentResolverTrait.php | 2 +- tests/src/Unit/ApiClient/ApiClientTest.php | 30 +- tests/src/Unit/ApiClient/ApiFixtureTest.php | 2 +- tests/src/Unit/Environment/AddressTest.php | 5 +- .../Unit/Environment/EnvironmentEnumTest.php | 3 +- .../Environment/EnvironmentResolverTest.php | 184 +----- .../src/Unit/Environment/EnvironmentTest.php | 44 +- .../Unit/Environment/ProjectMetadataTest.php | 25 +- tests/src/Unit/Environment/ProjectTest.php | 54 +- 19 files changed, 459 insertions(+), 1117 deletions(-) delete mode 100644 fixtures/environments.json delete mode 100644 tests/fixtures/environments.json diff --git a/documentation/environment-resolver.md b/documentation/environment-resolver.md index eef8f2d9..c27c905e 100644 --- a/documentation/environment-resolver.md +++ b/documentation/environment-resolver.md @@ -28,8 +28,9 @@ $internalUrl = $environment->getInternalAddress('fi'); // 'https://helfi-asumine $path = $environment->getPath('fi'); // '/fi/dev-asuminen'. $domain = $environment->getDomain(); // 'nginx-asuminen-dev.agw.arodevtest.hel.fi'. $baseUrl = $environment->getBaseUrl(); // 'https://nginx-asuminen-dev.agw.arodevtest.hel.fi' -/** @var \Drupal\helfi_api_base\Environment\Service $environmentMetadata */ -$environmentMetadata = $environment->getMetadata(); +/** @var \Drupal\helfi_api_base\Environment\Service $services */ +$services = $environment->getServices(); +$service = $environment->getService('elastic-proxy'); // Gets the elastic-proxy service. ``` ### Active environment @@ -52,7 +53,3 @@ $environment = $service->getActiveEnvironment(); // Failure will throw an InvalidArgumentException. $project = $service->getActiveProject(); ``` - -## Usage in other projects - -The [environments.json](/fixtures/environments.json) file should contain up-to-date information of all our available projects in JSON format. diff --git a/fixtures/environments.json b/fixtures/environments.json deleted file mode 100644 index 7abda1a6..00000000 --- a/fixtures/environments.json +++ /dev/null @@ -1,622 +0,0 @@ -{ - "asuminen": { - "meta": { - "repository": "City-of-Helsinki/drupal-helfi-asuminen" - }, - "environments": { - "local": { - "path": { - "fi": "/fi/asuminen", - "sv": "/sv/boende", - "en": "/en/housing" - }, - "address": { - "protocol": "https", - "domain": "helfi-asuminen.docker.so" - }, - "internal_address": { - "protocol": "http", - "domain": "helfi-asuminen", - "port": 8080 - } - }, - "test": { - "path": { - "fi": "/fi/asuminen", - "sv": "/sv/boende", - "en": "/en/housing" - }, - "address": { - "protocol": "https", - "domain": "www.test.hel.ninja" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-asuminen-test.apps.arodevtest.hel.fi" - } - }, - "stage": { - "path": { - "fi": "/fi/asuminen", - "sv": "/sv/boende", - "en": "/en/housing" - }, - "address": { - "protocol": "https", - "domain": "www.stage.hel.ninja" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-asuminen-staging.apps.platta.hel.fi" - } - }, - "prod": { - "path": { - "fi": "/fi/asuminen", - "sv": "/sv/boende", - "en": "/en/housing" - }, - "address": { - "protocol": "https", - "domain": "www.hel.fi" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-asuminen-prod.apps.platta.hel.fi" - } - } - } - }, - "etusivu": { - "meta": { - "repository": "City-of-Helsinki/drupal-helfi-etusivu" - }, - "environments": { - "local": { - "path": { - "fi": "/fi", - "sv": "/sv", - "en": "/en" - }, - "address": { - "protocol": "https", - "domain": "helfi-etusivu.docker.so" - }, - "internal_address": { - "protocol": "http", - "domain": "helfi-etusivu", - "port": 8080 - }, - "services": { - "elastic-proxy": { - "address": { - "protocol": "http", - "domain": "helfi-etusivu-elastic" - } - } - } - }, - "test": { - "path": { - "fi": "/fi", - "sv": "/sv", - "en": "/en" - }, - "address": { - "protocol": "https", - "domain": "www.test.hel.ninja" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-etusivu-test.apps.arodevtest.hel.fi" - } - }, - "stage": { - "path": { - "fi": "/fi", - "sv": "/sv", - "en": "/en" - }, - "address": { - "protocol": "https", - "domain": "www.stage.hel.ninja" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-etusivu-staging.apps.platta.hel.fi" - } - }, - "prod": { - "path": { - "fi": "/fi", - "sv": "/sv", - "en": "/en" - }, - "address": { - "protocol": "https", - "domain": "www.hel.fi" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-etusivu-prod.apps.platta.hel.fi" - } - } - } - }, - "kasvatus-koulutus": { - "meta": { - "repository": "City-of-Helsinki/drupal-helfi-kasvatus-koulutus" - }, - "environments": { - "local": { - "path": { - "fi": "/fi/kasvatus-ja-koulutus", - "sv": "/sv/fostran-och-utbildning", - "en": "/en/childhood-and-education" - }, - "address": { - "protocol": "https", - "domain": "helfi-kasko.docker.so" - }, - "internal_address": { - "protocol": "http", - "domain": "helfi-kasko", - "port": 8080 - } - }, - "test": { - "path": { - "fi": "/fi/kasvatus-ja-koulutus", - "sv": "/sv/fostran-och-utbildning", - "en": "/en/childhood-and-education" - }, - "address": { - "protocol": "https", - "domain": "www.test.hel.ninja" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-kasvatus-koulutus-test.apps.arodevtest.hel.fi" - } - }, - "stage": { - "path": { - "fi": "/fi/kasvatus-ja-koulutus", - "sv": "/sv/fostran-och-utbildning", - "en": "/en/childhood-and-education" - }, - "address": { - "protocol": "https", - "domain": "www.stage.hel.ninja" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-kasvatus-koulutus-staging.apps.platta.hel.fi" - } - }, - "prod": { - "path": { - "fi": "/fi/kasvatus-ja-koulutus", - "sv": "/sv/fostran-och-utbildning", - "en": "/en/childhood-and-education" - }, - "address": { - "protocol": "https", - "domain": "www.hel.fi" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-kasvatus-koulutus-prod.apps.platta.hel.fi" - } - } - } - }, - "kuva": { - "meta": { - "repository": "City-of-Helsinki/drupal-helfi-kuva" - }, - "environments": { - "local": { - "path": { - "fi": "/fi/kulttuuri-ja-vapaa-aika", - "sv": "/sv/kultur-och-fritid", - "en": "/en/culture-and-leisure" - }, - "address": { - "protocol": "https", - "domain": "helfi-kuva.docker.so" - }, - "internal_address": { - "protocol": "http", - "domain": "helfi-kuva", - "port": 8080 - } - }, - "test": { - "path": { - "fi": "/fi/kulttuuri-ja-vapaa-aika", - "sv": "/sv/kultur-och-fritid", - "en": "/en/culture-and-leisure" - }, - "address": { - "protocol": "https", - "domain": "www.test.hel.ninja" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-kuva-test.apps.arodevtest.hel.fi" - } - }, - "stage": { - "path": { - "fi": "/fi/kulttuuri-ja-vapaa-aika", - "sv": "/sv/kultur-och-fritid", - "en": "/en/culture-and-leisure" - }, - "address": { - "protocol": "https", - "domain": "www.stage.hel.ninja" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-kuva-staging.apps.platta.hel.fi" - } - }, - "prod": { - "path": { - "fi": "/fi/kulttuuri-ja-vapaa-aika", - "sv": "/sv/kultur-och-fritid", - "en": "/en/culture-and-leisure" - }, - "address": { - "protocol": "https", - "domain": "www.hel.fi" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-kuva-prod.apps.platta.hel.fi" - } - } - } - }, - "liikenne": { - "meta": { - "repository": "City-of-Helsinki/drupal-helfi-kymp" - }, - "environments": { - "local": { - "path": { - "fi": "/fi/kaupunkiymparisto-ja-liikenne", - "sv": "/sv/stadsmiljo-och-trafik", - "en": "/en/urban-environment-and-traffic" - }, - "address": { - "protocol": "https", - "domain": "helfi-kymp.docker.so" - }, - "internal_address": { - "protocol": "http", - "domain": "helfi-kymp", - "port": 8080 - } - }, - "test": { - "path": { - "fi": "/fi/kaupunkiymparisto-ja-liikenne", - "sv": "/sv/stadsmiljo-och-trafik", - "en": "/en/urban-environment-and-traffic" - }, - "address": { - "protocol": "https", - "domain": "www.test.hel.ninja" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-liikenne-test.apps.arodevtest.hel.fi" - } - }, - "stage": { - "path": { - "fi": "/fi/kaupunkiymparisto-ja-liikenne", - "sv": "/sv/stadsmiljo-och-trafik", - "en": "/en/urban-environment-and-traffic" - }, - "address": { - "protocol": "https", - "domain": "www.stage.hel.ninja" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-liikenne-staging.apps.platta.hel.fi" - } - }, - "prod": { - "path": { - "fi": "/fi/kaupunkiymparisto-ja-liikenne", - "sv": "/sv/stadsmiljo-och-trafik", - "en": "/en/urban-environment-and-traffic" - }, - "address": { - "protocol": "https", - "domain": "www.hel.fi" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-liikenne-prod.apps.platta.hel.fi" - } - } - } - }, - "rekry": { - "meta": { - "repository": "City-of-Helsinki/drupal-helfi-rekry" - }, - "environments": { - "local": { - "path": { - "fi": "/fi/avoimet-tyopaikat", - "sv": "/sv/lediga-jobb", - "en": "/en/open-jobs" - }, - "address": { - "protocol": "https", - "domain": "helfi-rekry.docker.so" - }, - "internal_address": { - "protocol": "http", - "domain": "helfi-rekry", - "port": 8080 - } - }, - "test": { - "path": { - "fi": "/fi/avoimet-tyopaikat", - "sv": "/sv/lediga-jobb", - "en": "/en/open-jobs" - }, - "address": { - "protocol": "https", - "domain": "www.test.hel.ninja" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-rekry-test.apps.arodevtest.hel.fi" - } - }, - "stage": { - "path": { - "fi": "/fi/avoimet-tyopaikat", - "sv": "/sv/lediga-jobb", - "en": "/en/open-jobs" - }, - "address": { - "protocol": "https", - "domain": "www.stage.hel.ninja" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-rekry-staging.apps.platta.hel.fi" - } - }, - "prod": { - "path": { - "fi": "/fi/avoimet-tyopaikat", - "sv": "/sv/lediga-jobb", - "en": "/en/open-jobs" - }, - "address": { - "protocol": "https", - "domain": "www.hel.fi" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-rekry-prod.apps.platta.hel.fi" - } - } - } - }, - "strategia": { - "meta": { - "repository": "City-of-Helsinki/drupal-helfi-strategia" - }, - "environments": { - "local": { - "path": { - "fi": "/fi/paatoksenteko-ja-hallinto", - "sv": "/sv/beslutsfattande-och-forvaltning", - "en": "/en/decision-making" - }, - "address": { - "protocol": "https", - "domain": "strategia.docker.so" - }, - "internal_address": { - "protocol": "http", - "domain": "strategia", - "port": 8080 - } - }, - "test": { - "path": { - "fi": "/fi/paatoksenteko-ja-hallinto", - "sv": "/sv/beslutsfattande-och-forvaltning", - "en": "/en/decision-making" - }, - "address": { - "protocol": "https", - "domain": "www.test.hel.ninja" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-strategia-talous-test.apps.arodevtest.hel.fi" - } - }, - "stage": { - "path": { - "fi": "/fi/paatoksenteko-ja-hallinto", - "sv": "/sv/beslutsfattande-och-forvaltning", - "en": "/en/decision-making" - }, - "address": { - "protocol": "https", - "domain": "www.stage.hel.ninja" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-strategia-talous-staging.apps.platta.hel.fi" - } - }, - "prod": { - "path": { - "fi": "/fi/paatoksenteko-ja-hallinto", - "sv": "/sv/beslutsfattande-och-forvaltning", - "en": "/en/decision-making" - }, - "address": { - "protocol": "https", - "domain": "www.hel.fi" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-strategia-talous-prod.apps.platta.hel.fi" - } - } - } - }, - "terveys": { - "meta": { - "repository": "City-of-Helsinki/drupal-helfi-sote" - }, - "environments": { - "local": { - "path": { - "fi": "/fi/sosiaali-ja-terveyspalvelut", - "sv": "/sv/social-och-halsovardstjanster", - "en": "/en/health-and-social-services" - }, - "address": { - "protocol": "https", - "domain": "helfi-sote.docker.so" - }, - "internal_address": { - "protocol": "http", - "domain": "helfi-sote", - "port": 8080 - } - }, - "test": { - "path": { - "fi": "/fi/sosiaali-ja-terveyspalvelut", - "sv": "/sv/social-och-halsovardstjanster", - "en": "/en/health-and-social-services" - }, - "address": { - "protocol": "https", - "domain": "www.test.hel.ninja" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-terveys-test.apps.arodevtest.hel.fi" - } - }, - "stage": { - "path": { - "fi": "/fi/sosiaali-ja-terveyspalvelut", - "sv": "/sv/social-och-halsovardstjanster", - "en": "/en/health-and-social-services" - }, - "address": { - "protocol": "https", - "domain": "www.stage.hel.ninja" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-terveys-staging.apps.platta.hel.fi" - } - }, - "prod": { - "path": { - "fi": "/fi/sosiaali-ja-terveyspalvelut", - "sv": "/sv/social-och-halsovardstjanster", - "en": "/en/health-and-social-services" - }, - "address": { - "protocol": "https", - "domain": "www.hel.fi" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-terveys-prod.apps.platta.hel.fi" - } - } - } - }, - "tyo-yrittaminen": { - "meta": { - "repository": "City-of-Helsinki/drupal-helfi-tyo-yrittaminen" - }, - "environments": { - "local": { - "path": { - "fi": "/fi/yritykset-ja-tyo", - "sv": "/sv/foretag-och-arbete", - "en": "/en/business-and-work" - }, - "address": { - "protocol": "https", - "domain": "helfi-elo.docker.so" - }, - "internal_address": { - "protocol": "http", - "domain": "helfi-elo", - "port": 8080 - } - }, - "test": { - "path": { - "fi": "/fi/yritykset-ja-tyo", - "sv": "/sv/foretag-och-arbete", - "en": "/en/business-and-work" - }, - "address": { - "protocol": "https", - "domain": "www.test.hel.ninja" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-tyo-yrittaminen-test.apps.arodevtest.hel.fi" - } - }, - "stage": { - "path": { - "fi": "/fi/yritykset-ja-tyo", - "sv": "/sv/foretag-och-arbete", - "en": "/en/business-and-work" - }, - "address": { - "protocol": "https", - "domain": "www.stage.hel.ninja" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-tyo-yrittaminen-staging.apps.platta.hel.fi" - } - }, - "prod": { - "path": { - "fi": "/fi/yritykset-ja-tyo", - "sv": "/sv/foretag-och-arbete", - "en": "/en/business-and-work" - }, - "address": { - "protocol": "https", - "domain": "www.hel.fi" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-tyo-yrittaminen-prod.apps.platta.hel.fi" - } - } - } - } -} diff --git a/helfi_api_base.services.yml b/helfi_api_base.services.yml index dc428794..1c4e2ffa 100644 --- a/helfi_api_base.services.yml +++ b/helfi_api_base.services.yml @@ -1,5 +1,4 @@ parameters: - helfi_api_base.environment_file: '' helfi_api_base.default_composer_lock: '%app.root%/../composer.lock' helfi_api_base.internal_domains: - 'hel.fi' @@ -33,7 +32,7 @@ services: Drupal\helfi_api_base\Environment\EnvironmentResolver: '@helfi_api_base.environment_resolver' helfi_api_base.environment_resolver: class: Drupal\helfi_api_base\Environment\EnvironmentResolver - arguments: ['%helfi_api_base.environment_file%', '@config.factory'] + arguments: ['@config.factory'] Drupal\helfi_api_base\Link\InternalDomainResolver: '@helfi_api_base.internal_domain_resolver' helfi_api_base.internal_domain_resolver: diff --git a/src/Environment/Environment.php b/src/Environment/Environment.php index 89664888..3279640e 100644 --- a/src/Environment/Environment.php +++ b/src/Environment/Environment.php @@ -4,11 +4,20 @@ namespace Drupal\helfi_api_base\Environment; +use Webmozart\Assert\Assert; + /** * A value object to store environment data. */ final class Environment { + /** + * The services. + * + * @var \Drupal\helfi_api_base\Environment\Service[] + */ + private array $services; + /** * Constructs a new instance. * @@ -18,31 +27,23 @@ final class Environment { * The internal address. * @param array $paths * The paths. - * @param string $id - * Environment resolver identifier for the project. * @param \Drupal\helfi_api_base\Environment\EnvironmentEnum $environment * The environment name. - * @param \Drupal\helfi_api_base\Environment\Service|null $services + * @param \Drupal\helfi_api_base\Environment\Service[] $services * The environment services. */ public function __construct( public readonly Address $address, public readonly Address $internalAddress, public readonly array $paths, - public readonly string $id, public readonly EnvironmentEnum $environment, - public readonly array $services = [], + array $services = [], ) { - } + Assert::allIsInstanceOf($services, Service::class); - /** - * Gets the project identifier. - * - * @return string - * Site identifier. - */ - public function getId() : string { - return $this->id; + foreach ($services as $service) { + $this->services[$service->name] = $service; + } } /** @@ -129,4 +130,27 @@ public function getEnvironment() : EnvironmentEnum { return $this->environment; } + /** + * Gets the services. + * + * @return \Drupal\helfi_api_base\Environment\Service[] + * The services. + */ + public function getServices(): array { + return $this->services; + } + + /** + * Gets the given service. + * + * @param string $name + * The service to get. + * + * @return \Drupal\helfi_api_base\Environment\Service|null + * The service or null. + */ + public function getService(string $name): ?Service { + return $this->services[$name] ?? NULL; + } + } diff --git a/src/Environment/EnvironmentResolver.php b/src/Environment/EnvironmentResolver.php index f1e9f30d..3c571573 100644 --- a/src/Environment/EnvironmentResolver.php +++ b/src/Environment/EnvironmentResolver.php @@ -5,7 +5,6 @@ namespace Drupal\helfi_api_base\Environment; use Drupal\Core\Config\ConfigFactoryInterface; -use Symfony\Component\DependencyInjection\Attribute\Autowire; /** * Environment resolver. @@ -41,84 +40,350 @@ final class EnvironmentResolver implements EnvironmentResolverInterface { /** * Constructs a new instance. * - * @param string $pathOrJson - * The path to environments.json file. * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory * The configuration factory. */ public function __construct( - #[Autowire('%helfi_api_base.environment_file%')] string $pathOrJson, private readonly ConfigFactoryInterface $configFactory, ) { - $this->populateEnvironments($pathOrJson); } /** - * Populates the environments for given json config file. - * - * @param string $pathOrJson - * The path to config.json file. + * Populates the environments. */ - private function populateEnvironments(string $pathOrJson) : void { - // Fallback to default environments.json file. - if ($pathOrJson === '') { - $pathOrJson = __DIR__ . '/../../fixtures/environments.json'; - } - - if (!is_file($pathOrJson)) { - try { - $projects = json_decode($pathOrJson, TRUE, flags: JSON_THROW_ON_ERROR); - } - catch (\JsonException) { - throw new \InvalidArgumentException('Environment file not found or is not a valid JSON.'); - } - } - else { - $projects = json_decode(file_get_contents($pathOrJson), TRUE); - } - - if (empty($projects)) { - throw new \InvalidArgumentException('Failed to parse projects.'); + private function populateEnvironments() : void { + if (!empty($this->projects)) { + return; } + $paths = [ + Project::ASUMINEN => [ + 'fi' => '/fi/asuminen', + 'sv' => '/sv/boende', + 'en' => '/en/housing', + ], + Project::ETUSIVU => [ + 'fi' => '/fi', + 'sv' => '/sv', + 'en' => '/en/housing', + ], + Project::KASVATUS_KOULUTUS => [ + 'fi' => '/fi/kasvatus-ja-koulutus', + 'sv' => '/sv/fostran-och-utbildning', + 'en' => '/en/childhood-and-education', + ], + Project::KUVA => [ + 'fi' => '/fi/kulttuuri-ja-vapaa-aika', + 'sv' => '/sv/kultur-och-fritid', + 'en' => '/en/culture-and-leisure', + ], + Project::LIIKENNE => [ + 'fi' => '/fi/kaupunkiymparisto-ja-liikenne', + 'sv' => '/sv/stadsmiljo-och-trafik', + 'en' => '/en/urban-environment-and-traffic', + ], + Project::REKRY => [ + 'fi' => '/fi/avoimet-tyopaikat', + 'sv' => '/sv/lediga-jobb', + 'en' => '/en/open-jobs', + ], + Project::STRATEGIA => [ + 'fi' => '/fi/paatoksenteko-ja-hallinto', + 'sv' => '/sv/beslutsfattande-och-forvaltning', + 'en' => '/en/decision-making', + ], + Project::TERVEYS => [ + 'fi' => '/fi/sosiaali-ja-terveyspalvelut', + 'sv' => '/sv/social-och-halsovardstjanster', + 'en' => '/en/health-and-social-services', + ], + Project::TYO_YRITTAMINEN => [ + 'fi' => '/fi/yritykset-ja-tyo', + 'sv' => '/sv/foretag-och-arbete', + 'en' => '/en/business-and-work', + ], + ]; + $this->projects[Project::ASUMINEN] = new Project( + Project::ASUMINEN, + new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-asuminen'), + [ + new Environment( + address: new Address('helfi-asuminen.docker.so'), + internalAddress: new Address('helfi-asuminen', 'http', 8080), + paths: $paths[Project::ASUMINEN], + environment: EnvironmentEnum::Local, + ), + new Environment( + address: new Address('www.test.hel.ninja'), + internalAddress: new Address('nginx-asuminen-test.apps.arodevtest.hel.fi'), + paths: $paths[Project::ASUMINEN], + environment: EnvironmentEnum::Test, + ), + new Environment( + address: new Address('www.stage.hel.ninja'), + internalAddress: new Address('nginx-asuminen-staging.apps.platta.hel.fi'), + paths: $paths[Project::ASUMINEN], + environment: EnvironmentEnum::Stage, + ), + new Environment( + address: new Address('www.hel.fi'), + internalAddress: new Address('nginx-asuminen-prod.apps.platta.hel.fi'), + paths: $paths[Project::ASUMINEN], + environment: EnvironmentEnum::Prod, + ), + ], + ); + $this->projects[Project::ETUSIVU] = new Project( + Project::ETUSIVU, + new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-etusivu'), + [ + new Environment( + address: new Address('helfi-etusivu.docker.so'), + internalAddress: new Address('helfi-etusivu', 'http', 8080), + paths: $paths[Project::ETUSIVU], + environment: EnvironmentEnum::Local, + services: [ + new Service('elastic-proxy', new Address('helfi-etusivu-elastic', 'http', 9200)), + ], + ), + new Environment( + address: new Address('www.test.hel.ninja'), + internalAddress: new Address('nginx-etusivu-test.apps.arodevtest.hel.fi'), + paths: $paths[Project::ETUSIVU], + environment: EnvironmentEnum::Test, + ), + new Environment( + address: new Address('www.stage.hel.ninja'), + internalAddress: new Address('nginx-etusivu-staging.apps.platta.hel.fi'), + paths: $paths[Project::ETUSIVU], + environment: EnvironmentEnum::Stage, + ), + new Environment( + address: new Address('www.hel.fi'), + internalAddress: new Address('nginx-etusivu-prod.apps.platta.hel.fi'), + paths: $paths[Project::ETUSIVU], + environment: EnvironmentEnum::Prod, + ), + ], + ); - foreach ($projects as $id => $item) { - if (!isset($item['meta'], $item['environments'])) { - throw new \InvalidArgumentException('Project missing meta or environments.'); - } - ['meta' => $meta, 'environments' => $environments] = $item; - - $project = new Project($id, ProjectMetadata::createFromArray($meta)); - - foreach ($environments as $environment => $settings) { - if (!isset($settings['address'], $settings['internal_address'], $settings['path'])) { - throw new \InvalidArgumentException('Project missing "address", "internal_address" or "paths" setting.'); - } - - $services = []; - foreach ($settings['services'] ?? [] as $name => $service) { - if (!isset($service['address'])) { - throw new \InvalidArgumentException('Service is missing "address".'); - } - $services[$name] = new Service($name, new Address(...$service['address'])); - } - - $project->addEnvironment($environment, new Environment( - new Address(...$settings['address']), - new Address(...$settings['internal_address']), - $settings['path'], - $id, - EnvironmentEnum::tryFrom($environment), - $services, - )); - } - $this->projects[$id] = $project; - } + $this->projects[Project::KASVATUS_KOULUTUS] = new Project( + Project::KASVATUS_KOULUTUS, + new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-kasvatus-koulutus'), + [ + new Environment( + address: new Address('helfi-kasko.docker.so'), + internalAddress: new Address('helfi-kasko', 'http', 8080), + paths: $paths[Project::KASVATUS_KOULUTUS], + environment: EnvironmentEnum::Local, + ), + new Environment( + address: new Address('www.test.hel.ninja'), + internalAddress: new Address('nginx-kasvatus-koulutus-test.apps.arodevtest.hel.fi'), + paths: $paths[Project::KASVATUS_KOULUTUS], + environment: EnvironmentEnum::Test, + ), + new Environment( + address: new Address('www.stage.hel.ninja'), + internalAddress: new Address('nginx-kasvatus-koulutus-staging.apps.platta.hel.fi'), + paths: $paths[Project::KASVATUS_KOULUTUS], + environment: EnvironmentEnum::Stage, + ), + new Environment( + address: new Address('www.hel.fi'), + internalAddress: new Address('nginx-kasvatus-koulutus-prod.apps.platta.hel.fi'), + paths: $paths[Project::KASVATUS_KOULUTUS], + environment: EnvironmentEnum::Prod, + ), + ], + ); + $this->projects[Project::KUVA] = new Project( + Project::KUVA, + new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-kuva'), + [ + new Environment( + address: new Address('helfi-kuva.docker.so'), + internalAddress: new Address('helfi-kuva', 'http', 8080), + paths: $paths[Project::KUVA], + environment: EnvironmentEnum::Local, + ), + new Environment( + address: new Address('www.test.hel.ninja'), + internalAddress: new Address('nginx-kuva-test.apps.arodevtest.hel.fi'), + paths: $paths[Project::KUVA], + environment: EnvironmentEnum::Test, + ), + new Environment( + address: new Address('www.stage.hel.ninja'), + internalAddress: new Address('nginx-kuva-staging.apps.platta.hel.fi'), + paths: $paths[Project::KUVA], + environment: EnvironmentEnum::Stage, + ), + new Environment( + address: new Address('www.hel.fi'), + internalAddress: new Address('nginx-kuva-prod.apps.platta.hel.fi'), + paths: $paths[Project::KUVA], + environment: EnvironmentEnum::Prod, + ), + ], + ); + $this->projects[Project::LIIKENNE] = new Project( + Project::LIIKENNE, + new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-kymp'), + [ + new Environment( + address: new Address('helfi-kymp.docker.so'), + internalAddress: new Address('helfi-kymp', 'http', 8080), + paths: $paths[Project::LIIKENNE], + environment: EnvironmentEnum::Local, + ), + new Environment( + address: new Address('www.test.hel.ninja'), + internalAddress: new Address('nginx-liikenne-test.apps.arodevtest.hel.fi'), + paths: $paths[Project::LIIKENNE], + environment: EnvironmentEnum::Test, + ), + new Environment( + address: new Address('www.stage.hel.ninja'), + internalAddress: new Address('nginx-liikenne-staging.apps.platta.hel.fi'), + paths: $paths[Project::LIIKENNE], + environment: EnvironmentEnum::Stage, + ), + new Environment( + address: new Address('www.hel.fi'), + internalAddress: new Address('nginx-liikenne-prod.apps.platta.hel.fi'), + paths: $paths[Project::LIIKENNE], + environment: EnvironmentEnum::Prod, + ), + ], + ); + $this->projects[Project::REKRY] = new Project( + Project::REKRY, + new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-rekry'), + [ + new Environment( + address: new Address('helfi-rekry.docker.so'), + internalAddress: new Address('helfi-rekry', 'http', 8080), + paths: $paths[Project::REKRY], + environment: EnvironmentEnum::Local, + ), + new Environment( + address: new Address('www.test.hel.ninja'), + internalAddress: new Address('nginx-rekry-test.apps.arodevtest.hel.fi'), + paths: $paths[Project::REKRY], + environment: EnvironmentEnum::Test, + ), + new Environment( + address: new Address('www.stage.hel.ninja'), + internalAddress: new Address('nginx-rekry-staging.apps.platta.hel.fi'), + paths: $paths[Project::REKRY], + environment: EnvironmentEnum::Stage, + ), + new Environment( + address: new Address('www.hel.fi'), + internalAddress: new Address('nginx-rekry-prod.apps.platta.hel.fi'), + paths: $paths[Project::REKRY], + environment: EnvironmentEnum::Prod, + ), + ], + ); + $this->projects[Project::STRATEGIA] = new Project( + Project::STRATEGIA, + new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-strategia'), + [ + new Environment( + address: new Address('helfi-strategia.docker.so'), + internalAddress: new Address('helfi-strategia', 'http', 8080), + paths: $paths[Project::STRATEGIA], + environment: EnvironmentEnum::Local, + ), + new Environment( + address: new Address('www.test.hel.ninja'), + internalAddress: new Address('nginx-strategia-talous-test.apps.arodevtest.hel.fi'), + paths: $paths[Project::STRATEGIA], + environment: EnvironmentEnum::Test, + ), + new Environment( + address: new Address('www.stage.hel.ninja'), + internalAddress: new Address('nginx-strategia-talous-staging.apps.platta.hel.fi'), + paths: $paths[Project::STRATEGIA], + environment: EnvironmentEnum::Stage, + ), + new Environment( + address: new Address('www.hel.fi'), + internalAddress: new Address('nginx-strategia-talous-prod.apps.platta.hel.fi'), + paths: $paths[Project::STRATEGIA], + environment: EnvironmentEnum::Prod, + ), + ], + ); + $this->projects[Project::TERVEYS] = new Project( + Project::TERVEYS, + new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-sote'), + [ + new Environment( + address: new Address('helfi-sote.docker.so'), + internalAddress: new Address('helfi-sote', 'http', 8080), + paths: $paths[Project::TERVEYS], + environment: EnvironmentEnum::Local, + ), + new Environment( + address: new Address('www.test.hel.ninja'), + internalAddress: new Address('nginx-terveys-test.apps.arodevtest.hel.fi'), + paths: $paths[Project::TERVEYS], + environment: EnvironmentEnum::Test, + ), + new Environment( + address: new Address('www.stage.hel.ninja'), + internalAddress: new Address('nginx-terveys-staging.apps.platta.hel.fi'), + paths: $paths[Project::TERVEYS], + environment: EnvironmentEnum::Stage, + ), + new Environment( + address: new Address('www.hel.fi'), + internalAddress: new Address('nginx-terveys-prod.apps.platta.hel.fi'), + paths: $paths[Project::TERVEYS], + environment: EnvironmentEnum::Prod, + ), + ], + ); + $this->projects[Project::TYO_YRITTAMINEN] = new Project( + Project::TYO_YRITTAMINEN, + new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-tyo-yrittaminen'), + [ + new Environment( + address: new Address('helfi-elo.docker.so'), + internalAddress: new Address('helfi-elo', 'http', 8080), + paths: $paths[Project::TYO_YRITTAMINEN], + environment: EnvironmentEnum::Local, + ), + new Environment( + address: new Address('www.test.hel.ninja'), + internalAddress: new Address('nginx-tyo-yrittaminen-test.apps.arodevtest.hel.fi'), + paths: $paths[Project::TYO_YRITTAMINEN], + environment: EnvironmentEnum::Test, + ), + new Environment( + address: new Address('www.stage.hel.ninja'), + internalAddress: new Address('nginx-tyo-yrittaminen-staging.apps.platta.hel.fi'), + paths: $paths[Project::TYO_YRITTAMINEN], + environment: EnvironmentEnum::Stage, + ), + new Environment( + address: new Address('www.hel.fi'), + internalAddress: new Address('nginx-tyo-yrittaminen-prod.apps.platta.hel.fi'), + paths: $paths[Project::TYO_YRITTAMINEN], + environment: EnvironmentEnum::Prod, + ), + ], + ); } /** * {@inheritdoc} */ public function getProjects() : array { + $this->populateEnvironments(); + return $this->projects; } @@ -227,6 +492,8 @@ private function getProjectForRepository(string $repository) : Project { * {@inheritdoc} */ public function getProject(string $project) : Project { + $this->populateEnvironments(); + if (!isset($this->projects[$project])) { return $this->getProjectForRepository($project); } diff --git a/src/Environment/EnvironmentTrait.php b/src/Environment/EnvironmentTrait.php index da12b679..cc6fd42e 100644 --- a/src/Environment/EnvironmentTrait.php +++ b/src/Environment/EnvironmentTrait.php @@ -19,6 +19,7 @@ trait EnvironmentTrait { * The environment name. */ protected function normalizeEnvironmentName(string $environment) : ? string { + $environment = strtolower($environment); // Some environments have an incorrect APP_ENV value, like 'production', // 'staging' and 'testing' instead of 'local', 'test,' 'stage' and 'prod'. // Map all known environment name variations to match environment resolver. diff --git a/src/Environment/Project.php b/src/Environment/Project.php index 2ba8b4f6..e7927910 100644 --- a/src/Environment/Project.php +++ b/src/Environment/Project.php @@ -47,7 +47,10 @@ public function __construct( array $environments = [], ) { Assert::allIsInstanceOf($environments, Environment::class); - $this->environments = $environments; + + foreach ($environments as $environment) { + $this->environments[$environment->environment->value] = $environment; + } } /** @@ -100,22 +103,6 @@ public function getEnvironments() : array { return $this->environments; } - /** - * Adds an environment. - * - * @param string $key - * The environment key. - * @param \Drupal\helfi_api_base\Environment\Environment $environment - * The environment. - * - * @return $this - * The self. - */ - public function addEnvironment(string $key, Environment $environment) : self { - $this->environments[$key] = $environment; - return $this; - } - /** * Checks if environment exists. * diff --git a/src/Environment/ProjectMetadata.php b/src/Environment/ProjectMetadata.php index 7681fa45..f8d37631 100644 --- a/src/Environment/ProjectMetadata.php +++ b/src/Environment/ProjectMetadata.php @@ -10,41 +10,25 @@ final class ProjectMetadata { /** - * Constructs a new instance. + * The repository. * - * @param string $repository - * The repository. + * @var string */ - public function __construct( - private readonly string $repository, - ) { - } + public readonly string $repository; /** - * Construct a new instance from array. - * - * @param array $data - * The data. + * Constructs a new instance. * - * @return self - * The + * @param string $repositoryUrl + * The repository url. */ - public static function createFromArray(array $data) : self { - $required = [ - 'repository', - ]; - - foreach ($required as $key) { - if (!isset($data[$key])) { - throw new \InvalidArgumentException(sprintf('Missing required "%s".', $key)); - } + public function __construct( + private readonly string $repositoryUrl, + ) { + if (!$path = parse_url($this->repositoryUrl, PHP_URL_PATH)) { + throw new \InvalidArgumentException('The repositoryUrl must be a valid URL.'); } - - [ - 'repository' => $repository, - ] = $data; - - return new self($repository); + $this->repository = ltrim($path, '/'); } /** @@ -74,7 +58,7 @@ public function getNormalizedRepository() : string { * The repository URL. */ public function getRepositoryUrl() : string { - return sprintf('https://github.com/%s', $this->repository); + return $this->repositoryUrl; } } diff --git a/src/EventSubscriber/EnvironmentResponseSubscriber.php b/src/EventSubscriber/EnvironmentResponseSubscriber.php index a3e1e64d..d3ae3af1 100644 --- a/src/EventSubscriber/EnvironmentResponseSubscriber.php +++ b/src/EventSubscriber/EnvironmentResponseSubscriber.php @@ -38,10 +38,12 @@ public function onResponse(ResponseEvent $event) : void { $response = $event->getResponse(); try { - $environment = $this->environmentResolver - ->getActiveEnvironment(); - $response->headers->add([self::INSTANCE_HEADER_NAME => $environment->getId()]); - $response->headers->add([self::ENVIRONMENT_HEADER_NAME => $environment->getEnvironmentName()]); + $response->headers->add([ + self::INSTANCE_HEADER_NAME => $this->environmentResolver->getActiveProject()->getName(), + ]); + $response->headers->add([ + self::ENVIRONMENT_HEADER_NAME => $this->environmentResolver->getActiveEnvironmentName(), + ]); } catch (\InvalidArgumentException) { } diff --git a/tests/fixtures/environments.json b/tests/fixtures/environments.json deleted file mode 100644 index ca58687d..00000000 --- a/tests/fixtures/environments.json +++ /dev/null @@ -1,78 +0,0 @@ -{ - "asuminen": { - "meta": { - "repository": "City-of-Helsinki/drupal-helfi-asuminen", - "azure_devops_link": "https://example.com" - }, - "environments": { - "local": { - "path": { - "fi": "/fi/asuminen", - "sv": "/sv/boende", - "en": "/en/housing" - }, - "address": { - "protocol": "https", - "domain": "helfi-asuminen.docker.so" - }, - "internal_address": { - "protocol": "http", - "domain": "helfi-asuminen.docker.so", - "port": 8080 - } - }, - "prod": { - "path": { - "fi": "/fi/asuminen", - "sv": "/sv/boende", - "en": "/en/housing" - }, - "address": { - "protocol": "https", - "domain": "www.hel.fi" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-asuminen-prod.apps.platta.hel.fi" - }, - "meta": {} - }, - "stage": { - "path": { - "fi": "/fi/staging-asuminen", - "sv": "/sv/staging-boende", - "en": "/en/staging-housing" - }, - "address": { - "protocol": "https", - "domain": "www.hel.fi" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-asuminen-staging.apps.platta.hel.fi" - }, - "meta": { - "openshift_console_link": "https://example.com" - } - }, - "test": { - "path": { - "fi": "/fi/test-asuminen", - "sv": "/sv/test-boende", - "en": "/en/test-housing" - }, - "address": { - "protocol": "https", - "domain": "www.hel.fi" - }, - "internal_address": { - "protocol": "https", - "domain": "nginx-asuminen-test.apps.arodevtest.hel.fi" - }, - "meta": { - "openshift_console_link": "https://example.com" - } - } - } - } -} diff --git a/tests/src/Traits/EnvironmentResolverTrait.php b/tests/src/Traits/EnvironmentResolverTrait.php index 5fd00864..abaf7e34 100644 --- a/tests/src/Traits/EnvironmentResolverTrait.php +++ b/tests/src/Traits/EnvironmentResolverTrait.php @@ -81,7 +81,7 @@ protected function getConfigStub(mixed $projectName = NULL, mixed $envName = NUL */ protected function getEnvironmentResolver(mixed $projectName = NULL, mixed $envName = NULL) : EnvironmentResolver { $configStub = $this->getConfigStub($projectName, $envName); - return new EnvironmentResolver(__DIR__ . '/../../../fixtures/environments.json', $configStub); + return new EnvironmentResolver($configStub); } } diff --git a/tests/src/Unit/ApiClient/ApiClientTest.php b/tests/src/Unit/ApiClient/ApiClientTest.php index 82f14f97..6df26736 100644 --- a/tests/src/Unit/ApiClient/ApiClientTest.php +++ b/tests/src/Unit/ApiClient/ApiClientTest.php @@ -11,10 +11,10 @@ use Drupal\helfi_api_base\ApiClient\ApiClient; use Drupal\helfi_api_base\ApiClient\ApiResponse; use Drupal\helfi_api_base\ApiClient\CacheValue; -use Drupal\helfi_api_base\Environment\EnvironmentResolver; -use Drupal\helfi_api_base\Environment\EnvironmentResolverInterface; +use Drupal\helfi_api_base\Environment\EnvironmentEnum; use Drupal\helfi_api_base\Environment\Project; use Drupal\Tests\helfi_api_base\Traits\ApiTestTrait; +use Drupal\Tests\helfi_api_base\Traits\EnvironmentResolverTrait; use Drupal\Tests\UnitTestCase; use GuzzleHttp\ClientInterface; use GuzzleHttp\Exception\ClientException; @@ -37,6 +37,7 @@ class ApiClientTest extends UnitTestCase { use ApiTestTrait; use ProphecyTrait; + use EnvironmentResolverTrait; /** * The cache. @@ -46,11 +47,11 @@ class ApiClientTest extends UnitTestCase { private ?CacheBackendInterface $cache; /** - * The default environment resolver config. + * The default environment. * - * @var array + * @var \Drupal\helfi_api_base\Environment\EnvironmentEnum */ - private array $environmentResolverConfiguration = []; + private EnvironmentEnum $environment = EnvironmentEnum::Local; /** * Response fixture JSON file. @@ -67,10 +68,6 @@ protected function setUp() : void { $this->fixture = sprintf('%s/../../../fixtures/response.json', __DIR__); $this->cache = new MemoryBackend(); - $this->environmentResolverConfiguration = [ - EnvironmentResolver::PROJECT_NAME_KEY => Project::ASUMINEN, - EnvironmentResolver::ENVIRONMENT_NAME_KEY => 'local', - ]; } /** @@ -97,8 +94,6 @@ private function getTimeMock(int $expectedTime) : ObjectProphecy { * The time prophecy. * @param \Psr\Log\LoggerInterface|null $logger * The logger. - * @param \Drupal\helfi_api_base\Environment\EnvironmentResolverInterface|null $environmentResolver - * The environment resolver. * @param array $requestOptions * The default request options. * @@ -109,7 +104,6 @@ private function getSut( ClientInterface $client = NULL, TimeInterface $time = NULL, LoggerInterface $logger = NULL, - EnvironmentResolverInterface $environmentResolver = NULL, array $requestOptions = [], ) : ApiClient { if (!$client) { @@ -123,17 +117,11 @@ private function getSut( if (!$logger) { $logger = $this->prophesize(LoggerInterface::class)->reveal(); } - if (!$environmentResolver) { - $environmentResolver = new EnvironmentResolver('', $this->getConfigFactoryStub([ - 'helfi_api_base.environment_resolver.settings' => $this->environmentResolverConfiguration, - ])); - } - return new ApiClient( $client, $this->cache, $time, - $environmentResolver, + $this->getEnvironmentResolver(Project::ASUMINEN, $this->environment), $logger, $requestOptions, ); @@ -342,8 +330,8 @@ public function testMockFallback() : void { * @covers ::getRequestOptions */ public function testFastRequestFailure() : void { - // Override environment name so we don't fallback to mock responses. - $this->environmentResolverConfiguration[EnvironmentResolver::ENVIRONMENT_NAME_KEY] = 'test'; + // Override environment so we don't fallback to mock responses. + $this->environment = EnvironmentEnum::Test; $client = $this->createMockHttpClient([ new ConnectException( diff --git a/tests/src/Unit/ApiClient/ApiFixtureTest.php b/tests/src/Unit/ApiClient/ApiFixtureTest.php index 490237a7..833400d9 100644 --- a/tests/src/Unit/ApiClient/ApiFixtureTest.php +++ b/tests/src/Unit/ApiClient/ApiFixtureTest.php @@ -20,7 +20,7 @@ class ApiFixtureTest extends UnitTestCase { * @covers \Drupal\helfi_api_base\ApiClient\ApiResponse */ public function testFixtures() { - $response = ApiFixture::requestFromFile(vsprintf('%s/../../../fixtures/environments.json', [ + $response = ApiFixture::requestFromFile(vsprintf('%s/../../../fixtures/response.json', [ __DIR__, ])); diff --git a/tests/src/Unit/Environment/AddressTest.php b/tests/src/Unit/Environment/AddressTest.php index 665e5ec5..28337426 100644 --- a/tests/src/Unit/Environment/AddressTest.php +++ b/tests/src/Unit/Environment/AddressTest.php @@ -10,14 +10,13 @@ /** * Tests Project value object. * - * @coversDefaultClass \Drupal\helfi_api_base\Environment\Address * @group helfi_api_base */ class AddressTest extends UnitTestCase { /** - * @covers ::__construct - * @covers ::getAddress + * Tests getAddress() method. + * * @dataProvider addressData */ public function testGetAddress(string $expected, array $values) : void { diff --git a/tests/src/Unit/Environment/EnvironmentEnumTest.php b/tests/src/Unit/Environment/EnvironmentEnumTest.php index 431fa868..bcfef1dd 100644 --- a/tests/src/Unit/Environment/EnvironmentEnumTest.php +++ b/tests/src/Unit/Environment/EnvironmentEnumTest.php @@ -11,13 +11,12 @@ /** * Tests environment enum. * - * @coversDefaultClass \Drupal\helfi_api_base\Environment\EnvironmentEnum * @group helfi_api_base */ class EnvironmentEnumTest extends UnitTestCase { /** - * @covers ::label + * Tests label() method. */ public function testLabel() : void { $found = 0; diff --git a/tests/src/Unit/Environment/EnvironmentResolverTest.php b/tests/src/Unit/Environment/EnvironmentResolverTest.php index e9a179aa..ccfdf608 100644 --- a/tests/src/Unit/Environment/EnvironmentResolverTest.php +++ b/tests/src/Unit/Environment/EnvironmentResolverTest.php @@ -7,6 +7,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\ImmutableConfig; use Drupal\helfi_api_base\Environment\Environment; +use Drupal\helfi_api_base\Environment\EnvironmentEnum; use Drupal\helfi_api_base\Environment\EnvironmentResolver; use Drupal\helfi_api_base\Environment\Project; use Drupal\Tests\helfi_api_base\Traits\EnvironmentResolverTrait; @@ -17,7 +18,6 @@ /** * Tests environment resolver value objects. * - * @coversDefaultClass \Drupal\helfi_api_base\Environment\EnvironmentResolver * @group helfi_api_base */ class EnvironmentResolverTest extends UnitTestCase { @@ -26,24 +26,11 @@ class EnvironmentResolverTest extends UnitTestCase { use EnvironmentResolverTrait; /** - * @covers ::populateEnvironments - * @covers ::__construct - * @covers ::getEnvironment - * @covers ::getProject - * @covers ::getProjects - * @covers \Drupal\helfi_api_base\Environment\Environment::__construct - * @covers \Drupal\helfi_api_base\Environment\Environment::getPath - * @covers \Drupal\helfi_api_base\Environment\Project::__construct - * @covers \Drupal\helfi_api_base\Environment\Project::getEnvironment - * @covers \Drupal\helfi_api_base\Environment\Project::hasEnvironment - * @covers \Drupal\helfi_api_base\Environment\Project::addEnvironment - * @covers \Drupal\helfi_api_base\Environment\EnvironmentTrait::normalizeEnvironmentName - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::__construct - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::createFromArray + * Ensures all defined projects have a matching constant. */ public function testProjectConstant() : void { $constants = new \ReflectionClass(Project::class); - $resolver = new EnvironmentResolver('', $this->getConfigStub()); + $resolver = new EnvironmentResolver($this->getConfigStub()); foreach ($constants->getConstants() as $value) { $this->assertNotEmpty($resolver->getProject($value)); @@ -53,70 +40,8 @@ public function testProjectConstant() : void { } /** - * @covers ::populateEnvironments - * @covers ::__construct - * @covers \Drupal\helfi_api_base\Environment\Project::__construct - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::__construct - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::createFromArray - * @dataProvider populateEnvironmentsExceptionsData - */ - public function testPopulateEnvironmentsExceptions(string $data, string $message) : void { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage($message); - new EnvironmentResolver($data, $this->getConfigStub()); - } - - /** - * Data provider. + * Tests getEnvironment() validation. * - * @return array - * The data. - */ - public function populateEnvironmentsExceptionsData() : array { - return [ - ['nonexistent.json', 'Environment file not found or is not a valid JSON.'], - [__FILE__, 'Failed to parse projects.'], - [ - json_encode([ - 'asuminen' => [ - 'meta' => [ - 'repository' => '123', - 'azure_devops_link' => 'https://example.com', - ], - 'environments' => [ - 'local' => [], - ], - ], - ]), - 'Project missing "address", "internal_address" or "paths" setting.', - ], - [ - json_encode([ - 'asuminen' => [], - ]), - 'Project missing meta or environments.', - ], - ]; - } - - /** - * @covers ::populateEnvironments - * @covers ::__construct - * @covers ::getEnvironment - * @covers ::getProject - * @covers ::getProjectForRepository - * @covers \Drupal\helfi_api_base\Environment\Environment::__construct - * @covers \Drupal\helfi_api_base\Environment\Environment::getPath - * @covers \Drupal\helfi_api_base\Environment\Environment::getUrl - * @covers \Drupal\helfi_api_base\Environment\Project::__construct - * @covers \Drupal\helfi_api_base\Environment\Project::getEnvironment - * @covers \Drupal\helfi_api_base\Environment\Project::hasEnvironment - * @covers \Drupal\helfi_api_base\Environment\Project::addEnvironment - * @covers \Drupal\helfi_api_base\Environment\Project::getMetadata - * @covers \Drupal\helfi_api_base\Environment\EnvironmentTrait::normalizeEnvironmentName - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::__construct - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::createFromArray - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::getNormalizedRepository * @dataProvider resolveEnvironmentExceptionData */ public function testGetEnvironmentException( @@ -145,21 +70,8 @@ public function resolveEnvironmentExceptionData() : array { } /** - * @covers ::populateEnvironments - * @covers ::__construct - * @covers ::getEnvironment - * @covers ::getProject - * @covers \Drupal\helfi_api_base\Environment\Environment::__construct - * @covers \Drupal\helfi_api_base\Environment\Environment::getPath - * @covers \Drupal\helfi_api_base\Environment\Environment::getUrl - * @covers \Drupal\helfi_api_base\Environment\Environment::getEnvironmentName - * @covers \Drupal\helfi_api_base\Environment\Project::__construct - * @covers \Drupal\helfi_api_base\Environment\Project::getEnvironment - * @covers \Drupal\helfi_api_base\Environment\Project::hasEnvironment - * @covers \Drupal\helfi_api_base\Environment\Project::addEnvironment - * @covers \Drupal\helfi_api_base\Environment\EnvironmentTrait::normalizeEnvironmentName - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::__construct - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::createFromArray + * Test environment mapping. + * * @dataProvider environmentMapData */ public function testEnvironmentMap(string $envName, string $expected) : void { @@ -183,20 +95,8 @@ public function environmentMapData() : array { } /** - * @covers ::populateEnvironments - * @covers ::__construct - * @covers ::getEnvironment - * @covers ::getProject - * @covers ::getActiveProject - * @covers ::getConfig - * @covers ::configurationMissingExceptionMessage - * @covers \Drupal\helfi_api_base\Environment\Environment::__construct - * @covers \Drupal\helfi_api_base\Environment\EnvironmentResolver::__construct - * @covers \Drupal\helfi_api_base\Environment\EnvironmentResolver::populateEnvironments - * @covers \Drupal\helfi_api_base\Environment\Project::__construct - * @covers \Drupal\helfi_api_base\Environment\Project::addEnvironment - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::__construct - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::createFromArray + * Test ::getActiveProject() validation. + * * @dataProvider activeProjectExceptionData */ public function testGetActiveProjectException(mixed $value) : void { @@ -210,7 +110,7 @@ public function testGetActiveProjectException(mixed $value) : void { $configFactory = $this->prophesize(ConfigFactoryInterface::class); $configFactory->get(Argument::any()) ->willReturn($config->reveal()); - $sut = new EnvironmentResolver('', $configFactory->reveal()); + $sut = new EnvironmentResolver($configFactory->reveal()); $sut->getActiveProject(); } @@ -229,21 +129,7 @@ public function activeProjectExceptionData() : array { } /** - * @covers ::populateEnvironments - * @covers ::__construct - * @covers ::getEnvironment - * @covers ::getProject - * @covers ::getActiveProject - * @covers ::getConfig - * @covers \Drupal\helfi_api_base\Environment\Environment::__construct - * @covers \Drupal\helfi_api_base\Environment\EnvironmentResolver::__construct - * @covers \Drupal\helfi_api_base\Environment\EnvironmentResolver::populateEnvironments - * @covers \Drupal\helfi_api_base\Environment\Project::__construct - * @covers \Drupal\helfi_api_base\Environment\Project::addEnvironment - * @covers \Drupal\helfi_api_base\Environment\Project::getEnvironments - * @covers \Drupal\helfi_api_base\Environment\EnvironmentResolver::getProject - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::__construct - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::createFromArray + * Test getActiveProject(). */ public function testGetActiveProject() : void { $sut = $this->getEnvironmentResolver(Project::ASUMINEN, 'dev'); @@ -252,22 +138,7 @@ public function testGetActiveProject() : void { } /** - * @covers ::populateEnvironments - * @covers ::__construct - * @covers ::getEnvironment - * @covers ::getProject - * @covers ::configurationMissingExceptionMessage - * @covers ::getActiveEnvironment - * @covers ::getActiveEnvironmentName - * @covers ::getConfig - * @covers \Drupal\helfi_api_base\Environment\Environment::__construct - * @covers \Drupal\helfi_api_base\Environment\EnvironmentResolver::__construct - * @covers \Drupal\helfi_api_base\Environment\EnvironmentResolver::populateEnvironments - * @covers \Drupal\helfi_api_base\Environment\EnvironmentResolver::getProject - * @covers \Drupal\helfi_api_base\Environment\Project::__construct - * @covers \Drupal\helfi_api_base\Environment\Project::addEnvironment - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::__construct - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::createFromArray + * Tests getActiveEnvironment() validation. */ public function testGetActiveEnvironmentException() : void { putenv('APP_ENV='); @@ -277,16 +148,7 @@ public function testGetActiveEnvironmentException() : void { } /** - * @covers ::populateEnvironments - * @covers ::__construct - * @covers ::getActiveEnvironmentName - * @covers ::getConfig - * @covers \Drupal\helfi_api_base\Environment\Environment::__construct - * @covers \Drupal\helfi_api_base\Environment\Project::__construct - * @covers \Drupal\helfi_api_base\Environment\Project::addEnvironment - * @covers \Drupal\helfi_api_base\Environment\EnvironmentTrait::normalizeEnvironmentName - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::__construct - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::createFromArray + * Make sure getActiveEnvironment() fallbacks to env variable. */ public function testGetActiveEnvironmentFallback() : void { // Make sure environment resolver fallbacks to APP_ENV env variable when @@ -296,28 +158,10 @@ public function testGetActiveEnvironmentFallback() : void { } /** - * @covers ::populateEnvironments - * @covers ::__construct - * @covers ::getEnvironment - * @covers ::getProject - * @covers ::getConfig - * @covers ::getActiveEnvironment - * @covers ::getActiveEnvironmentName - * @covers ::getActiveProject - * @covers \Drupal\helfi_api_base\Environment\Environment::__construct - * @covers \Drupal\helfi_api_base\Environment\EnvironmentResolver::__construct - * @covers \Drupal\helfi_api_base\Environment\EnvironmentResolver::getProject - * @covers \Drupal\helfi_api_base\Environment\EnvironmentResolver::populateEnvironments - * @covers \Drupal\helfi_api_base\Environment\Project::__construct - * @covers \Drupal\helfi_api_base\Environment\Project::addEnvironment - * @covers \Drupal\helfi_api_base\Environment\Project::getEnvironment - * @covers \Drupal\helfi_api_base\Environment\Project::hasEnvironment - * @covers \Drupal\helfi_api_base\Environment\EnvironmentTrait::normalizeEnvironmentName - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::__construct - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::createFromArray + * Tests getActiveEnvironment(). */ public function testGetActiveEnvironment() : void { - $sut = $this->getEnvironmentResolver(Project::ASUMINEN, 'test'); + $sut = $this->getEnvironmentResolver(Project::ASUMINEN, EnvironmentEnum::Test); $this->assertInstanceOf(Environment::class, $sut->getActiveEnvironment()); } diff --git a/tests/src/Unit/Environment/EnvironmentTest.php b/tests/src/Unit/Environment/EnvironmentTest.php index aa066619..c455badf 100644 --- a/tests/src/Unit/Environment/EnvironmentTest.php +++ b/tests/src/Unit/Environment/EnvironmentTest.php @@ -12,30 +12,20 @@ /** * Tests environment value object. * - * @coversDefaultClass \Drupal\helfi_api_base\Environment\Environment * @group helfi_api_base */ class EnvironmentTest extends UnitTestCase { /** - * @covers ::__construct - * @covers ::getId - * @covers ::getEnvironment - * @covers ::getEnvironmentName - * @covers ::getInternalBaseUrl - * @covers ::getBaseUrl - * @cove - * @covers ::getMetadata + * Tests getters. */ public function testSimpleGetters() : void { $sut = new Environment( new Address('www.hel.fi'), new Address('internal-address.local', 'http', 8080), [], - 'test', EnvironmentEnum::Test, ); - $this->assertEquals('test', $sut->getId()); $this->assertEquals(EnvironmentEnum::Test, $sut->getEnvironment()); $this->assertEquals(EnvironmentEnum::Test->value, $sut->getEnvironmentName()); $this->assertEquals('https://www.hel.fi', $sut->getBaseUrl()); @@ -43,37 +33,37 @@ public function testSimpleGetters() : void { } /** - * @covers ::__construct - * @covers ::getUrl - * @covers ::getPath - * @covers ::getInternalAddress + * Test path validation. + */ + public function testGetUrlException() : void { + $sut = new Environment( + new Address('www.hel.fi'), + new Address('www.hel.fi', 'http'), + ['fi' => 'test-path'], + EnvironmentEnum::Local, + ); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Path not found for "en" language.'); + $sut->getUrl('en'); + } + + /** + * Tests getUrl() method. */ public function testGetUrl() : void { $sut = new Environment( new Address('www.hel.fi'), new Address('www.hel.fi', 'http'), ['fi' => 'test-path'], - 'test', EnvironmentEnum::Local, ); $this->assertEquals('https://www.hel.fi/test-path', $sut->getUrl('fi')); $this->assertEquals('http://www.hel.fi/test-path', $sut->getInternalAddress('fi')); - $caught = FALSE; - try { - $sut->getUrl('en'); - } - catch (\InvalidArgumentException $e) { - $this->assertEquals('Path not found for "en" language.', $e->getMessage()); - $caught = TRUE; - } - $this->assertTrue($caught); - $sut = new Environment( new Address('www.hel.fi'), new Address('www.hel.fi', 'https', 8080), ['fi' => 'test-path'], - 'test', EnvironmentEnum::Local, ); $this->assertEquals('https://www.hel.fi/test-path', $sut->getUrl('fi')); diff --git a/tests/src/Unit/Environment/ProjectMetadataTest.php b/tests/src/Unit/Environment/ProjectMetadataTest.php index 9833428a..2d031546 100644 --- a/tests/src/Unit/Environment/ProjectMetadataTest.php +++ b/tests/src/Unit/Environment/ProjectMetadataTest.php @@ -10,37 +10,24 @@ /** * Tests Project metadata value object. * - * @coversDefaultClass \Drupal\helfi_api_base\Environment\ProjectMetadata * @group helfi_api_base */ class ProjectMetadataTest extends UnitTestCase { /** - * @covers ::createFromArray + * Tests constructor validation. */ public function testRequiredValueException() : void { - $caught = FALSE; - try { - ProjectMetadata::createFromArray(['dsad' => 'test']); - } - catch (\InvalidArgumentException $e) { - $this->assertMatchesRegularExpression('/Missing required/', $e->getMessage()); - $caught = TRUE; - } - $this->assertTrue($caught); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The repositoryUrl must be a valid URL.'); + new ProjectMetadata(''); } /** - * @covers ::__construct - * @covers ::createFromArray - * @covers ::getRepository - * @covers ::getRepositoryUrl - * @covers ::getNormalizedRepository + * Test getter methods. */ public function testGetters() : void { - $sut = ProjectMetadata::createFromArray([ - 'repository' => 'City-of-Helsinki/test', - ]); + $sut = new ProjectMetadata('https://github.com/City-of-Helsinki/test'); $this->assertEquals('City-of-Helsinki/test', $sut->getRepository()); $this->assertEquals('city-of-helsinki/test', $sut->getNormalizedRepository()); $this->assertEquals('https://github.com/City-of-Helsinki/test', $sut->getRepositoryUrl()); diff --git a/tests/src/Unit/Environment/ProjectTest.php b/tests/src/Unit/Environment/ProjectTest.php index 012d0297..42a1d6f7 100644 --- a/tests/src/Unit/Environment/ProjectTest.php +++ b/tests/src/Unit/Environment/ProjectTest.php @@ -15,81 +15,55 @@ /** * Tests Project value object. * - * @coversDefaultClass \Drupal\helfi_api_base\Environment\Project * @group helfi_api_base */ class ProjectTest extends UnitTestCase { /** - * @covers ::__construct - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::__construct + * Validate constructor arguments. */ public function testConstructorException() : void { - $caught = FALSE; - try { - // Make sure $environments parameter must be an Environment object. - new Project(Project::ASUMINEN, new ProjectMetadata(''), ['invalid env']); - } - catch (\InvalidArgumentException $e) { - $caught = TRUE; - } - $this->assertTrue($caught); + $this->expectException(\InvalidArgumentException::class); + // Make sure $environments parameter must be an Environment object. + new Project(Project::ASUMINEN, new ProjectMetadata(''), ['invalid env']); } /** - * @covers ::__construct - * @covers ::getName - * @covers ::getMetadata - * @covers ::getEnvironments - * @covers \Drupal\helfi_api_base\Environment\Environment::__construct - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::__construct + * Test getters. */ public function testGetters() : void { - $sut = new Project(Project::ASUMINEN, new ProjectMetadata(''), [ + $sut = new Project(Project::ASUMINEN, new ProjectMetadata('https://github.com/city-of-helsinki/something'), [ new Environment( new Address('www.hel.fi'), new Address('www.hel.fi'), [], - Project::ASUMINEN, EnvironmentEnum::Local, ), ]); $this->assertEquals(Project::ASUMINEN, $sut->getName()); $this->assertInstanceOf(ProjectMetadata::class, $sut->getMetadata()); - $this->assertInstanceOf(Environment::class, $sut->getEnvironments()[0]); + $this->assertInstanceOf(Environment::class, $sut->getEnvironments()[EnvironmentEnum::Local->value]); } /** - * @covers ::getEnvironment - * @covers ::hasEnvironment - * @covers ::__construct - * @covers \Drupal\helfi_api_base\Environment\EnvironmentTrait::normalizeEnvironmentName - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::__construct + * Validate environment. */ public function testGetEnvironmentException() : void { - $caught = FALSE; - $sut = new Project(Project::ASUMINEN, new ProjectMetadata('')); - try { - $sut->getEnvironment('local'); - } - catch (\InvalidArgumentException $e) { - $this->assertEquals('Environment "local" not found.', $e->getMessage()); - $caught = TRUE; - } - $this->assertTrue($caught); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Environment "local" not found.'); + $sut = new Project(Project::ASUMINEN, new ProjectMetadata('https://github.com/city-of-helsinki/something')); + $sut->getEnvironment('local'); } /** - * @covers ::__construct - * @covers ::label - * @covers \Drupal\helfi_api_base\Environment\ProjectMetadata::__construct + * Test label. */ public function testLabel() : void { $constants = new \ReflectionClass(Project::class); $found = 0; foreach ($constants->getConstants() as $value) { $found++; - $sut = new Project($value, new ProjectMetadata('')); + $sut = new Project($value, new ProjectMetadata('https://github.com/city-of-helsinki/something')); $this->assertInstanceOf(TranslatableMarkup::class, $sut->label()); } $this->assertTrue($found > 0); From 66fc94d22be97ba734d3ca979902780ca3be42e2 Mon Sep 17 00:00:00 2001 From: tuutti Date: Mon, 29 Apr 2024 09:09:34 +0300 Subject: [PATCH 06/11] UHF-9833: Service enum --- src/Environment/Environment.php | 8 ++++---- src/Environment/EnvironmentResolver.php | 2 +- src/Environment/Service.php | 2 +- src/Environment/ServiceEnum.php | 12 ++++++++++++ 4 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 src/Environment/ServiceEnum.php diff --git a/src/Environment/Environment.php b/src/Environment/Environment.php index 3279640e..86869f88 100644 --- a/src/Environment/Environment.php +++ b/src/Environment/Environment.php @@ -42,7 +42,7 @@ public function __construct( Assert::allIsInstanceOf($services, Service::class); foreach ($services as $service) { - $this->services[$service->name] = $service; + $this->services[$service->name->value] = $service; } } @@ -143,14 +143,14 @@ public function getServices(): array { /** * Gets the given service. * - * @param string $name + * @param \Drupal\helfi_api_base\Environment\ServiceEnum $name * The service to get. * * @return \Drupal\helfi_api_base\Environment\Service|null * The service or null. */ - public function getService(string $name): ?Service { - return $this->services[$name] ?? NULL; + public function getService(ServiceEnum $name): ?Service { + return $this->services[$name->value] ?? NULL; } } diff --git a/src/Environment/EnvironmentResolver.php b/src/Environment/EnvironmentResolver.php index 3c571573..8e82d997 100644 --- a/src/Environment/EnvironmentResolver.php +++ b/src/Environment/EnvironmentResolver.php @@ -142,7 +142,7 @@ private function populateEnvironments() : void { paths: $paths[Project::ETUSIVU], environment: EnvironmentEnum::Local, services: [ - new Service('elastic-proxy', new Address('helfi-etusivu-elastic', 'http', 9200)), + new Service(ServiceEnum::ElasticProxy, new Address('helfi-etusivu-elastic', 'http', 9200)), ], ), new Environment( diff --git a/src/Environment/Service.php b/src/Environment/Service.php index c3514f48..e36bf16d 100644 --- a/src/Environment/Service.php +++ b/src/Environment/Service.php @@ -13,7 +13,7 @@ final class Service { * Constructs a new instance. */ public function __construct( - public readonly string $name, + public readonly ServiceEnum $name, public readonly Address $address, ) { } diff --git a/src/Environment/ServiceEnum.php b/src/Environment/ServiceEnum.php new file mode 100644 index 00000000..9f89fc1f --- /dev/null +++ b/src/Environment/ServiceEnum.php @@ -0,0 +1,12 @@ + Date: Tue, 30 Apr 2024 11:42:50 +0300 Subject: [PATCH 07/11] UHF-9833: Missing test coverage --- src/Environment/Environment.php | 10 ---- src/Environment/EnvironmentResolver.php | 10 ++++ .../src/Unit/Environment/EnvironmentTest.php | 54 +++++++++++++++---- 3 files changed, 54 insertions(+), 20 deletions(-) diff --git a/src/Environment/Environment.php b/src/Environment/Environment.php index 86869f88..29a45c96 100644 --- a/src/Environment/Environment.php +++ b/src/Environment/Environment.php @@ -130,16 +130,6 @@ public function getEnvironment() : EnvironmentEnum { return $this->environment; } - /** - * Gets the services. - * - * @return \Drupal\helfi_api_base\Environment\Service[] - * The services. - */ - public function getServices(): array { - return $this->services; - } - /** * Gets the given service. * diff --git a/src/Environment/EnvironmentResolver.php b/src/Environment/EnvironmentResolver.php index 8e82d997..acbfce83 100644 --- a/src/Environment/EnvironmentResolver.php +++ b/src/Environment/EnvironmentResolver.php @@ -150,18 +150,28 @@ private function populateEnvironments() : void { internalAddress: new Address('nginx-etusivu-test.apps.arodevtest.hel.fi'), paths: $paths[Project::ETUSIVU], environment: EnvironmentEnum::Test, + services: [ + new Service(ServiceEnum::ElasticProxy, new Address('etusivu-elastic-proxy-test.agw.arodevtest.hel.fi')), + ], ), new Environment( address: new Address('www.stage.hel.ninja'), internalAddress: new Address('nginx-etusivu-staging.apps.platta.hel.fi'), paths: $paths[Project::ETUSIVU], environment: EnvironmentEnum::Stage, + services: [ + // @todo This shouldn't be using prod address. + new Service(ServiceEnum::ElasticProxy, new Address('uutisapi.hel.fi')), + ], ), new Environment( address: new Address('www.hel.fi'), internalAddress: new Address('nginx-etusivu-prod.apps.platta.hel.fi'), paths: $paths[Project::ETUSIVU], environment: EnvironmentEnum::Prod, + services: [ + new Service(ServiceEnum::ElasticProxy, new Address('uutisapi.hel.fi')), + ], ), ], ); diff --git a/tests/src/Unit/Environment/EnvironmentTest.php b/tests/src/Unit/Environment/EnvironmentTest.php index c455badf..39a0df89 100644 --- a/tests/src/Unit/Environment/EnvironmentTest.php +++ b/tests/src/Unit/Environment/EnvironmentTest.php @@ -7,6 +7,8 @@ use Drupal\helfi_api_base\Environment\Address; use Drupal\helfi_api_base\Environment\Environment; use Drupal\helfi_api_base\Environment\EnvironmentEnum; +use Drupal\helfi_api_base\Environment\Service; +use Drupal\helfi_api_base\Environment\ServiceEnum; use Drupal\Tests\UnitTestCase; /** @@ -17,31 +19,63 @@ class EnvironmentTest extends UnitTestCase { /** - * Tests getters. + * Gets the SUT. + * + * @param array $paths + * The paths. + * @param array $services + * The services. + * + * @return \Drupal\helfi_api_base\Environment\Environment + * The SUT. */ - public function testSimpleGetters() : void { - $sut = new Environment( + private function getSut(array $paths = [], array $services = []) : Environment { + return new Environment( new Address('www.hel.fi'), new Address('internal-address.local', 'http', 8080), - [], + $paths, EnvironmentEnum::Test, + $services, ); + } + + /** + * Tests getters. + */ + public function testSimpleGetters() : void { + $sut = $this->getSut(); $this->assertEquals(EnvironmentEnum::Test, $sut->getEnvironment()); $this->assertEquals(EnvironmentEnum::Test->value, $sut->getEnvironmentName()); $this->assertEquals('https://www.hel.fi', $sut->getBaseUrl()); $this->assertEquals('http://internal-address.local:8080', $sut->getInternalBaseUrl()); + $this->assertNull($sut->getService(ServiceEnum::ElasticProxy)); + } + + /** + * Make sure only Service instances can be passed. + */ + public function testServiceException() : void { + $this->expectException(\InvalidArgumentException::class); + $this->getSut(services: [1]); + } + + /** + * Tests service getter. + */ + public function testGetService() : void { + $sut = $this->getSut( + services: [ + new Service(ServiceEnum::ElasticProxy, new Address('helfi-etusivu-elastic')), + ], + ); + $this->assertInstanceOf(Service::class, $sut->getService(ServiceEnum::ElasticProxy)); } /** * Test path validation. */ public function testGetUrlException() : void { - $sut = new Environment( - new Address('www.hel.fi'), - new Address('www.hel.fi', 'http'), - ['fi' => 'test-path'], - EnvironmentEnum::Local, - ); + $sut = $this->getSut(['fi' => 'test-path']); $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Path not found for "en" language.'); $sut->getUrl('en'); From fd5cd242b3ebfca09da6f861d467919a2b33fb30 Mon Sep 17 00:00:00 2001 From: tuutti Date: Tue, 30 Apr 2024 11:43:43 +0300 Subject: [PATCH 08/11] UHF-9833: Fixed documentation --- documentation/environment-resolver.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/documentation/environment-resolver.md b/documentation/environment-resolver.md index c27c905e..3caf4b68 100644 --- a/documentation/environment-resolver.md +++ b/documentation/environment-resolver.md @@ -29,8 +29,7 @@ $path = $environment->getPath('fi'); // '/fi/dev-asuminen'. $domain = $environment->getDomain(); // 'nginx-asuminen-dev.agw.arodevtest.hel.fi'. $baseUrl = $environment->getBaseUrl(); // 'https://nginx-asuminen-dev.agw.arodevtest.hel.fi' /** @var \Drupal\helfi_api_base\Environment\Service $services */ -$services = $environment->getServices(); -$service = $environment->getService('elastic-proxy'); // Gets the elastic-proxy service. +$service = $environment->getService(\Drupal\helfi_api_base\Environment\ServiceEnum::ElasticProxy); // Gets the elastic-proxy service. ``` ### Active environment From 05219a7517ca28cdbe934f757747028583d07e39 Mon Sep 17 00:00:00 2001 From: tuutti Date: Tue, 30 Apr 2024 11:46:53 +0300 Subject: [PATCH 09/11] UHF-9833: Fixed comment --- src/Environment/Service.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Environment/Service.php b/src/Environment/Service.php index e36bf16d..43cd578c 100644 --- a/src/Environment/Service.php +++ b/src/Environment/Service.php @@ -5,7 +5,7 @@ namespace Drupal\helfi_api_base\Environment; /** - * A value object to store environment metadata. + * A value object to store service data. */ final class Service { From 4e62b5ce65695a1b8fe07d8e6db554d92e4e0440 Mon Sep 17 00:00:00 2001 From: tuutti Date: Tue, 30 Apr 2024 12:23:24 +0300 Subject: [PATCH 10/11] UHF-9833: Fixed array --- src/Environment/EnvironmentResolver.php | 569 ++++++++++++------------ 1 file changed, 285 insertions(+), 284 deletions(-) diff --git a/src/Environment/EnvironmentResolver.php b/src/Environment/EnvironmentResolver.php index acbfce83..5f5d8221 100644 --- a/src/Environment/EnvironmentResolver.php +++ b/src/Environment/EnvironmentResolver.php @@ -102,290 +102,291 @@ private function populateEnvironments() : void { 'en' => '/en/business-and-work', ], ]; - $this->projects[Project::ASUMINEN] = new Project( - Project::ASUMINEN, - new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-asuminen'), - [ - new Environment( - address: new Address('helfi-asuminen.docker.so'), - internalAddress: new Address('helfi-asuminen', 'http', 8080), - paths: $paths[Project::ASUMINEN], - environment: EnvironmentEnum::Local, - ), - new Environment( - address: new Address('www.test.hel.ninja'), - internalAddress: new Address('nginx-asuminen-test.apps.arodevtest.hel.fi'), - paths: $paths[Project::ASUMINEN], - environment: EnvironmentEnum::Test, - ), - new Environment( - address: new Address('www.stage.hel.ninja'), - internalAddress: new Address('nginx-asuminen-staging.apps.platta.hel.fi'), - paths: $paths[Project::ASUMINEN], - environment: EnvironmentEnum::Stage, - ), - new Environment( - address: new Address('www.hel.fi'), - internalAddress: new Address('nginx-asuminen-prod.apps.platta.hel.fi'), - paths: $paths[Project::ASUMINEN], - environment: EnvironmentEnum::Prod, - ), - ], - ); - $this->projects[Project::ETUSIVU] = new Project( - Project::ETUSIVU, - new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-etusivu'), - [ - new Environment( - address: new Address('helfi-etusivu.docker.so'), - internalAddress: new Address('helfi-etusivu', 'http', 8080), - paths: $paths[Project::ETUSIVU], - environment: EnvironmentEnum::Local, - services: [ - new Service(ServiceEnum::ElasticProxy, new Address('helfi-etusivu-elastic', 'http', 9200)), - ], - ), - new Environment( - address: new Address('www.test.hel.ninja'), - internalAddress: new Address('nginx-etusivu-test.apps.arodevtest.hel.fi'), - paths: $paths[Project::ETUSIVU], - environment: EnvironmentEnum::Test, - services: [ - new Service(ServiceEnum::ElasticProxy, new Address('etusivu-elastic-proxy-test.agw.arodevtest.hel.fi')), - ], - ), - new Environment( - address: new Address('www.stage.hel.ninja'), - internalAddress: new Address('nginx-etusivu-staging.apps.platta.hel.fi'), - paths: $paths[Project::ETUSIVU], - environment: EnvironmentEnum::Stage, - services: [ - // @todo This shouldn't be using prod address. - new Service(ServiceEnum::ElasticProxy, new Address('uutisapi.hel.fi')), - ], - ), - new Environment( - address: new Address('www.hel.fi'), - internalAddress: new Address('nginx-etusivu-prod.apps.platta.hel.fi'), - paths: $paths[Project::ETUSIVU], - environment: EnvironmentEnum::Prod, - services: [ - new Service(ServiceEnum::ElasticProxy, new Address('uutisapi.hel.fi')), - ], - ), - ], - ); - - $this->projects[Project::KASVATUS_KOULUTUS] = new Project( - Project::KASVATUS_KOULUTUS, - new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-kasvatus-koulutus'), - [ - new Environment( - address: new Address('helfi-kasko.docker.so'), - internalAddress: new Address('helfi-kasko', 'http', 8080), - paths: $paths[Project::KASVATUS_KOULUTUS], - environment: EnvironmentEnum::Local, - ), - new Environment( - address: new Address('www.test.hel.ninja'), - internalAddress: new Address('nginx-kasvatus-koulutus-test.apps.arodevtest.hel.fi'), - paths: $paths[Project::KASVATUS_KOULUTUS], - environment: EnvironmentEnum::Test, - ), - new Environment( - address: new Address('www.stage.hel.ninja'), - internalAddress: new Address('nginx-kasvatus-koulutus-staging.apps.platta.hel.fi'), - paths: $paths[Project::KASVATUS_KOULUTUS], - environment: EnvironmentEnum::Stage, - ), - new Environment( - address: new Address('www.hel.fi'), - internalAddress: new Address('nginx-kasvatus-koulutus-prod.apps.platta.hel.fi'), - paths: $paths[Project::KASVATUS_KOULUTUS], - environment: EnvironmentEnum::Prod, - ), - ], - ); - $this->projects[Project::KUVA] = new Project( - Project::KUVA, - new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-kuva'), - [ - new Environment( - address: new Address('helfi-kuva.docker.so'), - internalAddress: new Address('helfi-kuva', 'http', 8080), - paths: $paths[Project::KUVA], - environment: EnvironmentEnum::Local, - ), - new Environment( - address: new Address('www.test.hel.ninja'), - internalAddress: new Address('nginx-kuva-test.apps.arodevtest.hel.fi'), - paths: $paths[Project::KUVA], - environment: EnvironmentEnum::Test, - ), - new Environment( - address: new Address('www.stage.hel.ninja'), - internalAddress: new Address('nginx-kuva-staging.apps.platta.hel.fi'), - paths: $paths[Project::KUVA], - environment: EnvironmentEnum::Stage, - ), - new Environment( - address: new Address('www.hel.fi'), - internalAddress: new Address('nginx-kuva-prod.apps.platta.hel.fi'), - paths: $paths[Project::KUVA], - environment: EnvironmentEnum::Prod, - ), - ], - ); - $this->projects[Project::LIIKENNE] = new Project( - Project::LIIKENNE, - new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-kymp'), - [ - new Environment( - address: new Address('helfi-kymp.docker.so'), - internalAddress: new Address('helfi-kymp', 'http', 8080), - paths: $paths[Project::LIIKENNE], - environment: EnvironmentEnum::Local, - ), - new Environment( - address: new Address('www.test.hel.ninja'), - internalAddress: new Address('nginx-liikenne-test.apps.arodevtest.hel.fi'), - paths: $paths[Project::LIIKENNE], - environment: EnvironmentEnum::Test, - ), - new Environment( - address: new Address('www.stage.hel.ninja'), - internalAddress: new Address('nginx-liikenne-staging.apps.platta.hel.fi'), - paths: $paths[Project::LIIKENNE], - environment: EnvironmentEnum::Stage, - ), - new Environment( - address: new Address('www.hel.fi'), - internalAddress: new Address('nginx-liikenne-prod.apps.platta.hel.fi'), - paths: $paths[Project::LIIKENNE], - environment: EnvironmentEnum::Prod, - ), - ], - ); - $this->projects[Project::REKRY] = new Project( - Project::REKRY, - new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-rekry'), - [ - new Environment( - address: new Address('helfi-rekry.docker.so'), - internalAddress: new Address('helfi-rekry', 'http', 8080), - paths: $paths[Project::REKRY], - environment: EnvironmentEnum::Local, - ), - new Environment( - address: new Address('www.test.hel.ninja'), - internalAddress: new Address('nginx-rekry-test.apps.arodevtest.hel.fi'), - paths: $paths[Project::REKRY], - environment: EnvironmentEnum::Test, - ), - new Environment( - address: new Address('www.stage.hel.ninja'), - internalAddress: new Address('nginx-rekry-staging.apps.platta.hel.fi'), - paths: $paths[Project::REKRY], - environment: EnvironmentEnum::Stage, - ), - new Environment( - address: new Address('www.hel.fi'), - internalAddress: new Address('nginx-rekry-prod.apps.platta.hel.fi'), - paths: $paths[Project::REKRY], - environment: EnvironmentEnum::Prod, - ), - ], - ); - $this->projects[Project::STRATEGIA] = new Project( - Project::STRATEGIA, - new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-strategia'), - [ - new Environment( - address: new Address('helfi-strategia.docker.so'), - internalAddress: new Address('helfi-strategia', 'http', 8080), - paths: $paths[Project::STRATEGIA], - environment: EnvironmentEnum::Local, - ), - new Environment( - address: new Address('www.test.hel.ninja'), - internalAddress: new Address('nginx-strategia-talous-test.apps.arodevtest.hel.fi'), - paths: $paths[Project::STRATEGIA], - environment: EnvironmentEnum::Test, - ), - new Environment( - address: new Address('www.stage.hel.ninja'), - internalAddress: new Address('nginx-strategia-talous-staging.apps.platta.hel.fi'), - paths: $paths[Project::STRATEGIA], - environment: EnvironmentEnum::Stage, - ), - new Environment( - address: new Address('www.hel.fi'), - internalAddress: new Address('nginx-strategia-talous-prod.apps.platta.hel.fi'), - paths: $paths[Project::STRATEGIA], - environment: EnvironmentEnum::Prod, - ), - ], - ); - $this->projects[Project::TERVEYS] = new Project( - Project::TERVEYS, - new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-sote'), - [ - new Environment( - address: new Address('helfi-sote.docker.so'), - internalAddress: new Address('helfi-sote', 'http', 8080), - paths: $paths[Project::TERVEYS], - environment: EnvironmentEnum::Local, - ), - new Environment( - address: new Address('www.test.hel.ninja'), - internalAddress: new Address('nginx-terveys-test.apps.arodevtest.hel.fi'), - paths: $paths[Project::TERVEYS], - environment: EnvironmentEnum::Test, - ), - new Environment( - address: new Address('www.stage.hel.ninja'), - internalAddress: new Address('nginx-terveys-staging.apps.platta.hel.fi'), - paths: $paths[Project::TERVEYS], - environment: EnvironmentEnum::Stage, - ), - new Environment( - address: new Address('www.hel.fi'), - internalAddress: new Address('nginx-terveys-prod.apps.platta.hel.fi'), - paths: $paths[Project::TERVEYS], - environment: EnvironmentEnum::Prod, - ), - ], - ); - $this->projects[Project::TYO_YRITTAMINEN] = new Project( - Project::TYO_YRITTAMINEN, - new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-tyo-yrittaminen'), - [ - new Environment( - address: new Address('helfi-elo.docker.so'), - internalAddress: new Address('helfi-elo', 'http', 8080), - paths: $paths[Project::TYO_YRITTAMINEN], - environment: EnvironmentEnum::Local, - ), - new Environment( - address: new Address('www.test.hel.ninja'), - internalAddress: new Address('nginx-tyo-yrittaminen-test.apps.arodevtest.hel.fi'), - paths: $paths[Project::TYO_YRITTAMINEN], - environment: EnvironmentEnum::Test, - ), - new Environment( - address: new Address('www.stage.hel.ninja'), - internalAddress: new Address('nginx-tyo-yrittaminen-staging.apps.platta.hel.fi'), - paths: $paths[Project::TYO_YRITTAMINEN], - environment: EnvironmentEnum::Stage, - ), - new Environment( - address: new Address('www.hel.fi'), - internalAddress: new Address('nginx-tyo-yrittaminen-prod.apps.platta.hel.fi'), - paths: $paths[Project::TYO_YRITTAMINEN], - environment: EnvironmentEnum::Prod, - ), - ], - ); + $this->projects = [ + Project::ASUMINEN => new Project( + Project::ASUMINEN, + new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-asuminen'), + [ + new Environment( + address: new Address('helfi-asuminen.docker.so'), + internalAddress: new Address('helfi-asuminen', 'http', 8080), + paths: $paths[Project::ASUMINEN], + environment: EnvironmentEnum::Local, + ), + new Environment( + address: new Address('www.test.hel.ninja'), + internalAddress: new Address('nginx-asuminen-test.apps.arodevtest.hel.fi'), + paths: $paths[Project::ASUMINEN], + environment: EnvironmentEnum::Test, + ), + new Environment( + address: new Address('www.stage.hel.ninja'), + internalAddress: new Address('nginx-asuminen-staging.apps.platta.hel.fi'), + paths: $paths[Project::ASUMINEN], + environment: EnvironmentEnum::Stage, + ), + new Environment( + address: new Address('www.hel.fi'), + internalAddress: new Address('nginx-asuminen-prod.apps.platta.hel.fi'), + paths: $paths[Project::ASUMINEN], + environment: EnvironmentEnum::Prod, + ), + ], + ), + Project::ETUSIVU => new Project( + Project::ETUSIVU, + new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-etusivu'), + [ + new Environment( + address: new Address('helfi-etusivu.docker.so'), + internalAddress: new Address('helfi-etusivu', 'http', 8080), + paths: $paths[Project::ETUSIVU], + environment: EnvironmentEnum::Local, + services: [ + new Service(ServiceEnum::ElasticProxy, new Address('helfi-etusivu-elastic', 'http', 9200)), + ], + ), + new Environment( + address: new Address('www.test.hel.ninja'), + internalAddress: new Address('nginx-etusivu-test.apps.arodevtest.hel.fi'), + paths: $paths[Project::ETUSIVU], + environment: EnvironmentEnum::Test, + services: [ + new Service(ServiceEnum::ElasticProxy, new Address('etusivu-elastic-proxy-test.agw.arodevtest.hel.fi')), + ], + ), + new Environment( + address: new Address('www.stage.hel.ninja'), + internalAddress: new Address('nginx-etusivu-staging.apps.platta.hel.fi'), + paths: $paths[Project::ETUSIVU], + environment: EnvironmentEnum::Stage, + services: [ + // @todo This shouldn't be using prod address. + new Service(ServiceEnum::ElasticProxy, new Address('uutisapi.hel.fi')), + ], + ), + new Environment( + address: new Address('www.hel.fi'), + internalAddress: new Address('nginx-etusivu-prod.apps.platta.hel.fi'), + paths: $paths[Project::ETUSIVU], + environment: EnvironmentEnum::Prod, + services: [ + new Service(ServiceEnum::ElasticProxy, new Address('uutisapi.hel.fi')), + ], + ), + ], + ), + Project::KASVATUS_KOULUTUS => new Project( + Project::KASVATUS_KOULUTUS, + new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-kasvatus-koulutus'), + [ + new Environment( + address: new Address('helfi-kasko.docker.so'), + internalAddress: new Address('helfi-kasko', 'http', 8080), + paths: $paths[Project::KASVATUS_KOULUTUS], + environment: EnvironmentEnum::Local, + ), + new Environment( + address: new Address('www.test.hel.ninja'), + internalAddress: new Address('nginx-kasvatus-koulutus-test.apps.arodevtest.hel.fi'), + paths: $paths[Project::KASVATUS_KOULUTUS], + environment: EnvironmentEnum::Test, + ), + new Environment( + address: new Address('www.stage.hel.ninja'), + internalAddress: new Address('nginx-kasvatus-koulutus-staging.apps.platta.hel.fi'), + paths: $paths[Project::KASVATUS_KOULUTUS], + environment: EnvironmentEnum::Stage, + ), + new Environment( + address: new Address('www.hel.fi'), + internalAddress: new Address('nginx-kasvatus-koulutus-prod.apps.platta.hel.fi'), + paths: $paths[Project::KASVATUS_KOULUTUS], + environment: EnvironmentEnum::Prod, + ), + ], + ), + Project::KUVA => new Project( + Project::KUVA, + new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-kuva'), + [ + new Environment( + address: new Address('helfi-kuva.docker.so'), + internalAddress: new Address('helfi-kuva', 'http', 8080), + paths: $paths[Project::KUVA], + environment: EnvironmentEnum::Local, + ), + new Environment( + address: new Address('www.test.hel.ninja'), + internalAddress: new Address('nginx-kuva-test.apps.arodevtest.hel.fi'), + paths: $paths[Project::KUVA], + environment: EnvironmentEnum::Test, + ), + new Environment( + address: new Address('www.stage.hel.ninja'), + internalAddress: new Address('nginx-kuva-staging.apps.platta.hel.fi'), + paths: $paths[Project::KUVA], + environment: EnvironmentEnum::Stage, + ), + new Environment( + address: new Address('www.hel.fi'), + internalAddress: new Address('nginx-kuva-prod.apps.platta.hel.fi'), + paths: $paths[Project::KUVA], + environment: EnvironmentEnum::Prod, + ), + ], + ), + Project::LIIKENNE => new Project( + Project::LIIKENNE, + new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-kymp'), + [ + new Environment( + address: new Address('helfi-kymp.docker.so'), + internalAddress: new Address('helfi-kymp', 'http', 8080), + paths: $paths[Project::LIIKENNE], + environment: EnvironmentEnum::Local, + ), + new Environment( + address: new Address('www.test.hel.ninja'), + internalAddress: new Address('nginx-liikenne-test.apps.arodevtest.hel.fi'), + paths: $paths[Project::LIIKENNE], + environment: EnvironmentEnum::Test, + ), + new Environment( + address: new Address('www.stage.hel.ninja'), + internalAddress: new Address('nginx-liikenne-staging.apps.platta.hel.fi'), + paths: $paths[Project::LIIKENNE], + environment: EnvironmentEnum::Stage, + ), + new Environment( + address: new Address('www.hel.fi'), + internalAddress: new Address('nginx-liikenne-prod.apps.platta.hel.fi'), + paths: $paths[Project::LIIKENNE], + environment: EnvironmentEnum::Prod, + ), + ], + ), + Project::REKRY => new Project( + Project::REKRY, + new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-rekry'), + [ + new Environment( + address: new Address('helfi-rekry.docker.so'), + internalAddress: new Address('helfi-rekry', 'http', 8080), + paths: $paths[Project::REKRY], + environment: EnvironmentEnum::Local, + ), + new Environment( + address: new Address('www.test.hel.ninja'), + internalAddress: new Address('nginx-rekry-test.apps.arodevtest.hel.fi'), + paths: $paths[Project::REKRY], + environment: EnvironmentEnum::Test, + ), + new Environment( + address: new Address('www.stage.hel.ninja'), + internalAddress: new Address('nginx-rekry-staging.apps.platta.hel.fi'), + paths: $paths[Project::REKRY], + environment: EnvironmentEnum::Stage, + ), + new Environment( + address: new Address('www.hel.fi'), + internalAddress: new Address('nginx-rekry-prod.apps.platta.hel.fi'), + paths: $paths[Project::REKRY], + environment: EnvironmentEnum::Prod, + ), + ], + ), + Project::STRATEGIA => new Project( + Project::STRATEGIA, + new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-strategia'), + [ + new Environment( + address: new Address('helfi-strategia.docker.so'), + internalAddress: new Address('helfi-strategia', 'http', 8080), + paths: $paths[Project::STRATEGIA], + environment: EnvironmentEnum::Local, + ), + new Environment( + address: new Address('www.test.hel.ninja'), + internalAddress: new Address('nginx-strategia-talous-test.apps.arodevtest.hel.fi'), + paths: $paths[Project::STRATEGIA], + environment: EnvironmentEnum::Test, + ), + new Environment( + address: new Address('www.stage.hel.ninja'), + internalAddress: new Address('nginx-strategia-talous-staging.apps.platta.hel.fi'), + paths: $paths[Project::STRATEGIA], + environment: EnvironmentEnum::Stage, + ), + new Environment( + address: new Address('www.hel.fi'), + internalAddress: new Address('nginx-strategia-talous-prod.apps.platta.hel.fi'), + paths: $paths[Project::STRATEGIA], + environment: EnvironmentEnum::Prod, + ), + ], + ), + Project::TERVEYS => new Project( + Project::TERVEYS, + new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-sote'), + [ + new Environment( + address: new Address('helfi-sote.docker.so'), + internalAddress: new Address('helfi-sote', 'http', 8080), + paths: $paths[Project::TERVEYS], + environment: EnvironmentEnum::Local, + ), + new Environment( + address: new Address('www.test.hel.ninja'), + internalAddress: new Address('nginx-terveys-test.apps.arodevtest.hel.fi'), + paths: $paths[Project::TERVEYS], + environment: EnvironmentEnum::Test, + ), + new Environment( + address: new Address('www.stage.hel.ninja'), + internalAddress: new Address('nginx-terveys-staging.apps.platta.hel.fi'), + paths: $paths[Project::TERVEYS], + environment: EnvironmentEnum::Stage, + ), + new Environment( + address: new Address('www.hel.fi'), + internalAddress: new Address('nginx-terveys-prod.apps.platta.hel.fi'), + paths: $paths[Project::TERVEYS], + environment: EnvironmentEnum::Prod, + ), + ], + ), + Project::TYO_YRITTAMINEN => new Project( + Project::TYO_YRITTAMINEN, + new ProjectMetadata('https://github.com/city-of-helsinki/drupal-helfi-tyo-yrittaminen'), + [ + new Environment( + address: new Address('helfi-elo.docker.so'), + internalAddress: new Address('helfi-elo', 'http', 8080), + paths: $paths[Project::TYO_YRITTAMINEN], + environment: EnvironmentEnum::Local, + ), + new Environment( + address: new Address('www.test.hel.ninja'), + internalAddress: new Address('nginx-tyo-yrittaminen-test.apps.arodevtest.hel.fi'), + paths: $paths[Project::TYO_YRITTAMINEN], + environment: EnvironmentEnum::Test, + ), + new Environment( + address: new Address('www.stage.hel.ninja'), + internalAddress: new Address('nginx-tyo-yrittaminen-staging.apps.platta.hel.fi'), + paths: $paths[Project::TYO_YRITTAMINEN], + environment: EnvironmentEnum::Stage, + ), + new Environment( + address: new Address('www.hel.fi'), + internalAddress: new Address('nginx-tyo-yrittaminen-prod.apps.platta.hel.fi'), + paths: $paths[Project::TYO_YRITTAMINEN], + environment: EnvironmentEnum::Prod, + ), + ], + ), + ]; } /** From 32a915722e62f8d59dc8b67cabb41760d83ed1b7 Mon Sep 17 00:00:00 2001 From: tuutti Date: Tue, 30 Apr 2024 12:46:49 +0300 Subject: [PATCH 11/11] UHF-9833: Fixed path --- src/Environment/EnvironmentResolver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Environment/EnvironmentResolver.php b/src/Environment/EnvironmentResolver.php index 5f5d8221..f906c23b 100644 --- a/src/Environment/EnvironmentResolver.php +++ b/src/Environment/EnvironmentResolver.php @@ -64,7 +64,7 @@ private function populateEnvironments() : void { Project::ETUSIVU => [ 'fi' => '/fi', 'sv' => '/sv', - 'en' => '/en/housing', + 'en' => '/en', ], Project::KASVATUS_KOULUTUS => [ 'fi' => '/fi/kasvatus-ja-koulutus',