Skip to content

Commit

Permalink
Merge pull request #714 from lucatume/v4-wploader-loadonly-event
Browse files Browse the repository at this point in the history
fix(WPLoader) restore loadOnly to SUITE_BEFORE
  • Loading branch information
lucatume authored Apr 7, 2024
2 parents c3a3491 + 67f5615 commit a7f4de9
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 24 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased] Unreleased

### Changed

- Load WordPress at `SUITE_BEFORE` in the `WPLoader` module, I had previously changed this to `SUITE_INIT` but that was causing issues.
- Update Core PHPUnit tests
- Update SQLite plugin.

## [4.1.5] 2024-03-28;

### Changed
Expand Down
1 change: 0 additions & 1 deletion bin/build-35-exclusions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ mkdocs.yml
README.md
tests/.env
tests/_support/_generated/*
includes/sqlite-database-integration
4 changes: 4 additions & 0 deletions config/typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ ignore-hidden = false

[default.extend-identifiers]
"RebOOter" = "RebOOter"

[default.extend-words]
# To handle the hipster default blog content about bike messengers gettin' caught in the rain.
"gettin" = "gettin"
4 changes: 4 additions & 0 deletions includes/core-phpunit/includes/abstract-testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ public function tear_down() {
*/
$GLOBALS['wp_sitemaps'] = null;

// Reset template globals.
$GLOBALS['wp_stylesheet_path'] = null;
$GLOBALS['wp_template_path'] = null;

$this->unregister_all_meta_keys();
remove_theme_support( 'html5' );
remove_filter( 'query', array( $this, '_create_temporary_tables' ) );
Expand Down
10 changes: 5 additions & 5 deletions includes/core-phpunit/includes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
* Returns a string of the required length containing random characters. Note that
* the maximum possible string length is 32.
*
* @param int $len Optional. The required length. Default 32.
* @param int $length Optional. The required length. Default 32.
* @return string The string.
*/
function rand_str( $len = 32 ) {
return substr( md5( uniqid( rand() ) ), 0, $len );
function rand_str( $length = 32 ) {
return substr( md5( uniqid( rand() ) ), 0, $length );
}

/**
* Returns a string of the required length containing random characters.
*
* @param int $len The required length.
* @param int $length The required length.
* @return string The string.
*/
function rand_long_str( $length ) {
Expand Down Expand Up @@ -49,7 +49,7 @@ function strip_ws( $txt ) {
return trim( implode( "\n", $result ) );
}

/*
/**
* Helper class for testing code that involves actions and filters.
*
* Typical use:
Expand Down
3 changes: 1 addition & 2 deletions includes/core-phpunit/includes/wp-profiler.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* A simple manually-instrumented profiler for WordPress.
*
* This records basic execution time, and a summary of the actions and SQL queries run within each block.
Expand All @@ -15,7 +15,6 @@
*
* Multiple profile blocks are permitted, and they may be nested.
*/

class WPProfiler {
public $stack;
public $profile;
Expand Down
1 change: 1 addition & 0 deletions includes/sqlite-database-integration/health-check.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function sqlite_plugin_filter_site_status_tests( $tests ) {
if ( 'sqlite' === $db_engine ) {
unset( $tests['direct']['utf8mb4_support'] );
unset( $tests['direct']['sql_server'] );
unset( $tests['direct']['persistent_object_cache'] ); // Throws an error because DB_NAME is not defined.
}

return $tests;
Expand Down
2 changes: 1 addition & 1 deletion includes/sqlite-database-integration/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: SQLite Database Integration
* Description: SQLite database driver drop-in.
* Author: The WordPress Team
* Version: 2.1.6
* Version: 2.1.7
* Requires PHP: 7.0
* Textdomain: sqlite-database-integration
*
Expand Down
2 changes: 1 addition & 1 deletion includes/sqlite-database-integration/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Contributors: wordpressdotorg, aristath
Requires at least: 6.0
Tested up to: 6.4
Requires PHP: 5.6
Stable tag: 2.1.6
Stable tag: 2.1.7
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Tags: performance, database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class WP_SQLite_Lexer {
*
* @var string[]
*/
protected const PARSER_METHODS = array(
const PARSER_METHODS = array(
// It is best to put the parsers in order of their complexity
// (ascending) and their occurrence rate (descending).
//
Expand Down Expand Up @@ -77,7 +77,7 @@ class WP_SQLite_Lexer {
*
* @var string[]
*/
protected const KEYWORD_NAME_INDICATORS = array(
const KEYWORD_NAME_INDICATORS = array(
'FROM',
'SET',
'WHERE',
Expand All @@ -89,7 +89,7 @@ class WP_SQLite_Lexer {
*
* @var string[]
*/
protected const OPERATOR_NAME_INDICATORS = array(
const OPERATOR_NAME_INDICATORS = array(
',',
'.',
);
Expand Down
2 changes: 1 addition & 1 deletion src/Iterators/Filters/ClassMethodQueriesFilter.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Keeps only quries originated by a class method call.
* Keeps only queries originated by a class method call.
*
* @package lucatume\WPBrowser\Iterators\Filters
*/
Expand Down
1 change: 1 addition & 0 deletions src/TestCase/WPTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class WPTestCase extends Unit
protected $backupStaticAttributesExcludeList = [
// WordPress
'WP_Block_Type_Registry' => ['instance'],
'WP_Block_Bindings_Registry' => ['instance'],
// wp-browser
'lucatume\WPBrowser\Events\Dispatcher' => ['eventDispatcher'],
self::class => ['coreTestCaseMap'],
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/lucatume/WPBrowser/Module/WPLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,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_INIT);
Dispatcher::dispatch(Events::SUITE_BEFORE);
});
}

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

Dispatcher::dispatch(Events::SUITE_INIT);
Dispatcher::dispatch(Events::SUITE_BEFORE);

Assert::assertEquals('test_file_002.php', getenv('LOADED_2'));
Assert::assertEquals($wpRootDir . '/', ABSPATH);
Expand Down Expand Up @@ -797,7 +797,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_INIT);
Dispatcher::dispatch(Events::SUITE_BEFORE);

Assert::assertEquals($wpRootDir . '/', ABSPATH);
});
Expand Down Expand Up @@ -1782,7 +1782,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_INIT);
Dispatcher::dispatch(Events::SUITE_BEFORE);

Assert::assertTrue(function_exists('do_action'));
Assert::assertInstanceOf(\WP_User::class, wp_get_current_user());
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/lucatume/WPBrowser/Project/PluginProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ public function should_provide_information_about_the_failure_to_activate_due_to_
$expected = "Could not activate plugin: Something went wrong. \n" .
"{{wp_root_dir}}/wp-content/plugins/acme-plugin/plugin.php:3\n" .
"This might happen because the plugin has unmet dependencies; wp-browser configuration will continue, " .
"but you will need to manually activate the plugin and update the dump in tests/Support/Data/dump.sql";
$this->assertEquals(
"but you will need to manually activate the plugin and update the dump in tests";
$this->assertStringContainsString(
$expected,
trim(str_replace($wpRootDir, '{{wp_root_dir}}', $output->fetch()))
);
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/lucatume/WPBrowser/Project/ThemeProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ public function should_provide_information_about_the_failure_to_activate_due_to_
$this->assertFalse($themeProject->activate($wpRootDir, 1234));
$expected = "Could not activate theme: Error: Current PHP version does not meet minimum requirements for Acme Theme. \n" .
"This might happen because the theme has unmet dependencies; wp-browser configuration will continue, " .
"but you will need to manually activate the theme and update the dump in tests/Support/Data/dump.sql";
$this->assertEquals(
"but you will need to manually activate the theme and update the dump in tests";
$this->assertStringContainsString(
$expected,
trim(str_replace($wpRootDir, '{{wp_root_dir}}', $output->fetch()))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,11 @@ public function should_throw_if_trying_to_convert_to_multisite(): void
}

/**
* It should throw if tryng to scaffold again
* It should throw if trying to scaffold again
*
* @test
*/
public function should_throw_if_tryng_to_scaffold_again(): void
public function should_throw_if_trying_to_scaffold_again(): void
{
$wpRootDir = FS::tmpDir('scaffolded_');
Installation::scaffold($wpRootDir, '6.1.1');
Expand Down

0 comments on commit a7f4de9

Please sign in to comment.