From d4c894f5c2ce52e9e822338e14bb042d0accf842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Sun, 5 Dec 2021 20:40:14 +0100 Subject: [PATCH 1/2] Use namespaced constants --- inc/helpers.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/inc/helpers.php b/inc/helpers.php index ccafc49..57bf400 100644 --- a/inc/helpers.php +++ b/inc/helpers.php @@ -2,15 +2,15 @@ namespace WPTS; -\define('WPTS_VERSION', '1.0.0'); +const VERSION = '1.0.0'; -\define('WPTS_CMD_INTRO', [ - 'Touchstone v' . \WPTS_VERSION, +const CMD_INTRO = [ + 'Touchstone v' . VERSION, '', -]); +]; -\define('WPTS_CMD_ICONS', [ +const CMD_ICONS = [ 'check' => '✓', 'cross' => '𐄂', 'loading' => '==>', -]); +]; From 2786c5aff1b9737bb552f05b69947c3c87d50444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Mon, 6 Dec 2021 13:16:28 +0000 Subject: [PATCH 2/2] Use new namespaced constants --- src/Console/Commands/Setup.php | 20 ++++++++++---------- src/Console/Commands/Test.php | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Console/Commands/Setup.php b/src/Console/Commands/Setup.php index 1dba99e..c0e539d 100644 --- a/src/Console/Commands/Setup.php +++ b/src/Console/Commands/Setup.php @@ -78,7 +78,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $output->writeln(\WPTS_CMD_INTRO); + $output->writeln(\WPTS\CMD_INTRO); $this->db_creds = [ 'host' => $input->getOption('db-host') ?: '', @@ -110,14 +110,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln([ '', - \WPTS_CMD_ICONS['check'] . " Setup complete", + \WPTS\CMD_ICONS['check'] . " Setup complete", ]); return Command::SUCCESS; } catch (\Throwable $e) { $output->writeln([ '', - \WPTS_CMD_ICONS['cross'] . " {$e->getMessage()}", + \WPTS\CMD_ICONS['cross'] . " {$e->getMessage()}", ]); return Command::FAILURE; @@ -155,7 +155,7 @@ protected function validateDatabaseCredentials(): void */ protected function connectToHost(InputInterface $input, OutputInterface &$output): void { - $output->writeln(\WPTS_CMD_ICONS['loading'] . ' Testing connection...'); + $output->writeln(\WPTS\CMD_ICONS['loading'] . ' Testing connection...'); $db_string = "mysql:host={$this->db_creds['host']};charset=UTF8"; @@ -197,7 +197,7 @@ protected function createDatabase(InputInterface $input, OutputInterface &$outpu return; } - $output->writeln(\WPTS_CMD_ICONS['loading'] . ' Creating database...'); + $output->writeln(\WPTS\CMD_ICONS['loading'] . ' Creating database...'); try { $this->db_connection->query("CREATE DATABASE IF NOT EXISTS {$this->db_creds['name']}"); @@ -233,7 +233,7 @@ protected function getLatestWordPressDownloadUrl() protected function downloadWordPressFiles(InputInterface $input, OutputInterface &$output): void { //---- Download zip file - $output->writeln(\WPTS_CMD_ICONS['loading'] . ' Downloading WordPress files...'); + $output->writeln(\WPTS\CMD_ICONS['loading'] . ' Downloading WordPress files...'); // Remove old files try { @@ -252,7 +252,7 @@ protected function downloadWordPressFiles(InputInterface $input, OutputInterface \file_put_contents($this->tmp_dir . '/' . $this->wpZipFilename, $files_request->getBody()->getContents()); //---- Unzip files - $output->writeln(\WPTS_CMD_ICONS['loading'] . ' Installing WordPress files...'); + $output->writeln(\WPTS\CMD_ICONS['loading'] . ' Installing WordPress files...'); if (!$this->filesystem->fileExists($this->wpZipFilename)) { throw new \InvalidArgumentException('No WordPress files found.'); @@ -284,7 +284,7 @@ protected function downloadWordPressFiles(InputInterface $input, OutputInterface protected function downloadWordPressTestFiles(InputInterface $input, OutputInterface &$output): void { //---- Download zip file - $output->writeln(\WPTS_CMD_ICONS['loading'] . ' Downloading WordPress test files...'); + $output->writeln(\WPTS\CMD_ICONS['loading'] . ' Downloading WordPress test files...'); // Remove old files try { @@ -305,7 +305,7 @@ protected function downloadWordPressTestFiles(InputInterface $input, OutputInter \file_put_contents($this->tmp_dir . '/' . $this->wpTestsZipFilename, $files_request->getBody()->getContents()); //---- Unzip files - $output->writeln(\WPTS_CMD_ICONS['loading'] . ' Installing WordPress test files...'); + $output->writeln(\WPTS\CMD_ICONS['loading'] . ' Installing WordPress test files...'); if (!$this->filesystem->fileExists($this->wpTestsZipFilename)) { throw new \InvalidArgumentException('No WordPress test files found.'); @@ -358,7 +358,7 @@ protected function downloadWordPressTestFiles(InputInterface $input, OutputInter */ protected function configureWordPressTestFiles(InputInterface $input, OutputInterface &$output): void { - $output->writeln(\WPTS_CMD_ICONS['loading'] . ' Configuring WordPress test files...'); + $output->writeln(\WPTS\CMD_ICONS['loading'] . ' Configuring WordPress test files...'); $transformer = new WPConfigTransformer( $this->tmp_dir . '/' . $this->wpTestsDirectoryName . '/' . 'wp-tests-config.php' diff --git a/src/Console/Commands/Test.php b/src/Console/Commands/Test.php index 1479672..8fdfe64 100644 --- a/src/Console/Commands/Test.php +++ b/src/Console/Commands/Test.php @@ -46,7 +46,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $output->writeln(\WPTS_CMD_INTRO); + $output->writeln(\WPTS\CMD_INTRO); if ($this->env == 'prod') { $this->phpunitExecutablePath = __DIR__ . '/../../../../../../vendor/bin/phpunit'; @@ -85,7 +85,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $output->writeln([ - \WPTS_CMD_ICONS['loading'] . " Running {$input->getOption('type')} tests...", + \WPTS\CMD_ICONS['loading'] . " Running {$input->getOption('type')} tests...", '', ]); @@ -103,14 +103,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln([ '', - \WPTS_CMD_ICONS['check'] . " Tests run successfully", + \WPTS\CMD_ICONS['check'] . " Tests run successfully", ]); return Command::SUCCESS; } catch (\Throwable $e) { $output->writeln([ '', - \WPTS_CMD_ICONS['cross'] . " {$e->getMessage()}", + \WPTS\CMD_ICONS['cross'] . " {$e->getMessage()}", ]); return Command::FAILURE;