mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
chore: phpstan level 5
This commit is contained in:
@ -62,7 +62,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "php-cs-fixer fix -v",
|
"lint": "php-cs-fixer fix -v",
|
||||||
"test:lint": "php-cs-fixer fix -v --dry-run",
|
"test:lint": "php-cs-fixer fix -v --dry-run",
|
||||||
"test:types": "phpstan analyse --ansi --memory-limit=-1",
|
"test:types": "phpstan analyse --ansi --memory-limit=-1 --debug",
|
||||||
"test:unit": "php bin/pest --colors=always --exclude-group=integration",
|
"test:unit": "php bin/pest --colors=always --exclude-group=integration",
|
||||||
"test:parallel": "exit 1",
|
"test:parallel": "exit 1",
|
||||||
"test:integration": "exit 1",
|
"test:integration": "exit 1",
|
||||||
|
|||||||
@ -4,7 +4,7 @@ includes:
|
|||||||
- vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon
|
- vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon
|
||||||
|
|
||||||
parameters:
|
parameters:
|
||||||
level: max
|
level: 5
|
||||||
paths:
|
paths:
|
||||||
- src
|
- src
|
||||||
|
|
||||||
|
|||||||
@ -74,11 +74,9 @@ final class Expectation
|
|||||||
/**
|
/**
|
||||||
* Dump the expectation value and end the script.
|
* Dump the expectation value and end the script.
|
||||||
*
|
*
|
||||||
* @param mixed $arguments
|
|
||||||
*
|
|
||||||
* @return never
|
* @return never
|
||||||
*/
|
*/
|
||||||
public function dd(...$arguments): void
|
public function dd(mixed ...$arguments): void
|
||||||
{
|
{
|
||||||
if (function_exists('dd')) {
|
if (function_exists('dd')) {
|
||||||
dd($this->value, ...$arguments);
|
dd($this->value, ...$arguments);
|
||||||
@ -91,13 +89,10 @@ final class Expectation
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Send the expectation value to Ray along with all given arguments.
|
* Send the expectation value to Ray along with all given arguments.
|
||||||
*
|
|
||||||
* @param ...mixed $arguments
|
|
||||||
*/
|
*/
|
||||||
public function ray(mixed ...$arguments): self
|
public function ray(mixed ...$arguments): self
|
||||||
{
|
{
|
||||||
if (function_exists('ray')) {
|
if (function_exists('ray')) {
|
||||||
// @phpstan-ignore-next-line
|
|
||||||
ray($this->value, ...$arguments);
|
ray($this->value, ...$arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,7 +219,7 @@ final class Expectation
|
|||||||
$condition = is_callable($condition)
|
$condition = is_callable($condition)
|
||||||
? $condition
|
? $condition
|
||||||
: static function () use ($condition): bool {
|
: static function () use ($condition): bool {
|
||||||
return $condition; // @phpstan-ignore-line
|
return $condition;
|
||||||
};
|
};
|
||||||
|
|
||||||
return $this->when(!$condition(), $callback);
|
return $this->when(!$condition(), $callback);
|
||||||
@ -241,7 +236,7 @@ final class Expectation
|
|||||||
$condition = is_callable($condition)
|
$condition = is_callable($condition)
|
||||||
? $condition
|
? $condition
|
||||||
: static function () use ($condition): bool {
|
: static function () use ($condition): bool {
|
||||||
return $condition; // @phpstan-ignore-line
|
return $condition;
|
||||||
};
|
};
|
||||||
|
|
||||||
if ($condition()) {
|
if ($condition()) {
|
||||||
@ -371,6 +366,8 @@ final class Expectation
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that the value starts with $expected.
|
* Asserts that the value starts with $expected.
|
||||||
|
*
|
||||||
|
* @param non-empty-string $expected
|
||||||
*/
|
*/
|
||||||
public function toStartWith(string $expected): Expectation
|
public function toStartWith(string $expected): Expectation
|
||||||
{
|
{
|
||||||
@ -381,6 +378,8 @@ final class Expectation
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that the value ends with $expected.
|
* Asserts that the value ends with $expected.
|
||||||
|
*
|
||||||
|
* @param non-empty-string $expected
|
||||||
*/
|
*/
|
||||||
public function toEndWith(string $expected): Expectation
|
public function toEndWith(string $expected): Expectation
|
||||||
{
|
{
|
||||||
@ -526,7 +525,6 @@ final class Expectation
|
|||||||
*/
|
*/
|
||||||
public function toBeInstanceOf(string $class): Expectation
|
public function toBeInstanceOf(string $class): Expectation
|
||||||
{
|
{
|
||||||
/* @phpstan-ignore-next-line */
|
|
||||||
Assert::assertInstanceOf($class, $this->value);
|
Assert::assertInstanceOf($class, $this->value);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|||||||
@ -71,11 +71,13 @@ final class TestCaseFactory
|
|||||||
|
|
||||||
public function make(): void
|
public function make(): void
|
||||||
{
|
{
|
||||||
$methods = array_filter($this->methods, function ($method) {
|
$methodsUsingOnly = $this->methodsUsingOnly();
|
||||||
return count($onlyTestCases = $this->methodsUsingOnly()) === 0 || in_array($method, $onlyTestCases, true);
|
|
||||||
|
$methods = array_filter($this->methods, function ($method) use ($methodsUsingOnly) {
|
||||||
|
return count($methodsUsingOnly) === 0 || in_array($method, $methodsUsingOnly, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (count($this->methods) > 0) {
|
if (count($methods) > 0) {
|
||||||
$this->evaluate($this->filename, $methods);
|
$this->evaluate($this->filename, $methods);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,7 +93,7 @@ final class TestCaseFactory
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_filter($this->methods, static fn ($method): bool => $method->only);
|
return array_values(array_filter($this->methods, static fn ($method): bool => $method->only));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -147,7 +149,7 @@ final class TestCaseFactory
|
|||||||
$annotations = (new $annotation())->add($method, $annotations);
|
$annotations = (new $annotation())->add($method, $annotations);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($method->datasets)) {
|
if (count($method->datasets) > 0) {
|
||||||
$dataProviderName = $methodName . '_dataset';
|
$dataProviderName = $methodName . '_dataset';
|
||||||
$annotations[] = "@dataProvider $dataProviderName";
|
$annotations[] = "@dataProvider $dataProviderName";
|
||||||
|
|
||||||
@ -214,7 +216,7 @@ EOF;
|
|||||||
throw ShouldNotHappen::fromMessage('The test description may not be empty.');
|
throw ShouldNotHappen::fromMessage('The test description may not be empty.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->methods[$method->description])) {
|
if (array_key_exists($method->description, $this->methods)) {
|
||||||
throw new TestAlreadyExist($method->filename, $method->description);
|
throw new TestAlreadyExist($method->filename, $method->description);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -81,7 +81,7 @@ final class TestCaseMethodFactory
|
|||||||
$method = $this;
|
$method = $this;
|
||||||
|
|
||||||
return function () use ($testCase, $method, $closure): mixed { // @phpstan-ignore-line
|
return function () use ($testCase, $method, $closure): mixed { // @phpstan-ignore-line
|
||||||
/** @var TestCase $this */
|
/* @var TestCase $this */
|
||||||
|
|
||||||
$testCase->proxies->proxy($this);
|
$testCase->proxies->proxy($this);
|
||||||
$method->proxies->proxy($this);
|
$method->proxies->proxy($this);
|
||||||
|
|||||||
@ -12,29 +12,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest\Logging;
|
namespace Pest\Logging;
|
||||||
|
|
||||||
use function class_exists;
|
|
||||||
use DOMDocument;
|
|
||||||
use DOMElement;
|
|
||||||
use Exception;
|
|
||||||
use function method_exists;
|
|
||||||
use Pest\Concerns\Testable;
|
|
||||||
use PHPUnit\Framework\AssertionFailedError;
|
|
||||||
use PHPUnit\Framework\ExceptionWrapper;
|
|
||||||
use PHPUnit\Framework\SelfDescribing;
|
|
||||||
use PHPUnit\Framework\Test;
|
|
||||||
use PHPUnit\Framework\TestFailure;
|
|
||||||
use PHPUnit\Framework\TestListener;
|
|
||||||
use PHPUnit\Framework\TestSuite;
|
|
||||||
use PHPUnit\Framework\Warning;
|
|
||||||
use PHPUnit\Util\Filter;
|
|
||||||
use PHPUnit\Util\Printer;
|
use PHPUnit\Util\Printer;
|
||||||
use PHPUnit\Util\Xml;
|
|
||||||
use ReflectionClass;
|
|
||||||
use ReflectionException;
|
|
||||||
use function sprintf;
|
|
||||||
use function str_replace;
|
|
||||||
use Throwable;
|
|
||||||
use function trim;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal This class is not covered by the backward compatibility promise for PHPUnit
|
* @internal This class is not covered by the backward compatibility promise for PHPUnit
|
||||||
|
|||||||
@ -69,9 +69,8 @@ final class OppositeExpectation
|
|||||||
public function __get(string $name): Expectation
|
public function __get(string $name): Expectation
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
/** @throws ExpectationFailedException */
|
|
||||||
$this->original->{$name}; // @phpstan-ignore-line
|
$this->original->{$name}; // @phpstan-ignore-line
|
||||||
} catch (ExpectationFailedException) {
|
} catch (ExpectationFailedException) { // @phpstan-ignore-line
|
||||||
return $this->original;
|
return $this->original;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,6 @@ namespace Pest\Support;
|
|||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use Pest\Exceptions\ShouldNotHappen;
|
use Pest\Exceptions\ShouldNotHappen;
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
|
|||||||
@ -13,7 +13,7 @@ use Throwable;
|
|||||||
*/
|
*/
|
||||||
final class HigherOrderTapProxy
|
final class HigherOrderTapProxy
|
||||||
{
|
{
|
||||||
private const UNDEFINED_PROPERTY = 'Undefined property: P\\';
|
private const UNDEFINED_PROPERTY = 'Undefined property: P\\'; // @phpstan-ignore-line
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new tap proxy instance.
|
* Create a new tap proxy instance.
|
||||||
@ -42,9 +42,8 @@ final class HigherOrderTapProxy
|
|||||||
public function __get(string $property)
|
public function __get(string $property)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
/** @throws Throwable */
|
|
||||||
return $this->target->{$property}; // @phpstan-ignore-line
|
return $this->target->{$property}; // @phpstan-ignore-line
|
||||||
} catch (Throwable $throwable) {
|
} catch (Throwable $throwable) { // @phpstan-ignore-line
|
||||||
Reflection::setPropertyValue($throwable, 'file', Backtrace::file());
|
Reflection::setPropertyValue($throwable, 'file', Backtrace::file());
|
||||||
Reflection::setPropertyValue($throwable, 'line', Backtrace::line());
|
Reflection::setPropertyValue($throwable, 'line', Backtrace::line());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user