', static function () {
+ my_function_that_echoes_html();
+ });
}
}
```
+> **Changed in 2.0.0:** earlier versions overrode PHPUnit's `expectOutputString()` to transparently strip tabs and newlines from output (toggled with the `@stripTabsAndNewlinesFromOutput` annotation). PHPUnit 10 removed `setOutputCallback()` and made `expectOutputString()` `final`, so that automatic behavior is no longer possible. Use `assertOutputEqualsHtml()` for whitespace-insensitive output assertions; PHPUnit's native `expectOutputString()` remains available for exact-match assertions.
+
### Mock static method
The `TestCase::mockStaticMethod()` function will mock a static method on a class, via Patchwork, returning a Mockery object.
diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php
index 8d02f6e..8a48ea0 100644
--- a/features/bootstrap/FeatureContext.php
+++ b/features/bootstrap/FeatureContext.php
@@ -44,7 +44,8 @@ public function ensureStrictModeOn() {
public static function forceStrictModeOn() {
$property = new ReflectionProperty( 'WP_Mock', '__strict_mode' );
$property->setAccessible( true );
- $property->setValue( true );
+ // Two-arg form (null object for a static property) — single-arg setValue() is deprecated since PHP 8.3.
+ $property->setValue( null, true );
}
/**
@@ -57,7 +58,8 @@ public function ensureStrictModeOff() {
public static function forceStrictModeOff() {
$property = new ReflectionProperty( 'WP_Mock', '__strict_mode' );
$property->setAccessible( true );
- $property->setValue( false );
+ // Two-arg form (null object for a static property) — single-arg setValue() is deprecated since PHP 8.3.
+ $property->setValue( null, false );
}
/**
diff --git a/features/bootstrap/FunctionsContext.php b/features/bootstrap/FunctionsContext.php
index e4325af..2da3b92 100644
--- a/features/bootstrap/FunctionsContext.php
+++ b/features/bootstrap/FunctionsContext.php
@@ -88,12 +88,10 @@ public function iExpectWhenIRunWithArgs( $return, $function, TableNode $args ) {
}
/**
- * @Then I expect :return when I run :function
- *
- * @deprected use static::iExpectWhenIRun instead
+ * @deprecated use iExpectWhenIRun() instead
*/
public function iExcpectWhenIRun( $return, $function ) {
- static::iExpectWhenIRun( $return, $function )
+ $this->iExpectWhenIRun( $return, $function );
}
/**
diff --git a/php/WP_Mock.php b/php/WP_Mock.php
index 49ef1f3..1c44a29 100644
--- a/php/WP_Mock.php
+++ b/php/WP_Mock.php
@@ -335,7 +335,7 @@ public static function expectFilterAdded(string $filter, $callback, int $priorit
* @param int $args the number of arguments that should be allowed
* @return void
*/
- public static function expectFilterNotAdded(string $filter, $callback, int $priority = 10, int $args = 10) : void
+ public static function expectFilterNotAdded(string $filter, $callback, int $priority = 10, int $args = 1) : void
{
self::expectHookNotAdded('filter', $filter, $callback, $priority, $args);
}
diff --git a/php/WP_Mock/DeprecatedMethodListener.php b/php/WP_Mock/DeprecatedMethodListener.php
index dffbfc6..81dbc70 100644
--- a/php/WP_Mock/DeprecatedMethodListener.php
+++ b/php/WP_Mock/DeprecatedMethodListener.php
@@ -2,19 +2,16 @@
namespace WP_Mock;
-use Mockery\MockInterface;
-use PHPUnit\Framework\RiskyTestError;
-use PHPUnit\Framework\TestCase;
-use PHPUnit\Framework\TestResult;
-
/**
* Internal handler for deprecated method calls.
*
- * This handler is used by WP_Mock to alert developers if they are using any WP_Mock deprecated methods.
- * Test cases using WP_Mock deprecated methods will report as risky.
- * In this way we can ensure that developers are aware of the deprecation and can update their code before any deprecated methods are permanently removed.
+ * Flags usage of deprecated WP_Mock methods by emitting an {@see E_USER_DEPRECATED} notice,
+ * which PHPUnit captures and attributes to the running test natively: it is reported per test
+ * and fails the suite when `failOnDeprecation="true"` is set in the PHPUnit configuration.
+ *
+ * To flag a method as deprecated, call the following from within the deprecated method's logic:
*
- * To flag a method as deprecated use {@see \WP_Mock::getDeprecatedMethodListener()->logDeprecatedCall()} within a deprecated method's logic.
+ * \WP_Mock::getDeprecatedMethodListener()->logDeprecatedCall(__METHOD__, func_get_args());
*/
class DeprecatedMethodListener
{
@@ -24,12 +21,6 @@ class DeprecatedMethodListener
/** @var string */
protected $testName = 'test';
- /** @var TestCase|MockInterface */
- protected $testCase;
-
- /** @var TestResult|MockInterface */
- protected $testResult;
-
/**
* Sets the test name in context.
*
@@ -44,33 +35,11 @@ public function setTestName(string $testName): DeprecatedMethodListener
}
/**
- * Sets the test case in context.
+ * Logs a deprecated method call and emits a deprecation notice.
*
- * @param TestCase|MockInterface $testCase
- * @return $this
- */
- public function setTestCase($testCase): DeprecatedMethodListener
- {
- $this->testCase = $testCase;
-
- return $this;
- }
-
- /**
- * Sets the test result in context.
- *
- * @param TestResult|MockInterface $testResult
- * @return $this
- */
- public function setTestResult($testResult): DeprecatedMethodListener
- {
- $this->testResult = $testResult;
-
- return $this;
- }
-
- /**
- * Logs a deprecated method call.
+ * The call is recorded (for inspection via {@see DeprecatedMethodListener::reset()} consumers)
+ * and an {@see E_USER_DEPRECATED} notice is triggered immediately so PHPUnit reports it against
+ * the running test.
*
* @param string $method
* @param array $args
@@ -80,6 +49,8 @@ public function logDeprecatedCall(string $method, array $args = []): DeprecatedM
{
$this->deprecatedCalls[] = [$method, $args];
+ trigger_error($this->buildMessage($method, $args), E_USER_DEPRECATED);
+
return $this;
}
@@ -96,98 +67,23 @@ public function reset(): DeprecatedMethodListener
}
/**
- * Checks for deprecated method calls.
- *
- * Adds failures to the test result if any are found.
- *
- * @return void
- */
- public function checkCalls(): void
- {
- if (empty($this->deprecatedCalls)) {
- return;
- }
-
- $error = new RiskyTestError($this->buildErrorMessage());
-
- /** @phpstan-ignore-next-line */
- $this->testResult->addFailure($this->testCase, $error, 0);
- }
-
- /**
- * Gets a deprecated method call usage message.
+ * Builds the deprecation message for a single deprecated method call.
*
+ * @param string $method
+ * @param array $args
* @return string
*/
- protected function buildErrorMessage(): string
+ protected function buildMessage(string $method, array $args): string
{
- $maxLength = array_reduce($this->getDeprecatedMethods(), function ($carry, $item) {
- return max($carry, strlen($item));
- }, 0) + 1;
-
- $message = sprintf('Deprecated WP Mock calls inside %s:', $this->testName);
-
- foreach ($this->getDeprecatedMethodsWithArgs() as $method => $args) {
- $firstRun = true;
- $extra = $maxLength - strlen($method);
-
- foreach ($args as $arg) {
- $message .= "\n ";
-
- if ($firstRun) {
- $message .= $method . str_repeat(' ', $extra);
- $firstRun = false;
- $extra = $maxLength;
- } else {
- $message .= str_repeat(' ', $extra);
- }
+ $message = sprintf('Deprecated WP_Mock call inside %s: %s', $this->testName, $method);
- $message .= $arg;
- }
+ if (! empty($args)) {
+ $message .= ' '.json_encode(array_map([$this, 'toScalar'], $args));
}
return $message;
}
- /**
- * Gets a list of deprecated methods having been called.
- *
- * @return string[]
- */
- protected function getDeprecatedMethods(): array
- {
- $methods = [];
-
- foreach ($this->deprecatedCalls as $call) {
- $methods[] = $call[0];
- }
-
- return array_unique($methods);
- }
-
- /**
- * Gets a list of deprecated methods having been called, with their arguments formatted as JSON.
- *
- * @return array>
- */
- protected function getDeprecatedMethodsWithArgs(): array
- {
- $collection = [];
-
- foreach ($this->deprecatedCalls as $call) {
- $method = $call[0];
- $args = json_encode(array_map([$this, 'toScalar'], $call[1]));
-
- if (empty($collection[$method])) {
- $collection[$method] = [];
- }
-
- $collection[$method][] = $args;
- }
-
- return array_map('array_unique', $collection);
- }
-
/**
* Transforms a value for use in a JSON string.
*
diff --git a/php/WP_Mock/Tools/Constraints/IsEqualHtml.php b/php/WP_Mock/Tools/Constraints/IsEqualHtml.php
index 0d0b525..8b13fb3 100644
--- a/php/WP_Mock/Tools/Constraints/IsEqualHtml.php
+++ b/php/WP_Mock/Tools/Constraints/IsEqualHtml.php
@@ -2,93 +2,66 @@
namespace WP_Mock\Tools\Constraints;
-use Exception;
use PHPUnit\Framework\Constraint\Constraint;
-use PHPUnit\Framework\Constraint\IsEqual;
-use PHPUnit\Framework\ExpectationFailedException;
/**
* HTML string constraint.
+ *
+ * Compares two HTML strings for equality while ignoring insignificant whitespace
+ * (tabs, newlines, carriage returns and collapsed runs of whitespace).
*/
class IsEqualHtml extends Constraint
{
/** @var string */
protected $value;
- /** @var float */
- private $delta;
-
- /** @var bool */
- private $canonicalize;
-
- /** @var bool */
- private $ignoreCase;
-
/**
* Constructor.
*
- * @param string $value
- * @param float $delta
- * @param bool $canonicalize
- * @param bool $ignoreCase
+ * @param string $value the expected HTML
*/
- public function __construct(string $value, float $delta = 0.0, bool $canonicalize = false, bool $ignoreCase = false)
+ public function __construct(string $value)
{
$this->value = $value;
- $this->delta = $delta;
- $this->canonicalize = $canonicalize;
- $this->ignoreCase = $ignoreCase;
}
/**
- * Trims and removes tabs, newlines and return carriages from a string.
+ * Evaluates whether $other equals the expected HTML, ignoring insignificant whitespace.
*
- * @param string $value
- * @return string
+ * @param mixed $other value to evaluate
+ * @return bool
*/
- protected function clean(string $value): string
+ public function matches(mixed $other): bool
{
- $value = preg_replace('/\n\s+/', '', $value) ?: '';
- $value = preg_replace('/\s\s+/', ' ', $value) ?: '';
+ $actual = is_scalar($other) ? (string) $other : '';
- return str_replace(array( "\r", "\n", "\t" ), '', $value);
+ return $this->clean($actual) === $this->clean($this->value);
}
/**
- * Evaluates the constraint for parameter $other.
+ * Returns a string representation of the constraint.
*
- * If $returnResult is false (default), an exception is thrown in case of a failure. null is returned otherwise.
- * If $returnResult is true, the result of the evaluation is returned as a boolean instead, based on success or failure.
+ * @see Constraint::toString()
*
- * @param string $other value to evaluate
- * @param string $description message used in failures
- * @param bool $returnResult whether to throw an exception in case of failure or return boolean
- * @return bool|null
- * @throws ExpectationFailedException
+ * @return string
*/
- public function evaluate($other, string $description = '', bool $returnResult = false): ?bool
+ public function toString(): string
{
- $other = $this->clean($other);
- $this->value = $this->clean($this->value);
-
- $isEqual = new IsEqual($this->value, $this->delta, $this->canonicalize, $this->ignoreCase);
- $result = $isEqual->evaluate($other, $description, $returnResult);
-
- return $returnResult ? $result : null;
+ // Note: do NOT use Constraint::exporter() here — it was removed in PHPUnit 11.0.
+ return sprintf("html is equal to '%s'", $this->clean($this->value));
}
/**
- * Returns a string representation of the constraint.
- *
- * @see Constraint::toString()
+ * Trims and removes tabs, newlines and return carriages from a string.
*
+ * @param string $value
* @return string
- * @throws Exception
*/
- public function toString(): string
+ protected function clean(string $value): string
{
- $isEqual = new IsEqual($this->value, $this->delta, $this->canonicalize, $this->ignoreCase);
+ $value = preg_replace('/\n\s+/', '', $value) ?: '';
+ $value = preg_replace('/\s\s+/', ' ', $value) ?: '';
- return 'html '.$isEqual->toString();
+ return str_replace(["\r", "\n", "\t"], '', $value);
}
}
diff --git a/php/WP_Mock/Tools/TestCase.php b/php/WP_Mock/Tools/TestCase.php
index 28d5f3c..4927639 100644
--- a/php/WP_Mock/Tools/TestCase.php
+++ b/php/WP_Mock/Tools/TestCase.php
@@ -7,8 +7,6 @@
use Mockery;
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\TestCase as PhpUnitTestCase;
-use PHPUnit\Framework\TestResult;
-use PHPUnit\Util\Test;
use ReflectionException;
use ReflectionMethod;
use RuntimeException;
@@ -40,9 +38,6 @@ abstract class TestCase extends PhpUnitTestCase
/** @var array */
protected $__default_request = [];
- /** @var bool|callable */
- protected $__contentFilterCallback = false;
-
/** @var array */
protected $testFiles = [];
@@ -64,7 +59,6 @@ public function setUp(): void
$_POST = (array) $this->__default_post;
$_REQUEST = (array) $this->__default_request;
- $this->setUpContentFiltering();
$this->cleanGlobals();
}
@@ -101,53 +95,6 @@ public function tearDown(): void
$_GET = $_POST = $_REQUEST = [];
}
- /**
- * Runs the test case and collects the results in a {@see TestResult} object.
- *
- * If no {@see TestResult} object is passed a new one will be created.
- *
- * @param TestResult|null $result
- * @return TestResult
- * @throws Exception
- */
- public function run(?TestResult $result = null): TestResult
- {
- if ($result === null) {
- $result = $this->createResult();
- }
-
- WP_Mock::getDeprecatedMethodListener()
- ->setTestResult($result)
- ->setTestCase($this);
-
- return parent::run($result);
- }
-
- /**
- * Runs logic after every test.
- *
- * @after
- *
- * @return void
- */
- public function after(): void
- {
- $this->checkDeprecatedCalls();
- }
-
- /**
- * Checks for deprecated usage calls.
- *
- * This method is called after every test to check if any deprecated WP_Mock functions are used.
- *
- * @return void
- */
- protected function checkDeprecatedCalls(): void
- {
- WP_Mock::getDeprecatedMethodListener()->checkCalls();
- WP_Mock::getDeprecatedMethodListener()->reset();
- }
-
/**
* Cleans common WordPress globals that may have been used in between tests.
*
@@ -167,49 +114,6 @@ protected function cleanGlobals(): void
}
}
- /**
- * Sets up content filtering.
- *
- * @return void
- * @throws Exception
- */
- protected function setUpContentFiltering(): void
- {
- $this->__contentFilterCallback = false;
-
- $annotations = Test::parseTestMethodAnnotations(
- static::class,
- $this->getName(false)
- );
-
- if (
- ! isset($annotations['stripTabsAndNewlinesFromOutput']) ||
- $annotations['stripTabsAndNewlinesFromOutput'][0] !== 'disabled' ||
- (
- /** @phpstan-ignore-next-line */
- is_numeric($annotations['stripTabsAndNewlinesFromOutput'][0]) &&
- (int) $annotations['stripTabsAndNewlinesFromOutput'][0] !== 0
- )
- ) {
- $this->__contentFilterCallback = [$this, 'stripTabsAndNewlines'];
- $this->setOutputCallback($this->__contentFilterCallback);
- }
- }
-
- /**
- * Strips tabs, newlines and carriage returns from a value.
- *
- * @internal may change to protected access in future versions
- * @see TestCase::setUpContentFiltering()
- *
- * @param string|string[] $value
- * @return string|string[]
- */
- public function stripTabsAndNewlines($value)
- {
- return str_replace([ "\t", "\r", "\n"], '', $value);
- }
-
/**
* Asserts that all actions have been called.
*
@@ -292,23 +196,29 @@ public function assertEqualsHtml(string $expected, string $actual, string $messa
}
/**
- * Sets the expectation that a string will be output.
+ * Asserts that the HTML output produced by the given callback equals the expected HTML, ignoring insignificant whitespace.
+ *
+ * Cross-version replacement for the implicit output filtering that previously relied on
+ * PHPUnit's setOutputCallback() (removed in PHPUnit 10) and the expectOutputString() override
+ * (expectOutputString() became final in PHPUnit 10).
*
- * @param string $expectedString
+ * @param string $expectedHtml the expected HTML
+ * @param callable $callback code that echoes or prints output
+ * @param string $message
* @return void
- * @throws InvalidArgumentException
+ * @throws ExpectationFailedException|Exception
*/
- public function expectOutputString(string $expectedString): void
+ public function assertOutputEqualsHtml(string $expectedHtml, callable $callback, string $message = ''): void
{
- if (is_callable($this->__contentFilterCallback)) {
- $expectedString = call_user_func($this->__contentFilterCallback, $expectedString);
- }
+ ob_start();
- if (! is_string($expectedString)) {
- throw new InvalidArgumentException(sprintf('%1$s expects string, %2$s passed from content filter callback.', __METHOD__, gettype($expectedString)));
+ try {
+ $callback();
+ } finally {
+ $actual = ob_get_clean();
}
- parent::expectOutputString($expectedString);
+ $this->assertThat((string) $actual, new IsEqualHtml($expectedHtml), $message);
}
/**
diff --git a/phpcs.xml b/phpcs.xml
index e18853e..5b46ceb 100644
--- a/phpcs.xml
+++ b/phpcs.xml
@@ -4,5 +4,5 @@
./tests
-
+
\ No newline at end of file
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index 9ca9448..bcf4e70 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -1,396 +1,757 @@
parameters:
ignoreErrors:
-
- message: "#^Call to an undefined method Mockery\\\\ExpectationInterface\\|Mockery\\\\HigherOrderMessage\\:\\:atLeast\\(\\)\\.$#"
+ message: '#^Call to an undefined method Mockery\\ExpectationInterface\|Mockery\\HigherOrderMessage\:\:atLeast\(\)\.$#'
+ identifier: method.notFound
count: 3
path: php/WP_Mock.php
-
- message: "#^Cannot call method perform\\(\\) on mixed\\.$#"
+ message: '#^Cannot call method andReturnUsing\(\) on mixed\.$#'
+ identifier: method.nonObject
count: 1
path: php/WP_Mock.php
-
- message: "#^Cannot call method reply\\(\\) on mixed\\.$#"
+ message: '#^Cannot call method once\(\) on mixed\.$#'
+ identifier: method.nonObject
+ count: 3
+ path: php/WP_Mock.php
+
+ -
+ message: '#^Cannot call method perform\(\) on mixed\.$#'
+ identifier: method.nonObject
+ count: 1
+ path: php/WP_Mock.php
+
+ -
+ message: '#^Cannot call method reply\(\) on mixed\.$#'
+ identifier: method.nonObject
+ count: 1
+ path: php/WP_Mock.php
+
+ -
+ message: '#^Method WP_Mock\:\:activateStrictMode\(\) has no return type specified\.$#'
+ identifier: missingType.return
count: 1
path: php/WP_Mock.php
-
- message: "#^Method WP_Mock\\:\\:activateStrictMode\\(\\) has no return type specified\\.$#"
+ message: '#^Method WP_Mock\:\:addAction\(\) has no return type specified\.$#'
+ identifier: missingType.return
count: 1
path: php/WP_Mock.php
-
- message: "#^Method WP_Mock\\:\\:addAction\\(\\) has no return type specified\\.$#"
+ message: '#^Method WP_Mock\:\:addAction\(\) has parameter \$hook with no type specified\.$#'
+ identifier: missingType.parameter
count: 1
path: php/WP_Mock.php
-
- message: "#^Method WP_Mock\\:\\:addAction\\(\\) has parameter \\$hook with no type specified\\.$#"
+ message: '#^Method WP_Mock\:\:addFilter\(\) has no return type specified\.$#'
+ identifier: missingType.return
count: 1
path: php/WP_Mock.php
-
- message: "#^Method WP_Mock\\:\\:addFilter\\(\\) has no return type specified\\.$#"
+ message: '#^Method WP_Mock\:\:addFilter\(\) has parameter \$hook with no type specified\.$#'
+ identifier: missingType.parameter
count: 1
path: php/WP_Mock.php
-
- message: "#^Method WP_Mock\\:\\:addFilter\\(\\) has parameter \\$hook with no type specified\\.$#"
+ message: '#^Method WP_Mock\:\:addHook\(\) has no return type specified\.$#'
+ identifier: missingType.return
count: 1
path: php/WP_Mock.php
-
- message: "#^Method WP_Mock\\:\\:addHook\\(\\) has no return type specified\\.$#"
+ message: '#^Method WP_Mock\:\:addHook\(\) has parameter \$hook with no type specified\.$#'
+ identifier: missingType.parameter
count: 1
path: php/WP_Mock.php
-
- message: "#^Method WP_Mock\\:\\:addHook\\(\\) has parameter \\$hook with no type specified\\.$#"
+ message: '#^Method WP_Mock\:\:addHook\(\) has parameter \$type with no type specified\.$#'
+ identifier: missingType.parameter
count: 1
path: php/WP_Mock.php
-
- message: "#^Method WP_Mock\\:\\:addHook\\(\\) has parameter \\$type with no type specified\\.$#"
+ message: '#^Method WP_Mock\:\:assertActionsCalled\(\) throws checked exception PHPUnit\\Framework\\ExpectationFailedException but it''s missing from the PHPDoc @throws tag\.$#'
+ identifier: missingType.checkedException
count: 1
path: php/WP_Mock.php
-
- message: "#^Method WP_Mock\\:\\:assertActionsCalled\\(\\) throws checked exception PHPUnit\\\\Framework\\\\ExpectationFailedException but it's missing from the PHPDoc @throws tag\\.$#"
+ message: '#^Method WP_Mock\:\:assertFiltersCalled\(\) throws checked exception PHPUnit\\Framework\\ExpectationFailedException but it''s missing from the PHPDoc @throws tag\.$#'
+ identifier: missingType.checkedException
count: 1
path: php/WP_Mock.php
-
- message: "#^Method WP_Mock\\:\\:assertActionsCalled\\(\\) throws checked exception SebastianBergmann\\\\RecursionContext\\\\InvalidArgumentException but it's missing from the PHPDoc @throws tag\\.$#"
+ message: '#^Method WP_Mock\:\:assertHooksAdded\(\) throws checked exception PHPUnit\\Framework\\ExpectationFailedException but it''s missing from the PHPDoc @throws tag\.$#'
+ identifier: missingType.checkedException
count: 1
path: php/WP_Mock.php
-
- message: "#^Method WP_Mock\\:\\:assertFiltersCalled\\(\\) throws checked exception PHPUnit\\\\Framework\\\\ExpectationFailedException but it's missing from the PHPDoc @throws tag\\.$#"
+ message: '#^Method WP_Mock\:\:invokeAction\(\) has no return type specified\.$#'
+ identifier: missingType.return
count: 1
path: php/WP_Mock.php
-
- message: "#^Method WP_Mock\\:\\:assertFiltersCalled\\(\\) throws checked exception SebastianBergmann\\\\RecursionContext\\\\InvalidArgumentException but it's missing from the PHPDoc @throws tag\\.$#"
+ message: '#^Method WP_Mock\:\:onHookAdded\(\) should return WP_Mock\\HookedCallback but returns mixed\.$#'
+ identifier: return.type
count: 1
path: php/WP_Mock.php
-
- message: "#^Method WP_Mock\\:\\:assertHooksAdded\\(\\) throws checked exception PHPUnit\\\\Framework\\\\ExpectationFailedException but it's missing from the PHPDoc @throws tag\\.$#"
+ message: '#^Method WP_Mock\:\:setUsePatchwork\(\) has no return type specified\.$#'
+ identifier: missingType.return
count: 1
path: php/WP_Mock.php
-
- message: "#^Method WP_Mock\\:\\:assertHooksAdded\\(\\) throws checked exception SebastianBergmann\\\\RecursionContext\\\\InvalidArgumentException but it's missing from the PHPDoc @throws tag\\.$#"
+ message: '#^Method WP_Mock\:\:usingPatchwork\(\) has no return type specified\.$#'
+ identifier: missingType.return
count: 1
path: php/WP_Mock.php
-
- message: "#^Method WP_Mock\\:\\:invokeAction\\(\\) has no return type specified\\.$#"
+ message: '#^Parameter \#1 \$callable of class WP_Mock\\InvokedFilterValue constructor expects callable\(\)\: mixed, array\{Mockery\\MockInterface, ''intercepted''\} given\.$#'
+ identifier: argument.type
count: 1
path: php/WP_Mock.php
-
- message: "#^Method WP_Mock\\:\\:setUsePatchwork\\(\\) has no return type specified\\.$#"
+ message: '#^Parameter \#1 \(mixed\) of echo cannot be converted to string\.$#'
+ identifier: echo.nonString
count: 1
path: php/WP_Mock.php
-
- message: "#^Method WP_Mock\\:\\:usingPatchwork\\(\\) has no return type specified\\.$#"
+ message: '#^Parameter \#2 \$args of method WP_Mock\\Functions\:\:register\(\) expects array\, array\ given\.$#'
+ identifier: argument.type
count: 1
path: php/WP_Mock.php
-
- message: "#^Parameter \\#1 \\$callable of class WP_Mock\\\\InvokedFilterValue constructor expects callable\\(\\)\\: mixed, array\\{Mockery\\\\LegacyMockInterface, 'intercepted'\\} given\\.$#"
+ message: '#^Parameter \#2 \$array of function implode expects array\, array given\.$#'
+ identifier: argument.type
+ count: 3
+ path: php/WP_Mock.php
+
+ -
+ message: '#^Part \$hook \(mixed\) of encapsed string cannot be cast to string\.$#'
+ identifier: encapsedStringPart.nonString
count: 1
path: php/WP_Mock.php
-
- message: "#^Property WP_Mock\\:\\:\\$__bootstrapped has no type specified\\.$#"
+ message: '#^Part \$type \(mixed\) of encapsed string cannot be cast to string\.$#'
+ identifier: encapsedStringPart.nonString
count: 1
path: php/WP_Mock.php
-
- message: "#^Property WP_Mock\\:\\:\\$__strict_mode has no type specified\\.$#"
+ message: '#^Property WP_Mock\:\:\$__bootstrapped has no type specified\.$#'
+ identifier: missingType.property
count: 1
path: php/WP_Mock.php
-
- message: "#^Property WP_Mock\\:\\:\\$__use_patchwork has no type specified\\.$#"
+ message: '#^Property WP_Mock\:\:\$__strict_mode has no type specified\.$#'
+ identifier: missingType.property
count: 1
path: php/WP_Mock.php
-
- message: "#^Function add_action\\(\\) has no return type specified\\.$#"
+ message: '#^Property WP_Mock\:\:\$__use_patchwork has no type specified\.$#'
+ identifier: missingType.property
+ count: 1
+ path: php/WP_Mock.php
+
+ -
+ message: '#^Function add_action\(\) has no return type specified\.$#'
+ identifier: missingType.return
count: 1
path: php/WP_Mock/API/function-mocks.php
-
- message: "#^Function add_filter\\(\\) has no return type specified\\.$#"
+ message: '#^Function add_filter\(\) has no return type specified\.$#'
+ identifier: missingType.return
count: 1
path: php/WP_Mock/API/function-mocks.php
-
- message: "#^PHPDoc tag @param references unknown parameter\\: \\$var$#"
+ message: '#^Function do_action\(\) should return null but returns mixed\.$#'
+ identifier: return.type
count: 1
path: php/WP_Mock/API/function-mocks.php
-
- message: "#^Cannot access offset string on mixed\\.$#"
+ message: '#^PHPDoc tag @param references unknown parameter\: \$var$#'
+ identifier: parameter.notFound
+ count: 1
+ path: php/WP_Mock/API/function-mocks.php
+
+ -
+ message: '#^Cannot access offset int\<0, max\> on mixed\.$#'
+ identifier: offsetAccess.nonOffsetAccessible
count: 2
path: php/WP_Mock/Action.php
-
- message: "#^Cannot call method react\\(\\) on mixed\\.$#"
+ message: '#^Cannot access offset string on mixed\.$#'
+ identifier: offsetAccess.nonOffsetAccessible
count: 1
path: php/WP_Mock/Action.php
-
- message: "#^Method WP_Mock\\\\Action\\:\\:new_responder\\(\\) has no return type specified\\.$#"
+ message: '#^Cannot call method react\(\) on mixed\.$#'
+ identifier: method.nonObject
+ count: 2
+ path: php/WP_Mock/Action.php
+
+ -
+ message: '#^Method WP_Mock\\Action\:\:new_responder\(\) has no return type specified\.$#'
+ identifier: missingType.return
count: 1
path: php/WP_Mock/Action.php
-
- message: "#^Method WP_Mock\\\\Action\\:\\:react\\(\\) has no return type specified\\.$#"
+ message: '#^Method WP_Mock\\Action\:\:react\(\) has no return type specified\.$#'
+ identifier: missingType.return
count: 1
path: php/WP_Mock/Action.php
-
- message: "#^Method WP_Mock\\\\Action\\:\\:react\\(\\) has parameter \\$args with no type specified\\.$#"
+ message: '#^Method WP_Mock\\Action\:\:react\(\) has parameter \$args with no type specified\.$#'
+ identifier: missingType.parameter
count: 1
path: php/WP_Mock/Action.php
-
- message: "#^Method WP_Mock\\\\Action\\:\\:react\\(\\) throws checked exception PHPUnit\\\\Framework\\\\ExpectationFailedException but it's missing from the PHPDoc @throws tag\\.$#"
+ message: '#^Method WP_Mock\\Action\:\:react\(\) throws checked exception PHPUnit\\Framework\\ExpectationFailedException but it''s missing from the PHPDoc @throws tag\.$#'
+ identifier: missingType.checkedException
count: 3
path: php/WP_Mock/Action.php
-
- message: "#^Method WP_Mock\\\\Action_Responder\\:\\:perform\\(\\) has no return type specified\\.$#"
+ message: '#^Method WP_Mock\\Action_Responder\:\:perform\(\) has no return type specified\.$#'
+ identifier: missingType.return
count: 1
path: php/WP_Mock/Action.php
-
- message: "#^Method WP_Mock\\\\Action_Responder\\:\\:perform\\(\\) has parameter \\$callable with no type specified\\.$#"
+ message: '#^Method WP_Mock\\Action_Responder\:\:perform\(\) has parameter \$callable with no type specified\.$#'
+ identifier: missingType.parameter
count: 1
path: php/WP_Mock/Action.php
-
- message: "#^Method WP_Mock\\\\Action_Responder\\:\\:react\\(\\) has no return type specified\\.$#"
+ message: '#^Method WP_Mock\\Action_Responder\:\:react\(\) has no return type specified\.$#'
+ identifier: missingType.return
count: 1
path: php/WP_Mock/Action.php
-
- message: "#^Parameter \\#1 \\$function of function call_user_func expects callable\\(\\)\\: mixed, mixed given\\.$#"
+ message: '#^Parameter \#1 \$callback of function call_user_func expects callable\(\)\: mixed, mixed given\.$#'
+ identifier: argument.type
count: 1
path: php/WP_Mock/Action.php
-
- message: "#^Method WP_Mock\\\\EventManager\\:\\:callback\\(\\) has no return type specified\\.$#"
+ message: '#^Parameter \#1 \$value of function count expects array\|Countable, mixed given\.$#'
+ identifier: argument.type
count: 1
+ path: php/WP_Mock/Action.php
+
+ -
+ message: '#^Cannot access offset non\-falsy\-string on mixed\.$#'
+ identifier: offsetAccess.nonOffsetAccessible
+ count: 2
path: php/WP_Mock/EventManager.php
-
- message: "#^Method WP_Mock\\\\EventManager\\:\\:callback\\(\\) has parameter \\$name with no type specified\\.$#"
+ message: '#^Method WP_Mock\\EventManager\:\:action\(\) should return WP_Mock\\Action but returns mixed\.$#'
+ identifier: return.type
count: 1
path: php/WP_Mock/EventManager.php
-
- message: "#^Method WP_Mock\\\\EventManager\\:\\:callback\\(\\) has parameter \\$type with no type specified\\.$#"
+ message: '#^Method WP_Mock\\EventManager\:\:callback\(\) has no return type specified\.$#'
+ identifier: missingType.return
count: 1
path: php/WP_Mock/EventManager.php
-
- message: "#^Method WP_Mock\\\\EventManager\\:\\:called\\(\\) has no return type specified\\.$#"
+ message: '#^Method WP_Mock\\EventManager\:\:callback\(\) has parameter \$name with no type specified\.$#'
+ identifier: missingType.parameter
count: 1
path: php/WP_Mock/EventManager.php
-
- message: "#^Method WP_Mock\\\\EventManager\\:\\:expectedActions\\(\\) return type has no value type specified in iterable type array\\.$#"
+ message: '#^Method WP_Mock\\EventManager\:\:callback\(\) has parameter \$type with no type specified\.$#'
+ identifier: missingType.parameter
count: 1
path: php/WP_Mock/EventManager.php
-
- message: "#^Method WP_Mock\\\\EventManager\\:\\:expectedFilters\\(\\) return type has no value type specified in iterable type array\\.$#"
+ message: '#^Method WP_Mock\\EventManager\:\:called\(\) has no return type specified\.$#'
+ identifier: missingType.return
count: 1
path: php/WP_Mock/EventManager.php
-
- message: "#^Method WP_Mock\\\\EventManager\\:\\:expectedHooks\\(\\) return type has no value type specified in iterable type array\\.$#"
+ message: '#^Method WP_Mock\\EventManager\:\:expectedActions\(\) return type has no value type specified in iterable type array\.$#'
+ identifier: missingType.iterableValue
count: 1
path: php/WP_Mock/EventManager.php
-
- message: "#^Method WP_Mock\\\\EventManager\\:\\:flush\\(\\) has no return type specified\\.$#"
+ message: '#^Method WP_Mock\\EventManager\:\:expectedFilters\(\) return type has no value type specified in iterable type array\.$#'
+ identifier: missingType.iterableValue
count: 1
path: php/WP_Mock/EventManager.php
-
- message: "#^Parameter \\#2 \\$offset of function array_splice expects int, int\\|string\\|false given\\.$#"
+ message: '#^Method WP_Mock\\EventManager\:\:expectedHooks\(\) return type has no value type specified in iterable type array\.$#'
+ identifier: missingType.iterableValue
count: 1
path: php/WP_Mock/EventManager.php
-
- message: "#^Property WP_Mock\\\\EventManager\\:\\:\\$actions type has no value type specified in iterable type array\\.$#"
+ message: '#^Method WP_Mock\\EventManager\:\:filter\(\) should return WP_Mock\\Filter but returns mixed\.$#'
+ identifier: return.type
count: 1
path: php/WP_Mock/EventManager.php
-
- message: "#^Property WP_Mock\\\\EventManager\\:\\:\\$callbacks has no type specified\\.$#"
+ message: '#^Method WP_Mock\\EventManager\:\:flush\(\) has no return type specified\.$#'
+ identifier: missingType.return
count: 1
path: php/WP_Mock/EventManager.php
-
- message: "#^Property WP_Mock\\\\EventManager\\:\\:\\$expected type has no value type specified in iterable type array\\.$#"
+ message: '#^Parameter \#1 \$array of function array_keys expects array, mixed given\.$#'
+ identifier: argument.type
count: 1
path: php/WP_Mock/EventManager.php
-
- message: "#^Property WP_Mock\\\\EventManager\\:\\:\\$filters type has no value type specified in iterable type array\\.$#"
+ message: '#^Parameter \#1 \$haystack of function strpos expects string, mixed given\.$#'
+ identifier: argument.type
+ count: 3
+ path: php/WP_Mock/EventManager.php
+
+ -
+ message: '#^Parameter \#1 \$name of class WP_Mock\\HookedCallback constructor expects string, mixed given\.$#'
+ identifier: argument.type
+ count: 1
+ path: php/WP_Mock/EventManager.php
+
+ -
+ message: '#^Parameter \#1 \$type of method WP_Mock\\HookedCallback\:\:setType\(\) expects string, mixed given\.$#'
+ identifier: argument.type
count: 1
path: php/WP_Mock/EventManager.php
-
- message: "#^Cannot call method send\\(\\) on mixed\\.$#"
+ message: '#^Parameter \#2 \$offset of function array_splice expects int, int\|string\|false given\.$#'
+ identifier: argument.type
+ count: 1
+ path: php/WP_Mock/EventManager.php
+
+ -
+ message: '#^Part \$name \(mixed\) of encapsed string cannot be cast to string\.$#'
+ identifier: encapsedStringPart.nonString
+ count: 1
+ path: php/WP_Mock/EventManager.php
+
+ -
+ message: '#^Part \$type \(mixed\) of encapsed string cannot be cast to string\.$#'
+ identifier: encapsedStringPart.nonString
+ count: 1
+ path: php/WP_Mock/EventManager.php
+
+ -
+ message: '#^Property WP_Mock\\EventManager\:\:\$actions type has no value type specified in iterable type array\.$#'
+ identifier: missingType.iterableValue
+ count: 1
+ path: php/WP_Mock/EventManager.php
+
+ -
+ message: '#^Property WP_Mock\\EventManager\:\:\$callbacks has no type specified\.$#'
+ identifier: missingType.property
+ count: 1
+ path: php/WP_Mock/EventManager.php
+
+ -
+ message: '#^Property WP_Mock\\EventManager\:\:\$expected type has no value type specified in iterable type array\.$#'
+ identifier: missingType.iterableValue
+ count: 1
+ path: php/WP_Mock/EventManager.php
+
+ -
+ message: '#^Property WP_Mock\\EventManager\:\:\$filters type has no value type specified in iterable type array\.$#'
+ identifier: missingType.iterableValue
+ count: 1
+ path: php/WP_Mock/EventManager.php
+
+ -
+ message: '#^Cannot call method send\(\) on mixed\.$#'
+ identifier: method.nonObject
count: 1
path: php/WP_Mock/Filter.php
-
- message: "#^Method WP_Mock\\\\Filter\\:\\:apply\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
+ message: '#^Method WP_Mock\\Filter\:\:apply\(\) has parameter \$args with no value type specified in iterable type array\.$#'
+ identifier: missingType.iterableValue
count: 1
path: php/WP_Mock/Filter.php
-
- message: "#^Method WP_Mock\\\\Filter\\:\\:apply\\(\\) throws checked exception PHPUnit\\\\Framework\\\\ExpectationFailedException but it's missing from the PHPDoc @throws tag\\.$#"
+ message: '#^Method WP_Mock\\Filter\:\:apply\(\) throws checked exception PHPUnit\\Framework\\ExpectationFailedException but it''s missing from the PHPDoc @throws tag\.$#'
+ identifier: missingType.checkedException
count: 2
path: php/WP_Mock/Filter.php
-
- message: "#^Method WP_Mock\\\\Filter\\:\\:new_responder\\(\\) has no return type specified\\.$#"
+ message: '#^Method WP_Mock\\Filter_Responder\:\:reply\(\) has no return type specified\.$#'
+ identifier: missingType.return
count: 1
path: php/WP_Mock/Filter.php
-
- message: "#^Method WP_Mock\\\\Filter_Responder\\:\\:reply\\(\\) has no return type specified\\.$#"
+ message: '#^Method WP_Mock\\Filter_Responder\:\:reply\(\) has parameter \$value with no type specified\.$#'
+ identifier: missingType.parameter
count: 1
path: php/WP_Mock/Filter.php
-
- message: "#^Method WP_Mock\\\\Filter_Responder\\:\\:reply\\(\\) has parameter \\$value with no type specified\\.$#"
+ message: '#^Method WP_Mock\\Filter_Responder\:\:send\(\) has no return type specified\.$#'
+ identifier: missingType.return
count: 1
path: php/WP_Mock/Filter.php
-
- message: "#^Method WP_Mock\\\\Filter_Responder\\:\\:send\\(\\) has no return type specified\\.$#"
+ message: '#^Parameter \#1 \$callback of function call_user_func_array expects callable\(\)\: mixed, array\{mixed, ''send''\} given\.$#'
+ identifier: argument.type
count: 1
path: php/WP_Mock/Filter.php
-
- message: "#^Parameter \\#1 \\$function of function call_user_func_array expects callable\\(\\)\\: mixed, array\\{mixed, 'send'\\} given\\.$#"
+ message: '#^Call to an undefined method Mockery\\CompositeExpectation\|Mockery\\Expectation\:\:atLeast\(\)\.$#'
+ identifier: method.notFound
count: 1
- path: php/WP_Mock/Filter.php
+ path: php/WP_Mock/Functions.php
-
- message: "#^Cannot access offset string on mixed\\.$#"
- count: 4
+ message: '#^Call to an undefined method Mockery\\CompositeExpectation\|Mockery\\Expectation\:\:atMost\(\)\.$#'
+ identifier: method.notFound
+ count: 1
+ path: php/WP_Mock/Functions.php
+
+ -
+ message: '#^Method WP_Mock\\Functions\:\:replaceFunction\(\) throws checked exception PHPUnit\\Framework\\ExpectationFailedException but it''s missing from the PHPDoc @throws tag\.$#'
+ identifier: missingType.checkedException
+ count: 1
+ path: php/WP_Mock/Functions.php
+
+ -
+ message: '#^Method WP_Mock\\Functions\:\:setExpectedTimes\(\) throws checked exception InvalidArgumentException but it''s missing from the PHPDoc @throws tag\.$#'
+ identifier: missingType.checkedException
+ count: 1
+ path: php/WP_Mock/Functions.php
+
+ -
+ message: '#^Parameter \#1 \$expectation of method WP_Mock\\Functions\:\:setExpectedReturn\(\) expects Mockery\\Expectation, Mockery\\CompositeExpectation\|Mockery\\Expectation given\.$#'
+ identifier: argument.type
+ count: 1
+ path: php/WP_Mock/Functions.php
+
+ -
+ message: '#^Cannot access offset string on mixed\.$#'
+ identifier: offsetAccess.nonOffsetAccessible
+ count: 3
+ path: php/WP_Mock/Hook.php
+
+ -
+ message: '#^Method WP_Mock\\Hook\:\:new_responder\(\) has no return type specified\.$#'
+ identifier: missingType.return
+ count: 1
path: php/WP_Mock/Hook.php
-
- message: "#^Method WP_Mock\\\\Hook\\:\\:new_responder\\(\\) has no return type specified\\.$#"
+ message: '#^Method WP_Mock\\Hook\:\:with\(\) should return WP_Mock\\Action_Responder\|WP_Mock\\Filter_Responder\|WP_Mock\\HookedCallbackResponder but returns mixed\.$#'
+ identifier: return.type
count: 1
path: php/WP_Mock/Hook.php
-
- message: "#^Cannot access offset 0 on callable\\(\\)\\: mixed\\.$#"
+ message: '#^Cannot access offset 0 on callable\(\)\: mixed\.$#'
+ identifier: offsetAccess.nonOffsetAccessible
count: 1
path: php/WP_Mock/HookedCallback.php
-
- message: "#^Cannot access offset 1 on callable\\(\\)\\: mixed\\.$#"
+ message: '#^Cannot access offset 1 on callable\(\)\: mixed\.$#'
+ identifier: offsetAccess.nonOffsetAccessible
count: 1
path: php/WP_Mock/HookedCallback.php
-
- message: "#^Cannot access offset mixed on mixed\\.$#"
- count: 5
+ message: '#^Cannot access offset mixed on mixed\.$#'
+ identifier: offsetAccess.nonOffsetAccessible
+ count: 2
+ path: php/WP_Mock/HookedCallback.php
+
+ -
+ message: '#^Cannot call method react\(\) on mixed\.$#'
+ identifier: method.nonObject
+ count: 1
+ path: php/WP_Mock/HookedCallback.php
+
+ -
+ message: '#^Method WP_Mock\\HookedCallback\:\:new_responder\(\) has no return type specified\.$#'
+ identifier: missingType.return
+ count: 1
+ path: php/WP_Mock/HookedCallback.php
+
+ -
+ message: '#^Method WP_Mock\\HookedCallback\:\:react\(\) has no return type specified\.$#'
+ identifier: missingType.return
+ count: 1
path: php/WP_Mock/HookedCallback.php
-
- message: "#^Cannot call method react\\(\\) on mixed\\.$#"
+ message: '#^Method WP_Mock\\HookedCallback\:\:react\(\) has parameter \$argument_count with no type specified\.$#'
+ identifier: missingType.parameter
count: 1
path: php/WP_Mock/HookedCallback.php
-
- message: "#^Method WP_Mock\\\\HookedCallback\\:\\:new_responder\\(\\) has no return type specified\\.$#"
+ message: '#^Method WP_Mock\\HookedCallback\:\:react\(\) has parameter \$callback with no type specified\.$#'
+ identifier: missingType.parameter
count: 1
path: php/WP_Mock/HookedCallback.php
-
- message: "#^Method WP_Mock\\\\HookedCallback\\:\\:react\\(\\) has no return type specified\\.$#"
+ message: '#^Method WP_Mock\\HookedCallback\:\:react\(\) has parameter \$priority with no type specified\.$#'
+ identifier: missingType.parameter
count: 1
path: php/WP_Mock/HookedCallback.php
-
- message: "#^Method WP_Mock\\\\HookedCallback\\:\\:react\\(\\) has parameter \\$argument_count with no type specified\\.$#"
+ message: '#^Method WP_Mock\\HookedCallback\:\:react\(\) throws checked exception Mockery\\Exception but it''s missing from the PHPDoc @throws tag\.$#'
+ identifier: missingType.checkedException
count: 1
path: php/WP_Mock/HookedCallback.php
-
- message: "#^Method WP_Mock\\\\HookedCallback\\:\\:react\\(\\) has parameter \\$callback with no type specified\\.$#"
+ message: '#^Method WP_Mock\\HookedCallback\:\:react\(\) throws checked exception PHPUnit\\Framework\\ExpectationFailedException but it''s missing from the PHPDoc @throws tag\.$#'
+ identifier: missingType.checkedException
count: 1
path: php/WP_Mock/HookedCallback.php
-
- message: "#^Method WP_Mock\\\\HookedCallback\\:\\:react\\(\\) has parameter \\$priority with no type specified\\.$#"
+ message: '#^Method WP_Mock\\HookedCallback\:\:react\(\) throws checked exception ReflectionException but it''s missing from the PHPDoc @throws tag\.$#'
+ identifier: missingType.checkedException
count: 1
path: php/WP_Mock/HookedCallback.php
-
- message: "#^Method WP_Mock\\\\HookedCallback\\:\\:react\\(\\) throws checked exception Mockery\\\\Exception but it's missing from the PHPDoc @throws tag\\.$#"
+ message: '#^Method WP_Mock\\HookedCallback\:\:setType\(\) has no return type specified\.$#'
+ identifier: missingType.return
count: 1
path: php/WP_Mock/HookedCallback.php
-
- message: "#^Method WP_Mock\\\\HookedCallback\\:\\:react\\(\\) throws checked exception PHPUnit\\\\Framework\\\\ExpectationFailedException but it's missing from the PHPDoc @throws tag\\.$#"
+ message: '#^Method WP_Mock\\HookedCallbackResponder\:\:perform\(\) has no return type specified\.$#'
+ identifier: missingType.return
count: 1
path: php/WP_Mock/HookedCallback.php
-
- message: "#^Method WP_Mock\\\\HookedCallback\\:\\:react\\(\\) throws checked exception ReflectionException but it's missing from the PHPDoc @throws tag\\.$#"
+ message: '#^Method WP_Mock\\HookedCallbackResponder\:\:perform\(\) has parameter \$callable with no type specified\.$#'
+ identifier: missingType.parameter
count: 1
path: php/WP_Mock/HookedCallback.php
-
- message: "#^Method WP_Mock\\\\HookedCallback\\:\\:setType\\(\\) has no return type specified\\.$#"
+ message: '#^Method WP_Mock\\HookedCallbackResponder\:\:react\(\) has no return type specified\.$#'
+ identifier: missingType.return
count: 1
path: php/WP_Mock/HookedCallback.php
-
- message: "#^Method WP_Mock\\\\HookedCallbackResponder\\:\\:perform\\(\\) has no return type specified\\.$#"
+ message: '#^Parameter \#1 \$callback of method WP_Mock\\HookedCallback\:\:callback_to_string\(\) expects callable\(\)\: mixed, mixed given\.$#'
+ identifier: argument.type
count: 1
path: php/WP_Mock/HookedCallback.php
-
- message: "#^Method WP_Mock\\\\HookedCallbackResponder\\:\\:perform\\(\\) has parameter \\$callable with no type specified\\.$#"
+ message: '#^Parameter \#1 \$expected of class WP_Mock\\Matcher\\AnyInstance constructor expects object\|string\|null, mixed given\.$#'
+ identifier: argument.type
count: 1
path: php/WP_Mock/HookedCallback.php
-
- message: "#^Method WP_Mock\\\\HookedCallbackResponder\\:\\:react\\(\\) has no return type specified\\.$#"
+ message: '#^Parameter \#1 \$object of function get_class expects object, mixed given\.$#'
+ identifier: argument.type
count: 1
path: php/WP_Mock/HookedCallback.php
-
- message: "#^Property WP_Mock\\\\HookedCallback\\:\\:\\$callback has no type specified\\.$#"
+ message: '#^Parameter \#2 \.\.\.\$values of function sprintf expects bool\|float\|int\|string\|null, mixed given\.$#'
+ identifier: argument.type
count: 1
path: php/WP_Mock/HookedCallback.php
-
- message: "#^Property WP_Mock\\\\HookedCallback\\:\\:\\$type has no type specified\\.$#"
+ message: '#^Part \$method \(mixed\) of encapsed string cannot be cast to string\.$#'
+ identifier: encapsedStringPart.nonString
count: 1
path: php/WP_Mock/HookedCallback.php
-
- message: "#^Method WP_Mock\\\\InvokedFilterValue\\:\\:__invoke\\(\\) has no return type specified\\.$#"
+ message: '#^Property WP_Mock\\HookedCallback\:\:\$callback has no type specified\.$#'
+ identifier: missingType.property
+ count: 1
+ path: php/WP_Mock/HookedCallback.php
+
+ -
+ message: '#^Property WP_Mock\\HookedCallback\:\:\$type has no type specified\.$#'
+ identifier: missingType.property
+ count: 1
+ path: php/WP_Mock/HookedCallback.php
+
+ -
+ message: '#^Property WP_Mock\\HookedCallbackResponder\:\:\$callable \(callable\(\)\: mixed\) does not accept mixed\.$#'
+ identifier: assign.propertyType
+ count: 1
+ path: php/WP_Mock/HookedCallback.php
+
+ -
+ message: '#^Method WP_Mock\\InvokedFilterValue\:\:__invoke\(\) has no return type specified\.$#'
+ identifier: missingType.return
+ count: 1
+ path: php/WP_Mock/InvokedFilterValue.php
+
+ -
+ message: '#^Binary operation "\." between mixed and string results in an error\.$#'
+ identifier: binaryOp.invalid
+ count: 2
+ path: php/WP_Mock/Tools/TestCase.php
+
+ -
+ message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsArray\(\) with array\{\} will always evaluate to true\.$#'
+ identifier: method.alreadyNarrowedType
+ count: 1
+ path: tests/Unit/WP_Mock/FunctionsTest.php
+
+ -
+ message: '#^Call to an undefined method Mockery\\ExpectationInterface\|Mockery\\HigherOrderMessage\:\:with\(\)\.$#'
+ identifier: method.notFound
+ count: 1
+ path: tests/Unit/WP_Mock/Matcher/FuzzyObjectTest.php
+
+ -
+ message: '#^Cannot call method andReturnTrue\(\) on mixed\.$#'
+ identifier: method.nonObject
+ count: 1
+ path: tests/Unit/WP_Mock/Matcher/FuzzyObjectTest.php
+
+ -
+ message: '#^Cannot call method getInaccessibleMethod\(\) on mixed\.$#'
+ identifier: method.nonObject
count: 1
- path: php/WP_Mock/InvokedFilterValue.php
\ No newline at end of file
+ path: tests/Unit/WP_Mock/Traits/AccessInaccessibleClassMembersTraitTest.php
+
+ -
+ message: '#^Cannot call method getInaccessibleProperty\(\) on mixed\.$#'
+ identifier: method.nonObject
+ count: 1
+ path: tests/Unit/WP_Mock/Traits/AccessInaccessibleClassMembersTraitTest.php
+
+ -
+ message: '#^Cannot call method getInaccessiblePropertyValue\(\) on mixed\.$#'
+ identifier: method.nonObject
+ count: 1
+ path: tests/Unit/WP_Mock/Traits/AccessInaccessibleClassMembersTraitTest.php
+
+ -
+ message: '#^Cannot call method getName\(\) on mixed\.$#'
+ identifier: method.nonObject
+ count: 2
+ path: tests/Unit/WP_Mock/Traits/AccessInaccessibleClassMembersTraitTest.php
+
+ -
+ message: '#^Cannot call method getValue\(\) on mixed\.$#'
+ identifier: method.nonObject
+ count: 3
+ path: tests/Unit/WP_Mock/Traits/AccessInaccessibleClassMembersTraitTest.php
+
+ -
+ message: '#^Cannot call method invoke\(\) on mixed\.$#'
+ identifier: method.nonObject
+ count: 1
+ path: tests/Unit/WP_Mock/Traits/AccessInaccessibleClassMembersTraitTest.php
+
+ -
+ message: '#^Cannot call method invokeInaccessibleMethod\(\) on mixed\.$#'
+ identifier: method.nonObject
+ count: 1
+ path: tests/Unit/WP_Mock/Traits/AccessInaccessibleClassMembersTraitTest.php
+
+ -
+ message: '#^Cannot call method setInaccessibleProperty\(\) on mixed\.$#'
+ identifier: method.nonObject
+ count: 1
+ path: tests/Unit/WP_Mock/Traits/AccessInaccessibleClassMembersTraitTest.php
+
+ -
+ message: '#^Cannot call method setInaccessiblePropertyValue\(\) on mixed\.$#'
+ identifier: method.nonObject
+ count: 1
+ path: tests/Unit/WP_Mock/Traits/AccessInaccessibleClassMembersTraitTest.php
+
+ -
+ message: '#^Parameter \#1 \$object of function get_class expects object, mixed given\.$#'
+ identifier: argument.type
+ count: 1
+ path: tests/Unit/WP_Mock/Traits/AccessInaccessibleClassMembersTraitTest.php
+
+ -
+ message: '#^Call to an undefined method WP_Mock\\Action_Responder\|WP_Mock\\Filter_Responder\|WP_Mock\\HookedCallbackResponder\:\:reply\(\)\.$#'
+ identifier: method.notFound
+ count: 5
+ path: tests/Unit/WP_MockTest.php
+
+ -
+ message: '#^PHPDoc tag @throws with type InvalidArgumentException\|PHPUnit\\Framework\\Exception\|SebastianBergmann\\RecursionContext\\InvalidArgumentException is not subtype of Throwable$#'
+ identifier: throws.notThrowable
+ count: 2
+ path: tests/Unit/WP_MockTest.php
+
+ -
+ message: '#^PHPDoc tag @throws with type Mockery\\Exception\|PHPUnit\\Framework\\Exception\|SebastianBergmann\\RecursionContext\\InvalidArgumentException is not subtype of Throwable$#'
+ identifier: throws.notThrowable
+ count: 1
+ path: tests/Unit/WP_MockTest.php
+
+ -
+ message: '#^PHPDoc tag @throws with type PHPUnit\\Framework\\Exception\|SebastianBergmann\\RecursionContext\\InvalidArgumentException is not subtype of Throwable$#'
+ identifier: throws.notThrowable
+ count: 4
+ path: tests/Unit/WP_MockTest.php
+
+ -
+ message: '#^PHPDoc tag @throws with type PHPUnit\\Framework\\ExpectationFailedException\|SebastianBergmann\\RecursionContext\\InvalidArgumentException is not subtype of Throwable$#'
+ identifier: throws.notThrowable
+ count: 3
+ path: tests/Unit/WP_MockTest.php
\ No newline at end of file
diff --git a/phpstan.neon b/phpstan.neon
index 7700f11..41e0036 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -5,6 +5,11 @@ parameters:
reportUnmatchedIgnoredErrors: false
treatPhpDocTypesAsCertain: false
exceptions:
+ # PHPUnit's mock-creation infrastructure throws these; they are test-runner concerns,
+ # not exceptions a test documents/handles, so don't require them in @throws tags.
+ uncheckedExceptionClasses:
+ - 'PHPUnit\Framework\MockObject\Exception'
+ - 'PHPUnit\Framework\InvalidArgumentException'
check:
missingCheckedExceptionInThrows: true
tooWideThrowType: true
diff --git a/phpunit.xml b/phpunit.xml
deleted file mode 100644
index 937ae22..0000000
--- a/phpunit.xml
+++ /dev/null
@@ -1,42 +0,0 @@
-
-
-
-
-
- ./tests/Unit
-
-
- ./tests/Integration
-
-
-
-
-
- ./php
-
-
-
-
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
new file mode 100644
index 0000000..1dcca93
--- /dev/null
+++ b/phpunit.xml.dist
@@ -0,0 +1,30 @@
+
+
+
+
+
+ ./tests/Unit
+
+
+ ./tests/Integration
+
+
+
+
+
+ ./php
+
+
+
+
diff --git a/tests/Integration/WP_MockTest.php b/tests/Integration/WP_MockTest.php
index 3af7bb3..f5c28b9 100644
--- a/tests/Integration/WP_MockTest.php
+++ b/tests/Integration/WP_MockTest.php
@@ -4,17 +4,23 @@
use Exception;
use Generator;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
+use PHPUnit\Framework\Attributes\PreserveGlobalState;
+use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\ExpectationFailedException;
use WP_Mock;
+use WP_Mock\Functions;
+use WP_Mock\Functions\Handler;
use WP_Mock\Tests\WP_MockTestCase;
-/**
- * @covers \WP_Mock
- */
+#[CoversClass(WP_Mock::class)]
+#[CoversClass(Functions::class)]
+#[CoversClass(Handler::class)]
class WP_MockTest extends WP_MockTestCase
{
/** @var string[] */
- private array $defaultMockedFunctions = [
+ private const DEFAULT_MOCKED_FUNCTIONS = [
'__',
'_e',
'_n',
@@ -44,7 +50,7 @@ class WP_MockTest extends WP_MockTestCase
*/
protected function setUp(): void
{
- if (! $this->isInIsolation()) {
+ if (! $this->isRunningInIsolation()) {
WP_Mock::setUp();
}
@@ -52,41 +58,31 @@ protected function setUp(): void
}
/**
- * @covers \WP_Mock::bootstrap()
- * @covers \WP_Mock\Functions::__construct()
- * @covers \WP_Mock\Functions::flush()
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
* @return void
* @throws Exception
*/
+ #[RunInSeparateProcess]
+ #[PreserveGlobalState(false)]
public function testCommonFunctionsAreDefined(): void
{
// First we assert that all common functions get removed from the returned array.
// If any one of these functions doesn't get removed, that means it already exists.
- $this->assertEmpty(array_filter($this->defaultMockedFunctions, 'function_exists'));
+ $this->assertEmpty(array_filter(self::DEFAULT_MOCKED_FUNCTIONS, 'function_exists'));
WP_Mock::bootstrap();
// Now we assert that the array doesn't lose any items after bootstrap,
// meaning all expected functions got defined correctly.
- $this->assertEquals($this->defaultMockedFunctions, array_filter($this->defaultMockedFunctions, 'function_exists'));
+ $this->assertEquals(self::DEFAULT_MOCKED_FUNCTIONS, array_filter(self::DEFAULT_MOCKED_FUNCTIONS, 'function_exists'));
}
/**
- * @covers \WP_Mock::userFunction()
- * @covers \WP_Mock\Functions::__construct()
- * @covers \WP_Mock\Functions::flush()
- *
- * @dataProvider providerCommonFunctionsDefaultFunctionality
- *
* @param callable&string $function
* @param string $action echo or return
* @return void
* @throws Exception
*/
+ #[DataProvider('providerCommonFunctionsDefaultFunctionality')]
public function testCommonFunctionsDefaultFunctionality($function, string $action)
{
$input = $expected = 'Something Random '.rand(0, 99);
@@ -110,9 +106,9 @@ public function testCommonFunctionsDefaultFunctionality($function, string $actio
*
* @return array
*/
- public function providerCommonFunctionsDefaultFunctionality(): array
+ public static function providerCommonFunctionsDefaultFunctionality(): array
{
- $functions = $this->defaultMockedFunctions;
+ $functions = self::DEFAULT_MOCKED_FUNCTIONS;
return array_filter(array_map(function ($function) {
// skip hook functions - only gettext functions under test
@@ -123,14 +119,10 @@ public function providerCommonFunctionsDefaultFunctionality(): array
}
/**
- * @covers \WP_Mock::activateStrictMode()
- * @covers \WP_Mock::bootstrap()
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
* @return void
*/
+ #[RunInSeparateProcess]
+ #[PreserveGlobalState(false)]
public function testDefaultFailsInStrictMode(): void
{
$this->expectExceptionMessageMatches('/No handler found for \w+/');
@@ -144,11 +136,6 @@ public function testDefaultFailsInStrictMode(): void
}
/**
- * @covers \WP_Mock::userFunction()
- * @covers \WP_Mock\Functions::register()
- * @covers \WP_Mock\Functions::generateFunction()
- * @covers \WP_Mock\Functions::setUpMock()
- *
* @return void
* @throws Exception
*/
@@ -164,11 +151,6 @@ public function testMockingOverridesDefaults(): void
}
/**
- * @covers \WP_Mock::userFunction()
- * @covers \WP_Mock\Functions::register()
- * @covers \WP_Mock\Functions::generateFunction()
- * @covers \WP_Mock\Functions::setUpMock()
- *
* @return void
* @throws Exception
*/
@@ -181,23 +163,12 @@ public function testBotchedMocksStillOverridesDefault(): void
}
/**
- * @covers \WP_Mock::userFunction()
- * @covers \WP_Mock\Functions::register()
- * @covers \WP_Mock\Functions::generateFunction()
- * @covers \WP_Mock\Functions::setUpMock()
- * @covers \WP_Mock\Functions::setExpectedTimes()
- * @covers \WP_Mock\Functions::setExpectedArgs()
- * @covers \WP_Mock\Functions::setExpectedReturn()
- * @covers \WP_Mock\Functions::parseExpectedReturn()
- * @covers \WP_Mock\Functions\Handler::registerHandler()
- *
- * @dataProvider providerUserFunctionExpectationArgs
- *
* @param array $expectationArgs
* @param array $expectedResults
* @return void
* @throws Exception
*/
+ #[DataProvider('providerUserFunctionExpectationArgs')]
public function testCanSetUserFunctionExpectationArgs(array $expectationArgs, array $expectedResults): void
{
WP_Mock::userFunction('wpMockTestReturnFunction', $expectationArgs);
@@ -215,7 +186,7 @@ public function testCanSetUserFunctionExpectationArgs(array $expectationArgs, ar
}
/** @see testCanSetUserFunctionExpectationArgs */
- public function providerUserFunctionExpectationArgs(): Generator
+ public static function providerUserFunctionExpectationArgs(): Generator
{
yield 'Function never called' => [
'expectationArgs' => [
@@ -265,9 +236,6 @@ public function providerUserFunctionExpectationArgs(): Generator
}
/**
- * @covers \WP_Mock::passthruFunction()
- * @covers \WP_Mock\Functions::register()
- *
* @return void
* @throws Exception
*/
@@ -281,9 +249,6 @@ public function testCanMockPassthruFunction(): void
}
/**
- * @covers \WP_Mock::echoFunction()
- * @covers \WP_Mock\Functions::register()
- *
* @return void
* @throws Exception
*/
@@ -299,11 +264,6 @@ public function testCanMockEchoFunction(): void
}
/**
- * @covers \WP_Mock::expectActionAdded()
- * @covers \WP_Mock::expectFilterAdded()
- * @covers \WP_Mock::expectHookAdded()
- * @covers \WP_Mock::assertHooksAdded()
- *
* @return void
*/
public function testCanExpectHooksAdded() : void
@@ -318,10 +278,6 @@ public function testCanExpectHooksAdded() : void
}
/**
- * @covers \WP_Mock::expectActionNotAdded()
- * @covers \WP_Mock::expectFilterNotAdded()
- * @covers \WP_Mock::expectHookNotAdded()
- *
* @return void
* @throws Exception
*/
diff --git a/tests/Unit/WP_Mock/API/FunctionMocksTest.php b/tests/Unit/WP_Mock/API/FunctionMocksTest.php
index 2ba4ce1..6bb3896 100644
--- a/tests/Unit/WP_Mock/API/FunctionMocksTest.php
+++ b/tests/Unit/WP_Mock/API/FunctionMocksTest.php
@@ -3,35 +3,20 @@
namespace Unit\WP_Mock\API;
use Exception;
+use PHPUnit\Framework\Attributes\PreserveGlobalState;
+use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use WP_Mock;
use WP_Mock\Tests\WP_MockTestCase;
-/**
- * @covers \WP_Mock
- * @covers \WP_Mock\Functions\Handler
- */
+// No coverage metadata: this exercises globally-defined function mocks (esc_url(), __(), …),
+// not a single class, so it contributes whole-suite coverage rather than per-class attribution.
final class FunctionMocksTest extends WP_MockTestCase
{
/**
- * @covers \__()
- * @covers \_n()
- * @covers \_x()
- * @covers \esc_attr()
- * @covers \esc_attr__()
- * @covers \esc_attr_x()
- * @covers \esc_html()
- * @covers \esc_html__()
- * @covers \esc_js()
- * @covers \esc_textarea()
- * @covers \esc_url()
- * @covers \esc_url_raw()
- * @covers \WP_Mock\Functions\Handler::handlePredefinedReturnFunction()
- *
- * @preserveGlobalState disabled
- * @runInSeparateProcess
- *
* @return void
*/
+ #[RunInSeparateProcess]
+ #[PreserveGlobalState(false)]
public function testPredefinedReturnFunctions(): void
{
WP_Mock::bootstrap();
@@ -64,17 +49,11 @@ public function testPredefinedReturnFunctions(): void
}
/**
- * @covers \_e()
- * @covers \esc_attr_e()
- * @covers \esc_html_e()
- * @covers \WP_Mock\Functions\Handler::handlePredefinedEchoFunction()
- *
- * @preserveGlobalState disabled
- * @runInSeparateProcess
- *
* @return void
* @throws Exception
*/
+ #[RunInSeparateProcess]
+ #[PreserveGlobalState(false)]
public function testPredefinedEchoFunctions(): void
{
WP_Mock::bootstrap();
diff --git a/tests/Unit/WP_Mock/DeprecatedMethodListenerTest.php b/tests/Unit/WP_Mock/DeprecatedMethodListenerTest.php
index 98f76af..8f30b95 100644
--- a/tests/Unit/WP_Mock/DeprecatedMethodListenerTest.php
+++ b/tests/Unit/WP_Mock/DeprecatedMethodListenerTest.php
@@ -4,11 +4,8 @@
use Exception;
use Generator;
-use Mockery;
-use PHPUnit\Framework\Assert;
-use PHPUnit\Framework\RiskyTestError;
-use PHPUnit\Framework\TestCase;
-use PHPUnit\Framework\TestResult;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use ReflectionException;
use ReflectionMethod;
use ReflectionProperty;
@@ -17,9 +14,8 @@
use WP_Mock\DeprecatedMethodListener;
use WP_Mock\Tests\WP_MockTestCase;
-/**
- * @covers \WP_Mock\DeprecatedMethodListener
- */
+#[CoversClass(WP_Mock::class)]
+#[CoversClass(DeprecatedMethodListener::class)]
final class DeprecatedMethodListenerTest extends WP_MockTestCase
{
/** @var DeprecatedMethodListener */
@@ -32,6 +28,8 @@ final class DeprecatedMethodListenerTest extends WP_MockTestCase
*/
protected function setUp(): void
{
+ parent::setUp();
+
$this->object = new DeprecatedMethodListener();
}
@@ -40,293 +38,116 @@ protected function setUp(): void
*
* @return void
*/
- public function tearDown(): void
+ protected function tearDown(): void
{
$this->object->reset();
- }
-
- /**
- * @covers \WP_Mock\DeprecatedMethodListener::setTestName()
- *
- * @return void
- * @throws ReflectionException|Exception
- */
- public function testCanSetTestName(): void
- {
- $property = new ReflectionProperty($this->object, 'testName');
- $property->setAccessible(true);
-
- $this->assertSame('test', $property->getValue($this->object));
-
- $this->assertSame($this->object, $this->object->setTestName('FooBar'));
- $this->assertSame('FooBar', $property->getValue($this->object));
+ parent::tearDown();
}
/**
- * @covers \WP_Mock\DeprecatedMethodListener::setTestCase()
+ * Captures the {@see E_USER_DEPRECATED} messages emitted while running $callback.
*
- * @return void
- * @throws ReflectionException|Exception
+ * A local error handler intercepts the notices so that PHPUnit's
+ * `failOnDeprecation` does not interfere with the assertions.
+ *
+ * @param callable $callback
+ * @return string[] the captured deprecation messages, in order
*/
- public function testCanSetTestCase(): void
+ protected function captureDeprecations(callable $callback): array
{
- /** @var TestCase&Mockery\MockInterface $testCase */
- $testCase = Mockery::mock(TestCase::class);
+ $messages = [];
- $this->assertSame($this->object, $this->object->setTestCase($testCase));
+ set_error_handler(static function (int $errno, string $errstr) use (&$messages): bool {
+ $messages[] = $errstr;
- $property = new ReflectionProperty($this->object, 'testCase');
- $property->setAccessible(true);
+ return true;
+ }, E_USER_DEPRECATED);
- $this->assertSame($testCase, $property->getValue($this->object));
+ try {
+ $callback();
+ } finally {
+ restore_error_handler();
+ }
+
+ return $messages;
}
/**
- * @covers \WP_Mock\DeprecatedMethodListener::setTestResult()
- *
* @return void
* @throws ReflectionException|Exception
*/
- public function testCanSetTestResult(): void
+ public function testCanSetTestName(): void
{
- $concreteTestResult = new TestResult();
- /** @var TestResult&Mockery\MockInterface $mockTestResult @phpstan-ignore-line */
- $mockTestResult = Mockery::mock($concreteTestResult);
+ $property = new ReflectionProperty($this->object, 'testName');
+ $property->setAccessible(true);
- $this->assertSame($this->object, $this->object->setTestResult($mockTestResult));
+ $this->assertSame('test', $property->getValue($this->object));
- $property = new ReflectionProperty($this->object, 'testResult');
- $property->setAccessible(true);
+ $this->assertSame($this->object, $this->object->setTestName('FooBar'));
- $this->assertSame($mockTestResult, $property->getValue($this->object));
+ $this->assertSame('FooBar', $property->getValue($this->object));
}
/**
- * @covers \WP_Mock\DeprecatedMethodListener::logDeprecatedCall()
- *
* @return void
* @throws ReflectionException|Exception
*/
- public function testCanLogDeprecatedCall(): void
+ public function testLogDeprecatedCallRecordsAndTriggersDeprecation(): void
{
- $method = 'Foo::bar'.rand(0, 9);
- $args = [rand(10, 99)];
+ $method = 'Foo::bar';
+ $args = [42];
- $this->assertSame($this->object, $this->object->logDeprecatedCall($method, $args));
+ $messages = $this->captureDeprecations(function () use ($method, $args) {
+ $this->assertSame($this->object, $this->object->logDeprecatedCall($method, $args));
+ });
- $this->assertEquals([[$method, $args]], $this->getDeprecatedMethodCalls($this->object));
- }
+ // the call is recorded for inspection
+ $this->assertSame([[$method, $args]], $this->getDeprecatedMethodCalls($this->object));
- /**
- * @covers \WP_Mock\DeprecatedMethodListener::reset()
- *
- * @return void
- * @throws Exception
- */
- public function testCanResetDeprecatedCallsLog(): void
- {
- $this->assertSame($this->object, $this->object->logDeprecatedCall('Foo::bar', ['baz']));
- $this->assertSame($this->object, $this->object->reset());
- $this->assertSame([], $this->getDeprecatedMethodCalls($this->object));
+ // exactly one E_USER_DEPRECATED was emitted, mentioning the method and its args
+ $this->assertCount(1, $messages);
+ $this->assertStringContainsString('Foo::bar', $messages[0]);
+ $this->assertStringContainsString('[42]', $messages[0]);
}
/**
- * @covers \WP_Mock\DeprecatedMethodListener::checkCalls()
- *
* @return void
* @throws Exception
*/
- public function testCheckDeprecatedMethodCallsWithNoCallsMade(): void
+ public function testDeprecationMessageIncludesTestNameAndArgs(): void
{
- $concreteTestResult = new TestResult();
- /** @var TestResult&Mockery\MockInterface $mockTestResult @phpstan-ignore-line */
- $mockTestResult = Mockery::mock($concreteTestResult);
- $mockTestResult->expects('addFailure')->never();
+ $this->object->setTestName('MyTest');
- $this->object->setTestResult($mockTestResult);
- $this->object->checkCalls();
+ $messages = $this->captureDeprecations(function () {
+ $this->object->logDeprecatedCall('Foo::bar', ['baz']);
+ });
- $this->assertConditionsMet();
+ $this->assertCount(1, $messages);
+ $this->assertSame('Deprecated WP_Mock call inside MyTest: Foo::bar ["baz"]', $messages[0]);
}
/**
- * @covers \WP_Mock\DeprecatedMethodListener::checkCalls()
- *
- * @return void
- */
- public function testCanCheckDeprecatedMethodCallsWithScalarArgs(): void
- {
- $this->object->logDeprecatedCall('FooBar::bazBat', ['string', true, 42]);
- $this->object->setTestName('TestName');
-
- /** @var TestCase&Mockery\MockInterface $mockTestCase */
- $mockTestCase = Mockery::mock(TestCase::class);
-
- $this->object->setTestCase($mockTestCase);
-
- $concreteTestResult = new TestResult();
- /** @var TestResult&Mockery\MockInterface $mockTestResult @phpstan-ignore-line */
- $mockTestResult = Mockery::mock($concreteTestResult)->makePartial();
-
- $mockTestResult->expects('addFailure')
- ->once()
- ->andReturnUsing(function ($concreteCase, $exception, $int) use ($mockTestCase) {
- $int = (int) $int; // It's coming as 0.0
- Assert::assertSame($mockTestCase, $concreteCase);
- Assert::assertTrue($exception instanceof RiskyTestError);
- $message = <<getMessage());
- Assert::assertTrue(0 === $int);
- });
-
- $this->object->setTestResult($mockTestResult);
- $this->object->checkCalls();
- }
-
- /**
- * @covers \WP_Mock\DeprecatedMethodListener::checkCalls()
- *
* @return void
* @throws Exception
*/
- public function testCanCheckDeprecatedMethodCallsWithNonScalarArgs(): void
- {
- $object1 = Mockery::mock('WP_Query');
- $range = rand(5, 10);
- $resource = fopen('php://temp', 'r');
- $callback1 = function () {
- };
-
- $this->object->logDeprecatedCall('BazBat::fooBar', [$callback1]);
- $this->object->logDeprecatedCall('BazBat::fooBar', [$object1]);
- $this->object->logDeprecatedCall('BazBat::fooBar', [$object1]);
- $this->object->logDeprecatedCall('LongerClassName::callback', [[$object1, 'shouldReceive']]);
- $this->object->logDeprecatedCall('BazBat::fooBar', [range(1, $range), $resource]);
- $this->object->setTestName('OtherTest');
-
- /** @var TestCase&Mockery\MockInterface $mockTestCase @phpstan-ignore-line */
- $mockTestCase = Mockery::mock(TestCase::class);
-
- $this->object->setTestCase($mockTestCase);
-
- $concreteTestResult = new TestResult();
- /** @var TestResult&Mockery\MockInterface $mockTestResult @phpstan-ignore-line */
- $mockTestResult = Mockery::mock($concreteTestResult);
-
- $testClosure = function ($case, $exception, $int) use ($mockTestCase, $callback1, $object1, $range) {
- $int = (int) $int; // It's coming as 0.0
- $callback1 = get_class($callback1) . ':' . spl_object_hash($callback1);
- $object1 = get_class($object1) . ':' . spl_object_hash($object1);
-
- Assert::assertSame($mockTestCase, $case);
- Assert::assertTrue($exception instanceof RiskyTestError);
-
- $message = <<"]
- ["<$object1>"]
- ["Array([$range] ...)","Resource"]
- LongerClassName::callback ["[<$object1>,shouldReceive]"]
-EOT;
- Assert::assertEquals($message, $exception->getMessage());
- Assert::assertTrue(0 === $int);
- };
-
- $mockTestResult->expects('addFailure')
- ->once()
- ->andReturnUsing($testClosure);
-
- $this->object->setTestResult($mockTestResult);
-
- try {
- $this->object->checkCalls();
- } catch (Exception $exception) {
- fclose($resource); // @phpstan-ignore-line
-
- throw $exception;
- }
-
- fclose($resource); // @phpstan-ignore-line
- }
-
- /**
- * @covers \WP_Mock\DeprecatedMethodListener::buildErrorMessage()
- *
- * @return void
- * @throws ReflectionException|Exception
- */
- public function testCanBuildErrorMessage(): void
- {
- $instance = new DeprecatedMethodListener();
- $instance->setTestName('MyTest');
- $instance->logDeprecatedCall('Foo::bar', ['baz']);
-
- $method = new ReflectionMethod($instance, 'buildErrorMessage');
- $method->setAccessible(true);
-
- $expectedMessage = 'Deprecated WP Mock calls inside MyTest:'."\n ".'Foo::bar ["baz"]';
-
- $this->assertSame($expectedMessage, $method->invoke($instance));
- }
-
- /**
- * @covers \WP_Mock\DeprecatedMethodListener::getDeprecatedMethods()
- *
- * @return void
- * @throws ReflectionException|Exception
- */
- public function testCanGetDeprecatedMethods(): void
- {
- $instance = new DeprecatedMethodListener();
- $instance->logDeprecatedCall('Foo::bar', ['baz']);
- $instance->logDeprecatedCall('Boz::qux');
-
- $method = new ReflectionMethod($instance, 'getDeprecatedMethods');
- $method->setAccessible(true);
-
- $this->assertSame(['Foo::bar', 'Boz::qux'], $method->invoke($instance));
- }
-
- /**
- * @covers \WP_Mock\DeprecatedMethodListener::getDeprecatedMethodsWithArgs()
- *
- * @return void
- * @throws ReflectionException|Exception
- */
- public function testCanGetDeprecatedMethodsWithArgs(): void
+ public function testCanResetDeprecatedCallsLog(): void
{
- $instance = new DeprecatedMethodListener();
- $instance->logDeprecatedCall('Foo::bar', ['baz']);
- $instance->logDeprecatedCall('Boz::qux');
+ $this->captureDeprecations(function () {
+ $this->object->logDeprecatedCall('Foo::bar', ['baz']);
+ });
- $method = new ReflectionMethod($instance, 'getDeprecatedMethodsWithArgs');
- $method->setAccessible(true);
-
- $expected = [
- 'Foo::bar' => [
- '["baz"]'
- ],
- 'Boz::qux' => [
- '[]'
- ],
- ];
-
- $this->assertSame($expected, $method->invoke($instance));
+ $this->assertSame($this->object, $this->object->reset());
+ $this->assertSame([], $this->getDeprecatedMethodCalls($this->object));
}
/**
- * @covers \WP_Mock\DeprecatedMethodListener::toScalar()
- * @dataProvider providerConvertsArgumentsToScalarValue
- *
* @param mixed $arg
* @param string|bool|null|float|int $expected
* @return void
* @throws ReflectionException|Exception
*/
+ #[DataProvider('providerConvertsArgumentsToScalarValue')]
public function testCanConvertArgumentsToScalarValue($arg, $expected): void
{
$instance = new DeprecatedMethodListener();
@@ -335,7 +156,7 @@ public function testCanConvertArgumentsToScalarValue($arg, $expected): void
$result = $method->invokeArgs($instance, [$arg]);
- if (is_object($arg) && is_string($expected) && is_string($result)) {
+ if (is_object($arg) && is_string($expected) && '' !== $expected && is_string($result)) {
$this->assertStringStartsWith($expected, $result);
} else {
$this->assertSame($expected, $result);
@@ -343,7 +164,7 @@ public function testCanConvertArgumentsToScalarValue($arg, $expected): void
}
/** @see testCanConvertArgumentsToScalarValue */
- public function providerConvertsArgumentsToScalarValue(): Generator
+ public static function providerConvertsArgumentsToScalarValue(): Generator
{
yield 'null' => [null, null];
yield 'true' => [true, true];
@@ -359,55 +180,28 @@ public function providerConvertsArgumentsToScalarValue(): Generator
}
/**
- * @covers \WP_Mock\DeprecatedMethodListener::logDeprecatedCall()
- * @covers \WP_Mock::getDeprecatedMethodListener()
- *
* @return void
* @throws Exception
*/
- public function testCanHandleDeprecatedMethodCall(): void
+ public function testCanHandleDeprecatedMethodCallThroughWpMock(): void
{
$deprecatedMethodListener = new DeprecatedMethodListener();
- $concreteTestResult = new TestResult();
- /** @var TestResult&Mockery\MockInterface $mockTestResult @phpstan-ignore-line */
- $mockTestResult = Mockery::mock($concreteTestResult);
- /** @var TestCase&Mockery\MockInterface $mockTestCase */
- $mockTestCase = Mockery::mock(TestCase::class);
-
- $instance = new class ($deprecatedMethodListener) extends WP_Mock {
- /**
- * @param DeprecatedMethodListener $deprecatedMethodListener
- */
- public function __construct(DeprecatedMethodListener $deprecatedMethodListener)
- {
- static::$deprecatedMethodListener = $deprecatedMethodListener;
- }
-
- /**
- * @param array $args
- * @return string
- */
- public function deprecatedMethod(array $args = []): string
- {
- static::getDeprecatedMethodListener()->logDeprecatedCall(__METHOD__, $args);
-
- return 'test';
- }
- };
-
- $mockTestResult->expects('addFailure')
- ->once()
- ->with($mockTestCase, Mockery::type(RiskyTestError::class), 0);
-
- $deprecatedMethodListener->setTestCase($mockTestCase);
- $deprecatedMethodListener->setTestResult($mockTestResult);
-
- $instance->deprecatedMethod(['foo' => 'bar']);
-
- $deprecatedMethodListener->checkCalls();
-
- $this->assertConditionsMet();
+ // Use a named fixture (defined below) rather than an anonymous class: anonymous class
+ // names embed a null byte that trigger_error() truncates on PHP <= 8.1, which would drop
+ // the method name from the deprecation message.
+ $instance = new WpMockWithDeprecatedMethod($deprecatedMethodListener);
+
+ $result = null;
+
+ $messages = $this->captureDeprecations(function () use ($instance, &$result) {
+ $result = $instance->deprecatedMethod(['foo' => 'bar']);
+ });
+
+ // the deprecated method still returns normally (a deprecation is a notice, not a hard stop)
+ $this->assertSame('test', $result);
+ $this->assertCount(1, $messages);
+ $this->assertStringContainsString('deprecatedMethod', $messages[0]);
}
/**
@@ -416,7 +210,7 @@ public function deprecatedMethod(array $args = []): string
* @see DeprecatedMethodListener::$deprecatedCalls
*
* @param DeprecatedMethodListener $listener
- * @return array}>
+ * @return array}> the logged [$method, $args] pairs
* @throws ReflectionException
*/
protected function getDeprecatedMethodCalls(DeprecatedMethodListener $listener): array
@@ -426,6 +220,38 @@ protected function getDeprecatedMethodCalls(DeprecatedMethodListener $listener):
$value = $property->getValue($listener);
- return is_array($value) ? $value : [];
+ if (! is_array($value)) {
+ return [];
+ }
+
+ /** @var array}> $value */
+ return $value;
+ }
+}
+
+/**
+ * Named WP_Mock subclass with a deprecated method, used by
+ * {@see DeprecatedMethodListenerTest::testCanHandleDeprecatedMethodCallThroughWpMock()}.
+ *
+ * Intentionally a named (not anonymous) class so `__METHOD__` is stable and free of the null byte
+ * that anonymous class names embed — which `trigger_error()` truncates on PHP <= 8.1, dropping the
+ * method name from the captured deprecation message.
+ */
+final class WpMockWithDeprecatedMethod extends WP_Mock
+{
+ public function __construct(DeprecatedMethodListener $deprecatedMethodListener)
+ {
+ static::$deprecatedMethodListener = $deprecatedMethodListener;
+ }
+
+ /**
+ * @param array $args
+ * @return string
+ */
+ public function deprecatedMethod(array $args = []): string
+ {
+ static::getDeprecatedMethodListener()->logDeprecatedCall(__METHOD__, $args);
+
+ return 'test';
}
}
diff --git a/tests/Unit/WP_Mock/Functions/HandlerTest.php b/tests/Unit/WP_Mock/Functions/HandlerTest.php
index 4d8eec6..41009cc 100644
--- a/tests/Unit/WP_Mock/Functions/HandlerTest.php
+++ b/tests/Unit/WP_Mock/Functions/HandlerTest.php
@@ -3,19 +3,18 @@
namespace Unit\WP_Mock\Functions;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\PreserveGlobalState;
+use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use ReflectionProperty;
use WP_Mock;
use WP_Mock\Functions\Handler;
use WP_Mock\Tests\WP_MockTestCase;
-/**
- * @covers \WP_Mock\Functions\Handler
- */
+#[CoversClass(Handler::class)]
final class HandlerTest extends WP_MockTestCase
{
/**
- * @covers \WP_Mock\Functions\Handler::registerHandler()
- *
* @return void
* @throws Exception
*/
@@ -43,14 +42,11 @@ public function testCanRegisterHandler(): void
}
/**
- * @covers \WP_Mock\Functions\Handler::handleFunction()
- *
- * @preserveGlobalState disabled
- * @runInSeparateProcess
- *
* @return void
* @throws Exception
*/
+ #[RunInSeparateProcess]
+ #[PreserveGlobalState(false)]
public function testCanHandleFunction(): void
{
$this->assertNull(Handler::handleFunction('invalid'));
@@ -66,14 +62,11 @@ public function testCanHandleFunction(): void
}
/**
- * @covers \WP_Mock\Functions\Handler::handlerExists()
- *
- * @preserveGlobalState disabled
- * @runInSeparateProcess
- *
* @return void
* @throws Exception
*/
+ #[RunInSeparateProcess]
+ #[PreserveGlobalState(false)]
public function testCanDetermineHandlerExists(): void
{
$functionName = 'test_function';
@@ -89,14 +82,11 @@ public function testCanDetermineHandlerExists(): void
}
/**
- * @covers \WP_Mock\Functions\Handler::cleanup()
- *
- * @preserveGlobalState disabled
- * @runInSeparateProcess
- *
* @return void
* @throws Exception
*/
+ #[RunInSeparateProcess]
+ #[PreserveGlobalState(false)]
public function testCanCleanup(): void
{
$property = new ReflectionProperty(Handler::class, 'handlers');
@@ -114,14 +104,11 @@ public function testCanCleanup(): void
}
/**
- * @covers \WP_Mock\Functions\Handler::handlePredefinedReturnFunction()
- *
- * @preserveGlobalState disabled
- * @runInSeparateProcess
- *
* @return void
* @throws Exception
*/
+ #[RunInSeparateProcess]
+ #[PreserveGlobalState(false)]
public function testCanHandlePredefinedReturnFunction(): void
{
WP_Mock::bootstrap();
@@ -135,14 +122,11 @@ public function testCanHandlePredefinedReturnFunction(): void
}
/**
- * @covers \WP_Mock\Functions\Handler::handlePredefinedEchoFunction()
- *
- * @preserveGlobalState disabled
- * @runInSeparateProcess
- *
* @return void
* @throws Exception
*/
+ #[RunInSeparateProcess]
+ #[PreserveGlobalState(false)]
public function testCanHandlePredefinedEchoFunction(): void
{
WP_Mock::bootstrap();
diff --git a/tests/Unit/WP_Mock/Functions/ReturnSequenceTest.php b/tests/Unit/WP_Mock/Functions/ReturnSequenceTest.php
index 5172a9a..169304c 100644
--- a/tests/Unit/WP_Mock/Functions/ReturnSequenceTest.php
+++ b/tests/Unit/WP_Mock/Functions/ReturnSequenceTest.php
@@ -3,18 +3,15 @@
namespace WP_Mock\Tests\Unit\WP_Mock\Functions;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use ReflectionProperty;
use WP_Mock\Functions\ReturnSequence;
use WP_Mock\Tests\WP_MockTestCase;
-/**
- * @covers \WP_Mock\Functions\ReturnSequence
- */
+#[CoversClass(ReturnSequence::class)]
final class ReturnSequenceTest extends WP_MockTestCase
{
/**
- * @covers \WP_Mock\Functions\ReturnSequence::__construct()
- *
* @return void
* @throws Exception
*/
@@ -28,9 +25,6 @@ public function testConstructor(): void
}
/**
- * @covers \WP_Mock\Functions\ReturnSequence::getReturnValues()
- * @covers \WP_Mock\Functions\ReturnSequence::setReturnValues()
- *
* @return void
* @throws Exception
*/
diff --git a/tests/Unit/WP_Mock/FunctionsTest.php b/tests/Unit/WP_Mock/FunctionsTest.php
index f82e980..670bfa2 100644
--- a/tests/Unit/WP_Mock/FunctionsTest.php
+++ b/tests/Unit/WP_Mock/FunctionsTest.php
@@ -9,6 +9,10 @@
use Mockery\CountValidator\Exact;
use Mockery\Expectation;
use Mockery\Mock;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
+use PHPUnit\Framework\Attributes\PreserveGlobalState;
+use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use ReflectionException;
use ReflectionMethod;
use ReflectionProperty;
@@ -16,20 +20,15 @@
use WP_Mock\Functions\Handler;
use WP_Mock\Tests\WP_MockTestCase;
-/**
- * @covers \WP_Mock\Functions
- */
+#[CoversClass(Functions::class)]
final class FunctionsTest extends WP_MockTestCase
{
/**
- * @covers \WP_Mock\Functions::__construct()
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
* @return void
* @throws ReflectionException|Exception
*/
+ #[RunInSeparateProcess]
+ #[PreserveGlobalState(false)]
public function testCanInitialize(): void
{
$functions = new Functions();
@@ -80,14 +79,11 @@ public function testCanInitialize(): void
}
/**
- * @covers \WP_Mock\Functions::register()
- *
- * @preserveGlobalState disabled
- * @runInSeparateProcess
- *
* @return void
* @throws Exception
*/
+ #[RunInSeparateProcess]
+ #[PreserveGlobalState(false)]
public function testCanRegister(): void
{
$handler = new ReflectionProperty(Handler::class, 'handlers');
@@ -118,13 +114,11 @@ public function testCanRegister(): void
}
/**
- * @covers \WP_Mock\Functions::setUpMock()
- * @dataProvider providerCanSetUpMock
- *
* @param array $expectationArgs
* @return void
* @throws Exception
*/
+ #[DataProvider('providerCanSetUpMock')]
public function testCanSetupMock(array $expectationArgs): void
{
$functions = new Functions();
@@ -172,7 +166,7 @@ public function testCanSetupMock(array $expectationArgs): void
}
/** @see testCanSetupMock */
- public function providerCanSetUpMock(): Generator
+ public static function providerCanSetUpMock(): Generator
{
yield 'With args' => [['args' => ['foo', 'bar']]];
yield 'With return value' => [['return' => 'foo']];
@@ -180,14 +174,12 @@ public function providerCanSetUpMock(): Generator
}
/**
- * @covers \WP_Mock\Functions::generateFunction()
- * @dataProvider providerCanGenerateFunction
- *
* @param bool $willCreate
* @param bool $willReplace
* @return void
* @throws ReflectionException|Exception
*/
+ #[DataProvider('providerCanGenerateFunction')]
public function testCanGenerateFunction(bool $willCreate, bool $willReplace): void
{
$functionName = 'myFunction';
@@ -221,7 +213,7 @@ public function testCanGenerateFunction(bool $willCreate, bool $willReplace): vo
}
/** @see testCanGenerateFunction */
- public function providerCanGenerateFunction(): Generator
+ public static function providerCanGenerateFunction(): Generator
{
yield 'Function is created' => [true, false];
yield 'Function is replaced' => [false, true];
@@ -229,12 +221,6 @@ public function providerCanGenerateFunction(): Generator
}
/**
- * @covers \WP_Mock\Functions::createFunction()
- * @dataProvider providerCanCreateFunction
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
* @param string $functionName
* @param string[] $functionsList
* @param bool $functionWillExist
@@ -243,6 +229,9 @@ public function providerCanGenerateFunction(): Generator
* @return void
* @throws ReflectionException|Exception
*/
+ #[DataProvider('providerCanCreateFunction')]
+ #[RunInSeparateProcess]
+ #[PreserveGlobalState(false)]
public function testCanCreateFunction(string $functionName, array $functionsList, bool $functionWillExist, bool $functionWillBeRegistered, bool $expectedReturnValue): void
{
$functions = new Functions();
@@ -266,7 +255,7 @@ public function testCanCreateFunction(string $functionName, array $functionsList
}
/** @see testCanCreateFunction */
- public function providerCanCreateFunction(): Generator
+ public static function providerCanCreateFunction(): Generator
{
yield 'Function is already registered' => ['myWpMockFunction', ['myWpMockFunction'], false, true, true];
yield 'Function already exists' => ['str_replace', [], true, false, false];
@@ -274,8 +263,6 @@ public function providerCanCreateFunction(): Generator
}
/**
- * @covers \WP_Mock\Functions::replaceFunction()
- *
* @return void
* @throws ReflectionException|Exception
*/
@@ -295,8 +282,6 @@ public function testCanReplaceFunction(): void
}
/**
- * @covers \WP_Mock\Functions::sanitizeFunctionName()
- *
* @return void
* @throws ReflectionException|Exception
*/
@@ -312,14 +297,12 @@ public function testCanSanitizeFunctionName(): void
}
/**
- * @covers \WP_Mock\Functions::validateFunctionName()
- * @dataProvider providerCanValidateFunction
- *
* @param string $functionName
* @param bool $validates
* @return void
* @throws ReflectionException|Exception
*/
+ #[DataProvider('providerCanValidateFunction')]
public function testCanValidateFunction(string $functionName, bool $validates): void
{
if (! $validates) {
@@ -335,7 +318,7 @@ public function testCanValidateFunction(string $functionName, bool $validates):
}
/** @see testCanValidateFunction */
- public function providerCanValidateFunction(): Generator
+ public static function providerCanValidateFunction(): Generator
{
yield 'Invalid function name' => ['#!?', false];
yield 'Internal PHP function' => ['str_replace', false];
@@ -344,15 +327,13 @@ public function providerCanValidateFunction(): Generator
}
/**
- * @covers \WP_Mock\Functions::anyOf()
- * @dataProvider providerMatchAnyTypes
- *
* @param bool $expected
* @param mixed $matchedValue
* @param mixed...$typesToMatch
* @return void
* @throws Exception
*/
+ #[DataProvider('providerMatchAnyTypes')]
public function testCanSetUpArgumentPlaceholderOfAnyType(bool $expected, $matchedValue, $typesToMatch): void
{
$anyType = Functions::anyOf($typesToMatch);
@@ -361,7 +342,7 @@ public function testCanSetUpArgumentPlaceholderOfAnyType(bool $expected, $matche
}
/** @see testCanSetUpArgumentPlaceholderOfAnyType */
- public function providerMatchAnyTypes(): Generator
+ public static function providerMatchAnyTypes(): Generator
{
yield 'Match expected string' => [true, 'string', 'string'];
yield 'Does not match expected string' => [false, 'string', 123];
@@ -372,14 +353,12 @@ public function providerMatchAnyTypes(): Generator
}
/**
- * @covers \WP_Mock\Functions::type()
- * @dataProvider providerMatchTypes
- *
* @param string $typeToMatch
* @param mixed $matchedValue
* @return void
* @throws Exception
*/
+ #[DataProvider('providerMatchTypes')]
public function testCanSetUpArgumentPlaceholderOfStrictType(string $typeToMatch, $matchedValue): void
{
$type = Functions::type($typeToMatch);
@@ -388,7 +367,7 @@ public function testCanSetUpArgumentPlaceholderOfStrictType(string $typeToMatch,
}
/** @see testCanSetUpArgumentPlaceholderOfType */
- public function providerMatchTypes(): Generator
+ public static function providerMatchTypes(): Generator
{
yield ['string', 'string'];
yield ['integer', 1];
diff --git a/tests/Unit/WP_Mock/HookTest.php b/tests/Unit/WP_Mock/HookTest.php
index fcfecf3..8a78e14 100644
--- a/tests/Unit/WP_Mock/HookTest.php
+++ b/tests/Unit/WP_Mock/HookTest.php
@@ -6,38 +6,38 @@
use Generator;
use Exception;
use Mockery;
+use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use ReflectionException;
use stdClass;
use WP_Mock\Hook;
use WP_Mock\Traits\AccessInaccessibleClassMembersTrait;
-/**
- * @covers \WP_Mock\Hook
- */
+#[CoversClass(Hook::class)]
+#[AllowMockObjectsWithoutExpectations]
final class HookTest extends TestCase
{
use AccessInaccessibleClassMembersTrait;
/**
- * @covers \WP_Mock\Hook::safe_offset()
- * @dataProvider providerSafeOffset
- *
* @param mixed $value
* @param string $expected
* @return void
* @throws ReflectionException|Exception
*/
+ #[DataProvider('providerSafeOffset')]
public function testCanParseSafeOffSet($value, string $expected): void
{
- $instance = $this->getMockForAbstractClass(Hook::class, [], '', false);
+ $instance = $this->createPartialMock(Hook::class, ['new_responder', 'get_strict_mode_message']);
$method = $this->getInaccessibleMethod($instance, 'safe_offset');
$this->assertSame($expected, $method->invokeArgs($instance, [$value]));
}
/** @see testCanParseSafeOffset */
- public function providerSafeOffset(): Generator
+ public static function providerSafeOffset(): Generator
{
$callbackInstance = new class () {
public function callback(): bool
diff --git a/tests/Unit/WP_Mock/Matcher/AnyInstanceTest.php b/tests/Unit/WP_Mock/Matcher/AnyInstanceTest.php
index 049a99a..aa7edf6 100644
--- a/tests/Unit/WP_Mock/Matcher/AnyInstanceTest.php
+++ b/tests/Unit/WP_Mock/Matcher/AnyInstanceTest.php
@@ -3,20 +3,17 @@
namespace WP_Mock\Tests\Unit\WP_Mock\Matcher;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use ReflectionException;
use WP_Mock\Matcher\AnyInstance;
use WP_Mock\Tests\Mocks\SampleClass;
use WP_Mock\Tests\Mocks\SampleSubClass;
use WP_Mock\Tests\WP_MockTestCase;
-/**
- * @covers \WP_Mock\Matcher\AnyInstance
- */
+#[CoversClass(AnyInstance::class)]
class AnyInstanceTest extends WP_MockTestCase
{
/**
- * @covers \WP_Mock\Matcher\AnyInstance::match()
- *
* @return void
* @throws ReflectionException|Exception
*/
@@ -32,8 +29,6 @@ public function testExactClassInstanceMatchesTrue(): void
}
/**
- * @covers \WP_Mock\Matcher\AnyInstance::match()
- *
* @return void
* @throws ReflectionException|Exception
*/
@@ -49,8 +44,6 @@ public function testExactClassStringMatchesTrue(): void
}
/**
- * @covers \WP_Mock\Matcher\AnyInstance::match()
- *
* @return void
* @throws ReflectionException|Exception
*/
@@ -66,8 +59,6 @@ public function testSubClassMatchesTrue(): void
}
/**
- * @covers \WP_Mock\Matcher\AnyInstance::match()
- *
* @return void
* @throws ReflectionException|Exception
*/
@@ -83,8 +74,6 @@ public function testWrongClassMatchesFalse(): void
}
/**
- * @covers \WP_Mock\Matcher\AnyInstance::match()
- *
* @return void
* @throws ReflectionException|Exception
*/
@@ -101,8 +90,6 @@ public function testClosureMatchesFalse(): void
}
/**
- * @covers \WP_Mock\Matcher\AnyInstance::match()
- *
* @return void
* @throws ReflectionException|Exception
*/
@@ -118,8 +105,6 @@ public function testStringFunctionMatchesFalse(): void
}
/**
- * @covers \WP_Mock\Matcher\AnyInstance::__toString()
- *
* @return void
* @throws Exception
*/
@@ -133,8 +118,6 @@ public function testToString(): void
}
/**
- * @covers \WP_Mock\Matcher\AnyInstance::__construct()
- *
* @return void
* @throws Exception
*/
diff --git a/tests/Unit/WP_Mock/Matcher/FuzzyObjectTest.php b/tests/Unit/WP_Mock/Matcher/FuzzyObjectTest.php
index 679e501..094536c 100644
--- a/tests/Unit/WP_Mock/Matcher/FuzzyObjectTest.php
+++ b/tests/Unit/WP_Mock/Matcher/FuzzyObjectTest.php
@@ -6,6 +6,8 @@
use Generator;
use Mockery;
use Mockery\Exception as MockeryException;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use ReflectionException;
use ReflectionMethod;
@@ -14,20 +16,16 @@
use WP_Mock\Tests\Mocks\SampleClassTwo;
use WP_Mock\Tests\Mocks\SampleSubClass;
-/**
- * @covers \WP_Mock\Matcher\FuzzyObject
- */
+#[CoversClass(FuzzyObject::class)]
final class FuzzyObjectTest extends TestCase
{
/**
- * @covers \WP_Mock\Matcher\FuzzyObject::__construct()
- * @dataProvider providerCanConstruct
- *
* @param object|array|mixed $expected
* @param bool $shouldThrowException
* @return void
* @throws Exception
*/
+ #[DataProvider('providerCanConstruct')]
public function testCanConstruct($expected, bool $shouldThrowException): void
{
if ($shouldThrowException) {
@@ -40,7 +38,7 @@ public function testCanConstruct($expected, bool $shouldThrowException): void
}
/** @see testCanConstruct */
- public function providerCanConstruct(): Generator
+ public static function providerCanConstruct(): Generator
{
yield 'Can construct when $expected is object' => [
'expected' => new SampleClass(),
@@ -79,15 +77,13 @@ public function providerCanConstruct(): Generator
}
/**
- * @covers \WP_Mock\Matcher\FuzzyObject::match()
- * @dataProvider providerCanMatch
- *
* @param mixed $testClass
* @param object $expectedClass
* @param bool $expectedResult
* @return void
* @throws Exception
*/
+ #[DataProvider('providerCanMatch')]
public function testCanMatch($testClass, object $expectedClass, bool $expectedResult): void
{
/** @var FuzzyObject&Mockery\LegacyMockInterface&Mockery\MockInterface $partialMock */
@@ -107,7 +103,7 @@ public function testCanMatch($testClass, object $expectedClass, bool $expectedRe
}
/** @see testCanMatch */
- public function providerCanMatch(): Generator
+ public static function providerCanMatch(): Generator
{
yield 'False when test class is not a class.' => [
'testClass' => 'not a class',
@@ -178,15 +174,13 @@ public function providerCanMatch(): Generator
}
/**
- * @covers \WP_Mock\Matcher\FuzzyObject::haveCommonAncestor()
- * @dataProvider providerCanDetermineHaveCommonAncestor
- *
* @param object|mixed $object1
* @param object|mixed $object2
* @param bool $expectedResult
* @return void
* @throws ReflectionException|Exception
*/
+ #[DataProvider('providerCanDetermineHaveCommonAncestor')]
public function testCanDetermineIfTwoObjectsHaveCommonAncestor($object1, $object2, bool $expectedResult): void
{
$instance = new FuzzyObject(new SampleClass());
@@ -198,7 +192,7 @@ public function testCanDetermineIfTwoObjectsHaveCommonAncestor($object1, $object
}
/** @see testCanDetermineIfTwoObjectsHaveCommonAncestor */
- public function providerCanDetermineHaveCommonAncestor(): Generator
+ public static function providerCanDetermineHaveCommonAncestor(): Generator
{
yield 'False when object1 is not an object' => [
'object1' => 'not an object',
@@ -232,14 +226,12 @@ public function providerCanDetermineHaveCommonAncestor(): Generator
}
/**
- * @covers \WP_Mock\Matcher\FuzzyObject::__toString()
- * @dataProvider providerToString
- *
* @param object|mixed $object
* @param string $expectedResult
* @return void
* @throws Exception
*/
+ #[DataProvider('providerToString')]
public function testCanConvertToString($object, string $expectedResult): void
{
$instance = new FuzzyObject($object);
@@ -248,10 +240,10 @@ public function testCanConvertToString($object, string $expectedResult): void
}
/** @see testCanConvertToString */
- public function providerToString(): Generator
+ public static function providerToString(): Generator
{
yield 'With expected object with all types of properties' => [
- 'expected' => new class() {
+ 'object' => new class() {
/** @var string[] */
public $testPropertyIsArray = ['foo','bar'];
@@ -271,17 +263,17 @@ public function __construct()
$this->testPropertyIsResource = stream_context_create();
}
},
- 'expectedString' => '',
+ 'expectedResult' => '',
];
yield 'With expected object with no properties' => [
- 'expected' => new class() {},
- 'expectedString' => '',
+ 'object' => new class() {},
+ 'expectedResult' => '',
];
yield 'With array' => [
- 'expected' => ['foo','bar'],
- 'expectedString' => '',
+ 'object' => ['foo','bar'],
+ 'expectedResult' => '',
];
}
}
diff --git a/tests/Unit/WP_Mock/Tools/Constraints/ExpectationsMetTest.php b/tests/Unit/WP_Mock/Tools/Constraints/ExpectationsMetTest.php
index 00d4c10..071f856 100644
--- a/tests/Unit/WP_Mock/Tools/Constraints/ExpectationsMetTest.php
+++ b/tests/Unit/WP_Mock/Tools/Constraints/ExpectationsMetTest.php
@@ -3,20 +3,17 @@
namespace WP_Mock\Tests\Unit\WP_Mock\Tools\Constraints;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use ReflectionException;
use ReflectionMethod;
use ReflectionProperty;
use WP_Mock\Tests\WP_MockTestCase;
use WP_Mock\Tools\Constraints\ExpectationsMet;
-/**
- * @covers \WP_Mock\Tools\Constraints\ExpectationsMet
- */
+#[CoversClass(ExpectationsMet::class)]
final class ExpectationsMetTest extends WP_MockTestCase
{
/**
- * @covers \WP_Mock\Tools\Constraints\ExpectationsMet::matches()
- *
* @return void
* @throws Exception
*/
@@ -28,8 +25,6 @@ public function testMatches(): void
}
/**
- * @covers \WP_Mock\Tools\Constraints\ExpectationsMet::toString()
- *
* @return void
* @throws Exception
*/
@@ -39,8 +34,6 @@ public function testCanConvertToString(): void
}
/**
- * @covers \WP_Mock\Tools\Constraints\ExpectationsMet::failureDescription()
- *
* @return void
* @throws ReflectionException|Exception
*/
@@ -54,8 +47,6 @@ public function testCanGetFailureDescription(): void
}
/**
- * @covers \WP_Mock\Tools\Constraints\ExpectationsMet::additionalFailureDescription()
- *
* @return void
* @throws ReflectionException|Exception
*/
diff --git a/tests/Unit/WP_Mock/Tools/Constraints/IsEqualHtmlTest.php b/tests/Unit/WP_Mock/Tools/Constraints/IsEqualHtmlTest.php
index 444650f..0edb731 100644
--- a/tests/Unit/WP_Mock/Tools/Constraints/IsEqualHtmlTest.php
+++ b/tests/Unit/WP_Mock/Tools/Constraints/IsEqualHtmlTest.php
@@ -4,46 +4,32 @@
use Exception;
use Generator;
-use PHPUnit\Framework\ExpectationFailedException;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use ReflectionException;
use ReflectionMethod;
use ReflectionProperty;
use WP_Mock\Tests\WP_MockTestCase;
use WP_Mock\Tools\Constraints\IsEqualHtml;
-/**
- * @covers \WP_Mock\Tools\Constraints\IsEqualHtml
- */
+#[CoversClass(IsEqualHtml::class)]
final class IsEqualHtmlTest extends WP_MockTestCase
{
/**
- * @covers \WP_Mock\Tools\Constraints\IsEqualHtml::__construct()
- *
* @return void
* @throws ReflectionException|Exception
*/
public function testConstructor(): void
{
- $props = [
- 'value' => 'Test',
- 'delta' => 1.2,
- 'canonicalize' => true,
- 'ignoreCase' => true,
- ];
-
- $constraint = new IsEqualHtml($props['value'], $props['delta'], $props['canonicalize'], $props['ignoreCase']);
+ $constraint = new IsEqualHtml('Test');
- foreach ($props as $key => $value) {
- $property = new ReflectionProperty($constraint, $key);
- $property->setAccessible(true);
+ $property = new ReflectionProperty($constraint, 'value');
+ $property->setAccessible(true);
- $this->assertSame($value, $property->getValue($constraint));
- }
+ $this->assertSame('Test', $property->getValue($constraint));
}
/**
- * @covers \WP_Mock\Tools\Constraints\IsEqualHtml::clean()
- *
* @return void
* @throws ReflectionException|Exception
*/
@@ -58,70 +44,43 @@ public function testCanClean(): void
}
/**
- * @covers \WP_Mock\Tools\Constraints\IsEqualHtml::evaluate()
- * @dataProvider providerEvaluate
- *
* @param string $value
* @param string $otherValue
- * @param bool $returnResult
- * @param bool|null $expected
- * @param bool|null $throwsException
+ * @param bool $expected
* @return void
* @throws Exception
*/
- public function testCanEvaluate(
- string $value,
- string $otherValue,
- bool $returnResult,
- ?bool $expected,
- ?bool $throwsException = null
- ): void {
+ #[DataProvider('providerMatches')]
+ public function testCanMatch(string $value, string $otherValue, bool $expected): void
+ {
$constraint = new IsEqualHtml($value);
- if ($throwsException) {
- $this->expectException(ExpectationFailedException::class);
- }
-
- $this->assertSame($expected, $constraint->evaluate($otherValue, 'Test error message', $returnResult));
+ $this->assertSame($expected, $constraint->matches($otherValue));
}
- /** @see testCanEvaluate */
- public function providerEvaluate(): Generator
+ /** @see testCanMatch */
+ public static function providerMatches(): Generator
{
- yield 'The two HTML strings are the same (return bool)' => [
+ yield 'identical HTML' => [
'value' => 'Test',
'otherValue' => 'Test',
- 'returnResult' => true,
'expected' => true,
];
- yield 'The two HTML strings are the same (throw exception)' => [
- 'value' => 'Test',
+ yield 'whitespace-insensitive match' => [
+ 'value' => "\n\t Test",
'otherValue' => 'Test',
- 'returnResult' => false,
- 'expected' => null,
- 'throwsException' => false,
+ 'expected' => true,
];
- yield 'The two HTML strings are not the same (return bool)' => [
+ yield 'different HTML' => [
'value' => 'Test',
'otherValue' => 'Test',
- 'returnResult' => true,
'expected' => false,
];
-
- yield 'The two HTML strings are not the same (throw exception)' => [
- 'value' => 'Test',
- 'otherValue' => 'Test',
- 'returnResult' => false,
- 'expected' => null,
- 'throwsException' => true,
- ];
}
/**
- * @covers \WP_Mock\Tools\Constraints\IsEqualHtml::toString()
- *
* @return void
* @throws Exception
*/
diff --git a/tests/Unit/WP_Mock/Tools/TestCaseTest.php b/tests/Unit/WP_Mock/Tools/TestCaseTest.php
index f9e6e84..3a867c0 100644
--- a/tests/Unit/WP_Mock/Tools/TestCaseTest.php
+++ b/tests/Unit/WP_Mock/Tools/TestCaseTest.php
@@ -4,25 +4,25 @@
use Exception;
use Generator;
-use InvalidArgumentException;
use Mockery;
+use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
+use PHPUnit\Framework\Attributes\PreserveGlobalState;
+use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\ExpectationFailedException;
use ReflectionException;
use ReflectionMethod;
use ReflectionProperty;
use WP_Mock;
-use WP_Mock\DeprecatedMethodListener;
use WP_Mock\Tests\WP_MockTestCase;
use WP_Mock\Tools\TestCase;
-/**
- * @covers \WP_Mock\Tools\TestCase
- */
+#[CoversClass(TestCase::class)]
+#[AllowMockObjectsWithoutExpectations]
final class TestCaseTest extends WP_MockTestCase
{
/**
- * @covers \WP_Mock\Tools\TestCase::setUp()
- *
* @return void
* @throws Exception
*/
@@ -32,12 +32,10 @@ public function testCanSetUpTests(): void
$_GET = 'test_get';
$_REQUEST = 'test_request';
- $methods = ['requireFileDependencies', 'setUpContentFiltering', 'cleanGlobals'];
- $instance = $this->getMockForAbstractClass(TestCase::class, [], '', false, false, true, $methods);
+ $instance = $this->createPartialMock(TestCase::class, ['requireFileDependencies', 'cleanGlobals']);
- foreach ($methods as $method) {
- $instance->expects($this->once())->method($method);
- }
+ $instance->expects($this->once())->method('requireFileDependencies');
+ $instance->expects($this->once())->method('cleanGlobals');
$instance->setUp();
@@ -47,22 +45,17 @@ public function testCanSetUpTests(): void
}
/**
- * @covers \WP_Mock\Tools\TestCase::tearDown()
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
* @return void
* @throws Exception|ReflectionException
*/
+ #[RunInSeparateProcess]
+ #[PreserveGlobalState(false)]
public function testCanTearDownTests(): void
{
$wpMock = Mockery::mock('overload:WP_Mock');
$wpMock->shouldReceive('tearDown');
- $instance = $this->getMockForAbstractClass(TestCase::class, [], '', false, false, true, [
- 'cleanGlobals',
- ]);
+ $instance = $this->createPartialMock(TestCase::class, ['cleanGlobals']);
$instance->expects($this->once())
->method('cleanGlobals');
@@ -77,73 +70,6 @@ public function testCanTearDownTests(): void
}
/**
- * @covers \WP_Mock\Tools\TestCase::run()
- *
- * @doesNotPerformAssertions
- *
- * @return void
- * @throws Exception
- */
- public function testCanRunTests(): void
- {
- $this->markTestSkipped('Cannot create test doubles for final classes from PHPUnit.');
- }
-
- /**
- * @covers \WP_Mock\Tools\TestCase::after()
- *
- * @return void
- * @throws Exception
- */
- public function testCanPerformLogicAfterTests(): void
- {
- $instance = $this->getMockForAbstractClass(TestCase::class, [], '', false, false, true, [
- 'checkDeprecatedCalls',
- ]);
-
- $instance->expects($this->once())
- ->method('checkDeprecatedCalls');
-
- $instance->after();
- }
-
- /**
- * @covers \WP_Mock\Tools\TestCase::checkDeprecatedCalls()
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
- * @return void
- * @throws Exception
- */
- public function testCanCheckDeprecatedCalls(): void
- {
- $deprecatedMethodListener = $this->getMockBuilder(DeprecatedMethodListener::class)
- ->disableOriginalConstructor()
- ->onlyMethods(['checkCalls', 'reset'])
- ->getMock();
-
- $deprecatedMethodListener->expects($this->atMost(1))
- ->method('checkCalls');
-
- $deprecatedMethodListener->expects($this->atMost(1))
- ->method('reset');
-
- /** @var Mockery\Mock $wpMock */
- $wpMock = Mockery::mock('overload:WP_Mock');
- /** @phpstan-ignore-next-line */
- $wpMock->shouldReceive('getDeprecatedMethodListener')
- ->andReturn($deprecatedMethodListener);
-
- $instance = $this->getMockForAbstractClass(TestCase::class);
- $method = new ReflectionMethod($instance, 'checkDeprecatedCalls');
- $method->setAccessible(true);
- $method->invoke($instance);
- }
-
- /**
- * @covers \WP_Mock\Tools\TestCase::cleanGlobals()
- *
* @return void
* @throws ReflectionException|Exception
*/
@@ -154,7 +80,7 @@ public function testCanCleanGlobals(): void
$post = 'foo';
$wp_query = 'bar';
- $instance = $this->getMockForAbstractClass(TestCase::class);
+ $instance = $this->createPartialMock(TestCase::class, []);
$method = new ReflectionMethod($instance, 'cleanGlobals');
$method->setAccessible(true);
$method->invoke($instance);
@@ -164,53 +90,16 @@ public function testCanCleanGlobals(): void
}
/**
- * @covers \WP_Mock\Tools\TestCase::setUpContentFiltering()
- *
- * @return void
- * @throws ReflectionException|Exception
- */
- public function testCanSetUpContentFiltering(): void
- {
- $instance = $this->getMockForAbstractClass(TestCase::class);
-
- $property = new ReflectionProperty($instance, '__contentFilterCallback');
- $property->setAccessible(true);
-
- $this->assertFalse($property->getValue($instance));
-
- $method = new ReflectionMethod($instance, 'setUpContentFiltering');
- $method->setAccessible(true);
- $method->invoke($instance);
-
- $this->assertSame([$instance, 'stripTabsAndNewlines'], $property->getValue($instance));
- }
-
- /**
- * @covers \WP_Mock\Tools\TestCase::stripTabsAndNewlines()
- *
- * @return void
- * @throws Exception
- */
- public function testCanStripTabsAndNewlinesForContentFiltering(): void
- {
- $instance = $this->getMockForAbstractClass(TestCase::class);
-
- $this->assertSame('Test', $instance->stripTabsAndNewlines("\n\n\tTest\r\t"));
- }
-
- /**
- * @covers \WP_Mock\Tools\TestCase::assertActionsCalled()
- * @dataProvider providerAssertActionsCalled
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
* @param bool $throwsException
* @return void
* @throws Exception
- */public function testCanAssertExpectedActionsWereCalled(bool $throwsException): void
+ */
+ #[DataProvider('providerAssertActionsCalled')]
+ #[RunInSeparateProcess]
+ #[PreserveGlobalState(false)]
+ public function testCanAssertExpectedActionsWereCalled(bool $throwsException): void
{
- $instance = $this->getMockForAbstractClass(TestCase::class);
+ $instance = $this->createPartialMock(TestCase::class, []);
/** @var Mockery\Mock $wpMock */
$wpMock = Mockery::mock('overload:WP_Mock');
@@ -227,26 +116,23 @@ public function testCanStripTabsAndNewlinesForContentFiltering(): void
}
/** @see testCanAssertExpectedActionsWereCalled */
- public function providerAssertActionsCalled(): Generator
+ public static function providerAssertActionsCalled(): Generator
{
yield 'Actions were not called' => [true];
yield 'Actions were called' => [false];
}
/**
- * @covers \WP_Mock\Tools\TestCase::assertHooksAdded()
- * @dataProvider providerAssertHooksAdded
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
* @param bool $throwsException
* @return void
* @throws Exception
*/
+ #[DataProvider('providerAssertHooksAdded')]
+ #[RunInSeparateProcess]
+ #[PreserveGlobalState(false)]
public function testCanAssertExpectedHooksWereAdded(bool $throwsException): void
{
- $instance = $this->getMockForAbstractClass(TestCase::class);
+ $instance = $this->createPartialMock(TestCase::class, []);
/** @var Mockery\Mock $wpMock */
$wpMock = Mockery::mock('overload:WP_Mock');
@@ -263,23 +149,19 @@ public function testCanAssertExpectedHooksWereAdded(bool $throwsException): void
}
/** @see testCanAssertExpectedHooksWereAdded */
- public function providerAssertHooksAdded(): Generator
+ public static function providerAssertHooksAdded(): Generator
{
yield 'Hooks were not added' => [true];
yield 'Hooks were added' => [false];
}
/**
- * @covers \WP_Mock\Tools\TestCase::assertCurrentConditionsMet()
- *
* @return void
* @throws Exception
*/
public function testCanAssertCurrentTestConditionsWereMet(): void
{
- $instance = $this->getMockForAbstractClass(TestCase::class, [], '', true, true, true, [
- 'assertConditionsMet'
- ]);
+ $instance = $this->createPartialMock(TestCase::class, ['assertConditionsMet']);
$instance->expects($this->once())
->method('assertConditionsMet')
@@ -289,82 +171,61 @@ public function testCanAssertCurrentTestConditionsWereMet(): void
}
/**
- * @covers \WP_Mock\Tools\TestCase::assertConditionsMet()
- *
* @return void
*/
public function testCanAssertTestConditionsWereMet(): void
{
- $instance = $this->getMockForAbstractClass(TestCase::class);
+ $instance = $this->createPartialMock(TestCase::class, []);
- // this will intentionally always pass and there are no assertions to be made
+ // this will intentionally always pass
$instance->assertConditionsMet('test');
}
/**
- * @covers \WP_Mock\Tools\TestCase::expectOutputString()
- * @dataProvider providerExpectOutputString
- *
- * @param bool $expectException
* @return void
- * @throws ReflectionException|Exception
+ * @throws Exception
*/
- public function testCanExpectOutputString(bool $expectException): void
+ public function testCanAssertEqualsHtml(): void
{
- $instance = $this->getMockForAbstractClass(TestCase::class);
-
- if ($expectException) {
- $property = new ReflectionProperty($instance, '__contentFilterCallback');
- $property->setAccessible(true);
- $property->setValue($instance, function () {
- return false;
- });
-
- $this->expectException(InvalidArgumentException::class);
- }
+ $instance = $this->createPartialMock(TestCase::class, []);
- $instance->expectOutputString('test');
+ $instance->assertEqualsHtml('
test
', "
test
");
- // parent method will not run in the context of this test, this will prevent method flagging no assertions performed
- $instance->assertConditionsMet();
- }
+ $this->expectException(ExpectationFailedException::class);
- /** @see testCanExpectOutputString */
- public function providerExpectOutputString(): Generator
- {
- yield 'Should not throw an exception' => [false];
- yield 'Should throw an exception' => [true];
+ $instance->assertEqualsHtml('
foo
', '
bar
');
}
/**
- * @covers \WP_Mock\Tools\TestCase::assertEqualsHtml()
- *
* @return void
* @throws Exception
*/
- public function testCanAssertEqualsHtml(): void
+ public function testCanAssertOutputEqualsHtml(): void
{
- $instance = $this->getMockForAbstractClass(TestCase::class);
+ $instance = $this->createPartialMock(TestCase::class, []);
- $instance->assertEqualsHtml('
test
', "
test
");
+ // whitespace-insensitive match passes
+ $instance->assertOutputEqualsHtml('