Skip to content

Commit

Permalink
Merge pull request #741 from lucatume/v35-db-import-export-docs
Browse files Browse the repository at this point in the history
Transpile #740
  • Loading branch information
lucatume authored Jun 26, 2024
2 parents df39f2b + 41bdd4e commit 04b0c88
Show file tree
Hide file tree
Showing 26 changed files with 263 additions and 215 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

- Updated documentation entry in EndToEnd suite bootstrap file.

## [3.6.4] 2024-06-06;

### Added
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
},
"autoload-dev": {
"psr-4": {
"lucatume\\WPBrowser\\Tests\\": "tests/_support"
"lucatume\\WPBrowser\\Tests\\FSTemplates\\": "tests/_support/FSTemplates",
"lucatume\\WPBrowser\\Tests\\Traits\\": "tests/_support/Traits"
}
},
"extra": {
Expand Down
6 changes: 2 additions & 4 deletions src/Project/ContentProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,10 @@ public function setup(): void
EOT;

$symlinkerConfig = [
'wpRootFolder' => '%WORDPRESS_ROOT_DIR%'
];
$symlinkerConfig = [ 'wpRootFolder' => '%WORDPRESS_ROOT_DIR%' ];

if ($this instanceof PluginProject) {
$symlinkerConfig['plugins']= ['.'];
$symlinkerConfig['plugins'] = ['.'];
} elseif ($this instanceof ThemeProject) {
$symlinkerConfig['themes'] = ['.'];
}
Expand Down
14 changes: 8 additions & 6 deletions src/Template/Wpbrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,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 <wp-cli command>` 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';
Expand Down
6 changes: 4 additions & 2 deletions src/WordPress/Database/SQLiteDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,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_%';");

Expand All @@ -293,7 +293,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) {
Expand Down Expand Up @@ -331,6 +331,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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,15 @@ modules:
* "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 <wp-cli command>` 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 <<<

Expand Down Expand Up @@ -288,8 +290,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:63999
WORDPRESS_DOMAIN=localhost:63999
WORDPRESS_URL=http://localhost:33117
WORDPRESS_DOMAIN=localhost:33117
WORDPRESS_ADMIN_PATH=/wp-admin

# The username and password of the administrator user of the WordPress site used in end-to-end tests.
Expand All @@ -298,10 +300,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=30951
CHROMEDRIVER_PORT=45469

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

<<< /tests/.env <<<

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,15 @@ modules:
* "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 <wp-cli command>` 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 <<<

Expand Down Expand Up @@ -285,8 +287,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:62570
WORDPRESS_DOMAIN=localhost:62570
WORDPRESS_URL=http://localhost:62040
WORDPRESS_DOMAIN=localhost:62040
WORDPRESS_ADMIN_PATH=/wp-admin

# The username and password of the administrator user of the WordPress site used in end-to-end tests.
Expand All @@ -295,10 +297,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=44885
CHROMEDRIVER_PORT=5257

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

<<< /.env <<<

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,15 @@ modules:
* "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 <wp-cli command>` 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 <<<

Expand Down Expand Up @@ -283,8 +285,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:22914
WORDPRESS_DOMAIN=localhost:22914
WORDPRESS_URL=http://localhost:46881
WORDPRESS_DOMAIN=localhost:46881
WORDPRESS_ADMIN_PATH=/wp-admin

# The username and password of the administrator user of the WordPress site used in end-to-end tests.
Expand All @@ -293,10 +295,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=60583
CHROMEDRIVER_PORT=7413

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

<<< /tests/.env <<<

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,15 @@ modules:
* "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 <wp-cli command>` 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 <<<

Expand Down Expand Up @@ -288,8 +290,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:38154
WORDPRESS_DOMAIN=localhost:38154
WORDPRESS_URL=http://localhost:9943
WORDPRESS_DOMAIN=localhost:9943
WORDPRESS_ADMIN_PATH=/wp-admin

# The username and password of the administrator user of the WordPress site used in end-to-end tests.
Expand All @@ -298,10 +300,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=38622
CHROMEDRIVER_PORT=28657

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

<<< /tests/.env <<<

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,15 @@ modules:
* "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 <wp-cli command>` 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 <<<

Expand Down Expand Up @@ -288,8 +290,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:24475
WORDPRESS_DOMAIN=localhost:24475
WORDPRESS_URL=http://localhost:33246
WORDPRESS_DOMAIN=localhost:33246
WORDPRESS_ADMIN_PATH=/wp-admin

# The username and password of the administrator user of the WordPress site used in end-to-end tests.
Expand All @@ -298,10 +300,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=34217
CHROMEDRIVER_PORT=45155

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

<<< /tests/.env <<<

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,15 @@ modules:
* "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 <wp-cli command>` 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 <<<

Expand Down Expand Up @@ -288,8 +290,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:37136
WORDPRESS_DOMAIN=localhost:37136
WORDPRESS_URL=http://localhost:46181
WORDPRESS_DOMAIN=localhost:46181
WORDPRESS_ADMIN_PATH=/wp-admin

# The username and password of the administrator user of the WordPress site used in end-to-end tests.
Expand All @@ -298,10 +300,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=28671
CHROMEDRIVER_PORT=37285

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

<<< /tests/.env <<<

Expand Down
Loading

0 comments on commit 04b0c88

Please sign in to comment.