mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 00:07:22 +01:00
Migrates to Pint
This commit is contained in:
@ -5,9 +5,7 @@ declare(strict_types=1);
|
||||
namespace Pest\Bootstrappers;
|
||||
|
||||
use Pest\Support\Str;
|
||||
|
||||
use function Pest\testDirectory;
|
||||
|
||||
use Pest\TestSuite;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
@ -37,19 +35,19 @@ final class BootFiles
|
||||
*/
|
||||
public function __invoke(): void
|
||||
{
|
||||
$rootPath = TestSuite::getInstance()->rootPath;
|
||||
$testsPath = $rootPath . DIRECTORY_SEPARATOR . testDirectory();
|
||||
$rootPath = TestSuite::getInstance()->rootPath;
|
||||
$testsPath = $rootPath.DIRECTORY_SEPARATOR.testDirectory();
|
||||
|
||||
foreach (self::STRUCTURE as $filename) {
|
||||
$filename = sprintf('%s%s%s', $testsPath, DIRECTORY_SEPARATOR, $filename);
|
||||
|
||||
if (!file_exists($filename)) {
|
||||
if (! file_exists($filename)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_dir($filename)) {
|
||||
$directory = new RecursiveDirectoryIterator($filename);
|
||||
$iterator = new RecursiveIteratorIterator($directory);
|
||||
$iterator = new RecursiveIteratorIterator($directory);
|
||||
/** @var \DirectoryIterator $file */
|
||||
foreach ($iterator as $file) {
|
||||
$this->load($file->__toString());
|
||||
|
||||
@ -16,8 +16,7 @@ trait Expectable
|
||||
*
|
||||
* Creates a new Expectation.
|
||||
*
|
||||
* @param TValue $value
|
||||
*
|
||||
* @param TValue $value
|
||||
* @return Expectation<TValue>
|
||||
*/
|
||||
public function expect(mixed $value): Expectation
|
||||
|
||||
@ -16,9 +16,8 @@ trait Retrievable
|
||||
*
|
||||
* @template TRetrievableValue
|
||||
*
|
||||
* @param array<string, TRetrievableValue>|object $value
|
||||
* @param TRetrievableValue|null $default
|
||||
*
|
||||
* @param array<string, TRetrievableValue>|object $value
|
||||
* @param TRetrievableValue|null $default
|
||||
* @return TRetrievableValue|null
|
||||
*/
|
||||
private function retrieve(string $key, mixed $value, mixed $default = null): mixed
|
||||
|
||||
@ -55,7 +55,7 @@ trait Testable
|
||||
public static function flush(): void
|
||||
{
|
||||
self::$__beforeAll = null;
|
||||
self::$__afterAll = null;
|
||||
self::$__afterAll = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,9 +68,9 @@ trait Testable
|
||||
$test = TestSuite::getInstance()->tests->get(self::$__filename);
|
||||
|
||||
if ($test->hasMethod($name)) {
|
||||
$method = $test->getMethod($name);
|
||||
$method = $test->getMethod($name);
|
||||
self::$__description = $method->description;
|
||||
$this->__test = $method->getClosure($this);
|
||||
$this->__test = $method->getClosure($this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ trait Testable
|
||||
*/
|
||||
public function __addBeforeAll(?Closure $hook): void
|
||||
{
|
||||
if (!$hook) {
|
||||
if (! $hook) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ trait Testable
|
||||
*/
|
||||
public function __addAfterAll(?Closure $hook): void
|
||||
{
|
||||
if (!$hook) {
|
||||
if (! $hook) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ trait Testable
|
||||
*/
|
||||
private function __addHook(string $property, ?Closure $hook): void
|
||||
{
|
||||
if (!$hook) {
|
||||
if (! $hook) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -222,7 +222,7 @@ trait Testable
|
||||
$method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name());
|
||||
|
||||
if ($this->dataName()) {
|
||||
self::$__description = $method->description . ' with ' . $this->dataName();
|
||||
self::$__description = $method->description.' with '.$this->dataName();
|
||||
} else {
|
||||
self::$__description = $method->description;
|
||||
}
|
||||
@ -231,11 +231,11 @@ trait Testable
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
if (!$arguments[0] instanceof Closure) {
|
||||
if (! $arguments[0] instanceof Closure) {
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
$underlyingTest = Reflection::getFunctionVariable($this->__test, 'closure');
|
||||
$underlyingTest = Reflection::getFunctionVariable($this->__test, 'closure');
|
||||
$testParameterTypes = array_values(Reflection::getFunctionArguments($underlyingTest));
|
||||
|
||||
if (in_array($testParameterTypes[0], ['Closure', 'callable'])) {
|
||||
@ -244,7 +244,7 @@ trait Testable
|
||||
|
||||
$boundDatasetResult = $this->__callClosure($arguments[0], []);
|
||||
|
||||
if (count($testParameterTypes) === 1 || !is_array($boundDatasetResult)) {
|
||||
if (count($testParameterTypes) === 1 || ! is_array($boundDatasetResult)) {
|
||||
return [$boundDatasetResult];
|
||||
}
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ final class ConfigLoader
|
||||
$suiteDirectory = $this->config->xpath('/phpunit/testsuites/testsuite/directory');
|
||||
|
||||
// @phpstan-ignore-next-line
|
||||
if (!$suiteDirectory || count($suiteDirectory) === 0) {
|
||||
if (! $suiteDirectory || count($suiteDirectory) === 0) {
|
||||
return self::DEFAULT_TESTS_PATH;
|
||||
}
|
||||
|
||||
@ -71,9 +71,9 @@ final class ConfigLoader
|
||||
public function getConfigurationFilePath(): string|false
|
||||
{
|
||||
$candidates = [
|
||||
$this->rootPath . '/phpunit.xml',
|
||||
$this->rootPath . '/phpunit.dist.xml',
|
||||
$this->rootPath . '/phpunit.xml.dist',
|
||||
$this->rootPath.'/phpunit.xml',
|
||||
$this->rootPath.'/phpunit.dist.xml',
|
||||
$this->rootPath.'/phpunit.xml.dist',
|
||||
];
|
||||
|
||||
foreach ($candidates as $candidate) {
|
||||
@ -97,7 +97,7 @@ final class ConfigLoader
|
||||
}
|
||||
|
||||
$oldReportingLevel = error_reporting(0);
|
||||
$content = file_get_contents($configPath);
|
||||
$content = file_get_contents($configPath);
|
||||
|
||||
if ($content !== false) {
|
||||
try {
|
||||
|
||||
@ -12,8 +12,7 @@ interface HandlesArguments
|
||||
/**
|
||||
* Adds arguments before of the Test Suite execution.
|
||||
*
|
||||
* @param array<int, string> $arguments
|
||||
*
|
||||
* @param array<int, string> $arguments
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function handleArguments(array $arguments): array;
|
||||
|
||||
@ -17,7 +17,7 @@ final class DatasetMissing extends BadFunctionCallException implements Exception
|
||||
/**
|
||||
* Creates a new Exception instance.
|
||||
*
|
||||
* @param array<string, string> $arguments
|
||||
* @param array<string, string> $arguments
|
||||
*/
|
||||
public function __construct(string $file, string $name, array $arguments)
|
||||
{
|
||||
|
||||
@ -37,7 +37,7 @@ final class Expectation
|
||||
/**
|
||||
* Creates a new expectation.
|
||||
*
|
||||
* @param TValue $value
|
||||
* @param TValue $value
|
||||
*/
|
||||
public function __construct(
|
||||
public mixed $value
|
||||
@ -50,8 +50,7 @@ final class Expectation
|
||||
*
|
||||
* @template TAndValue
|
||||
*
|
||||
* @param TAndValue $value
|
||||
*
|
||||
* @param TAndValue $value
|
||||
* @return self<TAndValue>
|
||||
*/
|
||||
public function and(mixed $value): Expectation
|
||||
@ -66,7 +65,7 @@ final class Expectation
|
||||
*/
|
||||
public function json(): Expectation
|
||||
{
|
||||
if (!is_string($this->value)) {
|
||||
if (! is_string($this->value)) {
|
||||
InvalidExpectationValue::expected('string');
|
||||
}
|
||||
|
||||
@ -139,7 +138,7 @@ final class Expectation
|
||||
*/
|
||||
public function each(callable $callback = null): EachExpectation
|
||||
{
|
||||
if (!is_iterable($this->value)) {
|
||||
if (! is_iterable($this->value)) {
|
||||
throw new BadMethodCallException('Expectation value is not iterable.');
|
||||
}
|
||||
|
||||
@ -158,25 +157,24 @@ final class Expectation
|
||||
* @template TSequenceValue
|
||||
*
|
||||
* @param (callable(self<TValue>, self<string|int>): void)|TSequenceValue ...$callbacks
|
||||
*
|
||||
* @return self<TValue>
|
||||
*/
|
||||
public function sequence(mixed ...$callbacks): Expectation
|
||||
{
|
||||
if (!is_iterable($this->value)) {
|
||||
if (! is_iterable($this->value)) {
|
||||
throw new BadMethodCallException('Expectation value is not iterable.');
|
||||
}
|
||||
|
||||
$value = is_array($this->value) ? $this->value : iterator_to_array($this->value);
|
||||
$keys = array_keys($value);
|
||||
$values = array_values($value);
|
||||
$value = is_array($this->value) ? $this->value : iterator_to_array($this->value);
|
||||
$keys = array_keys($value);
|
||||
$values = array_values($value);
|
||||
$callbacksCount = count($callbacks);
|
||||
|
||||
$index = 0;
|
||||
|
||||
while (count($callbacks) < count($values)) {
|
||||
$callbacks[] = $callbacks[$index];
|
||||
$index = $index < count($values) - 1 ? $index + 1 : 0;
|
||||
$index = $index < count($values) - 1 ? $index + 1 : 0;
|
||||
}
|
||||
|
||||
if ($callbacksCount > count($values)) {
|
||||
@ -203,7 +201,6 @@ final class Expectation
|
||||
*
|
||||
* @param (callable(): TMatchSubject)|TMatchSubject $subject
|
||||
* @param array<TMatchSubject, (callable(self<TValue>): mixed)|TValue> $expressions
|
||||
*
|
||||
* @return self<TValue>
|
||||
*/
|
||||
public function match(mixed $subject, array $expressions): Expectation
|
||||
@ -241,8 +238,7 @@ final class Expectation
|
||||
* Apply the callback if the given "condition" is falsy.
|
||||
*
|
||||
* @param (callable(): bool)|bool $condition
|
||||
* @param callable(Expectation<TValue>): mixed $callback
|
||||
*
|
||||
* @param callable(Expectation<TValue>): mixed $callback
|
||||
* @return self<TValue>
|
||||
*/
|
||||
public function unless(callable|bool $condition, callable $callback): Expectation
|
||||
@ -253,15 +249,14 @@ final class Expectation
|
||||
return $condition;
|
||||
};
|
||||
|
||||
return $this->when(!$condition(), $callback);
|
||||
return $this->when(! $condition(), $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the callback if the given "condition" is truthy.
|
||||
*
|
||||
* @param (callable(): bool)|bool $condition
|
||||
* @param callable(self<TValue>): mixed $callback
|
||||
*
|
||||
* @param callable(self<TValue>): mixed $callback
|
||||
* @return self<TValue>
|
||||
*/
|
||||
public function when(callable|bool $condition, callable $callback): Expectation
|
||||
@ -282,13 +277,12 @@ final class Expectation
|
||||
/**
|
||||
* Dynamically calls methods on the class or creates a new higher order expectation.
|
||||
*
|
||||
* @param array<int, mixed> $parameters
|
||||
*
|
||||
* @param array<int, mixed> $parameters
|
||||
* @return Expectation<TValue>|HigherOrderExpectation<Expectation<TValue>, TValue>
|
||||
*/
|
||||
public function __call(string $method, array $parameters): Expectation|HigherOrderExpectation
|
||||
{
|
||||
if (!self::hasMethod($method)) {
|
||||
if (! self::hasMethod($method)) {
|
||||
/* @phpstan-ignore-next-line */
|
||||
return new HigherOrderExpectation($this, $this->value->$method(...$parameters));
|
||||
}
|
||||
@ -331,7 +325,7 @@ final class Expectation
|
||||
*/
|
||||
public function __get(string $name)
|
||||
{
|
||||
if (!self::hasMethod($name)) {
|
||||
if (! self::hasMethod($name)) {
|
||||
/* @phpstan-ignore-next-line */
|
||||
return new HigherOrderExpectation($this, $this->retrieve($name, $this->value));
|
||||
}
|
||||
|
||||
@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace Pest\Expectations;
|
||||
|
||||
use function expect;
|
||||
|
||||
use Pest\Expectation;
|
||||
|
||||
/**
|
||||
@ -22,7 +21,7 @@ final class EachExpectation
|
||||
/**
|
||||
* Creates an expectation on each item of the iterable "value".
|
||||
*
|
||||
* @param Expectation<TValue> $original
|
||||
* @param Expectation<TValue> $original
|
||||
*/
|
||||
public function __construct(private Expectation $original)
|
||||
{
|
||||
@ -33,8 +32,7 @@ final class EachExpectation
|
||||
*
|
||||
* @template TAndValue
|
||||
*
|
||||
* @param TAndValue $value
|
||||
*
|
||||
* @param TAndValue $value
|
||||
* @return Expectation<TAndValue>
|
||||
*/
|
||||
public function and(mixed $value): Expectation
|
||||
@ -57,8 +55,7 @@ final class EachExpectation
|
||||
/**
|
||||
* Dynamically calls methods on the class with the given arguments on each item.
|
||||
*
|
||||
* @param array<int|string, mixed> $arguments
|
||||
*
|
||||
* @param array<int|string, mixed> $arguments
|
||||
* @return self<TValue>
|
||||
*/
|
||||
public function __call(string $name, array $arguments): EachExpectation
|
||||
|
||||
@ -32,8 +32,8 @@ final class HigherOrderExpectation
|
||||
/**
|
||||
* Creates a new higher order expectation.
|
||||
*
|
||||
* @param Expectation<TOriginalValue> $original
|
||||
* @param TValue $value
|
||||
* @param Expectation<TOriginalValue> $original
|
||||
* @param TValue $value
|
||||
*/
|
||||
public function __construct(private Expectation $original, mixed $value)
|
||||
{
|
||||
@ -47,7 +47,7 @@ final class HigherOrderExpectation
|
||||
*/
|
||||
public function not(): HigherOrderExpectation
|
||||
{
|
||||
$this->opposite = !$this->opposite;
|
||||
$this->opposite = ! $this->opposite;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -57,8 +57,7 @@ final class HigherOrderExpectation
|
||||
*
|
||||
* @template TExpectValue
|
||||
*
|
||||
* @param TExpectValue $value
|
||||
*
|
||||
* @param TExpectValue $value
|
||||
* @return Expectation<TExpectValue>
|
||||
*/
|
||||
public function expect(mixed $value): Expectation
|
||||
@ -71,8 +70,7 @@ final class HigherOrderExpectation
|
||||
*
|
||||
* @template TExpectValue
|
||||
*
|
||||
* @param TExpectValue $value
|
||||
*
|
||||
* @param TExpectValue $value
|
||||
* @return Expectation<TExpectValue>
|
||||
*/
|
||||
public function and(mixed $value): Expectation
|
||||
@ -84,8 +82,7 @@ final class HigherOrderExpectation
|
||||
* Scope an expectation callback to the current value in
|
||||
* the HigherOrderExpectation chain.
|
||||
*
|
||||
* @param Closure(Expectation<TValue>): void $expectation
|
||||
*
|
||||
* @param Closure(Expectation<TValue>): void $expectation
|
||||
* @return HigherOrderExpectation<TOriginalValue, TOriginalValue>
|
||||
*/
|
||||
public function scoped(Closure $expectation): self
|
||||
@ -108,13 +105,12 @@ final class HigherOrderExpectation
|
||||
/**
|
||||
* Dynamically calls methods on the class with the given arguments.
|
||||
*
|
||||
* @param array<int, mixed> $arguments
|
||||
*
|
||||
* @param array<int, mixed> $arguments
|
||||
* @return self<TOriginalValue, mixed>|self<TOriginalValue, TValue>
|
||||
*/
|
||||
public function __call(string $name, array $arguments): self
|
||||
{
|
||||
if (!$this->expectationHasMethod($name)) {
|
||||
if (! $this->expectationHasMethod($name)) {
|
||||
/* @phpstan-ignore-next-line */
|
||||
return new self($this->original, $this->getValue()->$name(...$arguments));
|
||||
}
|
||||
@ -133,7 +129,7 @@ final class HigherOrderExpectation
|
||||
return $this->not();
|
||||
}
|
||||
|
||||
if (!$this->expectationHasMethod($name)) {
|
||||
if (! $this->expectationHasMethod($name)) {
|
||||
/** @var array<string, mixed>|object $value */
|
||||
$value = $this->getValue();
|
||||
|
||||
@ -165,8 +161,7 @@ final class HigherOrderExpectation
|
||||
/**
|
||||
* Performs the given assertion with the current expectation.
|
||||
*
|
||||
* @param array<int, mixed> $arguments
|
||||
*
|
||||
* @param array<int, mixed> $arguments
|
||||
* @return self<TOriginalValue, TValue>
|
||||
*/
|
||||
private function performAssertion(string $name, array $arguments): self
|
||||
@ -174,7 +169,7 @@ final class HigherOrderExpectation
|
||||
/* @phpstan-ignore-next-line */
|
||||
$this->expectation = ($this->opposite ? $this->expectation->not() : $this->expectation)->{$name}(...$arguments);
|
||||
|
||||
$this->opposite = false;
|
||||
$this->opposite = false;
|
||||
$this->shouldReset = true;
|
||||
|
||||
return $this;
|
||||
|
||||
@ -21,7 +21,7 @@ final class OppositeExpectation
|
||||
/**
|
||||
* Creates a new opposite expectation.
|
||||
*
|
||||
* @param Expectation<TValue> $original
|
||||
* @param Expectation<TValue> $original
|
||||
*/
|
||||
public function __construct(private Expectation $original)
|
||||
{
|
||||
@ -30,8 +30,7 @@ final class OppositeExpectation
|
||||
/**
|
||||
* Asserts that the value array not has the provided $keys.
|
||||
*
|
||||
* @param array<int, int|string|array<int-string, mixed>> $keys
|
||||
*
|
||||
* @param array<int, int|string|array<int-string, mixed>> $keys
|
||||
* @return Expectation<TValue>
|
||||
*/
|
||||
public function toHaveKeys(array $keys): Expectation
|
||||
@ -39,7 +38,7 @@ final class OppositeExpectation
|
||||
foreach ($keys as $k => $key) {
|
||||
try {
|
||||
if (is_array($key)) {
|
||||
$this->toHaveKeys(array_keys(Arr::dot($key, $k . '.')));
|
||||
$this->toHaveKeys(array_keys(Arr::dot($key, $k.'.')));
|
||||
} else {
|
||||
$this->original->toHaveKey($key);
|
||||
}
|
||||
@ -56,8 +55,7 @@ final class OppositeExpectation
|
||||
/**
|
||||
* Handle dynamic method calls into the original expectation.
|
||||
*
|
||||
* @param array<int, mixed> $arguments
|
||||
*
|
||||
* @param array<int, mixed> $arguments
|
||||
* @return Expectation<TValue>|Expectation<mixed>|never
|
||||
*/
|
||||
public function __call(string $name, array $arguments): Expectation
|
||||
@ -91,8 +89,7 @@ final class OppositeExpectation
|
||||
/**
|
||||
* Creates a new expectation failed exception with a nice readable message.
|
||||
*
|
||||
* @param array<int, mixed> $arguments
|
||||
*
|
||||
* @param array<int, mixed> $arguments
|
||||
* @return never
|
||||
*/
|
||||
private function throwExpectationFailedException(string $name, array $arguments = []): void
|
||||
|
||||
@ -15,8 +15,7 @@ final class CoversNothing
|
||||
/**
|
||||
* Adds annotations regarding the "depends" feature.
|
||||
*
|
||||
* @param array<int, string> $annotations
|
||||
*
|
||||
* @param array<int, string> $annotations
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function __invoke(TestCaseMethodFactory $method, array $annotations): array
|
||||
|
||||
@ -15,8 +15,7 @@ final class Depends
|
||||
/**
|
||||
* Adds annotations regarding the "depends" feature.
|
||||
*
|
||||
* @param array<int, string> $annotations
|
||||
*
|
||||
* @param array<int, string> $annotations
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function __invoke(TestCaseMethodFactory $method, array $annotations): array
|
||||
|
||||
@ -14,8 +14,7 @@ final class Groups
|
||||
/**
|
||||
* Adds annotations regarding the "groups" feature.
|
||||
*
|
||||
* @param array<int, string> $annotations
|
||||
*
|
||||
* @param array<int, string> $annotations
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function __invoke(TestCaseMethodFactory $method, array $annotations): array
|
||||
|
||||
@ -19,8 +19,7 @@ abstract class Attribute
|
||||
public const ABOVE_CLASS = false;
|
||||
|
||||
/**
|
||||
* @param array<int, string> $attributes
|
||||
*
|
||||
* @param array<int, string> $attributes
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function __invoke(TestCaseMethodFactory $method, array $attributes): array // @phpstan-ignore-line
|
||||
|
||||
@ -23,8 +23,7 @@ final class Covers extends Attribute
|
||||
/**
|
||||
* Adds attributes regarding the "covers" feature.
|
||||
*
|
||||
* @param array<int, string> $attributes
|
||||
*
|
||||
* @param array<int, string> $attributes
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function __invoke(TestCaseMethodFactory $method, array $attributes): array
|
||||
@ -33,7 +32,7 @@ final class Covers extends Attribute
|
||||
if ($covering instanceof CoversClass) {
|
||||
// Prepend a backslash for FQN classes
|
||||
if (str_contains($covering->class, '\\')) {
|
||||
$covering->class = '\\' . $covering->class;
|
||||
$covering->class = '\\'.$covering->class;
|
||||
}
|
||||
|
||||
$attributes[] = "#[\PHPUnit\Framework\Attributes\CoversClass({$covering->class}::class)]";
|
||||
|
||||
@ -28,8 +28,8 @@ trait HigherOrderable
|
||||
*/
|
||||
private function bootHigherOrderable(): void
|
||||
{
|
||||
$this->chains = new HigherOrderMessageCollection();
|
||||
$this->chains = new HigherOrderMessageCollection();
|
||||
$this->factoryProxies = new HigherOrderMessageCollection();
|
||||
$this->proxies = new HigherOrderMessageCollection();
|
||||
$this->proxies = new HigherOrderMessageCollection();
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ final class TestCaseFactory
|
||||
/**
|
||||
* Creates a Test Case class using a runtime evaluate.
|
||||
*
|
||||
* @param array<int, TestCaseMethodFactory> $methods
|
||||
* @param array<int, TestCaseMethodFactory> $methods
|
||||
*/
|
||||
public function evaluate(string $filename, array $methods): void
|
||||
{
|
||||
@ -118,9 +118,9 @@ final class TestCaseFactory
|
||||
$filename = (string) preg_replace_callback('~^(?P<drive>[a-z]+:\\\)~i', static fn ($match): string => strtolower($match['drive']), $filename);
|
||||
}
|
||||
|
||||
$filename = str_replace('\\\\', '\\', addslashes((string) realpath($filename)));
|
||||
$rootPath = TestSuite::getInstance()->rootPath;
|
||||
$relativePath = str_replace($rootPath . DIRECTORY_SEPARATOR, '', $filename);
|
||||
$filename = str_replace('\\\\', '\\', addslashes((string) realpath($filename)));
|
||||
$rootPath = TestSuite::getInstance()->rootPath;
|
||||
$relativePath = str_replace($rootPath.DIRECTORY_SEPARATOR, '', $filename);
|
||||
|
||||
$basename = basename($relativePath, '.php');
|
||||
|
||||
@ -130,7 +130,7 @@ final class TestCaseFactory
|
||||
$basename = substr($basename, 0, $dotPos);
|
||||
}
|
||||
|
||||
$relativePath = dirname(ucfirst($relativePath)) . DIRECTORY_SEPARATOR . $basename;
|
||||
$relativePath = dirname(ucfirst($relativePath)).DIRECTORY_SEPARATOR.$basename;
|
||||
|
||||
$relativePath = str_replace(DIRECTORY_SEPARATOR, '\\', $relativePath);
|
||||
|
||||
@ -141,29 +141,29 @@ final class TestCaseFactory
|
||||
// Limit to A-Z, a-z, 0-9, '_', '-'.
|
||||
$relativePath = (string) preg_replace('/[^A-Za-z0-9\\\\]/', '', $relativePath);
|
||||
|
||||
$classFQN = 'P\\' . $relativePath;
|
||||
$classFQN = 'P\\'.$relativePath;
|
||||
|
||||
if (class_exists($classFQN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$hasPrintableTestCaseClassFQN = sprintf('\%s', HasPrintableTestCaseName::class);
|
||||
$traitsCode = sprintf('use %s;', implode(', ', array_map(
|
||||
$traitsCode = sprintf('use %s;', implode(', ', array_map(
|
||||
static fn ($trait): string => sprintf('\%s', $trait), $this->traits))
|
||||
);
|
||||
|
||||
$partsFQN = explode('\\', $classFQN);
|
||||
$partsFQN = explode('\\', $classFQN);
|
||||
$className = array_pop($partsFQN);
|
||||
$namespace = implode('\\', $partsFQN);
|
||||
$baseClass = sprintf('\%s', $this->class);
|
||||
|
||||
if ('' === trim($className)) {
|
||||
$className = 'InvalidTestName' . Str::random();
|
||||
$className = 'InvalidTestName'.Str::random();
|
||||
$classFQN .= $className;
|
||||
}
|
||||
|
||||
$classAvailableAttributes = array_filter(self::$attributes, fn (string $attribute) => $attribute::ABOVE_CLASS);
|
||||
$methodAvailableAttributes = array_filter(self::$attributes, fn (string $attribute) => !$attribute::ABOVE_CLASS);
|
||||
$classAvailableAttributes = array_filter(self::$attributes, fn (string $attribute) => $attribute::ABOVE_CLASS);
|
||||
$methodAvailableAttributes = array_filter(self::$attributes, fn (string $attribute) => ! $attribute::ABOVE_CLASS);
|
||||
|
||||
$classAttributes = [];
|
||||
|
||||
@ -225,7 +225,7 @@ final class TestCaseFactory
|
||||
throw new TestAlreadyExist($method->filename, $method->description);
|
||||
}
|
||||
|
||||
if (!$method->receivesArguments()) {
|
||||
if (! $method->receivesArguments()) {
|
||||
if ($method->closure === null) {
|
||||
throw ShouldNotHappen::fromMessage('The test closure may not be empty.');
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ final class TestCaseMethodFactory
|
||||
$method = $this;
|
||||
|
||||
return function () use ($testCase, $method, $closure): mixed { // @phpstan-ignore-line
|
||||
/* @var TestCase $this */
|
||||
/* @var TestCase $this */
|
||||
$testCase->proxies->proxy($this);
|
||||
$method->proxies->proxy($this);
|
||||
|
||||
@ -112,8 +112,8 @@ final class TestCaseMethodFactory
|
||||
/**
|
||||
* Creates a PHPUnit method as a string ready for evaluation.
|
||||
*
|
||||
* @param array<int, class-string> $annotationsToUse
|
||||
* @param array<int, class-string<\Pest\Factories\Attributes\Attribute>> $attributesToUse
|
||||
* @param array<int, class-string> $annotationsToUse
|
||||
* @param array<int, class-string<\Pest\Factories\Attributes\Attribute>> $attributesToUse
|
||||
*/
|
||||
public function buildForEvaluation(string $classFQN, array $annotationsToUse, array $attributesToUse): string
|
||||
{
|
||||
@ -123,13 +123,13 @@ final class TestCaseMethodFactory
|
||||
|
||||
$methodName = Str::evaluable($this->description);
|
||||
|
||||
if (Retry::$retrying && !TestSuite::getInstance()->retryTempRepository->exists(sprintf('%s::%s', $classFQN, $methodName))) {
|
||||
if (Retry::$retrying && ! TestSuite::getInstance()->retryTempRepository->exists(sprintf('%s::%s', $classFQN, $methodName))) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$datasetsCode = '';
|
||||
$annotations = ['@test'];
|
||||
$attributes = [];
|
||||
$annotations = ['@test'];
|
||||
$attributes = [];
|
||||
|
||||
foreach ($annotationsToUse as $annotation) {
|
||||
/** @phpstan-ignore-next-line */
|
||||
@ -141,9 +141,9 @@ final class TestCaseMethodFactory
|
||||
}
|
||||
|
||||
if (count($this->datasets) > 0) {
|
||||
$dataProviderName = $methodName . '_dataset';
|
||||
$annotations[] = "@dataProvider $dataProviderName";
|
||||
$datasetsCode = $this->buildDatasetForEvaluation($methodName, $dataProviderName);
|
||||
$dataProviderName = $methodName.'_dataset';
|
||||
$annotations[] = "@dataProvider $dataProviderName";
|
||||
$datasetsCode = $this->buildDatasetForEvaluation($methodName, $dataProviderName);
|
||||
}
|
||||
|
||||
$annotations = implode('', array_map(
|
||||
|
||||
@ -13,14 +13,13 @@ use Pest\Support\HigherOrderTapProxy;
|
||||
use Pest\TestSuite;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
if (!function_exists('expect')) {
|
||||
if (! function_exists('expect')) {
|
||||
/**
|
||||
* Creates a new expectation.
|
||||
*
|
||||
* @template TValue
|
||||
*
|
||||
* @param TValue $value
|
||||
*
|
||||
* @param TValue $value
|
||||
* @return Expectation<TValue>
|
||||
*/
|
||||
function expect(mixed $value = null): Expectation
|
||||
@ -29,7 +28,7 @@ if (!function_exists('expect')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('beforeAll')) {
|
||||
if (! function_exists('beforeAll')) {
|
||||
/**
|
||||
* Runs the given closure before all tests in the current file.
|
||||
*/
|
||||
@ -39,7 +38,7 @@ if (!function_exists('beforeAll')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('beforeEach')) {
|
||||
if (! function_exists('beforeEach')) {
|
||||
/**
|
||||
* Runs the given closure before each test in the current file.
|
||||
*
|
||||
@ -53,11 +52,11 @@ if (!function_exists('beforeEach')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('dataset')) {
|
||||
if (! function_exists('dataset')) {
|
||||
/**
|
||||
* Registers the given dataset.
|
||||
*
|
||||
* @param Closure|iterable<int|string, mixed> $dataset
|
||||
* @param Closure|iterable<int|string, mixed> $dataset
|
||||
*/
|
||||
function dataset(string $name, Closure|iterable $dataset): void
|
||||
{
|
||||
@ -65,12 +64,12 @@ if (!function_exists('dataset')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('uses')) {
|
||||
if (! function_exists('uses')) {
|
||||
/**
|
||||
* The uses function binds the given
|
||||
* arguments to test closures.
|
||||
*
|
||||
* @param class-string ...$classAndTraits
|
||||
* @param class-string ...$classAndTraits
|
||||
*/
|
||||
function uses(string ...$classAndTraits): UsesCall
|
||||
{
|
||||
@ -80,7 +79,7 @@ if (!function_exists('uses')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('test')) {
|
||||
if (! function_exists('test')) {
|
||||
/**
|
||||
* Adds the given closure as a test. The first argument
|
||||
* is the test description; the second argument is
|
||||
@ -100,7 +99,7 @@ if (!function_exists('test')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('it')) {
|
||||
if (! function_exists('it')) {
|
||||
/**
|
||||
* Adds the given closure as a test. The first argument
|
||||
* is the test description; the second argument is
|
||||
@ -119,7 +118,7 @@ if (!function_exists('it')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('todo')) {
|
||||
if (! function_exists('todo')) {
|
||||
/**
|
||||
* Adds the given todo test. Internally, this test
|
||||
* is marked as incomplete. Yet, Collision, Pest's
|
||||
@ -136,7 +135,7 @@ if (!function_exists('todo')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('afterEach')) {
|
||||
if (! function_exists('afterEach')) {
|
||||
/**
|
||||
* Runs the given closure after each test in the current file.
|
||||
*
|
||||
@ -150,7 +149,7 @@ if (!function_exists('afterEach')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('afterAll')) {
|
||||
if (! function_exists('afterAll')) {
|
||||
/**
|
||||
* Runs the given closure after all tests in the current file.
|
||||
*/
|
||||
|
||||
@ -55,7 +55,7 @@ final class Kernel
|
||||
/**
|
||||
* Handles the given argv.
|
||||
*
|
||||
* @param array<int, string> $argv
|
||||
* @param array<int, string> $argv
|
||||
*/
|
||||
public function handle(array $argv): int
|
||||
{
|
||||
@ -90,7 +90,7 @@ final class Kernel
|
||||
$returnCode = self::FAILURE_EXIT;
|
||||
|
||||
if ($result->wasSuccessfulIgnoringPhpunitWarnings()
|
||||
&& !$result->hasTestTriggeredPhpunitWarningEvents()) {
|
||||
&& ! $result->hasTestTriggeredPhpunitWarningEvents()) {
|
||||
$returnCode = self::SUCCESS_EXIT;
|
||||
}
|
||||
|
||||
|
||||
@ -8,9 +8,7 @@ use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
use Pest\Exceptions\InvalidConsoleArgument;
|
||||
|
||||
use function Pest\testDirectory;
|
||||
|
||||
use Pest\TestSuite;
|
||||
|
||||
/**
|
||||
@ -53,7 +51,7 @@ final class PestDatasetCommand extends Command
|
||||
throw new InvalidConsoleArgument(sprintf('%s already exist', $target));
|
||||
}
|
||||
|
||||
if (!File::exists(dirname($relativePath))) {
|
||||
if (! File::exists(dirname($relativePath))) {
|
||||
File::makeDirectory(dirname($relativePath));
|
||||
}
|
||||
|
||||
@ -63,10 +61,10 @@ final class PestDatasetCommand extends Command
|
||||
'Dataset.php',
|
||||
]));
|
||||
|
||||
$name = mb_strtolower($name);
|
||||
$name = mb_strtolower($name);
|
||||
$contents = str_replace('{dataset_name}', $name, $contents);
|
||||
|
||||
$element = Str::singular($name);
|
||||
$element = Str::singular($name);
|
||||
$contents = str_replace('{dataset_element}', $element, $contents);
|
||||
File::put($target, str_replace('{dataset_name}', $name, $contents));
|
||||
$message = sprintf('`%s` created successfully.', $relativePath);
|
||||
|
||||
@ -8,9 +8,7 @@ use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Pest\Console\Thanks;
|
||||
use Pest\Exceptions\InvalidConsoleArgument;
|
||||
|
||||
use function Pest\testDirectory;
|
||||
|
||||
use Pest\TestSuite;
|
||||
|
||||
/**
|
||||
@ -41,7 +39,7 @@ final class PestInstallCommand extends Command
|
||||
TestSuite::getInstance(base_path(), $this->option('test-directory'));
|
||||
|
||||
/* @phpstan-ignore-next-line */
|
||||
$pest = base_path(testDirectory('Pest.php'));
|
||||
$pest = base_path(testDirectory('Pest.php'));
|
||||
$stubs = 'stubs/Laravel';
|
||||
|
||||
if (File::exists($pest)) {
|
||||
@ -56,7 +54,7 @@ final class PestInstallCommand extends Command
|
||||
|
||||
$this->output->success('`tests/Pest.php` created successfully.');
|
||||
|
||||
if (!(bool) $this->option('no-interaction')) {
|
||||
if (! (bool) $this->option('no-interaction')) {
|
||||
(new Thanks($this->output))();
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,9 +8,7 @@ use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Pest\Exceptions\InvalidConsoleArgument;
|
||||
use Pest\Support\Str;
|
||||
|
||||
use function Pest\testDirectory;
|
||||
|
||||
use Pest\TestSuite;
|
||||
|
||||
/**
|
||||
@ -54,11 +52,11 @@ final class PestTestCommand extends Command
|
||||
/* @phpstan-ignore-next-line */
|
||||
$target = base_path($relativePath);
|
||||
|
||||
if (!File::isDirectory(dirname($target))) {
|
||||
if (! File::isDirectory(dirname($target))) {
|
||||
File::makeDirectory(dirname($target), 0777, true, true);
|
||||
}
|
||||
|
||||
if (File::exists($target) && !(bool) $this->option('force')) {
|
||||
if (File::exists($target) && ! (bool) $this->option('force')) {
|
||||
throw new InvalidConsoleArgument(sprintf('%s already exist', $target));
|
||||
}
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ final class Expectation
|
||||
/**
|
||||
* Creates a new expectation.
|
||||
*
|
||||
* @param TValue $value
|
||||
* @param TValue $value
|
||||
*/
|
||||
public function __construct(
|
||||
public mixed $value
|
||||
@ -180,7 +180,7 @@ final class Expectation
|
||||
// @phpstan-ignore-next-line
|
||||
Assert::assertStringContainsString((string) $needle, $this->value);
|
||||
} else {
|
||||
if (!is_iterable($this->value)) {
|
||||
if (! is_iterable($this->value)) {
|
||||
InvalidExpectationValue::expected('iterable');
|
||||
}
|
||||
Assert::assertContains($needle, $this->value);
|
||||
@ -193,13 +193,12 @@ final class Expectation
|
||||
/**
|
||||
* Asserts that the value starts with $expected.
|
||||
*
|
||||
* @param non-empty-string $expected
|
||||
*
|
||||
* @param non-empty-string $expected
|
||||
*@return Expectation<TValue>
|
||||
*/
|
||||
public function toStartWith(string $expected): Expectation
|
||||
{
|
||||
if (!is_string($this->value)) {
|
||||
if (! is_string($this->value)) {
|
||||
InvalidExpectationValue::expected('string');
|
||||
}
|
||||
|
||||
@ -211,13 +210,12 @@ final class Expectation
|
||||
/**
|
||||
* Asserts that the value ends with $expected.
|
||||
*
|
||||
* @param non-empty-string $expected
|
||||
*
|
||||
* @param non-empty-string $expected
|
||||
*@return Expectation<TValue>
|
||||
*/
|
||||
public function toEndWith(string $expected): Expectation
|
||||
{
|
||||
if (!is_string($this->value)) {
|
||||
if (! is_string($this->value)) {
|
||||
InvalidExpectationValue::expected('string');
|
||||
}
|
||||
|
||||
@ -265,7 +263,7 @@ final class Expectation
|
||||
*/
|
||||
public function toHaveCount(int $count): Expectation
|
||||
{
|
||||
if (!is_countable($this->value) && !is_iterable($this->value)) {
|
||||
if (! is_countable($this->value) && ! is_iterable($this->value)) {
|
||||
InvalidExpectationValue::expected('string');
|
||||
}
|
||||
|
||||
@ -297,8 +295,7 @@ final class Expectation
|
||||
/**
|
||||
* Asserts that the value contains the provided properties $names.
|
||||
*
|
||||
* @param iterable<array-key, string> $names
|
||||
*
|
||||
* @param iterable<array-key, string> $names
|
||||
*@return Expectation<TValue>
|
||||
*/
|
||||
public function toHaveProperties(iterable $names): Expectation
|
||||
@ -356,8 +353,7 @@ final class Expectation
|
||||
/**
|
||||
* Asserts that the value is one of the given values.
|
||||
*
|
||||
* @param iterable<int|string, mixed> $values
|
||||
*
|
||||
* @param iterable<int|string, mixed> $values
|
||||
* @return Expectation<TValue>
|
||||
*/
|
||||
public function toBeIn(iterable $values): Expectation
|
||||
@ -382,8 +378,7 @@ final class Expectation
|
||||
/**
|
||||
* Asserts that the value is an instance of $class.
|
||||
*
|
||||
* @param class-string $class
|
||||
*
|
||||
* @param class-string $class
|
||||
* @return Expectation<TValue>
|
||||
*/
|
||||
public function toBeInstanceOf(string $class): Expectation
|
||||
@ -595,15 +590,14 @@ final class Expectation
|
||||
/**
|
||||
* Asserts that the value array has the provided $keys.
|
||||
*
|
||||
* @param array<int, int|string|array<int-string, mixed>> $keys
|
||||
*
|
||||
* @param array<int, int|string|array<int-string, mixed>> $keys
|
||||
* @return Expectation<TValue>
|
||||
*/
|
||||
public function toHaveKeys(array $keys): Expectation
|
||||
{
|
||||
foreach ($keys as $k => $key) {
|
||||
if (is_array($key)) {
|
||||
$this->toHaveKeys(array_keys(Arr::dot($key, $k . '.')));
|
||||
$this->toHaveKeys(array_keys(Arr::dot($key, $k.'.')));
|
||||
} else {
|
||||
$this->toHaveKey($key);
|
||||
}
|
||||
@ -619,7 +613,7 @@ final class Expectation
|
||||
*/
|
||||
public function toBeDirectory(): Expectation
|
||||
{
|
||||
if (!is_string($this->value)) {
|
||||
if (! is_string($this->value)) {
|
||||
InvalidExpectationValue::expected('string');
|
||||
}
|
||||
|
||||
@ -635,7 +629,7 @@ final class Expectation
|
||||
*/
|
||||
public function toBeReadableDirectory(): Expectation
|
||||
{
|
||||
if (!is_string($this->value)) {
|
||||
if (! is_string($this->value)) {
|
||||
InvalidExpectationValue::expected('string');
|
||||
}
|
||||
|
||||
@ -651,7 +645,7 @@ final class Expectation
|
||||
*/
|
||||
public function toBeWritableDirectory(): Expectation
|
||||
{
|
||||
if (!is_string($this->value)) {
|
||||
if (! is_string($this->value)) {
|
||||
InvalidExpectationValue::expected('string');
|
||||
}
|
||||
|
||||
@ -667,7 +661,7 @@ final class Expectation
|
||||
*/
|
||||
public function toBeFile(): Expectation
|
||||
{
|
||||
if (!is_string($this->value)) {
|
||||
if (! is_string($this->value)) {
|
||||
InvalidExpectationValue::expected('string');
|
||||
}
|
||||
|
||||
@ -683,7 +677,7 @@ final class Expectation
|
||||
*/
|
||||
public function toBeReadableFile(): Expectation
|
||||
{
|
||||
if (!is_string($this->value)) {
|
||||
if (! is_string($this->value)) {
|
||||
InvalidExpectationValue::expected('string');
|
||||
}
|
||||
|
||||
@ -699,7 +693,7 @@ final class Expectation
|
||||
*/
|
||||
public function toBeWritableFile(): Expectation
|
||||
{
|
||||
if (!is_string($this->value)) {
|
||||
if (! is_string($this->value)) {
|
||||
InvalidExpectationValue::expected('string');
|
||||
}
|
||||
Assert::assertFileIsWritable($this->value);
|
||||
@ -710,8 +704,7 @@ final class Expectation
|
||||
/**
|
||||
* Asserts that the value array matches the given array subset.
|
||||
*
|
||||
* @param iterable<int|string, mixed> $array
|
||||
*
|
||||
* @param iterable<int|string, mixed> $array
|
||||
* @return Expectation<TValue>
|
||||
*/
|
||||
public function toMatchArray(iterable $array): Expectation
|
||||
@ -743,14 +736,13 @@ final class Expectation
|
||||
* Asserts that the value object matches a subset
|
||||
* of the properties of an given object.
|
||||
*
|
||||
* @param iterable<string, mixed> $object
|
||||
*
|
||||
* @param iterable<string, mixed> $object
|
||||
* @return Expectation<TValue>
|
||||
*/
|
||||
public function toMatchObject(iterable $object): Expectation
|
||||
{
|
||||
foreach ((array) $object as $property => $value) {
|
||||
if (!is_object($this->value) && !is_string($this->value)) {
|
||||
if (! is_object($this->value) && ! is_string($this->value)) {
|
||||
InvalidExpectationValue::expected('object|string');
|
||||
}
|
||||
|
||||
@ -779,7 +771,7 @@ final class Expectation
|
||||
*/
|
||||
public function toMatch(string $expression): Expectation
|
||||
{
|
||||
if (!is_string($this->value)) {
|
||||
if (! is_string($this->value)) {
|
||||
InvalidExpectationValue::expected('string');
|
||||
}
|
||||
Assert::assertMatchesRegularExpression($expression, $this->value);
|
||||
@ -800,13 +792,12 @@ final class Expectation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string $class
|
||||
*
|
||||
* @param class-string $class
|
||||
* @return Expectation<TValue>
|
||||
*/
|
||||
public function toContainOnlyInstancesOf(string $class): Expectation
|
||||
{
|
||||
if (!is_iterable($this->value)) {
|
||||
if (! is_iterable($this->value)) {
|
||||
InvalidExpectationValue::expected('iterable');
|
||||
}
|
||||
|
||||
@ -819,7 +810,6 @@ final class Expectation
|
||||
* Asserts that executing value throws an exception.
|
||||
*
|
||||
* @param (Closure(Throwable): mixed)|string $exception
|
||||
*
|
||||
* @return Expectation<TValue>
|
||||
*/
|
||||
public function toThrow(callable|string $exception, string $exceptionMessage = null): Expectation
|
||||
@ -827,14 +817,14 @@ final class Expectation
|
||||
$callback = NullClosure::create();
|
||||
|
||||
if ($exception instanceof Closure) {
|
||||
$callback = $exception;
|
||||
$callback = $exception;
|
||||
$parameters = (new ReflectionFunction($exception))->getParameters();
|
||||
|
||||
if (1 !== count($parameters)) {
|
||||
throw new InvalidArgumentException('The given closure must have a single parameter type-hinted as the class string.');
|
||||
}
|
||||
|
||||
if (!($type = $parameters[0]->getType()) instanceof ReflectionNamedType) {
|
||||
if (! ($type = $parameters[0]->getType()) instanceof ReflectionNamedType) {
|
||||
throw new InvalidArgumentException('The given closure\'s parameter must be type-hinted as the class string.');
|
||||
}
|
||||
|
||||
@ -844,7 +834,7 @@ final class Expectation
|
||||
try {
|
||||
($this->value)();
|
||||
} catch (Throwable $e) {
|
||||
if (!class_exists($exception)) {
|
||||
if (! class_exists($exception)) {
|
||||
if ($e instanceof Error && $e->getMessage() === "Class \"$exception\" not found") {
|
||||
throw $e;
|
||||
}
|
||||
@ -864,7 +854,7 @@ final class Expectation
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (!class_exists($exception)) {
|
||||
if (! class_exists($exception)) {
|
||||
throw new ExpectationFailedException("Exception with message \"$exception\" not thrown.");
|
||||
}
|
||||
|
||||
|
||||
@ -57,7 +57,7 @@ final class AfterEachCall
|
||||
/**
|
||||
* Saves the calls to be used on the target.
|
||||
*
|
||||
* @param array<int, mixed> $arguments
|
||||
* @param array<int, mixed> $arguments
|
||||
*/
|
||||
public function __call(string $name, array $arguments): self
|
||||
{
|
||||
|
||||
@ -57,7 +57,7 @@ final class BeforeEachCall
|
||||
/**
|
||||
* Saves the calls to be used on the target.
|
||||
*
|
||||
* @param array<int, mixed> $arguments
|
||||
* @param array<int, mixed> $arguments
|
||||
*/
|
||||
public function __call(string $name, array $arguments): self
|
||||
{
|
||||
|
||||
@ -42,7 +42,7 @@ final class TestCall
|
||||
string $description = null,
|
||||
Closure $closure = null
|
||||
) {
|
||||
$this->testCaseMethod = new TestCaseMethodFactory($filename, $description, $closure);
|
||||
$this->testCaseMethod = new TestCaseMethodFactory($filename, $description, $closure);
|
||||
$this->descriptionLess = $description === null;
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ final class TestCall
|
||||
* Runs the current test multiple times with
|
||||
* each item of the given `iterable`.
|
||||
*
|
||||
* @param array<\Closure|iterable<int|string, mixed>|string> $data
|
||||
* @param array<\Closure|iterable<int|string, mixed>|string> $data
|
||||
*/
|
||||
public function with(Closure|iterable|string ...$data): TestCall
|
||||
{
|
||||
@ -178,10 +178,10 @@ final class TestCall
|
||||
public function covers(string ...$classesOrFunctions): TestCall
|
||||
{
|
||||
foreach ($classesOrFunctions as $classOrFunction) {
|
||||
$isClass = class_exists($classOrFunction);
|
||||
$isClass = class_exists($classOrFunction);
|
||||
$isMethod = function_exists($classOrFunction);
|
||||
|
||||
if (!$isClass && !$isMethod) {
|
||||
if (! $isClass && ! $isMethod) {
|
||||
throw new InvalidArgumentException(sprintf('No class or method named "%s" has been found.', $classOrFunction));
|
||||
}
|
||||
|
||||
@ -252,7 +252,7 @@ final class TestCall
|
||||
/**
|
||||
* Saves the calls to be used on the target.
|
||||
*
|
||||
* @param array<int, mixed> $arguments
|
||||
* @param array<int, mixed> $arguments
|
||||
*/
|
||||
public function __call(string $name, array $arguments): self
|
||||
{
|
||||
@ -262,7 +262,7 @@ final class TestCall
|
||||
/**
|
||||
* Add a chain to the test case factory. Omitting the arguments will treat it as a property accessor.
|
||||
*
|
||||
* @param array<int, mixed>|null $arguments
|
||||
* @param array<int, mixed>|null $arguments
|
||||
*/
|
||||
private function addChain(string $file, int $line, string $name, array $arguments = null): self
|
||||
{
|
||||
|
||||
@ -43,7 +43,7 @@ final class UsesCall
|
||||
/**
|
||||
* Creates a new Pending Call.
|
||||
*
|
||||
* @param array<int, string> $classAndTraits
|
||||
* @param array<int, string> $classAndTraits
|
||||
*/
|
||||
public function __construct(
|
||||
private string $filename,
|
||||
@ -58,7 +58,7 @@ final class UsesCall
|
||||
*/
|
||||
public function in(string ...$targets): void
|
||||
{
|
||||
$targets = array_map(function ($path): string {
|
||||
$targets = array_map(function ($path): string {
|
||||
$startChar = DIRECTORY_SEPARATOR;
|
||||
|
||||
if ('\\' === DIRECTORY_SEPARATOR || preg_match('~\A[A-Z]:(?![^/\\\\])~i', $path) > 0) {
|
||||
|
||||
@ -11,5 +11,5 @@ function version(): string
|
||||
|
||||
function testDirectory(string $file = ''): string
|
||||
{
|
||||
return TestSuite::getInstance()->testPath . '/' . $file;
|
||||
return TestSuite::getInstance()->testPath.'/'.$file;
|
||||
}
|
||||
|
||||
@ -18,12 +18,12 @@ final class Plugin
|
||||
/**
|
||||
* Lazy loads an `uses` call on the context of plugins.
|
||||
*
|
||||
* @param class-string ...$traits
|
||||
* @param class-string ...$traits
|
||||
*/
|
||||
public static function uses(string ...$traits): void
|
||||
{
|
||||
self::$callables[] = function () use ($traits): void {
|
||||
uses(...$traits)->in(TestSuite::getInstance()->rootPath . DIRECTORY_SEPARATOR . testDirectory());
|
||||
uses(...$traits)->in(TestSuite::getInstance()->rootPath.DIRECTORY_SEPARATOR.testDirectory());
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ final class HandleArguments
|
||||
*
|
||||
* Transform the input arguments by passing it to the relevant plugins.
|
||||
*
|
||||
* @param array<int, string> $argv
|
||||
*
|
||||
* @param array<int, string> $argv
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function __invoke(array $argv): array
|
||||
|
||||
@ -12,7 +12,7 @@ trait HandleArguments
|
||||
/**
|
||||
* Checks if the given argument exists on the arguments.
|
||||
*
|
||||
* @param array<int, string> $arguments
|
||||
* @param array<int, string> $arguments
|
||||
*/
|
||||
public function hasArgument(string $argument, array $arguments): bool
|
||||
{
|
||||
@ -22,8 +22,7 @@ trait HandleArguments
|
||||
/**
|
||||
* Adds the given argument and value to the list of arguments.
|
||||
*
|
||||
* @param array<int, string> $arguments
|
||||
*
|
||||
* @param array<int, string> $arguments
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function pushArgument(string $argument, array $arguments): array
|
||||
@ -36,8 +35,7 @@ trait HandleArguments
|
||||
/**
|
||||
* Pops the given argument from the arguments.
|
||||
*
|
||||
* @param array<int, string> $arguments
|
||||
*
|
||||
* @param array<int, string> $arguments
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function popArgument(string $argument, array $arguments): array
|
||||
|
||||
@ -66,15 +66,15 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
}
|
||||
$originals = array_flip($originals);
|
||||
|
||||
$inputs = [];
|
||||
$inputs = [];
|
||||
$inputs[] = new InputOption(self::COVERAGE_OPTION, null, InputOption::VALUE_NONE);
|
||||
$inputs[] = new InputOption(self::MIN_OPTION, null, InputOption::VALUE_REQUIRED);
|
||||
|
||||
$input = new ArgvInput($arguments, new InputDefinition($inputs));
|
||||
if ((bool) $input->getOption(self::COVERAGE_OPTION)) {
|
||||
$this->coverage = true;
|
||||
$originals[] = '--coverage-php';
|
||||
$originals[] = \Pest\Support\Coverage::getPath();
|
||||
$originals[] = '--coverage-php';
|
||||
$originals[] = \Pest\Support\Coverage::getPath();
|
||||
}
|
||||
|
||||
if ($input->getOption(self::MIN_OPTION) !== null) {
|
||||
@ -93,7 +93,7 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
public function addOutput(int $exitCode): int
|
||||
{
|
||||
if ($exitCode === 0 && $this->coverage) {
|
||||
if (!\Pest\Support\Coverage::isAvailable()) {
|
||||
if (! \Pest\Support\Coverage::isAvailable()) {
|
||||
$this->output->writeln(
|
||||
"\n <fg=white;bg=red;options=bold> ERROR </> No code coverage driver is available.</>",
|
||||
);
|
||||
|
||||
@ -23,8 +23,8 @@ final class Init implements HandlesArguments
|
||||
* The files that will be created.
|
||||
*/
|
||||
private const STUBS = [
|
||||
'phpunit.xml' => 'phpunit.xml',
|
||||
'Pest.php' => 'tests/Pest.php',
|
||||
'phpunit.xml' => 'phpunit.xml',
|
||||
'Pest.php' => 'tests/Pest.php',
|
||||
'ExampleTest.php' => 'tests/ExampleTest.php',
|
||||
];
|
||||
|
||||
@ -43,7 +43,7 @@ final class Init implements HandlesArguments
|
||||
*/
|
||||
public function handleArguments(array $arguments): array
|
||||
{
|
||||
if (!array_key_exists(1, $arguments) || $arguments[1] !== self::INIT_OPTION) {
|
||||
if (! array_key_exists(1, $arguments) || $arguments[1] !== self::INIT_OPTION) {
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
@ -58,8 +58,8 @@ final class Init implements HandlesArguments
|
||||
{
|
||||
$testsBaseDir = "{$this->testSuite->rootPath}/tests";
|
||||
|
||||
if (!is_dir($testsBaseDir)) {
|
||||
if (!mkdir($testsBaseDir) && !is_dir($testsBaseDir)) {
|
||||
if (! is_dir($testsBaseDir)) {
|
||||
if (! mkdir($testsBaseDir) && ! is_dir($testsBaseDir)) {
|
||||
$this->output->writeln(sprintf(
|
||||
"\n <fg=white;bg=red;options=bold> ERROR </> Directory `%s` was not created.</>",
|
||||
$testsBaseDir
|
||||
@ -74,8 +74,8 @@ final class Init implements HandlesArguments
|
||||
}
|
||||
|
||||
foreach (self::STUBS as $from => $to) {
|
||||
$fromPath = __DIR__ . "/../../stubs/init/{$from}";
|
||||
$toPath = "{$this->testSuite->rootPath}/{$to}";
|
||||
$fromPath = __DIR__."/../../stubs/init/{$from}";
|
||||
$toPath = "{$this->testSuite->rootPath}/{$to}";
|
||||
|
||||
if (file_exists($toPath)) {
|
||||
$this->output->writeln(sprintf(
|
||||
@ -86,16 +86,16 @@ final class Init implements HandlesArguments
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($from === 'phpunit.xml' && file_exists($toPath . '.dist')) {
|
||||
if ($from === 'phpunit.xml' && file_exists($toPath.'.dist')) {
|
||||
$this->output->writeln(sprintf(
|
||||
' <fg=black;bg=yellow;options=bold> INFO </> File `%s` already exists, skipped.</>',
|
||||
$to . '.dist'
|
||||
$to.'.dist'
|
||||
));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!copy($fromPath, $toPath)) {
|
||||
if (! copy($fromPath, $toPath)) {
|
||||
$this->output->writeln(sprintf(
|
||||
'<fg=black;bg=red>[WARNING] Failed to copy stub `%s` to `%s`</>',
|
||||
$from,
|
||||
|
||||
@ -18,7 +18,7 @@ final class Printer implements HandlesArguments
|
||||
*/
|
||||
public function handleArguments(array $arguments): array
|
||||
{
|
||||
if (!array_key_exists('COLLISION_PRINTER', $_SERVER)) {
|
||||
if (! array_key_exists('COLLISION_PRINTER', $_SERVER)) {
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
|
||||
@ -5,9 +5,7 @@ declare(strict_types=1);
|
||||
namespace Pest\Plugins;
|
||||
|
||||
use Pest\Contracts\Plugins\HandlesArguments;
|
||||
|
||||
use function Pest\version;
|
||||
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
|
||||
@ -9,9 +9,7 @@ use Pest\Exceptions\DatasetAlreadyExist;
|
||||
use Pest\Exceptions\DatasetDoesNotExist;
|
||||
use Pest\Exceptions\ShouldNotHappen;
|
||||
use SebastianBergmann\Exporter\Exporter;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
@ -36,7 +34,7 @@ final class DatasetsRepository
|
||||
/**
|
||||
* Sets the given.
|
||||
*
|
||||
* @param Closure|iterable<int|string, mixed> $data
|
||||
* @param Closure|iterable<int|string, mixed> $data
|
||||
*/
|
||||
public static function set(string $name, Closure|iterable $data): void
|
||||
{
|
||||
@ -50,16 +48,16 @@ final class DatasetsRepository
|
||||
/**
|
||||
* Sets the given "with".
|
||||
*
|
||||
* @param array<Closure|iterable<int|string, mixed>|string> $with
|
||||
* @param array<Closure|iterable<int|string, mixed>|string> $with
|
||||
*/
|
||||
public static function with(string $filename, string $description, array $with): void
|
||||
{
|
||||
self::$withs[$filename . '>>>' . $description] = $with;
|
||||
self::$withs[$filename.'>>>'.$description] = $with;
|
||||
}
|
||||
|
||||
public static function has(string $filename, string $description): bool
|
||||
{
|
||||
return array_key_exists($filename . '>>>' . $description, self::$withs);
|
||||
return array_key_exists($filename.'>>>'.$description, self::$withs);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,7 +67,7 @@ final class DatasetsRepository
|
||||
*/
|
||||
public static function get(string $filename, string $description): Closure|iterable
|
||||
{
|
||||
$dataset = self::$withs[$filename . '>>>' . $description];
|
||||
$dataset = self::$withs[$filename.'>>>'.$description];
|
||||
|
||||
$dataset = self::resolve($description, $dataset);
|
||||
|
||||
@ -83,8 +81,7 @@ final class DatasetsRepository
|
||||
/**
|
||||
* Resolves the current dataset to an array value.
|
||||
*
|
||||
* @param array<Closure|iterable<int|string, mixed>|string> $dataset
|
||||
*
|
||||
* @param array<Closure|iterable<int|string, mixed>|string> $dataset
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public static function resolve(string $description, array $dataset): array|null
|
||||
@ -99,11 +96,11 @@ final class DatasetsRepository
|
||||
$datasetCombinations = self::getDatasetsCombinations($dataset);
|
||||
|
||||
$datasetDescriptions = [];
|
||||
$datasetValues = [];
|
||||
$datasetValues = [];
|
||||
|
||||
foreach ($datasetCombinations as $datasetCombination) {
|
||||
$partialDescriptions = [];
|
||||
$values = [];
|
||||
$values = [];
|
||||
|
||||
foreach ($datasetCombination as $datasetCombinationElement) {
|
||||
$partialDescriptions[] = $datasetCombinationElement['label'];
|
||||
@ -113,7 +110,7 @@ final class DatasetsRepository
|
||||
}
|
||||
|
||||
$datasetDescriptions[] = implode(' / ', $partialDescriptions);
|
||||
$datasetValues[] = $values;
|
||||
$datasetValues[] = $values;
|
||||
}
|
||||
|
||||
foreach (array_count_values($datasetDescriptions) as $descriptionToCheck => $count) {
|
||||
@ -136,8 +133,7 @@ final class DatasetsRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Closure|iterable<int|string, mixed>|string> $datasets
|
||||
*
|
||||
* @param array<Closure|iterable<int|string, mixed>|string> $datasets
|
||||
* @return array<array<mixed>>
|
||||
*/
|
||||
private static function processDatasets(array $datasets): array
|
||||
@ -148,7 +144,7 @@ final class DatasetsRepository
|
||||
$processedDataset = [];
|
||||
|
||||
if (is_string($data)) {
|
||||
if (!array_key_exists($data, self::$datasets)) {
|
||||
if (! array_key_exists($data, self::$datasets)) {
|
||||
throw new DatasetDoesNotExist($data);
|
||||
}
|
||||
|
||||
@ -165,9 +161,9 @@ final class DatasetsRepository
|
||||
|
||||
// @phpstan-ignore-next-line
|
||||
foreach ($datasets[$index] as $key => $values) {
|
||||
$values = is_array($values) ? $values : [$values];
|
||||
$values = is_array($values) ? $values : [$values];
|
||||
$processedDataset[] = [
|
||||
'label' => self::getDatasetDescription($key, $values), // @phpstan-ignore-line
|
||||
'label' => self::getDatasetDescription($key, $values), // @phpstan-ignore-line
|
||||
'values' => $values,
|
||||
];
|
||||
}
|
||||
@ -179,8 +175,7 @@ final class DatasetsRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<array<mixed>> $combinations
|
||||
*
|
||||
* @param array<array<mixed>> $combinations
|
||||
* @return array<array<array<mixed>>>
|
||||
*/
|
||||
private static function getDatasetsCombinations(array $combinations): array
|
||||
@ -201,7 +196,7 @@ final class DatasetsRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, mixed> $data
|
||||
* @param array<int, mixed> $data
|
||||
*/
|
||||
private static function getDatasetDescription(int|string $key, array $data): string
|
||||
{
|
||||
|
||||
@ -9,7 +9,7 @@ namespace Pest\Repositories;
|
||||
*/
|
||||
final class TempRepository
|
||||
{
|
||||
private const FOLDER = __DIR__ . '/../../.temp';
|
||||
private const FOLDER = __DIR__.'/../../.temp';
|
||||
|
||||
/**
|
||||
* Creates a new Temp Repository instance.
|
||||
@ -35,7 +35,7 @@ final class TempRepository
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
@unlink(self::FOLDER . '/' . $this->filename . '.json'); // @phpstan-ignore-line
|
||||
@unlink(self::FOLDER.'/'.$this->filename.'.json'); // @phpstan-ignore-line
|
||||
|
||||
$this->save([]);
|
||||
}
|
||||
@ -55,7 +55,7 @@ final class TempRepository
|
||||
*/
|
||||
private function all(): array
|
||||
{
|
||||
$contents = file_get_contents(self::FOLDER . '/' . $this->filename . '.json');
|
||||
$contents = file_get_contents(self::FOLDER.'/'.$this->filename.'.json');
|
||||
|
||||
assert(is_string($contents));
|
||||
|
||||
@ -67,12 +67,12 @@ final class TempRepository
|
||||
/**
|
||||
* Save the given elements.
|
||||
*
|
||||
* @param array<int, string> $elements
|
||||
* @param array<int, string> $elements
|
||||
*/
|
||||
private function save(array $elements): void
|
||||
{
|
||||
$contents = json_encode($elements);
|
||||
|
||||
file_put_contents(self::FOLDER . '/' . $this->filename . '.json', $contents);
|
||||
file_put_contents(self::FOLDER.'/'.$this->filename.'.json', $contents);
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,15 +54,15 @@ final class TestRepository
|
||||
/**
|
||||
* Uses the given `$testCaseClass` on the given `$paths`.
|
||||
*
|
||||
* @param array<int, string> $classOrTraits
|
||||
* @param array<int, string> $groups
|
||||
* @param array<int, string> $paths
|
||||
* @param array<int, Closure> $hooks
|
||||
* @param array<int, string> $classOrTraits
|
||||
* @param array<int, string> $groups
|
||||
* @param array<int, string> $paths
|
||||
* @param array<int, Closure> $hooks
|
||||
*/
|
||||
public function use(array $classOrTraits, array $groups, array $paths, array $hooks): void
|
||||
{
|
||||
foreach ($classOrTraits as $classOrTrait) {
|
||||
if (!class_exists($classOrTrait) && !trait_exists($classOrTrait)) {
|
||||
if (! class_exists($classOrTrait) && ! trait_exists($classOrTrait)) {
|
||||
throw new TestCaseClassOrTraitNotFound($classOrTrait);
|
||||
}
|
||||
}
|
||||
@ -90,7 +90,7 @@ final class TestRepository
|
||||
*/
|
||||
public function set(TestCaseMethodFactory $method): void
|
||||
{
|
||||
if (!array_key_exists($method->filename, $this->testCases)) {
|
||||
if (! array_key_exists($method->filename, $this->testCases)) {
|
||||
$this->testCases[$method->filename] = new TestCaseFactory($method->filename);
|
||||
}
|
||||
|
||||
@ -112,12 +112,12 @@ final class TestRepository
|
||||
*/
|
||||
private function make(TestCaseFactory $testCase): void
|
||||
{
|
||||
$startsWith = static fn (string $target, string $directory): bool => Str::startsWith($target, $directory . DIRECTORY_SEPARATOR);
|
||||
$startsWith = static fn (string $target, string $directory): bool => Str::startsWith($target, $directory.DIRECTORY_SEPARATOR);
|
||||
|
||||
foreach ($this->uses as $path => $uses) {
|
||||
[$classOrTraits, $groups, $hooks] = $uses;
|
||||
|
||||
if ((!is_dir($path) && $testCase->filename === $path) || (is_dir($path) && $startsWith($testCase->filename, $path))) {
|
||||
if ((! is_dir($path) && $testCase->filename === $path) || (is_dir($path) && $startsWith($testCase->filename, $path))) {
|
||||
foreach ($classOrTraits as $class) {
|
||||
/** @var string $class */
|
||||
if (class_exists($class)) {
|
||||
|
||||
@ -12,7 +12,7 @@ final class Arr
|
||||
/**
|
||||
* Checks if the given array has the given key.
|
||||
*
|
||||
* @param array<array-key, mixed> $array
|
||||
* @param array<array-key, mixed> $array
|
||||
*/
|
||||
public static function has(array $array, string|int $key): bool
|
||||
{
|
||||
@ -36,7 +36,7 @@ final class Arr
|
||||
/**
|
||||
* Gets the given key value.
|
||||
*
|
||||
* @param array<array-key, mixed> $array
|
||||
* @param array<array-key, mixed> $array
|
||||
*/
|
||||
public static function get(array $array, string|int $key, mixed $default = null): mixed
|
||||
{
|
||||
@ -46,7 +46,7 @@ final class Arr
|
||||
return $array[$key];
|
||||
}
|
||||
|
||||
if (!str_contains($key, '.')) {
|
||||
if (! str_contains($key, '.')) {
|
||||
return $array[$key] ?? $default;
|
||||
}
|
||||
|
||||
@ -64,8 +64,7 @@ final class Arr
|
||||
/**
|
||||
* Flatten a multi-dimensional associative array with dots.
|
||||
*
|
||||
* @param array<array-key, mixed> $array
|
||||
*
|
||||
* @param array<array-key, mixed> $array
|
||||
* @return array<int|string, mixed>
|
||||
*/
|
||||
public static function dot(array $array, string $prepend = ''): array
|
||||
@ -74,9 +73,9 @@ final class Arr
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
if (is_array($value) && count($value) > 0) {
|
||||
$results = array_merge($results, static::dot($value, $prepend . $key . '.'));
|
||||
$results = array_merge($results, static::dot($value, $prepend.$key.'.'));
|
||||
} else {
|
||||
$results[$prepend . $value] = $value;
|
||||
$results[$prepend.$value] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ final class ChainableClosure
|
||||
public static function from(Closure $closure, Closure $next): Closure
|
||||
{
|
||||
return function () use ($closure, $next): void {
|
||||
if (!is_object($this)) { // @phpstan-ignore-line
|
||||
if (! is_object($this)) { // @phpstan-ignore-line
|
||||
throw ShouldNotHappen::fromMessage('$this not bound to chainable closure.');
|
||||
}
|
||||
|
||||
|
||||
@ -35,13 +35,12 @@ final class Container
|
||||
/**
|
||||
* Gets a dependency from the container.
|
||||
*
|
||||
* @param class-string $id
|
||||
*
|
||||
* @param class-string $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function get(string $id)
|
||||
{
|
||||
if (!array_key_exists($id, $this->instances)) {
|
||||
if (! array_key_exists($id, $this->instances)) {
|
||||
$this->instances[$id] = $this->build($id);
|
||||
}
|
||||
|
||||
@ -51,7 +50,7 @@ final class Container
|
||||
/**
|
||||
* Adds the given instance to the container.
|
||||
*
|
||||
* @param mixed $instance
|
||||
* @param mixed $instance
|
||||
*/
|
||||
public function add(string $id, $instance): void
|
||||
{
|
||||
@ -61,7 +60,7 @@ final class Container
|
||||
/**
|
||||
* Tries to build the given instance.
|
||||
*
|
||||
* @param class-string $id
|
||||
* @param class-string $id
|
||||
*/
|
||||
private function build(string $id): object
|
||||
{
|
||||
|
||||
@ -11,7 +11,6 @@ use SebastianBergmann\CodeCoverage\Node\File;
|
||||
use SebastianBergmann\Environment\Runtime;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Terminal;
|
||||
|
||||
use function Termwind\render;
|
||||
use function Termwind\renderUsing;
|
||||
|
||||
@ -54,7 +53,7 @@ final class Coverage
|
||||
*/
|
||||
public static function report(OutputInterface $output): float
|
||||
{
|
||||
if (!file_exists($reportPath = self::getPath())) {
|
||||
if (! file_exists($reportPath = self::getPath())) {
|
||||
if (self::usingXdebug()) {
|
||||
$output->writeln(
|
||||
" <fg=black;bg=yellow;options=bold> WARN </> Unable to get coverage using Xdebug. Did you set <href=https://xdebug.org/docs/code_coverage#mode>Xdebug's coverage mode</>?</>",
|
||||
@ -80,10 +79,10 @@ final class Coverage
|
||||
$report = $codeCoverage->getReport();
|
||||
|
||||
foreach ($report->getIterator() as $file) {
|
||||
if (!$file instanceof File) {
|
||||
if (! $file instanceof File) {
|
||||
continue;
|
||||
}
|
||||
$dirname = dirname($file->id());
|
||||
$dirname = dirname($file->id());
|
||||
$basename = basename($file->id(), '.php');
|
||||
|
||||
$name = $dirname === '.' ? $basename : implode(DIRECTORY_SEPARATOR, [
|
||||
@ -106,7 +105,7 @@ final class Coverage
|
||||
? '100.0'
|
||||
: number_format($file->percentageOfExecutedLines()->asFloat(), 1, '.', '');
|
||||
|
||||
$takenSize = strlen($rawName . $percentage) + 2 + $linesExecutedTakenSize; // adding 3 space and percent sign
|
||||
$takenSize = strlen($rawName.$percentage) + 2 + $linesExecutedTakenSize; // adding 3 space and percent sign
|
||||
|
||||
$percentage = sprintf(
|
||||
'<fg=%s>%s</>',
|
||||
@ -146,8 +145,7 @@ final class Coverage
|
||||
* ['11', '20..25', '50', '60..80'];
|
||||
* ```
|
||||
*
|
||||
* @param File $file
|
||||
*
|
||||
* @param File $file
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function getMissingCoverage($file): array
|
||||
@ -162,7 +160,7 @@ final class Coverage
|
||||
}
|
||||
|
||||
if ($shouldBeNewLine) {
|
||||
$array[] = (string) $line;
|
||||
$array[] = (string) $line;
|
||||
$shouldBeNewLine = false;
|
||||
|
||||
return $array;
|
||||
@ -171,7 +169,7 @@ final class Coverage
|
||||
$lastKey = count($array) - 1;
|
||||
|
||||
if (array_key_exists($lastKey, $array) && str_contains($array[$lastKey], '..')) {
|
||||
[$from] = explode('..', $array[$lastKey]);
|
||||
[$from] = explode('..', $array[$lastKey]);
|
||||
$array[$lastKey] = $line > $from ? sprintf('%s..%s', $from, $line) : sprintf('%s..%s', $line, $from);
|
||||
|
||||
return $array;
|
||||
|
||||
@ -44,7 +44,7 @@ final class ExceptionTrace
|
||||
*/
|
||||
public static function removePestReferences(Throwable $t): void
|
||||
{
|
||||
if (!property_exists($t, 'serializableTrace')) {
|
||||
if (! property_exists($t, 'serializableTrace')) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -59,7 +59,7 @@ final class ExpectationPipeline
|
||||
/**
|
||||
* Sets the list of pipes.
|
||||
*
|
||||
* @param array<int, Closure> $pipes
|
||||
* @param array<int, Closure> $pipes
|
||||
*/
|
||||
public function through(array $pipes): self
|
||||
{
|
||||
|
||||
@ -26,7 +26,6 @@ final class HigherOrderCallables
|
||||
* Create a new expectation. Callable values will be executed prior to returning the new expectation.
|
||||
*
|
||||
* @param (Closure():TValue)|TValue $value
|
||||
*
|
||||
* @return Expectation<TValue>
|
||||
*/
|
||||
public function expect(mixed $value): Expectation
|
||||
@ -42,8 +41,7 @@ final class HigherOrderCallables
|
||||
*
|
||||
* Create a new expectation. Callable values will be executed prior to returning the new expectation.
|
||||
*
|
||||
* @param callable|TValue $value
|
||||
*
|
||||
* @param callable|TValue $value
|
||||
* @return Expectation<(callable(): mixed)|TValue>
|
||||
*/
|
||||
public function and(mixed $value)
|
||||
|
||||
@ -25,7 +25,7 @@ final class HigherOrderMessage
|
||||
/**
|
||||
* Creates a new higher order message.
|
||||
*
|
||||
* @param array<int, mixed> $arguments
|
||||
* @param array<int, mixed> $arguments
|
||||
*/
|
||||
public function __construct(
|
||||
public string $filename,
|
||||
@ -41,7 +41,7 @@ final class HigherOrderMessage
|
||||
*
|
||||
* @template TValue of object
|
||||
*
|
||||
* @param TValue $target
|
||||
* @param TValue $target
|
||||
*/
|
||||
public function call(object $target): mixed
|
||||
{
|
||||
@ -77,7 +77,7 @@ final class HigherOrderMessage
|
||||
/**
|
||||
* Indicates that this message should only be called when the given condition is true.
|
||||
*
|
||||
* @param callable(): bool $condition
|
||||
* @param callable(): bool $condition
|
||||
*/
|
||||
public function when(callable $condition): self
|
||||
{
|
||||
|
||||
@ -17,7 +17,7 @@ final class HigherOrderMessageCollection
|
||||
/**
|
||||
* Adds a new higher order message to the collection.
|
||||
*
|
||||
* @param array<int, mixed>|null $arguments
|
||||
* @param array<int, mixed>|null $arguments
|
||||
*/
|
||||
public function add(string $filename, int $line, string $name, ?array $arguments): void
|
||||
{
|
||||
@ -27,7 +27,7 @@ final class HigherOrderMessageCollection
|
||||
/**
|
||||
* Adds a new higher order message to the collection if the callable condition is does not return false.
|
||||
*
|
||||
* @param array<int, mixed>|null $arguments
|
||||
* @param array<int, mixed>|null $arguments
|
||||
*/
|
||||
public function addWhen(callable $condition, string $filename, int $line, string $name, ?array $arguments): void
|
||||
{
|
||||
@ -58,7 +58,7 @@ final class HigherOrderMessageCollection
|
||||
/**
|
||||
* Count the number of messages with the given name.
|
||||
*
|
||||
* @param string $name A higher order message name (usually a method name)
|
||||
* @param string $name A higher order message name (usually a method name)
|
||||
*/
|
||||
public function count(string $name): int
|
||||
{
|
||||
|
||||
@ -27,7 +27,7 @@ final class HigherOrderTapProxy
|
||||
/**
|
||||
* Dynamically sets properties on the target.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __set(string $property, $value): void
|
||||
{
|
||||
@ -60,14 +60,13 @@ final class HigherOrderTapProxy
|
||||
/**
|
||||
* Dynamically pass method calls to the target.
|
||||
*
|
||||
* @param array<int, mixed> $arguments
|
||||
*
|
||||
* @param array<int, mixed> $arguments
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call(string $methodName, array $arguments)
|
||||
{
|
||||
$filename = Backtrace::file();
|
||||
$line = Backtrace::line();
|
||||
$line = Backtrace::line();
|
||||
|
||||
return (new HigherOrderMessage($filename, $line, $methodName, $arguments))
|
||||
->call($this->target);
|
||||
|
||||
@ -33,7 +33,7 @@ abstract class Printer implements \PHPUnit\Util\Printer
|
||||
|
||||
$this->isPhpStream = str_starts_with($out, 'php://');
|
||||
|
||||
if (!$this->isPhpStream && !Filesystem::createDirectory(dirname($out))) {
|
||||
if (! $this->isPhpStream && ! Filesystem::createDirectory(dirname($out))) {
|
||||
throw new Exception(sprintf('Directory "%s" was not created', dirname($out)));
|
||||
}
|
||||
|
||||
|
||||
@ -22,8 +22,7 @@ final class Reflection
|
||||
/**
|
||||
* Calls the given method with args on the given object.
|
||||
*
|
||||
* @param array<int, mixed> $args
|
||||
*
|
||||
* @param array<int, mixed> $args
|
||||
* @return mixed
|
||||
*/
|
||||
public static function call(object $object, string $method, array $args = [])
|
||||
@ -52,8 +51,7 @@ final class Reflection
|
||||
/**
|
||||
* Bind a callable to the TestCase and return the result.
|
||||
*
|
||||
* @param array<int, mixed> $args
|
||||
*
|
||||
* @param array<int, mixed> $args
|
||||
* @return mixed
|
||||
*/
|
||||
public static function bindCallable(callable $callable, array $args = [])
|
||||
@ -104,7 +102,7 @@ final class Reflection
|
||||
} catch (ReflectionException $reflectionException) {
|
||||
$reflectionClass = $reflectionClass->getParentClass();
|
||||
|
||||
if (!$reflectionClass instanceof ReflectionClass) {
|
||||
if (! $reflectionClass instanceof ReflectionClass) {
|
||||
throw new ShouldNotHappen($reflectionException);
|
||||
}
|
||||
}
|
||||
@ -120,8 +118,8 @@ final class Reflection
|
||||
*
|
||||
* @template TValue of object
|
||||
*
|
||||
* @param TValue $object
|
||||
* @param mixed $value
|
||||
* @param TValue $object
|
||||
* @param mixed $value
|
||||
*/
|
||||
public static function setPropertyValue(object $object, string $property, $value): void
|
||||
{
|
||||
@ -137,7 +135,7 @@ final class Reflection
|
||||
} catch (ReflectionException $reflectionException) {
|
||||
$reflectionClass = $reflectionClass->getParentClass();
|
||||
|
||||
if (!$reflectionClass instanceof ReflectionClass) {
|
||||
if (! $reflectionClass instanceof ReflectionClass) {
|
||||
throw new ShouldNotHappen($reflectionException);
|
||||
}
|
||||
}
|
||||
@ -156,7 +154,7 @@ final class Reflection
|
||||
{
|
||||
$type = $parameter->getType();
|
||||
|
||||
if (!$type instanceof ReflectionNamedType || $type->isBuiltin()) {
|
||||
if (! $type instanceof ReflectionNamedType || $type->isBuiltin()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -183,7 +181,7 @@ final class Reflection
|
||||
public static function getFunctionArguments(Closure $function): array
|
||||
{
|
||||
$parameters = (new ReflectionFunction($function))->getParameters();
|
||||
$arguments = [];
|
||||
$arguments = [];
|
||||
|
||||
foreach ($parameters as $parameter) {
|
||||
/** @var ReflectionNamedType|ReflectionUnionType|null $types */
|
||||
|
||||
@ -19,7 +19,7 @@ final class Str
|
||||
* Create a (unsecure & non-cryptographically safe) random alpha-numeric
|
||||
* string value.
|
||||
*
|
||||
* @param int $length the length of the resulting randomized string
|
||||
* @param int $length the length of the resulting randomized string
|
||||
*
|
||||
* @see https://github.com/laravel/framework/blob/4.2/src/Illuminate/Support/Str.php#L240-L242
|
||||
*/
|
||||
|
||||
@ -70,11 +70,11 @@ final class TestSuite
|
||||
string $rootPath,
|
||||
public string $testPath)
|
||||
{
|
||||
$this->beforeAll = new BeforeAllRepository();
|
||||
$this->beforeEach = new BeforeEachRepository();
|
||||
$this->tests = new TestRepository();
|
||||
$this->afterEach = new AfterEachRepository();
|
||||
$this->afterAll = new AfterAllRepository();
|
||||
$this->beforeAll = new BeforeAllRepository();
|
||||
$this->beforeEach = new BeforeEachRepository();
|
||||
$this->tests = new TestRepository();
|
||||
$this->afterEach = new AfterEachRepository();
|
||||
$this->afterAll = new AfterAllRepository();
|
||||
$this->retryTempRepository = new TempRepository('retry');
|
||||
|
||||
$this->rootPath = (string) realpath($rootPath);
|
||||
|
||||
Reference in New Issue
Block a user