mirror of
https://github.com/pestphp/pest.git
synced 2026-09-06 06:43:35 +02:00
chore: coding style changes
This commit is contained in:
@@ -10,8 +10,6 @@ namespace Pest\Support;
|
||||
final class Arr
|
||||
{
|
||||
/**
|
||||
* Checks if the given array has the given key.
|
||||
*
|
||||
* @param array<array-key, mixed> $array
|
||||
*/
|
||||
public static function has(array $array, string|int $key): bool
|
||||
@@ -34,8 +32,6 @@ final class Arr
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the given key value.
|
||||
*
|
||||
* @param array<array-key, mixed> $array
|
||||
*/
|
||||
public static function get(array $array, string|int $key, mixed $default = null): mixed
|
||||
@@ -62,8 +58,6 @@ final class Arr
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten a multi-dimensional associative array with dots.
|
||||
*
|
||||
* @param array<array-key, mixed> $array
|
||||
* @return array<int|string, mixed>
|
||||
*/
|
||||
@@ -83,8 +77,6 @@ final class Arr
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the last element or false for empty array
|
||||
*
|
||||
* @param array<array-key, mixed> $array
|
||||
*/
|
||||
public static function last(array $array): mixed
|
||||
|
||||
@@ -15,9 +15,6 @@ final class Backtrace
|
||||
|
||||
private const int BACKTRACE_OPTIONS = DEBUG_BACKTRACE_IGNORE_ARGS;
|
||||
|
||||
/**
|
||||
* Returns the current test file.
|
||||
*/
|
||||
public static function testFile(): string
|
||||
{
|
||||
$current = null;
|
||||
@@ -46,9 +43,6 @@ final class Backtrace
|
||||
return $current[self::FILE];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current datasets file.
|
||||
*/
|
||||
public static function datasetsFile(): string
|
||||
{
|
||||
$current = null;
|
||||
@@ -72,9 +66,6 @@ final class Backtrace
|
||||
return $current[self::FILE];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filename that called the current function/method.
|
||||
*/
|
||||
public static function file(): string
|
||||
{
|
||||
$trace = self::backtrace();
|
||||
@@ -82,9 +73,6 @@ final class Backtrace
|
||||
return $trace[self::FILE];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the dirname that called the current function/method.
|
||||
*/
|
||||
public static function dirname(): string
|
||||
{
|
||||
$trace = self::backtrace();
|
||||
@@ -92,9 +80,6 @@ final class Backtrace
|
||||
return dirname($trace[self::FILE]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the line that called the current function/method.
|
||||
*/
|
||||
public static function line(): int
|
||||
{
|
||||
$trace = self::backtrace();
|
||||
|
||||
@@ -12,9 +12,6 @@ use Pest\Exceptions\ShouldNotHappen;
|
||||
*/
|
||||
final class ChainableClosure
|
||||
{
|
||||
/**
|
||||
* Calls the given `$closure` when the given condition is true, "bound" to the same object.
|
||||
*/
|
||||
public static function boundWhen(Closure $condition, Closure $next): Closure
|
||||
{
|
||||
return function (...$arguments) use ($condition, $next): void {
|
||||
@@ -28,9 +25,6 @@ final class ChainableClosure
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the given `$closure` and chains the `$next` closure, "bound" to the same object.
|
||||
*/
|
||||
public static function bound(Closure $closure, Closure $next): Closure
|
||||
{
|
||||
return function (...$arguments) use ($closure, $next): void {
|
||||
@@ -43,9 +37,6 @@ final class ChainableClosure
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the given `$closure` and chains the `$next` closure, "unbound" of any object.
|
||||
*/
|
||||
public static function unbound(Closure $closure, Closure $next): Closure
|
||||
{
|
||||
return function (...$arguments) use ($closure, $next): void {
|
||||
@@ -54,9 +45,6 @@ final class ChainableClosure
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the given static `$closure` and chains the `$next` closure, "bound" to the same object statically.
|
||||
*/
|
||||
public static function boundStatically(Closure $closure, Closure $next): Closure
|
||||
{
|
||||
return static function (...$arguments) use ($closure, $next): void {
|
||||
|
||||
@@ -13,8 +13,6 @@ use Pest\Exceptions\ShouldNotHappen;
|
||||
final class Closure
|
||||
{
|
||||
/**
|
||||
* Binds the given closure to the given "this".
|
||||
*
|
||||
* @throws ShouldNotHappen
|
||||
*/
|
||||
public static function bind(?BaseClosure $closure, ?object $newThis, object|string|null $newScope = 'static'): BaseClosure
|
||||
|
||||
@@ -13,9 +13,6 @@ use ReflectionParameter;
|
||||
*/
|
||||
final class Container
|
||||
{
|
||||
/**
|
||||
* The instance of the container.
|
||||
*/
|
||||
private static ?Container $instance = null;
|
||||
|
||||
/**
|
||||
@@ -23,9 +20,6 @@ final class Container
|
||||
*/
|
||||
private array $instances = [];
|
||||
|
||||
/**
|
||||
* Gets a new or already existing container.
|
||||
*/
|
||||
public static function getInstance(): self
|
||||
{
|
||||
if (! self::$instance instanceof Container) {
|
||||
@@ -35,9 +29,6 @@ final class Container
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a dependency from the container.
|
||||
*/
|
||||
public function get(string $id): object|string
|
||||
{
|
||||
if (! array_key_exists($id, $this->instances)) {
|
||||
@@ -49,8 +40,6 @@ final class Container
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given instance to the container.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function add(string $id, object|string $instance): self
|
||||
@@ -61,8 +50,6 @@ final class Container
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to build the given instance.
|
||||
*
|
||||
* @template TObject of object
|
||||
*
|
||||
* @param class-string<TObject> $id
|
||||
|
||||
@@ -22,9 +22,6 @@ use function Termwind\terminal;
|
||||
*/
|
||||
final class Coverage
|
||||
{
|
||||
/**
|
||||
* Returns the coverage path.
|
||||
*/
|
||||
public static function getPath(): string
|
||||
{
|
||||
return implode(DIRECTORY_SEPARATOR, [
|
||||
@@ -34,9 +31,6 @@ final class Coverage
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs true there is any code coverage driver available.
|
||||
*/
|
||||
public static function isAvailable(): bool
|
||||
{
|
||||
$runtime = new Runtime;
|
||||
@@ -64,18 +58,11 @@ final class Coverage
|
||||
return in_array('coverage', xdebug_info('mode'), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the user is using Xdebug.
|
||||
*/
|
||||
public static function usingXdebug(): bool
|
||||
{
|
||||
return (new Runtime)->hasXdebug();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports the code coverage report to the
|
||||
* console and returns the result in float.
|
||||
*/
|
||||
public static function report(OutputInterface $output, bool $compact = false, bool $showOnlyCovered = false): float
|
||||
{
|
||||
if (! file_exists($reportPath = self::getPath())) {
|
||||
@@ -174,13 +161,6 @@ final class Coverage
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an array of missing coverage on the following format:.
|
||||
*
|
||||
* ```
|
||||
* ['11', '20..25', '50', '60..80'];
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* @param File $file
|
||||
* @return array<int, string>
|
||||
*/
|
||||
|
||||
@@ -6,14 +6,8 @@ namespace Pest\Support;
|
||||
|
||||
final readonly class Description implements \Stringable
|
||||
{
|
||||
/**
|
||||
* Creates a new Description instance.
|
||||
*/
|
||||
public function __construct(private string $description) {}
|
||||
|
||||
/**
|
||||
* Returns the description as a string.
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->description;
|
||||
|
||||
@@ -16,8 +16,6 @@ final class ExceptionTrace
|
||||
private const string UNDEFINED_METHOD = 'Call to undefined method P\\';
|
||||
|
||||
/**
|
||||
* Ensures the given closure reports the good execution context.
|
||||
*
|
||||
* @throws Throwable
|
||||
*/
|
||||
public static function ensure(Closure $closure): mixed
|
||||
|
||||
@@ -12,37 +12,24 @@ use Closure;
|
||||
final class ExpectationPipeline
|
||||
{
|
||||
/**
|
||||
* The list of pipes.
|
||||
*
|
||||
* @var array<int, Closure>
|
||||
*/
|
||||
private array $pipes = [];
|
||||
|
||||
/**
|
||||
* The list of passables.
|
||||
*
|
||||
* @var array<array-key, mixed>
|
||||
*/
|
||||
private array $passables;
|
||||
|
||||
/**
|
||||
* Creates a new instance of Expectation Pipeline.
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly Closure $closure
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Creates a new instance of Expectation Pipeline with given closure.
|
||||
*/
|
||||
public static function for(Closure $closure): self
|
||||
{
|
||||
return new self($closure);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the list of passables.
|
||||
*/
|
||||
public function send(mixed ...$passables): self
|
||||
{
|
||||
$this->passables = $passables;
|
||||
@@ -51,8 +38,6 @@ final class ExpectationPipeline
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the list of pipes.
|
||||
*
|
||||
* @param array<int, Closure> $pipes
|
||||
*/
|
||||
public function through(array $pipes): self
|
||||
@@ -62,9 +47,6 @@ final class ExpectationPipeline
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the pipeline.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$pipeline = array_reduce(
|
||||
@@ -78,9 +60,6 @@ final class ExpectationPipeline
|
||||
$pipeline();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Closure that will carry of the expectation.
|
||||
*/
|
||||
public function carry(): Closure
|
||||
{
|
||||
return fn (mixed $stack, callable $pipe): Closure => fn () => $pipe($stack, ...$this->passables);
|
||||
|
||||
@@ -12,23 +12,14 @@ use SebastianBergmann\RecursionContext\Context;
|
||||
*/
|
||||
final readonly class Exporter
|
||||
{
|
||||
/**
|
||||
* The maximum number of items in an array to export.
|
||||
*/
|
||||
private const int MAX_ARRAY_ITEMS = 3;
|
||||
|
||||
/**
|
||||
* Creates a new Exporter instance.
|
||||
*/
|
||||
public function __construct(
|
||||
private BaseExporter $exporter,
|
||||
) {
|
||||
// ...
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Exporter instance.
|
||||
*/
|
||||
public static function default(): self
|
||||
{
|
||||
return new self(
|
||||
@@ -37,8 +28,6 @@ final readonly class Exporter
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports a value into a single-line string recursively.
|
||||
*
|
||||
* @param array<int|string, mixed> $data
|
||||
*/
|
||||
public function shortenedRecursiveExport(array &$data, ?Context $context = null): string
|
||||
@@ -73,9 +62,6 @@ final readonly class Exporter
|
||||
return implode(', ', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports a value into a single-line string.
|
||||
*/
|
||||
public function shortenedExport(mixed $value): string
|
||||
{
|
||||
$map = [
|
||||
@@ -87,9 +73,6 @@ final readonly class Exporter
|
||||
return (string) preg_replace(array_keys($map), array_values($map), $this->exporter->shortenedExport($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports a value into a full single-line string without truncation.
|
||||
*/
|
||||
public function export(mixed $value): string
|
||||
{
|
||||
$map = [
|
||||
|
||||
@@ -12,19 +12,14 @@ use Pest\Expectation;
|
||||
*/
|
||||
final readonly class HigherOrderCallables
|
||||
{
|
||||
/**
|
||||
* Creates a new Higher Order Callables instances.
|
||||
*/
|
||||
public function __construct(private object $target)
|
||||
{
|
||||
// ..
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* @template TValue
|
||||
*
|
||||
* Create a new expectation. Callable values will be executed prior to returning the new expectation.
|
||||
*
|
||||
* @param (Closure():TValue)|TValue $value
|
||||
* @return Expectation<TValue>
|
||||
*/
|
||||
@@ -39,8 +34,6 @@ final readonly class HigherOrderCallables
|
||||
/**
|
||||
* @template TValue
|
||||
*
|
||||
* Create a new expectation. Callable values will be executed prior to returning the new expectation.
|
||||
*
|
||||
* @param callable|TValue $value
|
||||
* @return Expectation<(callable(): mixed)|TValue>
|
||||
*/
|
||||
@@ -50,9 +43,6 @@ final readonly class HigherOrderCallables
|
||||
return $this->expect($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the given callable after the test has executed the setup method.
|
||||
*/
|
||||
public function defer(callable $callable): object
|
||||
{
|
||||
Reflection::bindCallableWithData($callable);
|
||||
|
||||
@@ -16,15 +16,11 @@ final class HigherOrderMessage
|
||||
public const string UNDEFINED_METHOD = 'Method %s does not exist';
|
||||
|
||||
/**
|
||||
* An optional condition that will determine if the message will be executed.
|
||||
*
|
||||
* @var (Closure(): bool)|null
|
||||
*/
|
||||
public ?Closure $condition = null;
|
||||
|
||||
/**
|
||||
* Creates a new higher order message.
|
||||
*
|
||||
* @param array<int, mixed>|null $arguments
|
||||
*/
|
||||
public function __construct(
|
||||
@@ -33,12 +29,10 @@ final class HigherOrderMessage
|
||||
public string $name,
|
||||
public ?array $arguments
|
||||
) {
|
||||
// ..
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-throws the given `$throwable` with the good line and filename.
|
||||
*
|
||||
* @template TValue of object
|
||||
*
|
||||
* @param TValue $target
|
||||
@@ -73,8 +67,6 @@ final class HigherOrderMessage
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates that this message should only be called when the given condition is true.
|
||||
*
|
||||
* @param callable(): bool $condition
|
||||
*/
|
||||
public function when(callable $condition): self
|
||||
@@ -84,9 +76,6 @@ final class HigherOrderMessage
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not there exists a higher order callable with the message name.
|
||||
*/
|
||||
private function hasHigherOrderCallable(): bool
|
||||
{
|
||||
return in_array($this->name, get_class_methods(HigherOrderCallables::class), true);
|
||||
|
||||
@@ -15,8 +15,6 @@ final class HigherOrderMessageCollection
|
||||
private array $messages = [];
|
||||
|
||||
/**
|
||||
* Adds a new higher order message to the collection.
|
||||
*
|
||||
* @param array<int, mixed>|null $arguments
|
||||
*/
|
||||
public function add(string $filename, int $line, string $name, ?array $arguments): void
|
||||
@@ -25,8 +23,6 @@ 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
|
||||
*/
|
||||
public function addWhen(callable $condition, string $filename, int $line, string $name, ?array $arguments): void
|
||||
@@ -34,9 +30,6 @@ final class HigherOrderMessageCollection
|
||||
$this->messages[] = new HigherOrderMessage($filename, $line, $name, $arguments)->when($condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy all the messages starting from the target.
|
||||
*/
|
||||
public function chain(object $target): void
|
||||
{
|
||||
foreach ($this->messages as $message) {
|
||||
@@ -44,9 +37,6 @@ final class HigherOrderMessageCollection
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy all the messages to the target.
|
||||
*/
|
||||
public function proxy(object $target): void
|
||||
{
|
||||
foreach ($this->messages as $message) {
|
||||
@@ -55,8 +45,6 @@ final class HigherOrderMessageCollection
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of messages with the given name.
|
||||
*
|
||||
* @param string $name A higher order message name (usually a method name)
|
||||
*/
|
||||
public function count(string $name): int
|
||||
|
||||
@@ -12,26 +12,17 @@ use ReflectionClass;
|
||||
*/
|
||||
final class HigherOrderTapProxy
|
||||
{
|
||||
/**
|
||||
* Create a new tap proxy instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public TestCase $target
|
||||
) {
|
||||
// ..
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically sets properties on the target.
|
||||
*/
|
||||
public function __set(string $property, mixed $value): void
|
||||
{
|
||||
$this->target->{$property} = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically pass properties gets to the target.
|
||||
*/
|
||||
public function __get(string $property): mixed
|
||||
{
|
||||
if (property_exists($this->target, $property)) {
|
||||
@@ -50,8 +41,6 @@ final class HigherOrderTapProxy
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically pass method calls to the target.
|
||||
*
|
||||
* @param array<int, mixed> $arguments
|
||||
* @return mixed
|
||||
*/
|
||||
|
||||
@@ -11,9 +11,6 @@ use Closure;
|
||||
*/
|
||||
final class NullClosure
|
||||
{
|
||||
/**
|
||||
* Creates a nullable closure.
|
||||
*/
|
||||
public static function create(): Closure
|
||||
{
|
||||
return Closure::fromCallable(function (): void {});
|
||||
|
||||
@@ -24,8 +24,6 @@ use ReflectionUnionType;
|
||||
final class Reflection
|
||||
{
|
||||
/**
|
||||
* Calls the given method with args on the given object.
|
||||
*
|
||||
* @param array<int, mixed> $args
|
||||
*/
|
||||
public static function call(object $object, string $method, array $args = []): mixed
|
||||
@@ -50,8 +48,6 @@ final class Reflection
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind a callable to the TestCase and return the result.
|
||||
*
|
||||
* @param array<int, mixed> $args
|
||||
*/
|
||||
public static function bindCallable(callable $callable, array $args = []): mixed
|
||||
@@ -59,10 +55,6 @@ final class Reflection
|
||||
return Closure::fromCallable($callable)->bindTo(TestSuite::getInstance()->test)(...$args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind a callable to the TestCase and return the result,
|
||||
* passing in the current dataset values as arguments.
|
||||
*/
|
||||
public static function bindCallableWithData(callable $callable): mixed
|
||||
{
|
||||
$test = TestSuite::getInstance()->test;
|
||||
@@ -80,9 +72,6 @@ final class Reflection
|
||||
return Closure::fromCallable($callable)->bindTo($test)(...$test->providedData());
|
||||
}
|
||||
|
||||
/**
|
||||
* Infers the file name from the given closure.
|
||||
*/
|
||||
public static function getFileNameFromClosure(Closure $closure): string
|
||||
{
|
||||
$reflectionClosure = new ReflectionFunction($closure);
|
||||
@@ -90,9 +79,6 @@ final class Reflection
|
||||
return (string) $reflectionClosure->getFileName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the property value from of the given object.
|
||||
*/
|
||||
public static function getPropertyValue(object $object, string $property): mixed
|
||||
{
|
||||
$reflectionClass = new ReflectionClass($object);
|
||||
@@ -116,8 +102,6 @@ final class Reflection
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property value of the given object.
|
||||
*
|
||||
* @template TValue of object
|
||||
*
|
||||
* @param TValue $object
|
||||
@@ -145,8 +129,6 @@ final class Reflection
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class name of the given parameter's type, if possible.
|
||||
*
|
||||
* @see https://github.com/laravel/framework/blob/v6.18.25/src/Illuminate/Support/Reflector.php
|
||||
*/
|
||||
public static function getParameterClassName(ReflectionParameter $parameter): ?string
|
||||
@@ -175,8 +157,6 @@ final class Reflection
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive a map of function argument names to their types.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function getFunctionArguments(Closure $function): array
|
||||
@@ -197,7 +177,7 @@ final class Reflection
|
||||
$arguments[$parameter->getName()] = implode('|', array_map(
|
||||
static fn (ReflectionNamedType $type): string => $type->getName(), // @phpstan-ignore-line
|
||||
($types instanceof ReflectionNamedType)
|
||||
? [$types] // NOTE: normalize as list of to handle unions
|
||||
? [$types]
|
||||
: $types->getTypes(),
|
||||
));
|
||||
}
|
||||
@@ -211,10 +191,6 @@ final class Reflection
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the properties from the given reflection class.
|
||||
*
|
||||
* Used by `expect()->toHavePropertiesDocumented()`.
|
||||
*
|
||||
* @param ReflectionClass<object> $reflectionClass
|
||||
* @return array<int, ReflectionProperty>
|
||||
*/
|
||||
@@ -246,10 +222,6 @@ final class Reflection
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the methods from the given reflection class.
|
||||
*
|
||||
* Used by `expect()->toHaveMethodsDocumented()`.
|
||||
*
|
||||
* @param ReflectionClass<object> $reflectionClass
|
||||
* @return array<int, ReflectionMethod>
|
||||
*/
|
||||
|
||||
@@ -16,9 +16,6 @@ use Psy\VersionUpdater\Checker;
|
||||
*/
|
||||
final class Shell
|
||||
{
|
||||
/**
|
||||
* Creates a new interactive shell.
|
||||
*/
|
||||
public static function open(): void
|
||||
{
|
||||
$config = new Configuration;
|
||||
@@ -39,8 +36,6 @@ final class Shell
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the casters for the Psy Shell.
|
||||
*
|
||||
* @return array<string, callable>
|
||||
*/
|
||||
private static function casters(): array
|
||||
@@ -72,9 +67,6 @@ final class Shell
|
||||
return array_merge($casters, (array) $config->get('tinker.casters', []));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tinkers the current shell, if the Tinker package is available.
|
||||
*/
|
||||
private static function tinkered(PsyShell $shell): ?object
|
||||
{
|
||||
if (function_exists('app') === false
|
||||
|
||||
@@ -167,7 +167,6 @@ final class StateGenerator
|
||||
}
|
||||
}
|
||||
|
||||
// for each test that passed, we need to add it to the state
|
||||
for ($i = 0; $i < $passedTests; $i++) {
|
||||
$state->add(TestResult::fromPestParallelTestCase(
|
||||
new TestMethod(
|
||||
@@ -186,11 +185,6 @@ final class StateGenerator
|
||||
return $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given class-level "hook" failure to the state. Collision's
|
||||
* `fromBeforeFirstTestMethodErrored` only accepts `BeforeFirstTestMethodErrored`
|
||||
* events, so the remaining class-level events get a synthesized test method.
|
||||
*/
|
||||
private function addClassLevelEvent(State $state, AfterLastTestMethodErrored|AfterLastTestMethodFailed|BeforeFirstTestMethodErrored|BeforeFirstTestMethodFailed $event): void
|
||||
{
|
||||
if ($event instanceof BeforeFirstTestMethodErrored) {
|
||||
|
||||
@@ -9,17 +9,11 @@ namespace Pest\Support;
|
||||
*/
|
||||
final class Str
|
||||
{
|
||||
/**
|
||||
* Pool of alpha-numeric characters for generating (unsafe) random strings
|
||||
* from.
|
||||
*/
|
||||
private const string POOL = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
|
||||
private const string PREFIX = '__pest_evaluable_';
|
||||
|
||||
/**
|
||||
* The list of names PHP reserves, and therefore refuses, as class names.
|
||||
*
|
||||
* @see https://github.com/php/php-src/blob/master/Zend/zend_compile.c
|
||||
*
|
||||
* @var array<int, string>
|
||||
@@ -45,9 +39,6 @@ final class Str
|
||||
];
|
||||
|
||||
/**
|
||||
* Create a (unsecure & non-cryptographically safe) random alpha-numeric
|
||||
* string value.
|
||||
*
|
||||
* @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
|
||||
@@ -57,17 +48,11 @@ final class Str
|
||||
return substr(str_shuffle(str_repeat(self::POOL, 5)), 0, $length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given `$target` starts with the given `$search`.
|
||||
*/
|
||||
public static function startsWith(string $target, string $search): bool
|
||||
{
|
||||
return str_starts_with($target, $search);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given `$target` ends with the given `$search`.
|
||||
*/
|
||||
public static function endsWith(string $target, string $search): bool
|
||||
{
|
||||
$length = strlen($search);
|
||||
@@ -78,31 +63,20 @@ final class Str
|
||||
return $search === substr($target, -$length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the given string evaluable by an `eval`.
|
||||
*/
|
||||
public static function evaluable(string $code): string
|
||||
{
|
||||
$code = str_replace('_', '__', $code);
|
||||
|
||||
$code = self::PREFIX.str_replace(' ', '_', $code);
|
||||
|
||||
// sticks to PHP8.2 function naming rules https://www.php.net/manual/en/functions.user-defined.php
|
||||
return (string) preg_replace('/[^a-zA-Z0-9_\x80-\xff]/', '_', $code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given name is a valid PHP identifier, and therefore may
|
||||
* be used as a single namespace name.
|
||||
*/
|
||||
public static function isValidIdentifier(string $name): bool
|
||||
{
|
||||
return preg_match('/^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/', $name) === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given name may be declared as a class name by an `eval`.
|
||||
*/
|
||||
public static function isValidClassName(string $name): bool
|
||||
{
|
||||
if (! self::isValidIdentifier($name)) {
|
||||
@@ -115,14 +89,9 @@ final class Str
|
||||
|
||||
$tokens = token_get_all(sprintf('<?php %s;', $name));
|
||||
|
||||
// Anything the lexer sees as a keyword, like `list` or `match`, may not
|
||||
// be used as a class name.
|
||||
return is_array($tokens[1] ?? null) && $tokens[1][0] === T_STRING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the portion of a string before the last occurrence of a given value.
|
||||
*/
|
||||
public static function beforeLast(string $subject, string $search): string
|
||||
{
|
||||
if ($search === '') {
|
||||
@@ -138,33 +107,22 @@ final class Str
|
||||
return mb_substr($subject, 0, $pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content after the given "search".
|
||||
*/
|
||||
public static function after(string $subject, string $search): string
|
||||
{
|
||||
return $search === '' ? $subject : array_reverse(explode($search, $subject, 2))[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a given value is a valid UUID.
|
||||
*/
|
||||
public static function isUuid(string $value): bool
|
||||
{
|
||||
return preg_match('/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iD', $value) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a given value is a valid ULID.
|
||||
*/
|
||||
public static function isUlid(string $value): bool
|
||||
{
|
||||
return preg_match('/^[0-9A-HJKMNP-TV-Z]{26}$/', $value) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a describe block as `$describeDescription` → `$testDescription` format.
|
||||
*
|
||||
* @param array<int, Description> $describeDescriptions
|
||||
*/
|
||||
public static function describe(array $describeDescriptions, string $testDescription): string
|
||||
@@ -174,25 +132,16 @@ final class Str
|
||||
return sprintf(str_repeat('`%s` → ', count($describeDescriptions)).'%s', ...$descriptionComponents);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a given value is a valid email address.
|
||||
*/
|
||||
public static function isEmail(string $value): bool
|
||||
{
|
||||
return (bool) filter_var($value, FILTER_VALIDATE_EMAIL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a given value is a valid URL.
|
||||
*/
|
||||
public static function isUrl(string $value): bool
|
||||
{
|
||||
return (bool) filter_var($value, FILTER_VALIDATE_URL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given `$target` to a URL-friendly "slug".
|
||||
*/
|
||||
public static function slugify(string $target): string
|
||||
{
|
||||
$target = preg_replace('/[^a-zA-Z0-9]+/', '-', $target);
|
||||
|
||||
@@ -15,22 +15,14 @@ use function Termwind\renderUsing;
|
||||
*/
|
||||
final class View
|
||||
{
|
||||
/**
|
||||
* The implementation of the output.
|
||||
*/
|
||||
private static OutputInterface $output;
|
||||
|
||||
/**
|
||||
* Renders views using the given Output instance.
|
||||
*/
|
||||
public static function renderUsing(OutputInterface $output): void
|
||||
{
|
||||
self::$output = $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the given view.
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public static function render(string $path, array $data = []): void
|
||||
@@ -49,8 +41,6 @@ final class View
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles the given view.
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
private static function compile(string $path, array $data): string
|
||||
|
||||
Reference in New Issue
Block a user