From 3e7195e69a45f5e2821379360fcee425aaf9056a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=BDoljom?= Date: Thu, 5 May 2022 15:41:53 +0200 Subject: [PATCH 1/3] Change the testing constant Namespaced the test constant so that it doesn't clash with external testing. --- phpunit.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index e589e411d..ed4824318 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -10,7 +10,7 @@ - + From a952de2c9b79feb0f92ff0992061b2910facda80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=BDoljom?= Date: Thu, 5 May 2022 15:42:23 +0200 Subject: [PATCH 2/3] Update the constant in the code --- src/Blocks/AbstractBlocks.php | 2 +- src/Blocks/AbstractBlocksCli.php | 2 +- src/Blocks/BlockVariationCli.php | 2 +- src/Blocks/BlockWrapperCli.php | 2 +- src/Cli/AbstractCli.php | 12 ++++++------ src/Cli/CliInitAll.php | 2 +- src/Cli/CliInitProject.php | 2 +- src/Cli/CliInitTheme.php | 2 +- src/Helpers/Components.php | 4 ++-- src/Manifest/AbstractManifest.php | 4 ++-- src/Setup/UpdateCli.php | 2 +- 11 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Blocks/AbstractBlocks.php b/src/Blocks/AbstractBlocks.php index fd6a75dd2..5b4015d50 100644 --- a/src/Blocks/AbstractBlocks.php +++ b/src/Blocks/AbstractBlocks.php @@ -396,7 +396,7 @@ private function getBlocksFolderPath(): string { $blocksPath = \dirname(__DIR__, 5) . self::PATH_BLOCKS_PARENT; - if (\getenv('TEST')) { + if (\getenv('ES_TEST')) { $blocksPath = \dirname(__DIR__, 2) . self::PATH_BLOCKS_PARENT_TESTS; } diff --git a/src/Blocks/AbstractBlocksCli.php b/src/Blocks/AbstractBlocksCli.php index 45943077f..3737f85c8 100644 --- a/src/Blocks/AbstractBlocksCli.php +++ b/src/Blocks/AbstractBlocksCli.php @@ -56,7 +56,7 @@ protected function blocksMove(array $assocArgs, string $outputDir, bool $isCompo $path = "{$outputDir}/{$block}"; $sourcePath = "{$sourcePathFolder}{$block}"; - if (!\getenv('TEST')) { + if (!\getenv('ES_TEST')) { $destinationPath = $root . \DIRECTORY_SEPARATOR . $path; } else { $destinationPath = $this->getProjectRootPath(true) . '/cliOutput'; diff --git a/src/Blocks/BlockVariationCli.php b/src/Blocks/BlockVariationCli.php index 6ee0a7233..8b3ae7ade 100644 --- a/src/Blocks/BlockVariationCli.php +++ b/src/Blocks/BlockVariationCli.php @@ -86,7 +86,7 @@ public function __invoke(array $args, array $assocArgs) $sourcePathFolder = $rootNode . $ds . static::OUTPUT_DIR . $ds; $sourcePath = "{$sourcePathFolder}{$name}"; - if (!\getenv('TEST')) { + if (!\getenv('ES_TEST')) { $destinationPath = $root . $ds . $path; } else { $destinationPath = $this->getProjectRootPath(true) . '/cliOutput'; diff --git a/src/Blocks/BlockWrapperCli.php b/src/Blocks/BlockWrapperCli.php index 2b1255391..dd488fa97 100644 --- a/src/Blocks/BlockWrapperCli.php +++ b/src/Blocks/BlockWrapperCli.php @@ -65,7 +65,7 @@ public function __invoke(array $args, array $assocArgs) $sourcePathFolder = $rootNode . $ds . static::OUTPUT_DIR . $ds; $sourcePath = "{$sourcePathFolder}"; - if (!\getenv('TEST')) { + if (!\getenv('ES_TEST')) { $destinationPath = $root . $ds . $path; } else { $destinationPath = $this->getProjectRootPath(true) . '/cliOutput'; diff --git a/src/Cli/AbstractCli.php b/src/Cli/AbstractCli.php index 8ae16d816..8f72fcbf5 100644 --- a/src/Cli/AbstractCli.php +++ b/src/Cli/AbstractCli.php @@ -345,7 +345,7 @@ public function outputWrite(string $outputDir, string $outputFile, array $args = */ public function getOutputDir(string $path = ''): string { - if (\function_exists('\add_action') && !\getenv('TEST')) { + if (\function_exists('\add_action') && !\getenv('ES_TEST')) { $root = $this->getProjectRootPath(); } else { $root = $this->getProjectRootPath(true) . '/cliOutput'; @@ -396,7 +396,7 @@ public function renameNamespace(array $args = []): self $namespace = $this->getNamespace($args); $vendorPrefix = $this->getVendorPrefix($args); - if (\function_exists('\add_action') && !\getenv('TEST')) { + if (\function_exists('\add_action') && !\getenv('ES_TEST')) { $output = \str_replace( "namespace {$vendorPrefix}\EightshiftBoilerplate\\", "namespace {$namespace}\\", @@ -554,7 +554,7 @@ public function renameProjectName(array $args = []): self { $projectName = 'eightshift-boilerplate'; - if (\function_exists('\add_action') && !\getenv('TEST')) { + if (\function_exists('\add_action') && !\getenv('ES_TEST')) { $projectName = \basename(\dirname(__DIR__, 5)); } @@ -796,7 +796,7 @@ public function getProjectRootPath(bool $isDev = false): string { $output = \dirname(__DIR__, 5); - if ($isDev || \getenv('TEST') !== false) { + if ($isDev || \getenv('ES_TEST') !== false) { $output = \dirname(__DIR__, 2); } @@ -818,7 +818,7 @@ public function getProjectConfigRootPath(bool $isDev = false): string $output = \dirname(__DIR__, 2); } - if (\getenv('TEST')) { + if (\getenv('ES_TEST')) { $output = \dirname(__DIR__, 2); } @@ -846,7 +846,7 @@ public function getFrontendLibsPath(string $path = ''): string */ public function getLibsPath(string $path = ''): string { - if (\getenv('TEST')) { + if (\getenv('ES_TEST')) { return "{$this->getProjectRootPath()}/{$path}"; } diff --git a/src/Cli/CliInitAll.php b/src/Cli/CliInitAll.php index 958c22f10..7815e2c41 100644 --- a/src/Cli/CliInitAll.php +++ b/src/Cli/CliInitAll.php @@ -65,7 +65,7 @@ public function __invoke(array $args, array $assocArgs) // phpcs:ignore WP_CLI::log('--------------------------------------------------'); - if (!\getenv('TEST')) { + if (!\getenv('ES_TEST')) { WP_CLI::log((string)shell_exec('npm run start')); // phpcs:ignore } diff --git a/src/Cli/CliInitProject.php b/src/Cli/CliInitProject.php index 99469db15..35e5cec7f 100644 --- a/src/Cli/CliInitProject.php +++ b/src/Cli/CliInitProject.php @@ -102,7 +102,7 @@ public function __invoke(array $args, array $assocArgs) WP_CLI::log('--------------------------------------------------'); - if (!\getenv('TEST')) { + if (!\getenv('ES_TEST')) { WP_CLI::log((string)shell_exec('npm run start')); // phpcs:ignore } diff --git a/src/Cli/CliInitTheme.php b/src/Cli/CliInitTheme.php index f65e22d62..eebfdffde 100644 --- a/src/Cli/CliInitTheme.php +++ b/src/Cli/CliInitTheme.php @@ -95,7 +95,7 @@ public function __invoke(array $args, array $assocArgs) WP_CLI::log('--------------------------------------------------'); - if (!\getenv('TEST')) { + if (!\getenv('ES_TEST')) { WP_CLI::log((string)shell_exec('npm run start')); // phpcs:ignore } diff --git a/src/Helpers/Components.php b/src/Helpers/Components.php index 3f93cc089..942a16b0c 100644 --- a/src/Helpers/Components.php +++ b/src/Helpers/Components.php @@ -82,7 +82,7 @@ public static function render(string $component, array $attributes = [], string if (empty($parentPath)) { $parentPath = \dirname(__DIR__, 5); - if (\getenv('TEST')) { + if (\getenv('ES_TEST')) { $parentPath = \dirname(__DIR__, 2); } } @@ -107,7 +107,7 @@ public static function render(string $component, array $attributes = [], string } else { $blocksPath = AbstractBlocks::PATH_BLOCKS_PARENT; - if (\getenv('TEST')) { + if (\getenv('ES_TEST')) { $blocksPath = AbstractBlocks::PATH_BLOCKS_PARENT_TESTS; } diff --git a/src/Manifest/AbstractManifest.php b/src/Manifest/AbstractManifest.php index fe8745bcc..d05f8d350 100644 --- a/src/Manifest/AbstractManifest.php +++ b/src/Manifest/AbstractManifest.php @@ -37,7 +37,7 @@ abstract class AbstractManifest implements ServiceInterface, ManifestInterface */ public function setAssetsManifestRaw(): void { - if (\defined('WP_CLI') && !\getenv('TEST')) { + if (\defined('WP_CLI') && !\getenv('ES_TEST')) { return; } @@ -73,7 +73,7 @@ function ($manifestItem) { */ public function getAssetsManifestItem(string $key): string { - if (\defined('WP_CLI') && !\getenv('TEST')) { + if (\defined('WP_CLI') && !\getenv('ES_TEST')) { return ''; } diff --git a/src/Setup/UpdateCli.php b/src/Setup/UpdateCli.php index a1c4df365..e723da928 100644 --- a/src/Setup/UpdateCli.php +++ b/src/Setup/UpdateCli.php @@ -82,7 +82,7 @@ public function __invoke(array $args, array $assocArgs) $setupFilename = 'setup.json'; - if (\getenv('TEST') !== false) { + if (\getenv('ES_TEST') !== false) { $setupFilename = $this->getProjectConfigRootPath() . '/cliOutput/setup.json'; } From 9c9593a91644ea99581328e400cc2e84d33ccd61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=BDoljom?= Date: Thu, 5 May 2022 15:44:37 +0200 Subject: [PATCH 3/3] Fix the test Constant name --- tests/Cli/AbstractCliTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Cli/AbstractCliTest.php b/tests/Cli/AbstractCliTest.php index 02bb10de2..002787e70 100644 --- a/tests/Cli/AbstractCliTest.php +++ b/tests/Cli/AbstractCliTest.php @@ -193,13 +193,13 @@ public function getDoc(): array $abstractMock = new AbstractTest('test'); // The test one is covered. Let's see if we can get the one that will be used - putenv('TEST'); + putenv('ES_TEST'); $output = $abstractMock->getLibsPath('test'); $this->assertIsString($output); $this->assertStringContainsString('/vendor/infinum/eightshift-libs/test', $output); - putenv('TEST=1'); + putenv('ES_TEST=1'); }); @@ -213,7 +213,7 @@ public function getDoc(): array test('Project config root path works if dev is false', function() { - putenv('TEST'); + putenv('ES_TEST'); $abstractMock = new AbstractTest('test'); $outputProd = $abstractMock->getProjectConfigRootPath(false); @@ -221,7 +221,7 @@ public function getDoc(): array $this->assertIsString($outputProd); $this->assertSame('/', $outputProd); - putenv('TEST=1'); + putenv('ES_TEST=1'); });