From aaf601137ac38fe366f8b1c391eaf960c10fabe5 Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Wed, 27 Mar 2024 19:19:09 +0100 Subject: [PATCH 1/2] refactor(setup) set dump path and tester namespace from CC version --- CHANGELOG.md | 4 ++++ src/Project/PluginProject.php | 10 +++++++--- src/Project/SiteProject.php | 5 ++++- src/Project/ThemeProject.php | 9 +++++++-- src/Template/Wpbrowser.php | 5 ++++- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 055558d2f..dea3bf9be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [unreleased] Unreleased +### Changed + +- Update init template to scaffold dump file path and example tests correctly (thanks @tarecord). + ## [4.1.4] 2024-03-19; ### Added diff --git a/src/Project/PluginProject.php b/src/Project/PluginProject.php index 8d1e47cc7..d3b43b37f 100644 --- a/src/Project/PluginProject.php +++ b/src/Project/PluginProject.php @@ -2,12 +2,12 @@ namespace lucatume\WPBrowser\Project; +use Codeception\Codecept; use lucatume\WPBrowser\Exceptions\InvalidArgumentException; use lucatume\WPBrowser\Exceptions\RuntimeException; use lucatume\WPBrowser\Process\Loop; use lucatume\WPBrowser\Process\ProcessException; use lucatume\WPBrowser\Process\WorkerException; -use lucatume\WPBrowser\TestCase\WPTestCase; use lucatume\WPBrowser\Utils\Filesystem as FS; use lucatume\WPBrowser\Utils\Strings; use lucatume\WPBrowser\WordPress\CodeExecution\CodeExecutionFactory; @@ -114,9 +114,11 @@ public function activate(string $wpRootDir, int $serverLocalhostPort): bool $message = $activationResult->getMessage(); $this->sayWarning('Could not activate plugin: ' . $message); $this->say($activationResult->getFile() . ":" . $activationResult->getLine()); + // @phpstan-ignore-next-line + $dumpPath = Codecept::VERSION >= 5 ? 'tests/Support/Data/dump.sql' : 'tests/_data/dump.sql'; $this->say('This might happen because the plugin has unmet dependencies; wp-browser configuration ' . 'will continue, but you will need to manually activate the plugin and update the dump in ' . - 'tests/Support/Data/dump.sql.'); + $dumpPath); return false; } @@ -127,13 +129,15 @@ public function activate(string $wpRootDir, int $serverLocalhostPort): bool protected function scaffoldEndToEndActivationCest(): void { + // @phpstan-ignore-next-line + $testerTrait = Codecept::VERSION >= 5 ? 'Tests\Support\EndToEndTester' : 'EndToEndTester'; $cestCode = Strings::renderString( <<< EOT = 5 ? 'Tests\Support\EndToEndTester' : 'EndToEndTester'; $cestCode = <<< EOT toSwitchTheme($this->basename, false); $activationResult = Loop::executeClosure($switchTheme)->getReturnValue(); if ($activationResult instanceof Throwable) { + // @phpstan-ignore-next-line + $dumpPath = Codecept::VERSION >= 5 ? 'tests/Support/Data/dump.sql' : 'tests/_data/dump.sql'; $message = $activationResult->getMessage(); $this->sayWarning('Could not activate theme: ' . $message); $this->say('This might happen because the theme has unmet dependencies; wp-browser configuration ' . 'will continue, but you will need to manually activate the theme and update the dump in ' . - 'tests/Support/Data/dump.sql.'); + $dumpPath); return false; } @@ -118,13 +121,15 @@ public function activate(string $wpRootDir, int $serverLocalhostPort): bool protected function scaffoldEndToEndActivationCest(): void { + // @phpstan-ignore-next-line + $testerTrait = Codecept::VERSION >= 5 ? 'Tests\Support\EndToEndTester' : 'EndToEndTester'; $cestCode = Strings::renderString( <<< EOT = 5 ? 'tests/Support/Data/dump.sql' : 'tests/_data/dump.sql'; $suiteConfig = << Date: Wed, 27 Mar 2024 19:54:03 +0100 Subject: [PATCH 2/2] tests(unit) update tests --- tests/unit/lucatume/WPBrowser/Project/PluginProjectTest.php | 2 +- tests/unit/lucatume/WPBrowser/Project/ThemeProjectTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/lucatume/WPBrowser/Project/PluginProjectTest.php b/tests/unit/lucatume/WPBrowser/Project/PluginProjectTest.php index 5bc13d065..599daf846 100644 --- a/tests/unit/lucatume/WPBrowser/Project/PluginProjectTest.php +++ b/tests/unit/lucatume/WPBrowser/Project/PluginProjectTest.php @@ -121,7 +121,7 @@ public function should_provide_information_about_the_failure_to_activate_due_to_ $expected = "Could not activate plugin: Something went wrong. \n" . "{{wp_root_dir}}/wp-content/plugins/acme-plugin/plugin.php:3\n" . "This might happen because the plugin has unmet dependencies; wp-browser configuration will continue, " . - "but you will need to manually activate the plugin and update the dump in tests/Support/Data/dump.sql."; + "but you will need to manually activate the plugin and update the dump in tests/Support/Data/dump.sql"; $this->assertEquals( $expected, trim(str_replace($wpRootDir, '{{wp_root_dir}}', $output->fetch())) diff --git a/tests/unit/lucatume/WPBrowser/Project/ThemeProjectTest.php b/tests/unit/lucatume/WPBrowser/Project/ThemeProjectTest.php index d7375225d..2e441b450 100644 --- a/tests/unit/lucatume/WPBrowser/Project/ThemeProjectTest.php +++ b/tests/unit/lucatume/WPBrowser/Project/ThemeProjectTest.php @@ -165,7 +165,7 @@ public function should_provide_information_about_the_failure_to_activate_due_to_ $this->assertFalse($themeProject->activate($wpRootDir, 1234)); $expected = "Could not activate theme: Error: Current PHP version does not meet minimum requirements for Acme Theme. \n" . "This might happen because the theme has unmet dependencies; wp-browser configuration will continue, " . - "but you will need to manually activate the theme and update the dump in tests/Support/Data/dump.sql."; + "but you will need to manually activate the theme and update the dump in tests/Support/Data/dump.sql"; $this->assertEquals( $expected, trim(str_replace($wpRootDir, '{{wp_root_dir}}', $output->fetch()))