Skip to content

Commit

Permalink
Merge branch 'main' into release/0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
anubisthejackle authored Oct 6, 2022
2 parents 6a761ef + 85769c1 commit 8489daf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
29 changes: 17 additions & 12 deletions src/mantle/testing/class-test-case.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ abstract public function create_application(): Application;
*/
public static function setUpBeforeClass(): void {
static::register_traits();
if ( isset( static::$test_uses[ Refresh_Database::class ] ) ) {
static::refresh_database_pre_setup_before_class();
}


if ( ! empty( static::$test_uses ) ) {

static::get_test_case_traits()
Expand Down Expand Up @@ -239,21 +236,29 @@ protected static function get_test_case_traits(): Collection {
// Boot traits on the test case.
$traits = array_values( class_uses_recursive( static::class ) );

$priority_traits = [
// This order is deliberate.
Refresh_Database::class,
WordPress_Authentication::class,
Admin_Screen::class,
Network_Admin_Screen::class,
];
$priority_traits = static::get_priority_traits();

// Combine the priority and non-priority traits.
return collect()
->merge( array_intersect( $priority_traits, $traits ) )
->merge( array_diff( $traits, $priority_traits ) )
->unique();
}


/**
* Get an array of priority traits.
*
* @return array
*/
protected static function get_priority_traits(): array {
return [
// This order is deliberate.
Refresh_Database::class,
WordPress_Authentication::class,
Admin_Screen::class,
Network_Admin_Screen::class,
];
}
/**
* Register the traits that this test case uses.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/mantle/testing/concerns/trait-refresh-database.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait Refresh_Database {
/**
* Routines to run before setupBeforeClass.
*/
public static function refresh_database_pre_setup_before_class() {
public static function refresh_database_setup_before_class() {
global $wpdb;

$wpdb->suppress_errors = false;
Expand Down
16 changes: 16 additions & 0 deletions src/mantle/testkit/class-test-case.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Mantle\Testkit;

use Mantle\Testkit\Concerns\Create_Application;
use Mantle\Testkit\Concerns\Installs_Wordpress;
use Mantle\Testing\Test_Case as Testing_Test_Case;

/**
Expand All @@ -18,4 +19,19 @@
*/
abstract class Test_Case extends Testing_Test_Case {
use Create_Application;

/**
* Add Testkit specific traits to Priority list.
*
* @return array
*/
protected static function get_priority_traits(): array {
$parent_priorities = parent::get_priority_traits();

$priorities = [
Installs_Wordpress::class,
];

return array_merge( $priorities, $parent_priorities );
}
}

0 comments on commit 8489daf

Please sign in to comment.