From 78262842ef5b13b51a6fc4358829f901ab7d6b6d Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Tue, 25 Jun 2024 09:32:59 +0200 Subject: [PATCH 1/6] fix(Wpbrowser) update default setup documentation Reference correct commands, ensure SQLite export drops tables before creating them. --- src/Template/Wpbrowser.php | 14 +++++++----- src/WordPress/Database/SQLiteDatabase.php | 6 +++-- ...ite_with_non_default_structure__0.snapshot | 14 +++++++----- ...re_using_default_configuration__0.snapshot | 22 ++++++++++--------- ...fold_for_child_theme_correctly__0.snapshot | 22 ++++++++++--------- ...ffold_for_multi_site_correctly__1.snapshot | 22 ++++++++++--------- ...lugin_with_non_plugin_php_file__0.snapshot | 22 ++++++++++--------- ...ith_non_plugin_php_file_custom__0.snapshot | 14 +++++++----- ...or_plugin_with_plugin_php_file__0.snapshot | 22 ++++++++++--------- ...in_with_plugin_php_file_custom__0.snapshot | 14 +++++++----- ...fold_for_single_site_correctly__1.snapshot | 22 ++++++++++--------- ...d_scaffold_for_theme_correctly__0.snapshot | 22 ++++++++++--------- ...old_for_theme_custom_correctly__0.snapshot | 14 +++++++----- 13 files changed, 128 insertions(+), 102 deletions(-) diff --git a/src/Template/Wpbrowser.php b/src/Template/Wpbrowser.php index 84dfafcd9..99e3db8ed 100644 --- a/src/Template/Wpbrowser.php +++ b/src/Template/Wpbrowser.php @@ -295,13 +295,15 @@ private function createEndToEndSuite(ProjectInterface $project): void * "modules.config.WPDb.dump" setting in the suite configuration file. The database will be dropped after each test * and re-created from the dump file(s). * - * You can modify and create new dump files using the `vendor/bin/codecept wp:cli EndToEnd ` command - * to run WP-CLI commands on the WordPress site and database used by the EndToEnd suite. + * You can modify and create new dump files using WP-CLI or by operating directly on the WordPress site and database, + * use the `vendor/bin/codecept dev:info` command to know the URL to the WordPress site. + * Note that WP-CLI will not natively handle SQLite databases, so you will need to use the `wp:db:import` and + * `wp:db:export` commands to import and export the database. * E.g.: - * `vendor/bin/codecept wp:cli EndToEnd db import tests/Support/Data/dump.sql` to load dump file. - * `vendor/bin/codecept wp:cli EndToEnd plugin activate woocommerce` to activate the WooCommerce plugin. - * `vendor/bin/codecept wp:cli EndToEnd user create alice alice@example.com --role=administrator` to create a new user. - * `vendor/bin/codecept wp:cli EndToEnd db export tests/Support/Data/dump.sql` to update the dump file. + * `vendor/bin/codecept wp:db:import tests/_wordpress tests/Support/Data/dump.sql` to load dump file. + * `wp --path=tests/_wordpress plugin activate woocommerce` to activate the WooCommerce plugin. + * `wp --path=tests/_wordpress user create alice alice@example.com --role=administrator` to create a new user. + * `vendor/bin/codecept wp:db:export tests/_wordpress tests/Support/Data/dump.sql` to update the dump file. */ EOF; $bootstrapPathname = $this->workDir . '/tests/EndToEnd/_bootstrap.php'; diff --git a/src/WordPress/Database/SQLiteDatabase.php b/src/WordPress/Database/SQLiteDatabase.php index 731d53ecb..1e2b0d88b 100644 --- a/src/WordPress/Database/SQLiteDatabase.php +++ b/src/WordPress/Database/SQLiteDatabase.php @@ -255,7 +255,7 @@ public function dump(string $dumpFilePath): void $db = new SQLite3($this->dbPathname); $db->busyTimeout(5000); - $sql = ""; + $sql = "PRAGMA foreign_keys = OFF;\n\n"; $tables = $db->query("SELECT name FROM sqlite_master WHERE type ='table' AND name NOT LIKE 'sqlite_%';"); @@ -270,7 +270,7 @@ public function dump(string $dumpFilePath): void throw new DbException("Could not read table $table[0] from database.", DbException::FAILED_DUMP); } - $sql .= $tableSql . ";\n\n"; + $sql .= "DROP TABLE IF EXISTS $table[0];\n" . $tableSql . ";\n\n"; $rows = $db->query("SELECT * FROM $table[0]"); if ($rows === false) { @@ -308,6 +308,8 @@ public function dump(string $dumpFilePath): void $sql = rtrim($sql, ",") . ";\n\n"; } + $sql .= "PRAGMA foreign_keys = ON\n"; + if (file_put_contents($dumpFilePath, $sql) === false) { throw new DbException("Could not write dump file $dumpFilePath.", DbException::FAILED_DUMP); } diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_correctly_on_site_with_non_default_structure__0.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_correctly_on_site_with_non_default_structure__0.snapshot index 680e49321..1103fec01 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_correctly_on_site_with_non_default_structure__0.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_correctly_on_site_with_non_default_structure__0.snapshot @@ -169,13 +169,15 @@ class EndToEndTester extends \Codeception\Actor * "modules.config.WPDb.dump" setting in the suite configuration file. The database will be dropped after each test * and re-created from the dump file(s). * - * You can modify and create new dump files using the `vendor/bin/codecept wp:cli EndToEnd ` command - * to run WP-CLI commands on the WordPress site and database used by the EndToEnd suite. + * You can modify and create new dump files using WP-CLI or by operating directly on the WordPress site and database, + * use the `vendor/bin/codecept dev:info` command to know the URL to the WordPress site. + * Note that WP-CLI will not natively handle SQLite databases, so you will need to use the `wp:db:import` and + * `wp:db:export` commands to import and export the database. * E.g.: - * `vendor/bin/codecept wp:cli EndToEnd db import tests/Support/Data/dump.sql` to load dump file. - * `vendor/bin/codecept wp:cli EndToEnd plugin activate woocommerce` to activate the WooCommerce plugin. - * `vendor/bin/codecept wp:cli EndToEnd user create alice alice@example.com --role=administrator` to create a new user. - * `vendor/bin/codecept wp:cli EndToEnd db export tests/Support/Data/dump.sql` to update the dump file. + * `vendor/bin/codecept wp:db:import tests/_wordpress tests/Support/Data/dump.sql` to load dump file. + * `wp --path=tests/_wordpress plugin activate woocommerce` to activate the WooCommerce plugin. + * `wp --path=tests/_wordpress user create alice alice@example.com --role=administrator` to create a new user. + * `vendor/bin/codecept wp:db:export tests/_wordpress tests/Support/Data/dump.sql` to update the dump file. */ <<< /EndToEnd/_bootstrap.php <<< diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_correctly_on_site_with_non_default_structure_using_default_configuration__0.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_correctly_on_site_with_non_default_structure_using_default_configuration__0.snapshot index 62ce0a039..8f1dd2d72 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_correctly_on_site_with_non_default_structure_using_default_configuration__0.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_correctly_on_site_with_non_default_structure_using_default_configuration__0.snapshot @@ -214,13 +214,15 @@ class EndToEndTester extends \Codeception\Actor * "modules.config.WPDb.dump" setting in the suite configuration file. The database will be dropped after each test * and re-created from the dump file(s). * - * You can modify and create new dump files using the `vendor/bin/codecept wp:cli EndToEnd ` command - * to run WP-CLI commands on the WordPress site and database used by the EndToEnd suite. + * You can modify and create new dump files using WP-CLI or by operating directly on the WordPress site and database, + * use the `vendor/bin/codecept dev:info` command to know the URL to the WordPress site. + * Note that WP-CLI will not natively handle SQLite databases, so you will need to use the `wp:db:import` and + * `wp:db:export` commands to import and export the database. * E.g.: - * `vendor/bin/codecept wp:cli EndToEnd db import tests/Support/Data/dump.sql` to load dump file. - * `vendor/bin/codecept wp:cli EndToEnd plugin activate woocommerce` to activate the WooCommerce plugin. - * `vendor/bin/codecept wp:cli EndToEnd user create alice alice@example.com --role=administrator` to create a new user. - * `vendor/bin/codecept wp:cli EndToEnd db export tests/Support/Data/dump.sql` to update the dump file. + * `vendor/bin/codecept wp:db:import tests/_wordpress tests/Support/Data/dump.sql` to load dump file. + * `wp --path=tests/_wordpress plugin activate woocommerce` to activate the WooCommerce plugin. + * `wp --path=tests/_wordpress user create alice alice@example.com --role=administrator` to create a new user. + * `vendor/bin/codecept wp:db:export tests/_wordpress tests/Support/Data/dump.sql` to update the dump file. */ <<< /EndToEnd/_bootstrap.php <<< @@ -267,8 +269,8 @@ 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:24423 -WORDPRESS_DOMAIN=localhost:24423 +WORDPRESS_URL=http://localhost:28388 +WORDPRESS_DOMAIN=localhost:28388 WORDPRESS_ADMIN_PATH=/wp/wp-admin # The username and password of the administrator user of the WordPress site used in end-to-end tests. @@ -277,10 +279,10 @@ 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=17558 +CHROMEDRIVER_PORT=9649 # The port on which the PHP built-in server will serve the WordPress installation. -BUILTIN_SERVER_PORT=24423 +BUILTIN_SERVER_PORT=28388 # The path to the directory that should be served on localhost, the one containing the wp-config.php file. WORDPRESS_DOCROOT=web diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_child_theme_correctly__0.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_child_theme_correctly__0.snapshot index 644e13d3b..491ac0733 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_child_theme_correctly__0.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_child_theme_correctly__0.snapshot @@ -222,13 +222,15 @@ class EndToEndTester extends \Codeception\Actor * "modules.config.WPDb.dump" setting in the suite configuration file. The database will be dropped after each test * and re-created from the dump file(s). * - * You can modify and create new dump files using the `vendor/bin/codecept wp:cli EndToEnd ` command - * to run WP-CLI commands on the WordPress site and database used by the EndToEnd suite. + * You can modify and create new dump files using WP-CLI or by operating directly on the WordPress site and database, + * use the `vendor/bin/codecept dev:info` command to know the URL to the WordPress site. + * Note that WP-CLI will not natively handle SQLite databases, so you will need to use the `wp:db:import` and + * `wp:db:export` commands to import and export the database. * E.g.: - * `vendor/bin/codecept wp:cli EndToEnd db import tests/Support/Data/dump.sql` to load dump file. - * `vendor/bin/codecept wp:cli EndToEnd plugin activate woocommerce` to activate the WooCommerce plugin. - * `vendor/bin/codecept wp:cli EndToEnd user create alice alice@example.com --role=administrator` to create a new user. - * `vendor/bin/codecept wp:cli EndToEnd db export tests/Support/Data/dump.sql` to update the dump file. + * `vendor/bin/codecept wp:db:import tests/_wordpress tests/Support/Data/dump.sql` to load dump file. + * `wp --path=tests/_wordpress plugin activate woocommerce` to activate the WooCommerce plugin. + * `wp --path=tests/_wordpress user create alice alice@example.com --role=administrator` to create a new user. + * `vendor/bin/codecept wp:db:export tests/_wordpress tests/Support/Data/dump.sql` to update the dump file. */ <<< /tests/EndToEnd/_bootstrap.php <<< @@ -270,8 +272,8 @@ 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:32347 -WORDPRESS_DOMAIN=localhost:32347 +WORDPRESS_URL=http://localhost:47453 +WORDPRESS_DOMAIN=localhost:47453 WORDPRESS_ADMIN_PATH=/wp-admin # The username and password of the administrator user of the WordPress site used in end-to-end tests. @@ -280,10 +282,10 @@ 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=59028 +CHROMEDRIVER_PORT=43984 # The port on which the PHP built-in server will serve the WordPress installation. -BUILTIN_SERVER_PORT=32347 +BUILTIN_SERVER_PORT=47453 <<< /tests/.env <<< diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_multi_site_correctly__1.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_multi_site_correctly__1.snapshot index 39177ae30..e72485b1a 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_multi_site_correctly__1.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_multi_site_correctly__1.snapshot @@ -214,13 +214,15 @@ class EndToEndTester extends \Codeception\Actor * "modules.config.WPDb.dump" setting in the suite configuration file. The database will be dropped after each test * and re-created from the dump file(s). * - * You can modify and create new dump files using the `vendor/bin/codecept wp:cli EndToEnd ` command - * to run WP-CLI commands on the WordPress site and database used by the EndToEnd suite. + * You can modify and create new dump files using WP-CLI or by operating directly on the WordPress site and database, + * use the `vendor/bin/codecept dev:info` command to know the URL to the WordPress site. + * Note that WP-CLI will not natively handle SQLite databases, so you will need to use the `wp:db:import` and + * `wp:db:export` commands to import and export the database. * E.g.: - * `vendor/bin/codecept wp:cli EndToEnd db import tests/Support/Data/dump.sql` to load dump file. - * `vendor/bin/codecept wp:cli EndToEnd plugin activate woocommerce` to activate the WooCommerce plugin. - * `vendor/bin/codecept wp:cli EndToEnd user create alice alice@example.com --role=administrator` to create a new user. - * `vendor/bin/codecept wp:cli EndToEnd db export tests/Support/Data/dump.sql` to update the dump file. + * `vendor/bin/codecept wp:db:import tests/_wordpress tests/Support/Data/dump.sql` to load dump file. + * `wp --path=tests/_wordpress plugin activate woocommerce` to activate the WooCommerce plugin. + * `wp --path=tests/_wordpress user create alice alice@example.com --role=administrator` to create a new user. + * `vendor/bin/codecept wp:db:export tests/_wordpress tests/Support/Data/dump.sql` to update the dump file. */ <<< /EndToEnd/_bootstrap.php <<< @@ -267,8 +269,8 @@ 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:9035 -WORDPRESS_DOMAIN=localhost:9035 +WORDPRESS_URL=http://localhost:14644 +WORDPRESS_DOMAIN=localhost:14644 WORDPRESS_ADMIN_PATH=/wp-admin # The username and password of the administrator user of the WordPress site used in end-to-end tests. @@ -277,10 +279,10 @@ 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=21043 +CHROMEDRIVER_PORT=17240 # The port on which the PHP built-in server will serve the WordPress installation. -BUILTIN_SERVER_PORT=9035 +BUILTIN_SERVER_PORT=14644 <<< /.env <<< diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_non_plugin_php_file__0.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_non_plugin_php_file__0.snapshot index dc1230795..316776553 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_non_plugin_php_file__0.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_non_plugin_php_file__0.snapshot @@ -209,13 +209,15 @@ class EndToEndTester extends \Codeception\Actor * "modules.config.WPDb.dump" setting in the suite configuration file. The database will be dropped after each test * and re-created from the dump file(s). * - * You can modify and create new dump files using the `vendor/bin/codecept wp:cli EndToEnd ` command - * to run WP-CLI commands on the WordPress site and database used by the EndToEnd suite. + * You can modify and create new dump files using WP-CLI or by operating directly on the WordPress site and database, + * use the `vendor/bin/codecept dev:info` command to know the URL to the WordPress site. + * Note that WP-CLI will not natively handle SQLite databases, so you will need to use the `wp:db:import` and + * `wp:db:export` commands to import and export the database. * E.g.: - * `vendor/bin/codecept wp:cli EndToEnd db import tests/Support/Data/dump.sql` to load dump file. - * `vendor/bin/codecept wp:cli EndToEnd plugin activate woocommerce` to activate the WooCommerce plugin. - * `vendor/bin/codecept wp:cli EndToEnd user create alice alice@example.com --role=administrator` to create a new user. - * `vendor/bin/codecept wp:cli EndToEnd db export tests/Support/Data/dump.sql` to update the dump file. + * `vendor/bin/codecept wp:db:import tests/_wordpress tests/Support/Data/dump.sql` to load dump file. + * `wp --path=tests/_wordpress plugin activate woocommerce` to activate the WooCommerce plugin. + * `wp --path=tests/_wordpress user create alice alice@example.com --role=administrator` to create a new user. + * `vendor/bin/codecept wp:db:export tests/_wordpress tests/Support/Data/dump.sql` to update the dump file. */ <<< /tests/EndToEnd/_bootstrap.php <<< @@ -265,8 +267,8 @@ 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:48989 -WORDPRESS_DOMAIN=localhost:48989 +WORDPRESS_URL=http://localhost:42934 +WORDPRESS_DOMAIN=localhost:42934 WORDPRESS_ADMIN_PATH=/wp-admin # The username and password of the administrator user of the WordPress site used in end-to-end tests. @@ -275,10 +277,10 @@ 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=10540 +CHROMEDRIVER_PORT=44670 # The port on which the PHP built-in server will serve the WordPress installation. -BUILTIN_SERVER_PORT=48989 +BUILTIN_SERVER_PORT=42934 <<< /tests/.env <<< diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_non_plugin_php_file_custom__0.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_non_plugin_php_file_custom__0.snapshot index 77f9d15dd..83c61685d 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_non_plugin_php_file_custom__0.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_non_plugin_php_file_custom__0.snapshot @@ -174,13 +174,15 @@ class EndToEndTester extends \Codeception\Actor * "modules.config.WPDb.dump" setting in the suite configuration file. The database will be dropped after each test * and re-created from the dump file(s). * - * You can modify and create new dump files using the `vendor/bin/codecept wp:cli EndToEnd ` command - * to run WP-CLI commands on the WordPress site and database used by the EndToEnd suite. + * You can modify and create new dump files using WP-CLI or by operating directly on the WordPress site and database, + * use the `vendor/bin/codecept dev:info` command to know the URL to the WordPress site. + * Note that WP-CLI will not natively handle SQLite databases, so you will need to use the `wp:db:import` and + * `wp:db:export` commands to import and export the database. * E.g.: - * `vendor/bin/codecept wp:cli EndToEnd db import tests/Support/Data/dump.sql` to load dump file. - * `vendor/bin/codecept wp:cli EndToEnd plugin activate woocommerce` to activate the WooCommerce plugin. - * `vendor/bin/codecept wp:cli EndToEnd user create alice alice@example.com --role=administrator` to create a new user. - * `vendor/bin/codecept wp:cli EndToEnd db export tests/Support/Data/dump.sql` to update the dump file. + * `vendor/bin/codecept wp:db:import tests/_wordpress tests/Support/Data/dump.sql` to load dump file. + * `wp --path=tests/_wordpress plugin activate woocommerce` to activate the WooCommerce plugin. + * `wp --path=tests/_wordpress user create alice alice@example.com --role=administrator` to create a new user. + * `vendor/bin/codecept wp:db:export tests/_wordpress tests/Support/Data/dump.sql` to update the dump file. */ <<< /tests/EndToEnd/_bootstrap.php <<< diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_plugin_php_file__0.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_plugin_php_file__0.snapshot index 745075eca..246a25dc4 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_plugin_php_file__0.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_plugin_php_file__0.snapshot @@ -214,13 +214,15 @@ class EndToEndTester extends \Codeception\Actor * "modules.config.WPDb.dump" setting in the suite configuration file. The database will be dropped after each test * and re-created from the dump file(s). * - * You can modify and create new dump files using the `vendor/bin/codecept wp:cli EndToEnd ` command - * to run WP-CLI commands on the WordPress site and database used by the EndToEnd suite. + * You can modify and create new dump files using WP-CLI or by operating directly on the WordPress site and database, + * use the `vendor/bin/codecept dev:info` command to know the URL to the WordPress site. + * Note that WP-CLI will not natively handle SQLite databases, so you will need to use the `wp:db:import` and + * `wp:db:export` commands to import and export the database. * E.g.: - * `vendor/bin/codecept wp:cli EndToEnd db import tests/Support/Data/dump.sql` to load dump file. - * `vendor/bin/codecept wp:cli EndToEnd plugin activate woocommerce` to activate the WooCommerce plugin. - * `vendor/bin/codecept wp:cli EndToEnd user create alice alice@example.com --role=administrator` to create a new user. - * `vendor/bin/codecept wp:cli EndToEnd db export tests/Support/Data/dump.sql` to update the dump file. + * `vendor/bin/codecept wp:db:import tests/_wordpress tests/Support/Data/dump.sql` to load dump file. + * `wp --path=tests/_wordpress plugin activate woocommerce` to activate the WooCommerce plugin. + * `wp --path=tests/_wordpress user create alice alice@example.com --role=administrator` to create a new user. + * `vendor/bin/codecept wp:db:export tests/_wordpress tests/Support/Data/dump.sql` to update the dump file. */ <<< /tests/EndToEnd/_bootstrap.php <<< @@ -270,8 +272,8 @@ 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:51713 -WORDPRESS_DOMAIN=localhost:51713 +WORDPRESS_URL=http://localhost:16769 +WORDPRESS_DOMAIN=localhost:16769 WORDPRESS_ADMIN_PATH=/wp-admin # The username and password of the administrator user of the WordPress site used in end-to-end tests. @@ -280,10 +282,10 @@ 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=41985 +CHROMEDRIVER_PORT=20529 # The port on which the PHP built-in server will serve the WordPress installation. -BUILTIN_SERVER_PORT=51713 +BUILTIN_SERVER_PORT=16769 <<< /tests/.env <<< diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_plugin_php_file_custom__0.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_plugin_php_file_custom__0.snapshot index 0734db2f2..82587e8b3 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_plugin_php_file_custom__0.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_plugin_php_file_custom__0.snapshot @@ -174,13 +174,15 @@ class EndToEndTester extends \Codeception\Actor * "modules.config.WPDb.dump" setting in the suite configuration file. The database will be dropped after each test * and re-created from the dump file(s). * - * You can modify and create new dump files using the `vendor/bin/codecept wp:cli EndToEnd ` command - * to run WP-CLI commands on the WordPress site and database used by the EndToEnd suite. + * You can modify and create new dump files using WP-CLI or by operating directly on the WordPress site and database, + * use the `vendor/bin/codecept dev:info` command to know the URL to the WordPress site. + * Note that WP-CLI will not natively handle SQLite databases, so you will need to use the `wp:db:import` and + * `wp:db:export` commands to import and export the database. * E.g.: - * `vendor/bin/codecept wp:cli EndToEnd db import tests/Support/Data/dump.sql` to load dump file. - * `vendor/bin/codecept wp:cli EndToEnd plugin activate woocommerce` to activate the WooCommerce plugin. - * `vendor/bin/codecept wp:cli EndToEnd user create alice alice@example.com --role=administrator` to create a new user. - * `vendor/bin/codecept wp:cli EndToEnd db export tests/Support/Data/dump.sql` to update the dump file. + * `vendor/bin/codecept wp:db:import tests/_wordpress tests/Support/Data/dump.sql` to load dump file. + * `wp --path=tests/_wordpress plugin activate woocommerce` to activate the WooCommerce plugin. + * `wp --path=tests/_wordpress user create alice alice@example.com --role=administrator` to create a new user. + * `vendor/bin/codecept wp:db:export tests/_wordpress tests/Support/Data/dump.sql` to update the dump file. */ <<< /tests/EndToEnd/_bootstrap.php <<< diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_single_site_correctly__1.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_single_site_correctly__1.snapshot index a808ee15b..81186b3b8 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_single_site_correctly__1.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_single_site_correctly__1.snapshot @@ -214,13 +214,15 @@ class EndToEndTester extends \Codeception\Actor * "modules.config.WPDb.dump" setting in the suite configuration file. The database will be dropped after each test * and re-created from the dump file(s). * - * You can modify and create new dump files using the `vendor/bin/codecept wp:cli EndToEnd ` command - * to run WP-CLI commands on the WordPress site and database used by the EndToEnd suite. + * You can modify and create new dump files using WP-CLI or by operating directly on the WordPress site and database, + * use the `vendor/bin/codecept dev:info` command to know the URL to the WordPress site. + * Note that WP-CLI will not natively handle SQLite databases, so you will need to use the `wp:db:import` and + * `wp:db:export` commands to import and export the database. * E.g.: - * `vendor/bin/codecept wp:cli EndToEnd db import tests/Support/Data/dump.sql` to load dump file. - * `vendor/bin/codecept wp:cli EndToEnd plugin activate woocommerce` to activate the WooCommerce plugin. - * `vendor/bin/codecept wp:cli EndToEnd user create alice alice@example.com --role=administrator` to create a new user. - * `vendor/bin/codecept wp:cli EndToEnd db export tests/Support/Data/dump.sql` to update the dump file. + * `vendor/bin/codecept wp:db:import tests/_wordpress tests/Support/Data/dump.sql` to load dump file. + * `wp --path=tests/_wordpress plugin activate woocommerce` to activate the WooCommerce plugin. + * `wp --path=tests/_wordpress user create alice alice@example.com --role=administrator` to create a new user. + * `vendor/bin/codecept wp:db:export tests/_wordpress tests/Support/Data/dump.sql` to update the dump file. */ <<< /EndToEnd/_bootstrap.php <<< @@ -267,8 +269,8 @@ 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:26712 -WORDPRESS_DOMAIN=localhost:26712 +WORDPRESS_URL=http://localhost:23271 +WORDPRESS_DOMAIN=localhost:23271 WORDPRESS_ADMIN_PATH=/wp-admin # The username and password of the administrator user of the WordPress site used in end-to-end tests. @@ -277,10 +279,10 @@ 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=12425 +CHROMEDRIVER_PORT=45511 # The port on which the PHP built-in server will serve the WordPress installation. -BUILTIN_SERVER_PORT=26712 +BUILTIN_SERVER_PORT=23271 <<< /.env <<< diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_theme_correctly__0.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_theme_correctly__0.snapshot index b8056a07b..2b3f7034b 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_theme_correctly__0.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_theme_correctly__0.snapshot @@ -222,13 +222,15 @@ class EndToEndTester extends \Codeception\Actor * "modules.config.WPDb.dump" setting in the suite configuration file. The database will be dropped after each test * and re-created from the dump file(s). * - * You can modify and create new dump files using the `vendor/bin/codecept wp:cli EndToEnd ` command - * to run WP-CLI commands on the WordPress site and database used by the EndToEnd suite. + * You can modify and create new dump files using WP-CLI or by operating directly on the WordPress site and database, + * use the `vendor/bin/codecept dev:info` command to know the URL to the WordPress site. + * Note that WP-CLI will not natively handle SQLite databases, so you will need to use the `wp:db:import` and + * `wp:db:export` commands to import and export the database. * E.g.: - * `vendor/bin/codecept wp:cli EndToEnd db import tests/Support/Data/dump.sql` to load dump file. - * `vendor/bin/codecept wp:cli EndToEnd plugin activate woocommerce` to activate the WooCommerce plugin. - * `vendor/bin/codecept wp:cli EndToEnd user create alice alice@example.com --role=administrator` to create a new user. - * `vendor/bin/codecept wp:cli EndToEnd db export tests/Support/Data/dump.sql` to update the dump file. + * `vendor/bin/codecept wp:db:import tests/_wordpress tests/Support/Data/dump.sql` to load dump file. + * `wp --path=tests/_wordpress plugin activate woocommerce` to activate the WooCommerce plugin. + * `wp --path=tests/_wordpress user create alice alice@example.com --role=administrator` to create a new user. + * `vendor/bin/codecept wp:db:export tests/_wordpress tests/Support/Data/dump.sql` to update the dump file. */ <<< /tests/EndToEnd/_bootstrap.php <<< @@ -270,8 +272,8 @@ 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:10603 -WORDPRESS_DOMAIN=localhost:10603 +WORDPRESS_URL=http://localhost:8847 +WORDPRESS_DOMAIN=localhost:8847 WORDPRESS_ADMIN_PATH=/wp-admin # The username and password of the administrator user of the WordPress site used in end-to-end tests. @@ -280,10 +282,10 @@ 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=43861 +CHROMEDRIVER_PORT=7561 # The port on which the PHP built-in server will serve the WordPress installation. -BUILTIN_SERVER_PORT=10603 +BUILTIN_SERVER_PORT=8847 <<< /tests/.env <<< diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_theme_custom_correctly__0.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_theme_custom_correctly__0.snapshot index 6cee5d442..adb4948b8 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_theme_custom_correctly__0.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_theme_custom_correctly__0.snapshot @@ -189,13 +189,15 @@ class EndToEndTester extends \Codeception\Actor * "modules.config.WPDb.dump" setting in the suite configuration file. The database will be dropped after each test * and re-created from the dump file(s). * - * You can modify and create new dump files using the `vendor/bin/codecept wp:cli EndToEnd ` command - * to run WP-CLI commands on the WordPress site and database used by the EndToEnd suite. + * You can modify and create new dump files using WP-CLI or by operating directly on the WordPress site and database, + * use the `vendor/bin/codecept dev:info` command to know the URL to the WordPress site. + * Note that WP-CLI will not natively handle SQLite databases, so you will need to use the `wp:db:import` and + * `wp:db:export` commands to import and export the database. * E.g.: - * `vendor/bin/codecept wp:cli EndToEnd db import tests/Support/Data/dump.sql` to load dump file. - * `vendor/bin/codecept wp:cli EndToEnd plugin activate woocommerce` to activate the WooCommerce plugin. - * `vendor/bin/codecept wp:cli EndToEnd user create alice alice@example.com --role=administrator` to create a new user. - * `vendor/bin/codecept wp:cli EndToEnd db export tests/Support/Data/dump.sql` to update the dump file. + * `vendor/bin/codecept wp:db:import tests/_wordpress tests/Support/Data/dump.sql` to load dump file. + * `wp --path=tests/_wordpress plugin activate woocommerce` to activate the WooCommerce plugin. + * `wp --path=tests/_wordpress user create alice alice@example.com --role=administrator` to create a new user. + * `vendor/bin/codecept wp:db:export tests/_wordpress tests/Support/Data/dump.sql` to update the dump file. */ <<< /tests/EndToEnd/_bootstrap.php <<< From 5e28acaf08d2c032af769cf34e2c9f67e9bd61f5 Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Tue, 25 Jun 2024 10:44:17 +0200 Subject: [PATCH 2/6] test(SymlinkerTest) restore removed code --- .../WPBrowser/Extension/SymlinkerTest.php | 80 ++++++++++++------- 1 file changed, 52 insertions(+), 28 deletions(-) diff --git a/tests/unit/lucatume/WPBrowser/Extension/SymlinkerTest.php b/tests/unit/lucatume/WPBrowser/Extension/SymlinkerTest.php index 634d06596..93a12d233 100644 --- a/tests/unit/lucatume/WPBrowser/Extension/SymlinkerTest.php +++ b/tests/unit/lucatume/WPBrowser/Extension/SymlinkerTest.php @@ -2,20 +2,33 @@ namespace unit\lucatume\WPBrowser\Extension; +use Codeception\Codecept; use Codeception\Event\SuiteEvent; use Codeception\Exception\ModuleConfigException; use Codeception\Exception\ModuleException; +use Codeception\Suite; use Codeception\Test\Unit; use lucatume\WPBrowser\Extension\Symlinker; use lucatume\WPBrowser\Tests\Traits\LoopIsolation; use lucatume\WPBrowser\Utils\Filesystem as FS; use lucatume\WPBrowser\WordPress\Installation; use PHPUnit\Framework\Assert; +use Symfony\Component\EventDispatcher\EventDispatcher; class SymlinkerTest extends Unit { use LoopIsolation; + private function getSuiteEvent(): SuiteEvent + { + if (Codecept::VERSION >= 5) { + return new SuiteEvent(new Suite(new EventDispatcher(), 'test')); + } + + // Codeception 4.x. + return new SuiteEvent(new Suite()); + } + public function test_exists(): void { $symlinker = new Symlinker([ @@ -29,10 +42,11 @@ public function test_throw_if_wp_root_folder_is_not_set(): void { $this->expectException(ModuleConfigException::class); $this->expectExceptionMessage('The `wpRootFolder` configuration parameter must be set.'); + $suiteEvent = $this->getSuiteEvent(); $symlinker = new Symlinker([ ], []); - $symlinker->onModuleInit(new SuiteEvent()); + $symlinker->onModuleInit($suiteEvent); } public function test_throw_if_wp_root_folder_does_not_point_to_a_valid_installation(): void @@ -40,12 +54,13 @@ public function test_throw_if_wp_root_folder_does_not_point_to_a_valid_installat $symlinker = new Symlinker([ 'wpRootFolder' => __DIR__, ], []); + $suiteEvent = $this->getSuiteEvent(); $this->expectException(ModuleConfigException::class); $this->expectExceptionMessage('The `wpRootFolder` does not point to a valid WordPress installation.'); - $this->assertInIsolation(static function () use ($symlinker) { - $symlinker->onModuleInit(new SuiteEvent()); + $this->assertInIsolation(static function () use ($symlinker, $suiteEvent) { + $symlinker->onModuleInit($suiteEvent); }); } @@ -53,24 +68,26 @@ public function test_throw_if_plugins_are_not_array(): void { $this->expectException(ModuleConfigException::class); $this->expectExceptionMessage('The `plugins` configuration parameter must be an array.'); + $suiteEvent = $this->getSuiteEvent(); $symlinker = new Symlinker([ 'wpRootFolder' => __DIR__, 'plugins' => 'not-an-array', ], []); - $symlinker->onModuleInit(new SuiteEvent()); + $symlinker->onModuleInit($suiteEvent); } public function test_throw_if_themes_are_not_array(): void { $this->expectException(ModuleConfigException::class); $this->expectExceptionMessage('The `themes` configuration parameter must be an array.'); + $suiteEvent = $this->getSuiteEvent(); $symlinker = new Symlinker([ 'wpRootFolder' => __DIR__, 'themes' => 'not-an-array', ], []); - $symlinker->onModuleInit(new SuiteEvent()); + $symlinker->onModuleInit($suiteEvent); } public function test_without_plugins_or_themes(): void @@ -78,18 +95,19 @@ public function test_without_plugins_or_themes(): void $workingDir = FS::tmpDir('symlinker_'); $wpRoot = FS::tmpDir('symlinker_'); Installation::scaffold($wpRoot); + $suiteEvent = $this->getSuiteEvent(); $symlinker = new Symlinker([ 'wpRootFolder' => $wpRoot, ], []); - $this->assertInIsolation(static function () use ($symlinker, $workingDir) { + $this->assertInIsolation(static function () use ($symlinker, $workingDir, $suiteEvent) { chdir($workingDir); Assert::assertSame($workingDir, getcwd()); - $symlinker->onModuleInit(new SuiteEvent()); - $symlinker->afterSuite(new SuiteEvent()); + $symlinker->onModuleInit($suiteEvent); + $symlinker->afterSuite($suiteEvent); }); } @@ -105,7 +123,6 @@ public function test_throws_if_plugin_file_does_not_exist(): void $this->expectException(ModuleConfigException::class); $this->expectExceptionMessage('Plugin file not-a-file/plugin.php does not exist.'); - $symlinker = new Symlinker([ 'wpRootFolder' => $wpRoot, 'plugins' => [ @@ -200,8 +217,9 @@ function theme_2_some_function() { ]); $wpRoot = FS::tmpDir('symlinker_'); Installation::scaffold($wpRoot); + $suiteEvent = $this->getSuiteEvent(); - $this->assertInIsolation(static function () use ($workingDir, $wpRoot) { + $this->assertInIsolation(static function () use ($workingDir, $wpRoot, $suiteEvent) { chdir($workingDir); Assert::assertSame($workingDir, getcwd()); @@ -228,7 +246,7 @@ function theme_2_some_function() { Assert::assertFileDoesNotExist($wpRoot . '/wp-content/themes/theme-2/index.php'); Assert::assertFileDoesNotExist($wpRoot . '/wp-content/themes/theme-2/functions.php'); - $symlinker->onModuleInit(new SuiteEvent()); + $symlinker->onModuleInit($suiteEvent); Assert::assertFileExists($wpRoot . '/wp-content/plugins/plugin-1/plugin-1.php'); Assert::assertFileExists($wpRoot . '/wp-content/plugins/plugin-2/main.php'); @@ -239,7 +257,7 @@ function theme_2_some_function() { Assert::assertFileExists($wpRoot . '/wp-content/themes/theme-2/index.php'); Assert::assertFileExists($wpRoot . '/wp-content/themes/theme-2/functions.php'); - $symlinker->afterSuite(new SuiteEvent()); + $symlinker->afterSuite($suiteEvent); Assert::assertFileDoesNotExist($wpRoot . '/wp-content/plugins/plugin-1/plugin-1.php'); Assert::assertFileDoesNotExist($wpRoot . '/wp-content/plugins/plugin-2/main.php'); @@ -318,8 +336,9 @@ function theme_2_some_function() { ]); $wpRoot = FS::tmpDir('symlinker_'); Installation::scaffold($wpRoot); + $suiteEvent = $this->getSuiteEvent(); - $this->assertInIsolation(static function () use ($workingDir, $wpRoot) { + $this->assertInIsolation(static function () use ($workingDir, $wpRoot, $suiteEvent) { chdir($workingDir); Assert::assertSame($workingDir, getcwd()); @@ -346,7 +365,7 @@ function theme_2_some_function() { Assert::assertFileDoesNotExist($wpRoot . '/wp-content/themes/theme-2/index.php'); Assert::assertFileDoesNotExist($wpRoot . '/wp-content/themes/theme-2/functions.php'); - $symlinker->onModuleInit(new SuiteEvent()); + $symlinker->onModuleInit($suiteEvent); Assert::assertFileExists($wpRoot . '/wp-content/plugins/plugin-1/plugin-1.php'); Assert::assertFileExists($wpRoot . '/wp-content/plugins/plugin-2/main.php'); @@ -357,7 +376,7 @@ function theme_2_some_function() { Assert::assertFileExists($wpRoot . '/wp-content/themes/theme-2/index.php'); Assert::assertFileExists($wpRoot . '/wp-content/themes/theme-2/functions.php'); - $symlinker->afterSuite(new SuiteEvent()); + $symlinker->afterSuite($suiteEvent); Assert::assertFileDoesNotExist($wpRoot . '/wp-content/plugins/plugin-1/plugin-1.php'); Assert::assertFileDoesNotExist($wpRoot . '/wp-content/plugins/plugin-2/main.php'); @@ -436,8 +455,9 @@ function theme_2_some_function() { ]); $wpRoot = FS::tmpDir('symlinker_'); Installation::scaffold($wpRoot); + $suiteEvent = $this->getSuiteEvent(); - $this->assertInIsolation(static function () use ($workingDir, $wpRoot) { + $this->assertInIsolation(static function () use ($workingDir, $wpRoot, $suiteEvent) { chdir($workingDir); Assert::assertSame($workingDir, getcwd()); @@ -463,7 +483,7 @@ function theme_2_some_function() { Assert::assertFileDoesNotExist($wpRoot . '/wp-content/themes/theme-2/index.php'); Assert::assertFileDoesNotExist($wpRoot . '/wp-content/themes/theme-2/functions.php'); - $symlinker->onModuleInit(new SuiteEvent()); + $symlinker->onModuleInit($suiteEvent); Assert::assertFileExists($wpRoot . '/wp-content/plugins/plugin-1/plugin-1.php'); Assert::assertFileExists($wpRoot . '/wp-content/plugins/plugin-2/main.php'); @@ -474,7 +494,7 @@ function theme_2_some_function() { Assert::assertFileExists($wpRoot . '/wp-content/themes/theme-2/index.php'); Assert::assertFileExists($wpRoot . '/wp-content/themes/theme-2/functions.php'); - $symlinker->afterSuite(new SuiteEvent()); + $symlinker->afterSuite($suiteEvent); Assert::assertFileExists($wpRoot . '/wp-content/plugins/plugin-1/plugin-1.php'); Assert::assertFileExists($wpRoot . '/wp-content/plugins/plugin-2/main.php'); @@ -553,8 +573,9 @@ function theme_2_some_function() { ]); $wpRoot = FS::tmpDir('symlinker_'); Installation::scaffold($wpRoot); + $suiteEvent = $this->getSuiteEvent(); - $this->assertInIsolation(static function () use ($workingDir, $wpRoot) { + $this->assertInIsolation(static function () use ($workingDir, $wpRoot, $suiteEvent) { chdir($workingDir); Assert::assertSame($workingDir, getcwd()); @@ -581,7 +602,7 @@ function theme_2_some_function() { Assert::assertFileDoesNotExist($wpRoot . '/wp-content/themes/theme-2/index.php'); Assert::assertFileDoesNotExist($wpRoot . '/wp-content/themes/theme-2/functions.php'); - $symlinker->onModuleInit(new SuiteEvent()); + $symlinker->onModuleInit($suiteEvent); Assert::assertFileExists($wpRoot . '/wp-content/plugins/plugin-1/plugin-1.php'); Assert::assertFileExists($wpRoot . '/wp-content/plugins/plugin-2/main.php'); @@ -592,7 +613,7 @@ function theme_2_some_function() { Assert::assertFileExists($wpRoot . '/wp-content/themes/theme-2/index.php'); Assert::assertFileExists($wpRoot . '/wp-content/themes/theme-2/functions.php'); - $symlinker->afterSuite(new SuiteEvent()); + $symlinker->afterSuite($suiteEvent); Assert::assertFileExists($wpRoot . '/wp-content/plugins/plugin-1/plugin-1.php'); Assert::assertFileExists($wpRoot . '/wp-content/plugins/plugin-2/main.php'); @@ -671,8 +692,9 @@ function theme_2_some_function() { ]); $wpRoot = FS::tmpDir('symlinker_'); Installation::scaffold($wpRoot); + $suiteEvent = $this->getSuiteEvent(); - $this->assertInIsolation(static function () use ($workingDir, $wpRoot) { + $this->assertInIsolation(static function () use ($workingDir, $wpRoot, $suiteEvent) { chdir($workingDir); Assert::assertSame($workingDir, getcwd()); @@ -708,7 +730,7 @@ function theme_2_some_function() { Assert::assertFileExists($wpRoot . '/wp-content/themes/theme-2/index.php'); Assert::assertFileExists($wpRoot . '/wp-content/themes/theme-2/functions.php'); - $symlinker->onModuleInit(new SuiteEvent()); + $symlinker->onModuleInit($suiteEvent); Assert::assertFileExists($wpRoot . '/wp-content/plugins/plugin-1/plugin-1.php'); Assert::assertFileExists($wpRoot . '/wp-content/plugins/plugin-2/main.php'); @@ -719,7 +741,7 @@ function theme_2_some_function() { Assert::assertFileExists($wpRoot . '/wp-content/themes/theme-2/index.php'); Assert::assertFileExists($wpRoot . '/wp-content/themes/theme-2/functions.php'); - $symlinker->afterSuite(new SuiteEvent()); + $symlinker->afterSuite($suiteEvent); Assert::assertFileExists($wpRoot . '/wp-content/plugins/plugin-1/plugin-1.php'); Assert::assertFileExists($wpRoot . '/wp-content/plugins/plugin-2/main.php'); @@ -767,13 +789,14 @@ function activate_plugin_2(){ $wpRoot = FS::tmpDir('symlinker_'); $otherDir = FS::tmpDir('symlinker_'); Installation::scaffold($wpRoot); + $suiteEvent = $this->getSuiteEvent(); $this->expectException(ModuleException::class); $this->expectExceptionMessage( "Could not symlink plugin $workingDir/vendor/acme/plugin-2 to $wpRoot/wp-content/plugins/plugin-2: link already exists and target is $otherDir." ); - $this->assertInIsolation(static function () use ($workingDir, $wpRoot, $otherDir) { + $this->assertInIsolation(static function () use ($workingDir, $wpRoot, $otherDir, $suiteEvent) { chdir($workingDir); Assert::assertSame($workingDir, getcwd()); @@ -794,7 +817,7 @@ function activate_plugin_2(){ throw new \RuntimeException('Could not create symlinks in ' . $wpRoot); } - $symlinker->onModuleInit(new SuiteEvent()); + $symlinker->onModuleInit($suiteEvent); }); } @@ -809,8 +832,9 @@ function plugin_1_canary() {} ]); $wpRoot = FS::tmpDir('symlinker_'); Installation::scaffold($wpRoot); + $suiteEvent = $this->getSuiteEvent(); - $this->assertInIsolation(static function () use ($workingDir, $wpRoot) { + $this->assertInIsolation(static function () use ($workingDir, $wpRoot, $suiteEvent) { chdir($workingDir); Assert::assertSame($workingDir, getcwd()); @@ -826,7 +850,7 @@ function plugin_1_canary() {} Assert::assertFileDoesNotExist($wpRoot . "/wp-content/plugins/{$workDirBasename}/plugin.php"); - $symlinker->onModuleInit(new SuiteEvent()); + $symlinker->onModuleInit($suiteEvent); Assert::assertFileExists($wpRoot . "/wp-content/plugins/{$workDirBasename}/plugin.php"); Assert::assertTrue(is_link($wpRoot . "/wp-content/plugins/{$workDirBasename}")); From 8e8e2122e4812286bfef0295fd50025413d819f5 Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Tue, 25 Jun 2024 10:54:26 +0200 Subject: [PATCH 3/6] refactor(WPBrowser) clean Symlinker setup output --- src/Project/ContentProject.php | 10 +++------- ...ould_scaffold_for_child_theme_correctly__0.snapshot | 9 ++++----- ...old_for_plugin_with_non_plugin_php_file__0.snapshot | 9 ++++----- ...caffold_for_plugin_with_plugin_php_file__0.snapshot | 9 ++++----- ...st__should_scaffold_for_theme_correctly__0.snapshot | 9 ++++----- 5 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/Project/ContentProject.php b/src/Project/ContentProject.php index f635e4eda..28ebdde44 100644 --- a/src/Project/ContentProject.php +++ b/src/Project/ContentProject.php @@ -115,16 +115,12 @@ public function setup(): void EOT; - $symlinkerConfig = [ - 'wpRootFolder' => '%WORDPRESS_ROOT_DIR%', - 'plugins' => [], - 'themes' => [] - ]; + $symlinkerConfig = [ 'wpRootFolder' => '%WORDPRESS_ROOT_DIR%' ]; if ($this instanceof PluginProject) { - $symlinkerConfig['plugins'][] = '.'; + $symlinkerConfig['plugins'] = ['.']; } elseif ($this instanceof ThemeProject) { - $symlinkerConfig['themes'][] = '.'; + $symlinkerConfig['themes'] = ['.']; } $this->testEnvironment->extensionsEnabled = [ diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_child_theme_correctly__0.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_child_theme_correctly__0.snapshot index 491ac0733..a400b43d1 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_child_theme_correctly__0.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_child_theme_correctly__0.snapshot @@ -272,8 +272,8 @@ 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:47453 -WORDPRESS_DOMAIN=localhost:47453 +WORDPRESS_URL=http://localhost:8970 +WORDPRESS_DOMAIN=localhost:8970 WORDPRESS_ADMIN_PATH=/wp-admin # The username and password of the administrator user of the WordPress site used in end-to-end tests. @@ -282,10 +282,10 @@ 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=43984 +CHROMEDRIVER_PORT=43956 # The port on which the PHP built-in server will serve the WordPress installation. -BUILTIN_SERVER_PORT=47453 +BUILTIN_SERVER_PORT=8970 <<< /tests/.env <<< @@ -327,7 +327,6 @@ extensions: DB_FILE: db.sqlite lucatume\WPBrowser\Extension\Symlinker: wpRootFolder: '%WORDPRESS_ROOT_DIR%' - plugins: { } themes: - . commands: diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_non_plugin_php_file__0.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_non_plugin_php_file__0.snapshot index 316776553..b48a1b4d4 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_non_plugin_php_file__0.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_non_plugin_php_file__0.snapshot @@ -267,8 +267,8 @@ 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:42934 -WORDPRESS_DOMAIN=localhost:42934 +WORDPRESS_URL=http://localhost:27090 +WORDPRESS_DOMAIN=localhost:27090 WORDPRESS_ADMIN_PATH=/wp-admin # The username and password of the administrator user of the WordPress site used in end-to-end tests. @@ -277,10 +277,10 @@ 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=44670 +CHROMEDRIVER_PORT=55678 # The port on which the PHP built-in server will serve the WordPress installation. -BUILTIN_SERVER_PORT=42934 +BUILTIN_SERVER_PORT=27090 <<< /tests/.env <<< @@ -324,7 +324,6 @@ extensions: wpRootFolder: '%WORDPRESS_ROOT_DIR%' plugins: - . - themes: { } commands: - lucatume\WPBrowser\Command\RunOriginal - lucatume\WPBrowser\Command\RunAll diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_plugin_php_file__0.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_plugin_php_file__0.snapshot index 246a25dc4..84bb022ec 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_plugin_php_file__0.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_plugin_php_file__0.snapshot @@ -272,8 +272,8 @@ 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:16769 -WORDPRESS_DOMAIN=localhost:16769 +WORDPRESS_URL=http://localhost:45130 +WORDPRESS_DOMAIN=localhost:45130 WORDPRESS_ADMIN_PATH=/wp-admin # The username and password of the administrator user of the WordPress site used in end-to-end tests. @@ -282,10 +282,10 @@ 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=20529 +CHROMEDRIVER_PORT=53682 # The port on which the PHP built-in server will serve the WordPress installation. -BUILTIN_SERVER_PORT=16769 +BUILTIN_SERVER_PORT=45130 <<< /tests/.env <<< @@ -329,7 +329,6 @@ extensions: wpRootFolder: '%WORDPRESS_ROOT_DIR%' plugins: - . - themes: { } commands: - lucatume\WPBrowser\Command\RunOriginal - lucatume\WPBrowser\Command\RunAll diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_theme_correctly__0.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_theme_correctly__0.snapshot index 2b3f7034b..f489b8c62 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_theme_correctly__0.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_theme_correctly__0.snapshot @@ -272,8 +272,8 @@ 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:8847 -WORDPRESS_DOMAIN=localhost:8847 +WORDPRESS_URL=http://localhost:32075 +WORDPRESS_DOMAIN=localhost:32075 WORDPRESS_ADMIN_PATH=/wp-admin # The username and password of the administrator user of the WordPress site used in end-to-end tests. @@ -282,10 +282,10 @@ 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=7561 +CHROMEDRIVER_PORT=26026 # The port on which the PHP built-in server will serve the WordPress installation. -BUILTIN_SERVER_PORT=8847 +BUILTIN_SERVER_PORT=32075 <<< /tests/.env <<< @@ -327,7 +327,6 @@ extensions: DB_FILE: db.sqlite lucatume\WPBrowser\Extension\Symlinker: wpRootFolder: '%WORDPRESS_ROOT_DIR%' - plugins: { } themes: - . commands: From 96587620c80a0655df24360ff4a3799193868da6 Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Wed, 26 Jun 2024 08:27:48 +0200 Subject: [PATCH 4/6] build(composer.json) fix strict PSR check --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fac292a68..aaff6ca95 100644 --- a/composer.json +++ b/composer.json @@ -67,7 +67,8 @@ }, "autoload-dev": { "psr-4": { - "lucatume\\WPBrowser\\Tests\\": "tests/_support", + "lucatume\\WPBrowser\\Tests\\FSTemplates\\": "tests/_support/FSTemplates", + "lucatume\\WPBrowser\\Tests\\Traits\\": "tests/_support/Traits", "lucatume\\Rector\\": "config/rector/src" } }, From 0753edabccc0d16799847e2a7898d9126d0cf584 Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Wed, 26 Jun 2024 08:59:49 +0200 Subject: [PATCH 5/6] doc(CHANGELOG.md) add missing change entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23b73a504..81ca3d825 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [unreleased] Unreleased +### Changed + +- Updated documentation entry in EndToEnd suite bootstrap file. + ## [4.2.4] 2024-06-06; ### Added From 442e488aec53278b8e3b2b6ee8f688bd4315b09b Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Wed, 26 Jun 2024 09:01:47 +0200 Subject: [PATCH 6/6] doc(CHANGELOG.md) update to version 4.2.5 --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81ca3d825..cdba43a84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [unreleased] Unreleased +## [4.2.5] 2024-06-26; + ### Changed - Updated documentation entry in EndToEnd suite bootstrap file. @@ -2225,4 +2227,5 @@ Read the [migration guide here](https://wpbrowser.wptestkit.dev/migration/from-v [4.2.1]: https://github.com/lucatume/wp-browser/compare/4.2.0...4.2.1 [4.2.3]: https://github.com/lucatume/wp-browser/compare/4.2.1...4.2.3 [4.2.4]: https://github.com/lucatume/wp-browser/compare/4.2.3...4.2.4 -[unreleased]: https://github.com/lucatume/wp-browser/compare/4.2.4...HEAD +[4.2.5]: https://github.com/lucatume/wp-browser/compare/4.2.4...4.2.5 +[unreleased]: https://github.com/lucatume/wp-browser/compare/4.2.5...HEAD