Skip to content

Commit

Permalink
refactor(WPLoader) make _loadWordPress public and internal for testin…
Browse files Browse the repository at this point in the history
…g purposes
  • Loading branch information
lucatume committed Jul 31, 2024
1 parent f3dc678 commit b1553ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/Module/WPLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ public function _initialize(): void
$this->debug('The WordPress installation will be loaded after all other modules have been initialized.');

Dispatcher::addListener(Events::SUITE_BEFORE, function (): void {
$this->loadWordPress(true);
$this->_loadWordPress(true);
});

return;
Expand All @@ -503,7 +503,7 @@ public function _initialize(): void

WPTestCase::beStrictAboutWpdbConnectionId($config['beStrictAboutWpdbConnectionId']);

$this->loadWordPress();
$this->_loadWordPress();
}

/**
Expand Down Expand Up @@ -553,10 +553,11 @@ private function ensureDbModuleCompat(): void
/**
* Loads WordPress calling the bootstrap file.
*
*
* @throws Throwable
*
* @internal This method is not covered by the backward compatibility promise for wp-browser.
*/
private function loadWordPress(bool $loadOnly = false): void
public function _loadWordPress(bool $loadOnly = false): void
{
$this->loadConfigFiles();

Expand Down
10 changes: 5 additions & 5 deletions tests/unit/lucatume/WPBrowser/Module/WPLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace lucatume\WPBrowser\Module;

use Codeception\Event\SuiteEvent;
use Codeception\Events;
use Codeception\Exception\ModuleConfigException;
use Codeception\Exception\ModuleException;
Expand Down Expand Up @@ -656,8 +657,7 @@ public function should_throw_if_load_only_and_word_press_not_installed(): void

$this->assertInIsolation(static function () use ($wpRootDir, $wpLoader) {
$wpLoader->_initialize();

Dispatcher::dispatch(Events::SUITE_BEFORE);
$wpLoader->_loadWordPress();
});
}

Expand Down Expand Up @@ -710,7 +710,7 @@ public function should_load_word_press_before_suite_if_load_only_w_config_files(
$actions[] = WPLoader::EVENT_AFTER_LOADONLY;
});

Dispatcher::dispatch(Events::SUITE_BEFORE);
$wpLoader->_loadWordPress();

Assert::assertEquals('test_file_002.php', getenv('LOADED_2'));
Assert::assertEquals($wpRootDir . '/', ABSPATH);
Expand Down Expand Up @@ -800,7 +800,7 @@ public function should_not_throw_when_load_only_true_and_using_db_module(
$this->assertInIsolation(static function () use ($wpLoader, $wpRootDir) {
$wpLoader->_initialize();

Dispatcher::dispatch(Events::SUITE_BEFORE);
$wpLoader->_loadWordPress();

Assert::assertEquals($wpRootDir . '/', ABSPATH);
});
Expand Down Expand Up @@ -1754,7 +1754,7 @@ public function should_initialize_correctly_with_sqlite_database_in_load_only_mo

$this->assertInIsolation(static function () use ($wpLoader) {
$wpLoader->_initialize();
Dispatcher::dispatch(Events::SUITE_BEFORE);
$wpLoader->_loadWordPress();

Assert::assertTrue(function_exists('do_action'));
Assert::assertInstanceOf(\WP_User::class, wp_get_current_user());
Expand Down

0 comments on commit b1553ba

Please sign in to comment.