Skip to content

Commit

Permalink
Merge pull request #307 from alleyinteractive/install-loaded
Browse files Browse the repository at this point in the history
Changing the loaded() action in installation manager to muplugins_loaded
  • Loading branch information
srtfisher authored Aug 1, 2022
2 parents a06e868 + d4f9590 commit f110421
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v0.5.1 - 2022-08-01

* Fixing issue with testing installation callback.

## v0.5.0 - 2022-07-29

- Prevent external requests during unit testing by @srtfisher in https://github.com/alleyinteractive/mantle-framework/pull/293
Expand Down
10 changes: 5 additions & 5 deletions src/mantle/testing/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

use function Mantle\Support\Helpers\tap;

require_once __DIR__ . '/preload.php';

/**
* Retrieve an instance of the Installation Manager
*
Expand All @@ -21,20 +23,18 @@
* @return Installation_Manager
*/
function manager(): Installation_Manager {
require_once __DIR__ . '/preload.php';

return Installation_Manager::instance();
}

/**
* Install the Mantle Testing Framework
*
* @param callable $callback_after_preload Callback to invoke before WordPress is loaded.
* @param callable $callback Callback to invoke once the installation has begun.
* @return Installation_Manager
*/
function install( callable $callback_after_preload = null ): Installation_Manager {
function install( callable $callback = null ): Installation_Manager {
return tap(
manager(),
fn ( Installation_Manager $manager ) => $manager->after( $callback_after_preload ),
fn ( Installation_Manager $manager ) => $manager->before( $callback ),
)->install();
}
6 changes: 3 additions & 3 deletions src/mantle/testing/class-installation-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ public function after( ?callable $callback ) {
}

/**
* Define a callback to be invoked after WordPress is loaded.
* Define a callback to be invoked using the 'muplugins_loaded' hook.
*
* @param callable $callback Callback to invoke after WordPress is loaded.
* @param callable $callback Callback to invoke on 'muplugins_loaded'.
* @return static
*/
public function loaded( ?callable $callback ) {
return $this->on( 'wp_loaded', $callback );
return $this->on( 'muplugins_loaded', $callback );
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/mantle/testkit/concerns/trait-installs-wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public static function installs_wordpress_set_up_before_class(): void {
*/
$callback = function_exists( 'mantle_after_wordpress_install' ) ? 'mantle_after_wordpress_install' : null;

\Mantle\Testing\install( $callback );
\Mantle\Testing\manager()
->after( $callback )
->install();

$installed = true;
}
Expand Down

0 comments on commit f110421

Please sign in to comment.