Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Switch to using SQLite for the tests #67

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@

/composer.lock
/package-lock.json
/tests/.env
/tests/hyper-schema/index.js
2 changes: 0 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 21 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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 [email protected] --skip-email",
"wp language core install de_DE it_IT ar he_IL",

Expand Down
4 changes: 0 additions & 4 deletions tests/.env.dist

This file was deleted.

21 changes: 7 additions & 14 deletions tests/wp-config.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
<?php

$_root_dir = getcwd();

require_once $_root_dir . '/vendor/autoload.php';

$_env_dir = __DIR__;

if ( is_readable( $_env_dir . '/.env' ) ) {
Dotenv\Dotenv::createImmutable( $_env_dir )->load();
}

// Configuration needed during testing:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_DISPLAY', true );
Expand All @@ -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 );
Expand Down
Loading