From 2bb23f2f1e4ce55a8d268bfec9b259d3ea91c5b7 Mon Sep 17 00:00:00 2001 From: Kathryn Anne S Tan Date: Fri, 5 Apr 2024 01:32:40 +0300 Subject: [PATCH] Install dotenv, include logic for overrding reference file with generated content, override Dockerfile references for previous tests --- .env.example | 1 + .gitignore | 1 + tests/Feature/GenerateCommandTest.php | 40 +++++++------------ tests/Feature/Supported/10_base/Dockerfile | 1 + .../Supported/10_octane_frankenphp/Dockerfile | 1 + .../Feature/Supported/10_octane_rr/Dockerfile | 1 + .../Supported/10_octane_swoole/Dockerfile | 1 + .../Supported/11_octane_frankenphp/Dockerfile | 1 + .../Feature/Supported/11_octane_rr/Dockerfile | 1 + .../Supported/11_octane_swoole/Dockerfile | 1 + 10 files changed, 24 insertions(+), 25 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..ba62e95 --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +OVERRIDE_TEST_REFERENCES= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 20d9dbd..353fb79 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /.vscode /.vagrant .phpunit.result.cache +.env diff --git a/tests/Feature/GenerateCommandTest.php b/tests/Feature/GenerateCommandTest.php index 572076f..ee3fe83 100644 --- a/tests/Feature/GenerateCommandTest.php +++ b/tests/Feature/GenerateCommandTest.php @@ -1,27 +1,10 @@ assertEquals( $il_expected, $il_generated, $msg); - }catch (ExpectationFailedException $f) { - - // However, if variants without newlines failed to match! - // That's a true failed match! - // To get a better diff error message, use original strings( with their newlines intact ) in comparison - $ins->assertEquals( $expected, $generated, $msg); - } -} - function getTestOptions( string $directory ): string { $composerContent = (new \App\Services\File())->composerJsonContent( $directory ); @@ -57,26 +40,33 @@ function getTestOptions( string $directory ): string $options = getTestOptions( $dir ); // Generate Dockerfile using options - // First assert: command successfully runs and exits + // FIRST assert: command successfully runs and exits $this->artisan('generate '.$options)->assertExitCode(0); - // Compare expected files from test directory with generated files + // Compare reference files from test directory with generated files $referenceFiles = \File::files( $dir ); foreach( $referenceFiles as $reference ){ $failedForMsg = 'Failed for: "'.$reference->getPathName().'"'; + // Skip if a setup file if( in_array( $reference->getFileName(), ignoreFiles()) ) continue; - // Second assert: a new file with the reference file's name was created-it should exist! + // SECOND assert: a new file with the reference file's name was created; it should exist! $this->assertFileExists( $reference->getFileName(), $failedForMsg ); - // Get contents i.e. /10_base/Dockerfile vs Dockerfile - $expected = file_get_contents( $reference->getPathName() ); // expected content from reference file - $generated = file_get_contents( $reference->getFileName() ); // new file content + // Contents of generated file + $generated = file_get_contents( $reference->getFileName() ); + + // Override the reference file with generated file content if needed; PLEASE double check diff and re-test this new ref manually! + if( env('OVERRIDE_TEST_REFERENCES')===true ) + file_put_contents( $reference->getPathName(), $generated ); + + // Contents of reference file + $expected = file_get_contents( $reference->getPathName() ); - // Third assert: contents are the same + // THIRD assert: contents are the same // TODO: ignore different ARG VALUES - assertEqualsIgnoreNewLine( $this, $expected, $generated, $failedForMsg); + $this->assertEquals( $expected, $generated, $failedForMsg); // Clean UP: Delete generated file, no longer needed unlink( $reference->getFileName() ); diff --git a/tests/Feature/Supported/10_base/Dockerfile b/tests/Feature/Supported/10_base/Dockerfile index 622f289..27f0f71 100644 --- a/tests/Feature/Supported/10_base/Dockerfile +++ b/tests/Feature/Supported/10_base/Dockerfile @@ -22,6 +22,7 @@ RUN composer install --optimize-autoloader --no-dev \ if [ -d .fly ]; then cp .fly/entrypoint.sh /entrypoint; chmod +x /entrypoint; fi; + # Multi-stage build: Build static assets # This allows us to not include Node within the final container FROM node:${NODE_VERSION} as node_modules_go_brrr diff --git a/tests/Feature/Supported/10_octane_frankenphp/Dockerfile b/tests/Feature/Supported/10_octane_frankenphp/Dockerfile index bc95692..1487805 100644 --- a/tests/Feature/Supported/10_octane_frankenphp/Dockerfile +++ b/tests/Feature/Supported/10_octane_frankenphp/Dockerfile @@ -28,6 +28,7 @@ RUN rm -rf /etc/supervisor/conf.d/fpm.conf; \ rm /etc/nginx/sites-enabled/default; \ ln -sf /etc/nginx/sites-available/default-octane /etc/nginx/sites-enabled/default; + # Multi-stage build: Build static assets # This allows us to not include Node within the final container FROM node:${NODE_VERSION} as node_modules_go_brrr diff --git a/tests/Feature/Supported/10_octane_rr/Dockerfile b/tests/Feature/Supported/10_octane_rr/Dockerfile index 84fc57e..81bbe22 100644 --- a/tests/Feature/Supported/10_octane_rr/Dockerfile +++ b/tests/Feature/Supported/10_octane_rr/Dockerfile @@ -28,6 +28,7 @@ RUN rm -rf /etc/supervisor/conf.d/fpm.conf; \ rm /etc/nginx/sites-enabled/default; \ ln -sf /etc/nginx/sites-available/default-octane /etc/nginx/sites-enabled/default; + # Multi-stage build: Build static assets # This allows us to not include Node within the final container FROM node:${NODE_VERSION} as node_modules_go_brrr diff --git a/tests/Feature/Supported/10_octane_swoole/Dockerfile b/tests/Feature/Supported/10_octane_swoole/Dockerfile index 9a6c73b..ec8693f 100644 --- a/tests/Feature/Supported/10_octane_swoole/Dockerfile +++ b/tests/Feature/Supported/10_octane_swoole/Dockerfile @@ -26,6 +26,7 @@ RUN rm -rf /etc/supervisor/conf.d/fpm.conf; \ rm /etc/nginx/sites-enabled/default; \ ln -sf /etc/nginx/sites-available/default-octane /etc/nginx/sites-enabled/default; + # Multi-stage build: Build static assets # This allows us to not include Node within the final container FROM node:${NODE_VERSION} as node_modules_go_brrr diff --git a/tests/Feature/Supported/11_octane_frankenphp/Dockerfile b/tests/Feature/Supported/11_octane_frankenphp/Dockerfile index 80f2307..95f4ecf 100644 --- a/tests/Feature/Supported/11_octane_frankenphp/Dockerfile +++ b/tests/Feature/Supported/11_octane_frankenphp/Dockerfile @@ -30,6 +30,7 @@ RUN rm -rf /etc/supervisor/conf.d/fpm.conf; \ rm /etc/nginx/sites-enabled/default; \ ln -sf /etc/nginx/sites-available/default-octane /etc/nginx/sites-enabled/default; + # Multi-stage build: Build static assets # This allows us to not include Node within the final container FROM node:${NODE_VERSION} as node_modules_go_brrr diff --git a/tests/Feature/Supported/11_octane_rr/Dockerfile b/tests/Feature/Supported/11_octane_rr/Dockerfile index d273b7a..69c7a90 100644 --- a/tests/Feature/Supported/11_octane_rr/Dockerfile +++ b/tests/Feature/Supported/11_octane_rr/Dockerfile @@ -30,6 +30,7 @@ RUN rm -rf /etc/supervisor/conf.d/fpm.conf; \ rm /etc/nginx/sites-enabled/default; \ ln -sf /etc/nginx/sites-available/default-octane /etc/nginx/sites-enabled/default; + # Multi-stage build: Build static assets # This allows us to not include Node within the final container FROM node:${NODE_VERSION} as node_modules_go_brrr diff --git a/tests/Feature/Supported/11_octane_swoole/Dockerfile b/tests/Feature/Supported/11_octane_swoole/Dockerfile index ef0d507..44eb6e9 100644 --- a/tests/Feature/Supported/11_octane_swoole/Dockerfile +++ b/tests/Feature/Supported/11_octane_swoole/Dockerfile @@ -28,6 +28,7 @@ RUN rm -rf /etc/supervisor/conf.d/fpm.conf; \ rm /etc/nginx/sites-enabled/default; \ ln -sf /etc/nginx/sites-available/default-octane /etc/nginx/sites-enabled/default; + # Multi-stage build: Build static assets # This allows us to not include Node within the final container FROM node:${NODE_VERSION} as node_modules_go_brrr