From c0200317ddb9e55722377c1802a3e13e6a2b2b83 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 22 Oct 2024 15:31:47 +0200 Subject: [PATCH] Load dev env vars via roadrunner instead of docker compose --- data/infra/roadrunner.Dockerfile | 2 +- docker-compose.yml | 3 -- .../MultiSegmentSlugProcessorTest.php | 40 ++++++++++--------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/data/infra/roadrunner.Dockerfile b/data/infra/roadrunner.Dockerfile index 2cb660d2..8c412350 100644 --- a/data/infra/roadrunner.Dockerfile +++ b/data/infra/roadrunner.Dockerfile @@ -74,4 +74,4 @@ CMD \ # Download roadrunner binary if [[ ! -f "./bin/rr" ]]; then ./vendor/bin/rr get --no-interaction --no-config --location bin/ && chmod +x bin/rr ; fi && \ # Run with `exec` so that signals are properly handled - exec ./bin/rr serve -c config/roadrunner/.rr.dev.yml + exec ./bin/rr serve --dotenv /home/shlink/shlink-dev.env -c config/roadrunner/.rr.dev.yml diff --git a/docker-compose.yml b/docker-compose.yml index b9fbd210..2052b1cf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -63,9 +63,6 @@ services: - shlink_matomo environment: DEFAULT_DOMAIN: localhost:8800 - env_file: - - path: shlink-dev.env - required: false extra_hosts: - 'host.docker.internal:host-gateway' diff --git a/module/Core/test/Config/PostProcessor/MultiSegmentSlugProcessorTest.php b/module/Core/test/Config/PostProcessor/MultiSegmentSlugProcessorTest.php index d811a2e2..487228ec 100644 --- a/module/Core/test/Config/PostProcessor/MultiSegmentSlugProcessorTest.php +++ b/module/Core/test/Config/PostProcessor/MultiSegmentSlugProcessorTest.php @@ -7,8 +7,11 @@ namespace ShlinkioTest\Shlink\Core\Config\PostProcessor; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; +use Shlinkio\Shlink\Core\Config\EnvVars; use Shlinkio\Shlink\Core\Config\PostProcessor\MultiSegmentSlugProcessor; +use function putenv; + class MultiSegmentSlugProcessorTest extends TestCase { private MultiSegmentSlugProcessor $processor; @@ -18,36 +21,35 @@ class MultiSegmentSlugProcessorTest extends TestCase $this->processor = new MultiSegmentSlugProcessor(); } - #[Test, DataProvider('provideConfigs')] - public function parsesRoutesAsExpected(array $config, array $expectedRoutes): void + protected function tearDown(): void { - self::assertEquals($expectedRoutes, ($this->processor)($config)['routes'] ?? []); + putenv(EnvVars::MULTI_SEGMENT_SLUGS_ENABLED->value); + } + + #[Test, DataProvider('provideConfigs')] + public function parsesRoutesAsExpected(bool $multiSegmentEnabled, array $routes, array $expectedRoutes): void + { + putenv(EnvVars::MULTI_SEGMENT_SLUGS_ENABLED->value . '=' . ($multiSegmentEnabled ? 'true' : 'false')); + self::assertEquals($expectedRoutes, ($this->processor)(['routes' => $routes])['routes'] ?? []); } public static function provideConfigs(): iterable { - yield [[], []]; - yield [['url_shortener' => []], []]; - yield [['url_shortener' => ['multi_segment_slugs_enabled' => false]], []]; yield [ - [ - 'url_shortener' => ['multi_segment_slugs_enabled' => false], - 'routes' => $routes = [ - ['path' => '/foo'], - ['path' => '/bar/{shortCode}'], - ['path' => '/baz/{shortCode}/foo'], - ], + false, + $routes = [ + ['path' => '/foo'], + ['path' => '/bar/{shortCode}'], + ['path' => '/baz/{shortCode}/foo'], ], $routes, ]; yield [ + true, [ - 'url_shortener' => ['multi_segment_slugs_enabled' => true], - 'routes' => [ - ['path' => '/foo'], - ['path' => '/bar/{shortCode}'], - ['path' => '/baz/{shortCode}/foo'], - ], + ['path' => '/foo'], + ['path' => '/bar/{shortCode}'], + ['path' => '/baz/{shortCode}/foo'], ], [ ['path' => '/foo'],