From 7b2fd5ae2af115e66d982db7bc4ec23577cd1038 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Thu, 5 Oct 2023 23:16:34 +0200 Subject: [PATCH] Switch to using SQLite for the tests. --- .gitignore | 1 - CONTRIBUTING.md | 2 -- composer.json | 25 +++++++++++++++++++++---- tests/.env.dist | 4 ---- tests/wp-config.php | 21 +++++++-------------- 5 files changed, 28 insertions(+), 25 deletions(-) delete mode 100644 tests/.env.dist diff --git a/.gitignore b/.gitignore index 82776d3..ff2d5b5 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,4 @@ /composer.lock /package-lock.json -/tests/.env /tests/hyper-schema/index.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 71a87b5..15c452e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -25,8 +25,6 @@ There is no fully automatic process to create these schemas. A schema for a PHP npm install -3. If you want to run the tests locally, check the MySQL database credentials in the `tests/.env` file and amend them as necessary. - ## Creating a REST API response schema The WordPress REST API response doesn't fully adhere to the JSON schema spec, so we need to tweak its output in order to generate a valid schema and to increase its specificity. diff --git a/composer.json b/composer.json index 65f7dff..d7a8a11 100644 --- a/composer.json +++ b/composer.json @@ -9,17 +9,29 @@ "homepage": "https://johnblackbourn.com/" } ], + "repositories": [ + { + "type": "composer", + "url": "https://wpackagist.org", + "only": [ + "wpackagist-plugin/*", + "wpackagist-theme/*" + ] + } + ], "require": { "php": "^7 || ^8" }, "require-dev": { + "ext-sqlite3": "*", + "ext-pdo_sqlite": "*", "johnbillion/args": "1.7.0", "roots/wordpress-core-installer": "^1.0.0", "roots/wordpress-full": "~6.3.0", - "vlucas/phpdotenv": "^5", "wp-cli/core-command": "^2", "wp-cli/db-command": "^2", - "wp-cli/language-command": "^2" + "wp-cli/language-command": "^2", + "wpackagist-plugin/sqlite-database-integration": "^2.1" }, "config": { "allow-plugins": { @@ -30,18 +42,23 @@ "sort-packages": true }, "extra": { + "installer-paths": { + "tests/wordpress/wp-content/plugins/{$name}/": [ + "wpackagist-plugin/sqlite-database-integration" + ] + }, "wordpress-install-dir": "tests/wordpress" }, "scripts": { "post-update-cmd": [ - "@php -r \"! file_exists( 'tests/.env' ) && copy( 'tests/.env.dist', 'tests/.env' );\"" + "@php -r \"file_exists( 'tests/wordpress/wp-content/db.php' ) || copy( 'tests/wordpress/wp-content/plugins/sqlite-database-integration/db.copy', 'tests/wordpress/wp-content/db.php' );\"" ], "test": [ "npm run validate", "npm run build-wp-types", "npm run test-wp-types", - "wp db reset --yes", + "rm -f tests/wordpress/wp-content/database/.ht.sqlite", "wp core multisite-install --url=example.org --title=Example --admin_user=admin --admin_email=admin@example.org --skip-email", "wp language core install de_DE it_IT ar he_IL", diff --git a/tests/.env.dist b/tests/.env.dist deleted file mode 100644 index 0c521df..0000000 --- a/tests/.env.dist +++ /dev/null @@ -1,4 +0,0 @@ -WP_TESTS_DB_NAME="wordpress_test" -WP_TESTS_DB_USER="root" -WP_TESTS_DB_PASS="" -WP_TESTS_DB_HOST="localhost" diff --git a/tests/wp-config.php b/tests/wp-config.php index 391829e..ff18fa7 100644 --- a/tests/wp-config.php +++ b/tests/wp-config.php @@ -1,15 +1,5 @@ load(); -} - // Configuration needed during testing: define( 'WP_DEBUG', true ); define( 'WP_DEBUG_DISPLAY', true ); @@ -21,13 +11,16 @@ // WARNING WARNING WARNING! // These tests will DROP ALL TABLES in the database with the prefix named below. // DO NOT use a production database or one that is shared with something else. -define( 'DB_NAME', getenv( 'WP_TESTS_DB_NAME' ) ?: 'wordpress_test' ); -define( 'DB_USER', getenv( 'WP_TESTS_DB_USER' ) ?: 'root' ); -define( 'DB_PASSWORD', getenv( 'WP_TESTS_DB_PASS' ) ?: 'root' ); -define( 'DB_HOST', getenv( 'WP_TESTS_DB_HOST' ) ?: 'localhost' ); +define( 'DB_NAME', 'db.sqlite' ); +define( 'DB_USER', '' ); +define( 'DB_PASSWORD', '' ); +define( 'DB_HOST', '' ); define( 'DB_CHARSET', 'utf8' ); define( 'DB_COLLATE', '' ); +// SQLite config: +define( 'SQLITE_MAIN_FILE', __DIR__ . '/wordpress/plugins/sqlite-database-integration/load.php' ); + // Enable Multisite: define( 'WP_ALLOW_MULTISITE', true ); define( 'MULTISITE', true );