Skip to content

Commit

Permalink
fix(setup) set dump path and tester namespace from CC version
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatume committed Mar 27, 2024
1 parent dccc275 commit c63a918
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 61 deletions.
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).

## [3.5.4] 2024-03-19;

### Fixed
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 @@ -128,9 +128,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 @@ -141,13 +143,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 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 @@ -197,12 +198,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 @@ -114,11 +115,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 @@ -129,13 +132,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 @@ -220,6 +221,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 @@ -255,7 +258,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 @@ -33,7 +33,7 @@ modules:
- "--no-sandbox"
lucatume\WPBrowser\Module\WPDb:
dbUrl: '%WORDPRESS_DB_URL%'
dump: 'tests/Support/Data/dump.sql'
dump: 'tests/_data/dump.sql'
populate: true
cleanup: true
reconnect: false
Expand Down Expand Up @@ -242,7 +242,7 @@ modules:

namespace Tests\EndToEnd;

use Tests\Support\EndToEndTester;
use EndToEndTester;

class ActivationCest
{
Expand Down Expand Up @@ -275,19 +275,19 @@ TEST_TABLE_PREFIX=test_
WORDPRESS_TABLE_PREFIX=wp_

# The URL and domain of the WordPress site used in end-to-end tests.
WORDPRESS_URL=http://localhost:41251
WORDPRESS_DOMAIN=localhost:41251
WORDPRESS_URL=http://localhost:35409
WORDPRESS_DOMAIN=localhost:35409

# The username and password of the administrator user of the WordPress site used in end-to-end tests.
WORDPRESS_ADMIN_USER=admin
WORDPRESS_ADMIN_PASSWORD=password

# The host and port of the ChromeDriver server that will be used in end-to-end tests.
CHROMEDRIVER_HOST=localhost
CHROMEDRIVER_PORT=29174
CHROMEDRIVER_PORT=20606

# The port on which the PHP built-in server will serve the WordPress installation.
BUILTIN_SERVER_PORT=41251
BUILTIN_SERVER_PORT=35409

<<< /tests/.env <<<

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ modules:
- "--no-sandbox"
lucatume\WPBrowser\Module\WPDb:
dbUrl: '%WORDPRESS_DB_URL%'
dump: 'tests/Support/Data/dump.sql'
dump: 'tests/_data/dump.sql'
populate: true
cleanup: true
reconnect: false
Expand Down Expand Up @@ -247,7 +247,7 @@ modules:

namespace Tests\EndToEnd;

use Tests\Support\EndToEndTester;
use EndToEndTester;

class ActivationCest
{
Expand Down Expand Up @@ -285,19 +285,19 @@ TEST_TABLE_PREFIX=test_
WORDPRESS_TABLE_PREFIX=wp_

# The URL and domain of the WordPress site used in end-to-end tests.
WORDPRESS_URL=http://localhost:9750
WORDPRESS_DOMAIN=localhost:9750
WORDPRESS_URL=http://localhost:37987
WORDPRESS_DOMAIN=localhost:37987

# The username and password of the administrator user of the WordPress site used in end-to-end tests.
WORDPRESS_ADMIN_USER=admin
WORDPRESS_ADMIN_PASSWORD=password

# The host and port of the ChromeDriver server that will be used in end-to-end tests.
CHROMEDRIVER_HOST=localhost
CHROMEDRIVER_PORT=51597
CHROMEDRIVER_PORT=54870

# The port on which the PHP built-in server will serve the WordPress installation.
BUILTIN_SERVER_PORT=9750
BUILTIN_SERVER_PORT=37987

<<< /.env <<<

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ modules:
- "--no-sandbox"
lucatume\WPBrowser\Module\WPDb:
dbUrl: '%WORDPRESS_DB_URL%'
dump: 'tests/Support/Data/dump.sql'
dump: 'tests/_data/dump.sql'
populate: true
cleanup: true
reconnect: false
Expand Down Expand Up @@ -242,7 +242,7 @@ modules:

namespace Tests\EndToEnd;

use Tests\Support\EndToEndTester;
use EndToEndTester;

class ActivationCest
{
Expand Down Expand Up @@ -283,19 +283,19 @@ TEST_TABLE_PREFIX=test_
WORDPRESS_TABLE_PREFIX=wp_

# The URL and domain of the WordPress site used in end-to-end tests.
WORDPRESS_URL=http://localhost:16145
WORDPRESS_DOMAIN=localhost:16145
WORDPRESS_URL=http://localhost:18237
WORDPRESS_DOMAIN=localhost:18237

# The username and password of the administrator user of the WordPress site used in end-to-end tests.
WORDPRESS_ADMIN_USER=admin
WORDPRESS_ADMIN_PASSWORD=password

# The host and port of the ChromeDriver server that will be used in end-to-end tests.
CHROMEDRIVER_HOST=localhost
CHROMEDRIVER_PORT=50293
CHROMEDRIVER_PORT=63427

# The port on which the PHP built-in server will serve the WordPress installation.
BUILTIN_SERVER_PORT=16145
BUILTIN_SERVER_PORT=18237

<<< /tests/.env <<<

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ modules:
- "--no-sandbox"
lucatume\WPBrowser\Module\WPDb:
dbUrl: '%WORDPRESS_DB_URL%'
dump: 'tests/Support/Data/dump.sql'
dump: 'tests/_data/dump.sql'
populate: true
cleanup: true
reconnect: false
Expand Down Expand Up @@ -247,7 +247,7 @@ modules:

namespace Tests\EndToEnd;

use Tests\Support\EndToEndTester;
use EndToEndTester;

class ActivationCest
{
Expand Down Expand Up @@ -288,19 +288,19 @@ TEST_TABLE_PREFIX=test_
WORDPRESS_TABLE_PREFIX=wp_

# The URL and domain of the WordPress site used in end-to-end tests.
WORDPRESS_URL=http://localhost:40096
WORDPRESS_DOMAIN=localhost:40096
WORDPRESS_URL=http://localhost:38047
WORDPRESS_DOMAIN=localhost:38047

# The username and password of the administrator user of the WordPress site used in end-to-end tests.
WORDPRESS_ADMIN_USER=admin
WORDPRESS_ADMIN_PASSWORD=password

# The host and port of the ChromeDriver server that will be used in end-to-end tests.
CHROMEDRIVER_HOST=localhost
CHROMEDRIVER_PORT=9351
CHROMEDRIVER_PORT=56902

# The port on which the PHP built-in server will serve the WordPress installation.
BUILTIN_SERVER_PORT=40096
BUILTIN_SERVER_PORT=38047

<<< /tests/.env <<<

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ modules:
- "--no-sandbox"
lucatume\WPBrowser\Module\WPDb:
dbUrl: '%WORDPRESS_DB_URL%'
dump: 'tests/Support/Data/dump.sql'
dump: 'tests/_data/dump.sql'
populate: true
cleanup: true
reconnect: false
Expand Down Expand Up @@ -247,7 +247,7 @@ modules:

namespace Tests\EndToEnd;

use Tests\Support\EndToEndTester;
use EndToEndTester;

class ActivationCest
{
Expand Down Expand Up @@ -288,19 +288,19 @@ TEST_TABLE_PREFIX=test_
WORDPRESS_TABLE_PREFIX=wp_

# The URL and domain of the WordPress site used in end-to-end tests.
WORDPRESS_URL=http://localhost:61506
WORDPRESS_DOMAIN=localhost:61506
WORDPRESS_URL=http://localhost:18285
WORDPRESS_DOMAIN=localhost:18285

# The username and password of the administrator user of the WordPress site used in end-to-end tests.
WORDPRESS_ADMIN_USER=admin
WORDPRESS_ADMIN_PASSWORD=password

# The host and port of the ChromeDriver server that will be used in end-to-end tests.
CHROMEDRIVER_HOST=localhost
CHROMEDRIVER_PORT=2860
CHROMEDRIVER_PORT=28492

# The port on which the PHP built-in server will serve the WordPress installation.
BUILTIN_SERVER_PORT=61506
BUILTIN_SERVER_PORT=18285

<<< /tests/.env <<<

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ modules:
- "--no-sandbox"
lucatume\WPBrowser\Module\WPDb:
dbUrl: '%WORDPRESS_DB_URL%'
dump: 'tests/Support/Data/dump.sql'
dump: 'tests/_data/dump.sql'
populate: true
cleanup: true
reconnect: false
Expand Down Expand Up @@ -247,7 +247,7 @@ modules:

namespace Tests\EndToEnd;

use Tests\Support\EndToEndTester;
use EndToEndTester;

class ActivationCest
{
Expand Down Expand Up @@ -288,19 +288,19 @@ TEST_TABLE_PREFIX=test_
WORDPRESS_TABLE_PREFIX=wp_

# The URL and domain of the WordPress site used in end-to-end tests.
WORDPRESS_URL=http://localhost:24356
WORDPRESS_DOMAIN=localhost:24356
WORDPRESS_URL=http://localhost:20511
WORDPRESS_DOMAIN=localhost:20511

# The username and password of the administrator user of the WordPress site used in end-to-end tests.
WORDPRESS_ADMIN_USER=admin
WORDPRESS_ADMIN_PASSWORD=password

# The host and port of the ChromeDriver server that will be used in end-to-end tests.
CHROMEDRIVER_HOST=localhost
CHROMEDRIVER_PORT=54335
CHROMEDRIVER_PORT=50604

# The port on which the PHP built-in server will serve the WordPress installation.
BUILTIN_SERVER_PORT=24356
BUILTIN_SERVER_PORT=20511

<<< /tests/.env <<<

Expand Down
Loading

0 comments on commit c63a918

Please sign in to comment.