Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrap #710 #712

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions src/Project/PluginProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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
<?php

namespace Tests\EndToEnd;

use Tests\Support\EndToEndTester;
use $testerTrait;

class ActivationCest
{
Expand Down
5 changes: 4 additions & 1 deletion src/Project/SiteProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace lucatume\WPBrowser\Project;

use Codeception\Codecept;
use Codeception\InitTemplate;
use lucatume\WPBrowser\Command\ChromedriverUpdate;
use lucatume\WPBrowser\Command\DevInfo;
Expand Down Expand Up @@ -186,12 +187,14 @@ private function getName(): string

private function scaffoldEndToEndActivationCest(): void
{
// @phpstan-ignore-next-line
$testerTrait = Codecept::VERSION >= 5 ? 'Tests\Support\EndToEndTester' : 'EndToEndTester';
$cestCode = <<< EOT
<?php

namespace Tests\EndToEnd;

use Tests\Support\EndToEndTester;
use $testerTrait;

class ActivationCest
{
Expand Down
9 changes: 7 additions & 2 deletions src/Project/ThemeProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace lucatume\WPBrowser\Project;

use Codeception\Codecept;
use lucatume\WPBrowser\Exceptions\InvalidArgumentException;
use lucatume\WPBrowser\Exceptions\RuntimeException;
use lucatume\WPBrowser\Process\Loop;
Expand Down Expand Up @@ -103,11 +104,13 @@ public function activate(string $wpRootDir, int $serverLocalhostPort): bool
$switchTheme = $codeExec->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;
}

Expand All @@ -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
<?php

namespace Tests\EndToEnd;

use Tests\Support\EndToEndTester;
use $testerTrait;

class ActivationCest
{
Expand Down
5 changes: 4 additions & 1 deletion src/Template/Wpbrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace lucatume\WPBrowser\Template;

use Codeception\Codecept;
use Codeception\Extension\RunFailed;
use Codeception\Template\Bootstrap;
use lucatume\WPBrowser\Command\DbExport;
Expand Down Expand Up @@ -226,6 +227,8 @@ private function createEnvFile(): void

private function createEndToEndSuite(ProjectInterface $project): void
{
// @phpstan-ignore-next-line
$dumpFilePath = Codecept::VERSION >= 5 ? 'tests/Support/Data/dump.sql' : 'tests/_data/dump.sql';
$suiteConfig = <<<EOF
# Integration suite configuration
#
Expand Down Expand Up @@ -261,7 +264,7 @@ private function createEndToEndSuite(ProjectInterface $project): void
- "--no-sandbox"
lucatume\WPBrowser\Module\WPDb:
dbUrl: '%WORDPRESS_DB_URL%'
dump: 'tests/Support/Data/dump.sql'
dump: '{$dumpFilePath}'
populate: true
cleanup: true
reconnect: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lucatume/WPBrowser/Project/ThemeProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
Loading