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 = <<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()))