Skip to content

Commit

Permalink
Merge pull request #28 from wp-cli/27-disable-cron-on-tests
Browse files Browse the repository at this point in the history
Disable WP Cron by default for Behat tests
  • Loading branch information
schlessera authored Nov 17, 2018
2 parents 32de18d + 2409f0e commit 4ec287a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
11 changes: 9 additions & 2 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -741,10 +741,13 @@ public function install_wp( $subdir = '' ) {

$subdir = $this->replace_variables( $subdir );

// Disable WP Cron by default to avoid bogus HTTP requests in CLI context.
$config_extra_php = "if ( ! defined( 'DISABLE_WP_CRON' ) ) { define( 'DISABLE_WP_CRON', true ); }\n";

$this->create_db();
$this->create_run_dir();
$this->download_wp( $subdir );
$this->create_config( $subdir );
$this->create_config( $subdir, $config_extra_php );

$install_args = array(
'url' => 'http://example.com',
Expand Down Expand Up @@ -786,7 +789,11 @@ public function install_wp_with_composer( $vendor_directory = 'vendor' ) {
$this->composer_command( 'config extra.wordpress-install-dir WordPress --no-interaction' );
$this->composer_command( 'require johnpbloch/wordpress-core-installer johnpbloch/wordpress-core --optimize-autoloader --no-interaction' );

$config_extra_php = "require_once dirname(__DIR__) . '/" . $vendor_directory . "/autoload.php';";
// Disable WP Cron by default to avoid bogus HTTP requests in CLI context.
$config_extra_php = "if ( ! defined( 'DISABLE_WP_CRON' ) ) { define( 'DISABLE_WP_CRON', true ); }\n";

$config_extra_php .= "require_once dirname(__DIR__) . '/" . $vendor_directory . "/autoload.php';\n";

$this->create_config( 'WordPress', $config_extra_php );

$install_args = array(
Expand Down
10 changes: 0 additions & 10 deletions features/load-wp-cli.feature

This file was deleted.

25 changes: 25 additions & 0 deletions features/testing.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Feature: Test that WP-CLI loads.

Scenario: WP-CLI loads for your tests
Given a WP install

When I run `wp eval 'echo "Hello world.";'`
Then STDOUT should contain:
"""
Hello world.
"""

Scenario: WP Cron is disabled by default
Given a WP install
And a test_cron.php file:
"""
<?php
$cron_disabled = defined( "DISABLE_WP_CRON" ) ? DISABLE_WP_CRON : false;
echo 'DISABLE_WP_CRON is: ' . ( $cron_disabled ? 'true' : 'false' );
"""

When I run `wp eval-file test_cron.php`
Then STDOUT should be:
"""
DISABLE_WP_CRON is: true
"""

0 comments on commit 4ec287a

Please sign in to comment.