Last active
March 24, 2019 23:55
-
-
Save seothemes/3ebdf1dc5061295cdf0929c13d85d265 to your computer and use it in GitHub Desktop.
WP PhpUnit test config and bootstrap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Bootstraps the WordPress Integration Tests | |
* | |
* File should be placed in tests/phpunit/integration. | |
* | |
* @since 1.5.0 | |
* @license GNU-2.0+ | |
*/ | |
if ( ! file_exists( '../../../wp-content' ) ) { | |
trigger_error( 'Unable to run the integration tests, as the wp-content folder does not exist.', E_USER_ERROR ); // @codingStandardsIgnoreLine. | |
} | |
// Define testing constants. | |
define( 'THEME_TESTS_DIR', __DIR__ ); | |
define( 'THEME_DIR', dirname( dirname( dirname( __DIR__ ) ) ) . DIRECTORY_SEPARATOR ); | |
define( 'WP_CONTENT_DIR', dirname( dirname( dirname( getcwd() ) ) ) . '/wp-content/' ); | |
if ( ! defined( 'WP_PLUGIN_DIR' ) ) { | |
define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . 'plugins/' ); // @codingStandardsIgnoreLine. | |
} | |
// Composer autoloader must be loaded before WP_PHPUNIT__DIR will be available | |
require_once THEME_DIR . 'vendor/autoload.php'; | |
// Give access to tests_add_filter() function. | |
require_once getenv( 'WP_PHPUNIT__DIR' ) . '/includes/functions.php'; | |
/** | |
* test set up, plugin activation, etc. | |
*/ | |
tests_add_filter( 'setup_theme', function () { | |
register_theme_directory( WP_CONTENT_DIR . 'themes' ); | |
switch_theme( basename( THEME_DIR ) ); | |
} ); | |
// Start up the WP testing environment. | |
require getenv( 'WP_PHPUNIT__DIR' ) . '/includes/bootstrap.php'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"test-integration": "\"vendor/bin/phpunit\" --testsuite integration --configuration tests/phpunit/integration/phpunit.xml.dist --color=always" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd" | |
bootstrap="bootstrap.php" | |
backupGlobals="false" | |
colors="true" | |
beStrictAboutCoversAnnotation="true" | |
beStrictAboutOutputDuringTests="true" | |
beStrictAboutTestsThatDoNotTestAnything="true" | |
beStrictAboutTodoAnnotatedTests="true" | |
convertErrorsToExceptions="true" | |
convertNoticesToExceptions="true" | |
convertWarningsToExceptions="true" | |
verbose="true"> | |
<php> | |
<env name="WP_PHPUNIT__TESTS_CONFIG" value="tests/config.php" /> | |
</php> | |
<testsuites> | |
<testsuite name="integration"> | |
<directory suffix=".php">.</directory> | |
</testsuite> | |
</testsuites> | |
</phpunit> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Place in tests/ directory. | |
*/ | |
/* Path to the WordPress codebase you'd like to test. Add a forward slash in the end. */ | |
define( 'ABSPATH', dirname( dirname( dirname( dirname( __DIR__ ) ) ) ) . DIRECTORY_SEPARATOR ); | |
/* | |
* Path to the theme to test with. | |
* | |
* The 'default' theme is symlinked from test/phpunit/data/themedir1/default into | |
* the themes directory of the WordPress installation defined above. | |
*/ | |
define( 'WP_DEFAULT_THEME', 'default' ); | |
// Test with multisite enabled. | |
// Alternatively, use the tests/phpunit/multisite.xml configuration file. | |
// define( 'WP_TESTS_MULTISITE', true ); | |
// Force known bugs to be run. | |
// Tests with an associated Trac ticket that is still open are normally skipped. | |
// define( 'WP_TESTS_FORCE_KNOWN_BUGS', true ); | |
// Test with WordPress debug mode (default). | |
define( 'WP_DEBUG', true ); | |
// ** MySQL settings ** // | |
// This configuration file will be used by the copy of WordPress being tested. | |
// wordpress/wp-config.php will be ignored. | |
// 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_DB_NAME' ) ?: 'tests' ); | |
define( 'DB_USER', getenv( 'WP_DB_USER' ) ?: 'root' ); | |
define( 'DB_PASSWORD', getenv( 'WP_DB_PASS' ) ?: '' ); | |
define( 'DB_HOST', 'localhost' ); | |
define( 'DB_CHARSET', 'utf8' ); | |
define( 'DB_COLLATE', '' ); | |
/**#@+ | |
* Authentication Unique Keys and Salts. | |
* | |
* Change these to different unique phrases! | |
* You can generate these using the | |
* {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service} | |
*/ | |
define( 'AUTH_KEY', 'put your unique phrase here' ); | |
define( 'SECURE_AUTH_KEY', 'put your unique phrase here' ); | |
define( 'LOGGED_IN_KEY', 'put your unique phrase here' ); | |
define( 'NONCE_KEY', 'put your unique phrase here' ); | |
define( 'AUTH_SALT', 'put your unique phrase here' ); | |
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' ); | |
define( 'LOGGED_IN_SALT', 'put your unique phrase here' ); | |
define( 'NONCE_SALT', 'put your unique phrase here' ); | |
$table_prefix = 'wpphpunittests_'; // Only numbers, letters, and underscores please! | |
define( 'WP_TESTS_DOMAIN', 'example.org' ); | |
define( 'WP_TESTS_EMAIL', '[email protected]' ); | |
define( 'WP_TESTS_TITLE', 'Test Blog' ); | |
define( 'WP_PHP_BINARY', 'php' ); | |
define( 'WPLANG', '' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment