diff --git a/.psalm/autoloader.php b/.psalm/autoloader.php
index 5474b0b..3592d19 100644
--- a/.psalm/autoloader.php
+++ b/.psalm/autoloader.php
@@ -3,7 +3,7 @@
return;
}
-define('ABSPATH', './vendor/roots/wordpress/');
+define('ABSPATH', './vendor/johnpbloch/wordpress-core/');
define('WPINC', 'wp-includes');
define('WP_CONTENT_DIR', ABSPATH . 'wp-content');
diff --git a/composer.json b/composer.json
index 1667e23..1d6c84d 100644
--- a/composer.json
+++ b/composer.json
@@ -22,10 +22,10 @@
"require-dev": {
"phpunit/phpunit": "~7.5.20 || ^8",
"inpsyde/php-coding-standards": "^1",
- "vimeo/psalm": "^3.14.2",
+ "vimeo/psalm": "@stable",
"mockery/mockery": "~1.3.3",
"brain/monkey": "^2.4.2",
- "roots/wordpress": "^5.5.1"
+ "johnpbloch/wordpress-core": "@stable"
},
"autoload": {
"psr-4": {
@@ -55,7 +55,6 @@
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
- },
- "wordpress-install-dir": "vendor/roots/wordpress"
+ }
}
}
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index ba9d37e..6708883 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -2,10 +2,20 @@
./src/
+ ./tests/
-
+
+
+
+
+
+
+
diff --git a/psalm.xml b/psalm.xml
index fb1ed5c..3469222 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -21,5 +21,6 @@
+
diff --git a/src/WpContext.php b/src/WpContext.php
index d1c764a..6558aa5 100644
--- a/src/WpContext.php
+++ b/src/WpContext.php
@@ -45,7 +45,7 @@ final class WpContext implements \JsonSerializable
*/
public static function new(): WpContext
{
- return new static(array_fill_keys(self::ALL, false));
+ return new self(array_fill_keys(self::ALL, false));
}
/**
@@ -70,9 +70,11 @@ public static function determine(): WpContext
// When nothing else matches, we assume it is a front-office request.
$isFront = $undetermined && !$isRest && !$isLogin;
- // Note that when core is installing **only** `INSTALLING` will be true, not even `CORE`.
- // This is done to do as less as possible during installation, when most of WP does not act
- // as expected.
+ /*
+ * Note that when core is installing **only** `INSTALLING` will be true, not even `CORE`.
+ * This is done to do as less as possible during installation, when most of WP does not act
+ * as expected.
+ */
$instance = new self(
[
@@ -107,9 +109,11 @@ private static function isRestRequest(): bool
return !empty($_GET['rest_route']); // phpcs:ignore
}
- // This is needed because, if called early, global $wp_rewrite is not defined but required
- // by get_rest_url(). WP will reuse what we set here, or in worst case will replace, but no
- // consequences for us in any case.
+ /*
+ * This is needed because, if called early, global $wp_rewrite is not defined but required
+ * by get_rest_url(). WP will reuse what we set here, or in worst case will replace, but no
+ * consequences for us in any case.
+ */
if (empty($GLOBALS['wp_rewrite'])) {
$GLOBALS['wp_rewrite'] = new \WP_Rewrite();
}
@@ -282,7 +286,7 @@ public function isInstalling(): bool
/**
* @return array
*/
- public function jsonSerialize()
+ public function jsonSerialize(): array
{
return $this->data;
}
@@ -328,6 +332,7 @@ private function removeActionHooks(): void
foreach ($this->actionCallbacks as $action => $callback) {
remove_action($action, $callback, PHP_INT_MIN);
}
+ $this->actionCallbacks = [];
}
/**
@@ -341,5 +346,7 @@ private function resetAndForce(string $context): void
$this->data[self::CORE] = true;
$this->data[self::CLI] = $cli;
$this->data[$context] = true;
+
+ $this->removeActionHooks();
}
}
diff --git a/tests/WpContextTest.php b/tests/WpContextTest.php
index 6e4da7d..d799ee9 100644
--- a/tests/WpContextTest.php
+++ b/tests/WpContextTest.php
@@ -1,4 +1,4 @@
-with([])->andReturnUsing(function (): string {
- return $this->currentPath;
- });
+ Monkey\Functions\expect('add_query_arg')
+ ->with([])
+ ->andReturnUsing(function (): string {
+ return $this->currentPath;
+ });
}
/**
@@ -105,7 +107,7 @@ public function testIsLoginLate(): void
$onLoginInit = null;
Monkey\Actions\expectAdded('login_init')
- ->whenHappen(function (callable $callback) use (&$onLoginInit) {
+ ->whenHappen(static function (callable $callback) use (&$onLoginInit) {
$onLoginInit = $callback;
});
@@ -161,7 +163,7 @@ public function testIsRestLate(): void
$onRestInit = null;
Monkey\Actions\expectAdded('rest_api_init')
- ->whenHappen(function (callable $callback) use (&$onRestInit) {
+ ->whenHappen(static function (callable $callback) use (&$onRestInit) {
$onRestInit = $callback;
});
@@ -364,8 +366,9 @@ private function mockIsLoginRequest(bool $is): void
{
$is and $this->currentPath = '/wp-login.php';
Monkey\Functions\when('wp_login_url')->justReturn('https://example.com/wp-login.php');
- Monkey\Functions\when('home_url')->alias(static function (string $path = ''): string {
- return 'https://example.com/' . ltrim($path, '/');
- });
+ Monkey\Functions\when('home_url')
+ ->alias(static function (string $path = ''): string {
+ return 'https://example.com/' . ltrim($path, '/');
+ });
}
}