mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
Compare commits
78 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 680111fb1e | |||
| aa6ff95ea4 | |||
| 863a0cc837 | |||
| 126a84a63e | |||
| d519e40b95 | |||
| 6a1161ead8 | |||
| a1b3547dd6 | |||
| b9e3146a47 | |||
| ce1607cba9 | |||
| ac07bc1770 | |||
| 521a41dd10 | |||
| 1b68b340e8 | |||
| 853f6efce6 | |||
| 62a9a78ee2 | |||
| 78d9fd31d0 | |||
| 602b696348 | |||
| 5b0f88c227 | |||
| f31a2c3220 | |||
| e8fa98c810 | |||
| 07e314fbf5 | |||
| 4baf27911e | |||
| 12e48a14d1 | |||
| 1bc0f79508 | |||
| cb0f256791 | |||
| 923970a117 | |||
| b3db7dfd4c | |||
| b303f9f818 | |||
| d29997d5b0 | |||
| 13f340a742 | |||
| eeade88ad2 | |||
| 06280ef75d | |||
| aa46f73888 | |||
| 3660865e5e | |||
| 13695d597b | |||
| fab2de833f | |||
| 5b630bcdff | |||
| e70edbfa38 | |||
| b1558ddde5 | |||
| 582529377b | |||
| 88714598b6 | |||
| 5136267bbe | |||
| 19e748f0d4 | |||
| a53a9d03cf | |||
| edaa045283 | |||
| c5ce355f3c | |||
| 62d8459627 | |||
| a5bf6a3fcb | |||
| 7a46514df8 | |||
| cb1735f4d8 | |||
| 607a4906ac | |||
| 317ea0356e | |||
| 1153531104 | |||
| cfb724cd77 | |||
| 0060b6f955 | |||
| 95cd550524 | |||
| 887bed3d45 | |||
| 79da02c500 | |||
| 0aecd5d5d7 | |||
| e95c4ee636 | |||
| 2e7fec6be5 | |||
| 4be7082de5 | |||
| fb90f778b9 | |||
| 9d58e1a77e | |||
| 9c077ed352 | |||
| 2562d36518 | |||
| 1d2fe2de2d | |||
| 2d82ee2837 | |||
| 1eee9df679 | |||
| 8c57cc1731 | |||
| 108d181a05 | |||
| be407ac904 | |||
| b1c59ec2e6 | |||
| 2e01776272 | |||
| 15cd7187e9 | |||
| 86c107ae5e | |||
| 79f5973e5a | |||
| 37c40cb735 | |||
| 28ee2917f1 |
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@ -3,8 +3,6 @@ name: Tests
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
schedule:
|
||||
- cron: '0 0 * * *'
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
|
||||
22
bin/pest
22
bin/pest
@ -13,39 +13,39 @@ use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
// Ensures Collision's Printer is registered.
|
||||
$_SERVER['COLLISION_PRINTER'] = 'DefaultPrinter';
|
||||
|
||||
$args = $_SERVER['argv'];
|
||||
$arguments = $originalArguments = $_SERVER['argv'];
|
||||
|
||||
$dirty = false;
|
||||
$todo = false;
|
||||
|
||||
foreach ($args as $key => $value) {
|
||||
foreach ($arguments as $key => $value) {
|
||||
if ($value === '--compact') {
|
||||
$_SERVER['COLLISION_PRINTER_COMPACT'] = 'true';
|
||||
unset($args[$key]);
|
||||
unset($arguments[$key]);
|
||||
}
|
||||
|
||||
if ($value === '--profile') {
|
||||
$_SERVER['COLLISION_PRINTER_PROFILE'] = 'true';
|
||||
unset($args[$key]);
|
||||
unset($arguments[$key]);
|
||||
}
|
||||
|
||||
if (str_contains($value, '--test-directory')) {
|
||||
unset($args[$key]);
|
||||
unset($arguments[$key]);
|
||||
}
|
||||
|
||||
if ($value === '--dirty') {
|
||||
$dirty = true;
|
||||
unset($args[$key]);
|
||||
unset($arguments[$key]);
|
||||
}
|
||||
|
||||
if (in_array($value, ['--todo', '--todos'], true)) {
|
||||
$todo = true;
|
||||
unset($args[$key]);
|
||||
unset($arguments[$key]);
|
||||
}
|
||||
|
||||
if (str_contains($value, '--teamcity')) {
|
||||
unset($args[$key]);
|
||||
$args[] = '--no-output';
|
||||
unset($arguments[$key]);
|
||||
$arguments[] = '--no-output';
|
||||
unset($_SERVER['COLLISION_PRINTER']);
|
||||
}
|
||||
}
|
||||
@ -88,9 +88,9 @@ use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
try {
|
||||
$kernel = Kernel::boot($testSuite, $input, $output);
|
||||
|
||||
$result = $kernel->handle($args);
|
||||
$result = $kernel->handle($originalArguments, $arguments);
|
||||
|
||||
$kernel->shutdown();
|
||||
$kernel->terminate();
|
||||
} catch (Throwable|Error $e) {
|
||||
Panic::with($e);
|
||||
}
|
||||
|
||||
@ -81,6 +81,7 @@ $bootPest = (static function (): void {
|
||||
$getopt['teamcity-file'] ?? null,
|
||||
$getopt['testdox-file'] ?? null,
|
||||
isset($getopt['testdox-color']),
|
||||
$getopt['testdox-columns'] ?? null,
|
||||
);
|
||||
|
||||
while (true) {
|
||||
|
||||
@ -19,14 +19,14 @@
|
||||
"require": {
|
||||
"php": "^8.1.0",
|
||||
"brianium/paratest": "^7.3.1",
|
||||
"nunomaduro/collision": "^7.10.0|^8.1.0",
|
||||
"nunomaduro/termwind": "^1.15.1|^2.0.0",
|
||||
"nunomaduro/collision": "^7.10.0|^8.1.1",
|
||||
"nunomaduro/termwind": "^1.15.1|^2.0.1",
|
||||
"pestphp/pest-plugin": "^2.1.1",
|
||||
"pestphp/pest-plugin-arch": "^2.6.1",
|
||||
"phpunit/phpunit": "^10.5.9"
|
||||
"pestphp/pest-plugin-arch": "^2.7.0",
|
||||
"phpunit/phpunit": "^10.5.16"
|
||||
},
|
||||
"conflict": {
|
||||
"phpunit/phpunit": ">10.5.9",
|
||||
"phpunit/phpunit": ">10.5.16",
|
||||
"sebastian/exporter": "<5.1.0",
|
||||
"webmozart/assert": "<1.11.0"
|
||||
},
|
||||
@ -52,8 +52,8 @@
|
||||
},
|
||||
"require-dev": {
|
||||
"pestphp/pest-dev-tools": "^2.16.0",
|
||||
"pestphp/pest-plugin-type-coverage": "^2.8.0",
|
||||
"symfony/process": "^6.4.0|^7.0.2"
|
||||
"pestphp/pest-plugin-type-coverage": "^2.8.1",
|
||||
"symfony/process": "^6.4.0|^7.0.4"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
|
||||
@ -2,13 +2,11 @@ ARG PHP=8.1
|
||||
FROM php:${PHP}-cli-alpine
|
||||
|
||||
RUN apk update && apk add \
|
||||
zip libzip-dev icu-dev git \
|
||||
zip libzip-dev icu-dev git
|
||||
|
||||
RUN docker-php-ext-configure zip intl
|
||||
RUN docker-php-ext-install zip intl
|
||||
RUN docker-php-ext-enable zip intl
|
||||
|
||||
RUN apk add --no-cache linux-headers
|
||||
RUN apk add --no-cache linux-headers autoconf build-base
|
||||
RUN pecl install xdebug
|
||||
RUN docker-php-ext-enable xdebug
|
||||
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
|
||||
|
||||
@ -59,7 +59,6 @@ use function file_get_contents;
|
||||
use function file_put_contents;
|
||||
use function is_array;
|
||||
use function is_dir;
|
||||
use function is_file;
|
||||
use function json_decode;
|
||||
use function json_encode;
|
||||
use function Pest\version;
|
||||
@ -129,13 +128,15 @@ final class DefaultResultCache implements ResultCache
|
||||
|
||||
public function load(): void
|
||||
{
|
||||
if (! is_file($this->cacheFilename)) {
|
||||
$contents = @file_get_contents($this->cacheFilename);
|
||||
|
||||
if ($contents === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = json_decode(
|
||||
file_get_contents($this->cacheFilename),
|
||||
true
|
||||
$contents,
|
||||
true,
|
||||
);
|
||||
|
||||
if ($data === null) {
|
||||
|
||||
@ -59,19 +59,14 @@ use function array_map;
|
||||
*/
|
||||
final class TestSuiteFilterProcessor
|
||||
{
|
||||
private Factory $filterFactory;
|
||||
|
||||
public function __construct(Factory $factory = new Factory)
|
||||
{
|
||||
$this->filterFactory = $factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Event\RuntimeException
|
||||
* @throws FilterNotConfiguredException
|
||||
*/
|
||||
public function process(Configuration $configuration, TestSuite $suite): void
|
||||
{
|
||||
$factory = new Factory;
|
||||
|
||||
if (! $configuration->hasFilter() &&
|
||||
! $configuration->hasGroups() &&
|
||||
! $configuration->hasExcludeGroups() &&
|
||||
@ -83,21 +78,21 @@ final class TestSuiteFilterProcessor
|
||||
}
|
||||
|
||||
if ($configuration->hasExcludeGroups()) {
|
||||
$this->filterFactory->addExcludeGroupFilter(
|
||||
$factory->addExcludeGroupFilter(
|
||||
$configuration->excludeGroups()
|
||||
);
|
||||
}
|
||||
|
||||
if (Only::isEnabled()) {
|
||||
$this->filterFactory->addIncludeGroupFilter(['__pest_only']);
|
||||
$factory->addIncludeGroupFilter(['__pest_only']);
|
||||
} elseif ($configuration->hasGroups()) {
|
||||
$this->filterFactory->addIncludeGroupFilter(
|
||||
$factory->addIncludeGroupFilter(
|
||||
$configuration->groups()
|
||||
);
|
||||
}
|
||||
|
||||
if ($configuration->hasTestsCovering()) {
|
||||
$this->filterFactory->addIncludeGroupFilter(
|
||||
$factory->addIncludeGroupFilter(
|
||||
array_map(
|
||||
static fn (string $name): string => '__phpunit_covers_'.$name,
|
||||
$configuration->testsCovering()
|
||||
@ -106,7 +101,7 @@ final class TestSuiteFilterProcessor
|
||||
}
|
||||
|
||||
if ($configuration->hasTestsUsing()) {
|
||||
$this->filterFactory->addIncludeGroupFilter(
|
||||
$factory->addIncludeGroupFilter(
|
||||
array_map(
|
||||
static fn (string $name): string => '__phpunit_uses_'.$name,
|
||||
$configuration->testsUsing()
|
||||
@ -115,12 +110,12 @@ final class TestSuiteFilterProcessor
|
||||
}
|
||||
|
||||
if ($configuration->hasFilter()) {
|
||||
$this->filterFactory->addNameFilter(
|
||||
$factory->addNameFilter(
|
||||
$configuration->filter()
|
||||
);
|
||||
}
|
||||
|
||||
$suite->injectFilter($this->filterFactory);
|
||||
$suite->injectFilter($factory);
|
||||
|
||||
Event\Facade::emitter()->testSuiteFiltered(
|
||||
Event\TestSuite\TestSuiteBuilder::from($suite)
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
?>
|
||||
|
||||
<div class="my-1">
|
||||
<span class="ml-2 px-1 bg-<?php echo $bgBadgeColor ?>-600 font-bold"><?php echo htmlspecialchars($bgBadgeText) ?></span>
|
||||
<span class="ml-2 px-1 bg-<?php echo $bgBadgeColor ?> font-bold"><?php echo htmlspecialchars($bgBadgeText) ?></span>
|
||||
<span class="ml-1">
|
||||
<?php echo htmlspecialchars($content) ?>
|
||||
</span>
|
||||
|
||||
@ -15,17 +15,17 @@ final class BootOverrides implements Bootstrapper
|
||||
/**
|
||||
* The list of files to be overridden.
|
||||
*
|
||||
* @var array<int, string>
|
||||
* @var array<string, string>
|
||||
*/
|
||||
private const FILES = [
|
||||
'Runner/Filter/NameFilterIterator.php',
|
||||
'Runner/ResultCache/DefaultResultCache.php',
|
||||
'Runner/TestSuiteLoader.php',
|
||||
'TextUI/Command/WarmCodeCoverageCacheCommand.php',
|
||||
'TextUI/Output/Default/ProgressPrinter/TestSkippedSubscriber.php',
|
||||
'TextUI/TestSuiteFilterProcessor.php',
|
||||
'Event/Value/ThrowableBuilder.php',
|
||||
'Logging/JUnit/JunitXmlLogger.php',
|
||||
public const FILES = [
|
||||
'c7b9c8a96006dea314204a8f09a8764e51ce0b9b79aadd58da52e8c328db4870' => 'Runner/Filter/NameFilterIterator.php',
|
||||
'c7c09ab7c9378710b27f761a4b2948196cbbdf2a73e4389bcdca1e7c94fa9c21' => 'Runner/ResultCache/DefaultResultCache.php',
|
||||
'bc8718c89264f65800beabc23e51c6d3bcff87dfc764a12179ef5dbfde272c8b' => 'Runner/TestSuiteLoader.php',
|
||||
'f41e48d6cb546772a7de4f8e66b6b7ce894a5318d063eb52e354d206e96c701c' => 'TextUI/Command/Commands/WarmCodeCoverageCacheCommand.php',
|
||||
'cb7519f2d82893640b694492cf7ec9528da80773cc1d259634181b5d393528b5' => 'TextUI/Output/Default/ProgressPrinter/Subscriber/TestSkippedSubscriber.php',
|
||||
'2f06e4b1a9f3a24145bfc7ea25df4f124117f940a2cde30a04d04d5678006bff' => 'TextUI/TestSuiteFilterProcessor.php',
|
||||
'ef64a657ed9c0067791483784944107827bf227c7e3200f212b6751876b99e25' => 'Event/Value/ThrowableBuilder.php',
|
||||
'c78f96e34b98ed01dd8106539d59b8aa8d67f733274118b827c01c5c4111c033' => 'Logging/JUnit/JunitXmlLogger.php',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@ -60,7 +60,7 @@ trait Pipeable
|
||||
}
|
||||
|
||||
/**
|
||||
* Get th list of pipes by the given name.
|
||||
* Get the list of pipes by the given name.
|
||||
*
|
||||
* @return array<int, Closure>
|
||||
*/
|
||||
|
||||
@ -290,7 +290,7 @@ trait Testable
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
if (in_array($testParameterTypes[0], [Closure::class, 'callable'])) {
|
||||
if (isset($testParameterTypes[0]) && in_array($testParameterTypes[0], [Closure::class, 'callable'])) {
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
|
||||
18
src/Contracts/Plugins/HandlesOriginalArguments.php
Normal file
18
src/Contracts/Plugins/HandlesOriginalArguments.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Contracts\Plugins;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
interface HandlesOriginalArguments
|
||||
{
|
||||
/**
|
||||
* Adds original arguments before the Test Suite execution.
|
||||
*
|
||||
* @param array<int, string> $arguments
|
||||
*/
|
||||
public function handleOriginalArguments(array $arguments): void;
|
||||
}
|
||||
@ -7,10 +7,10 @@ namespace Pest\Contracts\Plugins;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
interface Shutdownable
|
||||
interface Terminable
|
||||
{
|
||||
/**
|
||||
* Shutdowns the plugin.
|
||||
* Terminates the plugin.
|
||||
*/
|
||||
public function shutdown(): void;
|
||||
public function terminate(): void;
|
||||
}
|
||||
16
src/Exceptions/FatalException.php
Normal file
16
src/Exceptions/FatalException.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Exceptions;
|
||||
|
||||
use NunoMaduro\Collision\Contracts\RenderlessTrace;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class FatalException extends RuntimeException implements RenderlessTrace
|
||||
{
|
||||
//
|
||||
}
|
||||
@ -32,6 +32,7 @@ use Pest\Matchers\Any;
|
||||
use Pest\Support\ExpectationPipeline;
|
||||
use PHPUnit\Architecture\Elements\ObjectDescription;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
use ReflectionEnum;
|
||||
|
||||
/**
|
||||
* @template TValue
|
||||
@ -347,9 +348,15 @@ final class Expectation
|
||||
return new HigherOrderExpectation($this, call_user_func_array($this->value->$method(...), $parameters));
|
||||
}
|
||||
|
||||
ExpectationPipeline::for($this->getExpectationClosure($method))
|
||||
$closure = $this->getExpectationClosure($method);
|
||||
$reflectionClosure = new \ReflectionFunction($closure);
|
||||
$expectation = $reflectionClosure->getClosureThis();
|
||||
|
||||
assert(is_object($expectation));
|
||||
|
||||
ExpectationPipeline::for($closure)
|
||||
->send(...$parameters)
|
||||
->through($this->pipes($method, $this, Expectation::class))
|
||||
->through($this->pipes($method, $expectation, Expectation::class))
|
||||
->run();
|
||||
|
||||
return $this;
|
||||
@ -876,4 +883,51 @@ final class Expectation
|
||||
{
|
||||
return $this->toHaveMethod('__destruct');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given expectation target is a backed enum of given type.
|
||||
*/
|
||||
private function toBeBackedEnum(string $backingType): ArchExpectation
|
||||
{
|
||||
return Targeted::make(
|
||||
$this,
|
||||
fn (ObjectDescription $object): bool => $object->reflectionClass->isEnum()
|
||||
&& (new ReflectionEnum($object->name))->isBacked() // @phpstan-ignore-line
|
||||
&& (string) (new ReflectionEnum($object->name))->getBackingType() === $backingType, // @phpstan-ignore-line
|
||||
'to be '.$backingType.' backed enum',
|
||||
FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given expectation targets are string backed enums.
|
||||
*/
|
||||
public function toBeStringBackedEnums(): ArchExpectation
|
||||
{
|
||||
return $this->toBeStringBackedEnum();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given expectation targets are int backed enums.
|
||||
*/
|
||||
public function toBeIntBackedEnums(): ArchExpectation
|
||||
{
|
||||
return $this->toBeIntBackedEnum();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given expectation target is a string backed enum.
|
||||
*/
|
||||
public function toBeStringBackedEnum(): ArchExpectation
|
||||
{
|
||||
return $this->toBeBackedEnum('string');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given expectation target is an int backed enum.
|
||||
*/
|
||||
public function toBeIntBackedEnum(): ArchExpectation
|
||||
{
|
||||
return $this->toBeBackedEnum('int');
|
||||
}
|
||||
}
|
||||
|
||||
@ -485,4 +485,51 @@ final class OppositeExpectation
|
||||
{
|
||||
return $this->toHaveMethod('__destruct');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given expectation target is not a backed enum of given type.
|
||||
*/
|
||||
private function toBeBackedEnum(string $backingType): ArchExpectation
|
||||
{
|
||||
return Targeted::make(
|
||||
$this->original,
|
||||
fn (ObjectDescription $object): bool => ! $object->reflectionClass->isEnum()
|
||||
|| ! (new \ReflectionEnum($object->name))->isBacked() // @phpstan-ignore-line
|
||||
|| (string) (new \ReflectionEnum($object->name))->getBackingType() !== $backingType, // @phpstan-ignore-line
|
||||
'not to be '.$backingType.' backed enum',
|
||||
FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given expectation targets are not string backed enums.
|
||||
*/
|
||||
public function toBeStringBackedEnums(): ArchExpectation
|
||||
{
|
||||
return $this->toBeStringBackedEnum();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given expectation targets are not int backed enums.
|
||||
*/
|
||||
public function toBeIntBackedEnums(): ArchExpectation
|
||||
{
|
||||
return $this->toBeIntBackedEnum();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given expectation target is not a string backed enum.
|
||||
*/
|
||||
public function toBeStringBackedEnum(): ArchExpectation
|
||||
{
|
||||
return $this->toBeBackedEnum('string');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given expectation target is not an int backed enum.
|
||||
*/
|
||||
public function toBeIntBackedEnum(): ArchExpectation
|
||||
{
|
||||
return $this->toBeBackedEnum('int');
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ final class TestCaseMethodFactory
|
||||
public ?Closure $closure,
|
||||
) {
|
||||
$this->closure ??= function (): void {
|
||||
Assert::getCount() > 0 ?: self::markTestIncomplete(); // @phpstan-ignore-line
|
||||
(Assert::getCount() > 0 || $this->doesNotPerformAssertions()) ?: self::markTestIncomplete(); // @phpstan-ignore-line
|
||||
};
|
||||
|
||||
$this->bootHigherOrderable();
|
||||
|
||||
@ -4,18 +4,25 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest;
|
||||
|
||||
use NunoMaduro\Collision\Writer;
|
||||
use Pest\Contracts\Bootstrapper;
|
||||
use Pest\Exceptions\FatalException;
|
||||
use Pest\Exceptions\NoDirtyTestsFound;
|
||||
use Pest\Plugins\Actions\CallsAddsOutput;
|
||||
use Pest\Plugins\Actions\CallsBoot;
|
||||
use Pest\Plugins\Actions\CallsHandleArguments;
|
||||
use Pest\Plugins\Actions\CallsShutdown;
|
||||
use Pest\Plugins\Actions\CallsHandleOriginalArguments;
|
||||
use Pest\Plugins\Actions\CallsTerminable;
|
||||
use Pest\Support\Container;
|
||||
use Pest\Support\Reflection;
|
||||
use Pest\Support\View;
|
||||
use PHPUnit\TestRunner\TestResult\Facade;
|
||||
use PHPUnit\TextUI\Application;
|
||||
use PHPUnit\TextUI\Configuration\Registry;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Throwable;
|
||||
use Whoops\Exception\Inspector;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@ -43,7 +50,7 @@ final class Kernel
|
||||
private readonly Application $application,
|
||||
private readonly OutputInterface $output,
|
||||
) {
|
||||
register_shutdown_function(fn () => $this->shutdown());
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,6 +66,13 @@ final class Kernel
|
||||
->add(OutputInterface::class, $output)
|
||||
->add(Container::class, $container);
|
||||
|
||||
$kernel = new self(
|
||||
new Application(),
|
||||
$output,
|
||||
);
|
||||
|
||||
register_shutdown_function(fn () => $kernel->shutdown());
|
||||
|
||||
foreach (self::BOOTSTRAPPERS as $bootstrapper) {
|
||||
$bootstrapper = Container::getInstance()->get($bootstrapper);
|
||||
assert($bootstrapper instanceof Bootstrapper);
|
||||
@ -68,11 +82,6 @@ final class Kernel
|
||||
|
||||
CallsBoot::execute();
|
||||
|
||||
$kernel = new self(
|
||||
new Application(),
|
||||
$output,
|
||||
);
|
||||
|
||||
Container::getInstance()->add(self::class, $kernel);
|
||||
|
||||
return $kernel;
|
||||
@ -81,14 +90,17 @@ final class Kernel
|
||||
/**
|
||||
* Runs the application, and returns the exit code.
|
||||
*
|
||||
* @param array<int, string> $args
|
||||
* @param array<int, string> $originalArguments
|
||||
* @param array<int, string> $arguments
|
||||
*/
|
||||
public function handle(array $args): int
|
||||
public function handle(array $originalArguments, array $arguments): int
|
||||
{
|
||||
$args = CallsHandleArguments::execute($args);
|
||||
CallsHandleOriginalArguments::execute($originalArguments);
|
||||
|
||||
$arguments = CallsHandleArguments::execute($arguments);
|
||||
|
||||
try {
|
||||
$this->application->run($args);
|
||||
$this->application->run($arguments);
|
||||
} catch (NoDirtyTestsFound) {
|
||||
$this->output->writeln([
|
||||
'',
|
||||
@ -106,16 +118,54 @@ final class Kernel
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown the Kernel.
|
||||
* Terminate the Kernel.
|
||||
*/
|
||||
public function shutdown(): void
|
||||
public function terminate(): void
|
||||
{
|
||||
$preBufferOutput = Container::getInstance()->get(KernelDump::class);
|
||||
|
||||
assert($preBufferOutput instanceof KernelDump);
|
||||
|
||||
$preBufferOutput->shutdown();
|
||||
$preBufferOutput->terminate();
|
||||
|
||||
CallsShutdown::execute();
|
||||
CallsTerminable::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdowns unexpectedly the Kernel.
|
||||
*/
|
||||
public function shutdown(): void
|
||||
{
|
||||
$this->terminate();
|
||||
|
||||
if (is_array($error = error_get_last())) {
|
||||
if (! in_array($error['type'], [E_ERROR, E_CORE_ERROR], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$message = $error['message'];
|
||||
$file = $error['file'];
|
||||
$line = $error['line'];
|
||||
|
||||
try {
|
||||
$writer = new Writer(null, $this->output);
|
||||
|
||||
$throwable = new FatalException($message);
|
||||
|
||||
Reflection::setPropertyValue($throwable, 'line', $line);
|
||||
Reflection::setPropertyValue($throwable, 'file', $file);
|
||||
|
||||
$inspector = new Inspector($throwable);
|
||||
|
||||
$writer->write($inspector);
|
||||
} catch (Throwable) { // @phpstan-ignore-line
|
||||
View::render('components.badge', [
|
||||
'type' => 'ERROR',
|
||||
'content' => sprintf('%s in %s:%d', $message, $file, $line),
|
||||
]);
|
||||
}
|
||||
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,9 +48,9 @@ final class KernelDump
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown the output buffering.
|
||||
* Terminate the output buffering.
|
||||
*/
|
||||
public function shutdown(): void
|
||||
public function terminate(): void
|
||||
{
|
||||
$this->disable();
|
||||
}
|
||||
|
||||
@ -131,7 +131,7 @@ final class Expectation
|
||||
*
|
||||
* @return self<TValue>
|
||||
*/
|
||||
public function toBeGreaterThan(int|float|DateTimeInterface $expected, string $message = ''): self
|
||||
public function toBeGreaterThan(int|float|string|DateTimeInterface $expected, string $message = ''): self
|
||||
{
|
||||
Assert::assertGreaterThan($expected, $this->value, $message);
|
||||
|
||||
@ -143,7 +143,7 @@ final class Expectation
|
||||
*
|
||||
* @return self<TValue>
|
||||
*/
|
||||
public function toBeGreaterThanOrEqual(int|float|DateTimeInterface $expected, string $message = ''): self
|
||||
public function toBeGreaterThanOrEqual(int|float|string|DateTimeInterface $expected, string $message = ''): self
|
||||
{
|
||||
Assert::assertGreaterThanOrEqual($expected, $this->value, $message);
|
||||
|
||||
@ -155,7 +155,7 @@ final class Expectation
|
||||
*
|
||||
* @return self<TValue>
|
||||
*/
|
||||
public function toBeLessThan(int|float|DateTimeInterface $expected, string $message = ''): self
|
||||
public function toBeLessThan(int|float|string|DateTimeInterface $expected, string $message = ''): self
|
||||
{
|
||||
Assert::assertLessThan($expected, $this->value, $message);
|
||||
|
||||
@ -167,7 +167,7 @@ final class Expectation
|
||||
*
|
||||
* @return self<TValue>
|
||||
*/
|
||||
public function toBeLessThanOrEqual(int|float|DateTimeInterface $expected, string $message = ''): self
|
||||
public function toBeLessThanOrEqual(int|float|string|DateTimeInterface $expected, string $message = ''): self
|
||||
{
|
||||
Assert::assertLessThanOrEqual($expected, $this->value, $message);
|
||||
|
||||
@ -196,6 +196,24 @@ final class Expectation
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that $needle equal an element of the value.
|
||||
*
|
||||
* @return self<TValue>
|
||||
*/
|
||||
public function toContainEqual(mixed ...$needles): self
|
||||
{
|
||||
if (! is_iterable($this->value)) {
|
||||
InvalidExpectationValue::expected('iterable');
|
||||
}
|
||||
|
||||
foreach ($needles as $needle) {
|
||||
Assert::assertContainsEquals($needle, $this->value);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the value starts with $expected.
|
||||
*
|
||||
|
||||
@ -6,7 +6,7 @@ namespace Pest;
|
||||
|
||||
function version(): string
|
||||
{
|
||||
return '2.32.2';
|
||||
return '2.34.6';
|
||||
}
|
||||
|
||||
function testDirectory(string $file = ''): string
|
||||
|
||||
31
src/Plugins/Actions/CallsHandleOriginalArguments.php
Normal file
31
src/Plugins/Actions/CallsHandleOriginalArguments.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins\Actions;
|
||||
|
||||
use Pest\Contracts\Plugins;
|
||||
use Pest\Plugin\Loader;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class CallsHandleOriginalArguments
|
||||
{
|
||||
/**
|
||||
* Executes the Plugin action.
|
||||
*
|
||||
* Transform the input arguments by passing it to the relevant plugins.
|
||||
*
|
||||
* @param array<int, string> $argv
|
||||
*/
|
||||
public static function execute(array $argv): void
|
||||
{
|
||||
$plugins = Loader::getPlugins(Plugins\HandlesOriginalArguments::class);
|
||||
|
||||
/** @var Plugins\HandlesOriginalArguments $plugin */
|
||||
foreach ($plugins as $plugin) {
|
||||
$plugin->handleOriginalArguments($argv);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -10,20 +10,20 @@ use Pest\Plugin\Loader;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class CallsShutdown
|
||||
final class CallsTerminable
|
||||
{
|
||||
/**
|
||||
* Executes the Plugin action.
|
||||
*
|
||||
* Provides an opportunity for any plugins to shutdown.
|
||||
* Provides an opportunity for any plugins to terminate.
|
||||
*/
|
||||
public static function execute(): void
|
||||
{
|
||||
$plugins = Loader::getPlugins(Plugins\Shutdownable::class);
|
||||
$plugins = Loader::getPlugins(Plugins\Terminable::class);
|
||||
|
||||
/** @var Plugins\Shutdownable $plugin */
|
||||
/** @var Plugins\Terminable $plugin */
|
||||
foreach ($plugins as $plugin) {
|
||||
$plugin->shutdown();
|
||||
$plugin->terminate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,6 +6,10 @@ namespace Pest\Plugins;
|
||||
|
||||
use Pest\Contracts\Plugins\HandlesArguments;
|
||||
use Pest\Plugins\Concerns\HandleArguments;
|
||||
use PHPUnit\TextUI\CliArguments\Builder as CliConfigurationBuilder;
|
||||
use PHPUnit\TextUI\CliArguments\XmlConfigurationFileFinder;
|
||||
use PHPUnit\TextUI\XmlConfiguration\DefaultConfiguration;
|
||||
use PHPUnit\TextUI\XmlConfiguration\Loader;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@ -31,9 +35,19 @@ final class Cache implements HandlesArguments
|
||||
public function handleArguments(array $arguments): array
|
||||
{
|
||||
if (! $this->hasArgument('--cache-directory', $arguments)) {
|
||||
$arguments = $this->pushArgument('--cache-directory', $arguments);
|
||||
|
||||
$arguments = $this->pushArgument((string) realpath(self::TEMPORARY_FOLDER), $arguments);
|
||||
$cliConfiguration = (new CliConfigurationBuilder)->fromParameters([]);
|
||||
$configurationFile = (new XmlConfigurationFileFinder)->find($cliConfiguration);
|
||||
$xmlConfiguration = DefaultConfiguration::create();
|
||||
|
||||
if (is_string($configurationFile)) {
|
||||
$xmlConfiguration = (new Loader)->load($configurationFile);
|
||||
}
|
||||
|
||||
if (! $xmlConfiguration->phpunit()->hasCacheDirectory()) {
|
||||
$arguments = $this->pushArgument('--cache-directory', $arguments);
|
||||
$arguments = $this->pushArgument((string) realpath(self::TEMPORARY_FOLDER), $arguments);
|
||||
}
|
||||
}
|
||||
|
||||
if (! $this->hasArgument('--parallel', $arguments)) {
|
||||
|
||||
@ -128,9 +128,9 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
|
||||
if ($exitCode === 1) {
|
||||
$this->output->writeln(sprintf(
|
||||
"\n <fg=white;bg=red;options=bold> FAIL </> Code coverage below expected:<fg=red;options=bold> %s %%</>. Minimum:<fg=white;options=bold> %s %%</>.",
|
||||
number_format($coverage, 1),
|
||||
number_format($this->coverageMin, 1)
|
||||
"\n <fg=white;bg=red;options=bold> FAIL </> Code coverage below expected <fg=white;options=bold> %s %%</>, currently <fg=red;options=bold> %s %%</>.",
|
||||
number_format($this->coverageMin, 1),
|
||||
number_format($coverage, 1)
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@ -61,6 +61,10 @@ final class Help implements HandlesArguments
|
||||
|
||||
assert(is_string($argument));
|
||||
|
||||
if (trim($argument) === '--process-isolation') {
|
||||
continue;
|
||||
}
|
||||
|
||||
View::render('components.two-column-detail', [
|
||||
'left' => $this->colorizeOptions($argument),
|
||||
'right' => preg_replace(['/</', '/>/'], ['[', ']'], $description),
|
||||
|
||||
@ -4,13 +4,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins;
|
||||
|
||||
use Pest\Contracts\Plugins\Shutdownable;
|
||||
use Pest\Contracts\Plugins\Terminable;
|
||||
use Pest\PendingCalls\TestCall;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Only implements Shutdownable
|
||||
final class Only implements Terminable
|
||||
{
|
||||
/**
|
||||
* The temporary folder.
|
||||
@ -26,7 +26,7 @@ final class Only implements Shutdownable
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function shutdown(): void
|
||||
public function terminate(): void
|
||||
{
|
||||
$lockFile = self::TEMPORARY_FOLDER.DIRECTORY_SEPARATOR.'only.lock';
|
||||
|
||||
@ -40,6 +40,10 @@ final class Only implements Shutdownable
|
||||
*/
|
||||
public static function enable(TestCall $testCall): void
|
||||
{
|
||||
if (Environment::name() == Environment::CI) {
|
||||
return;
|
||||
}
|
||||
|
||||
$testCall->group('__pest_only');
|
||||
|
||||
$lockFile = self::TEMPORARY_FOLDER.DIRECTORY_SEPARATOR.'only.lock';
|
||||
|
||||
@ -363,6 +363,15 @@ final class WrapperRunner implements RunnerInterface
|
||||
$this->codeCoverageFilterRegistry,
|
||||
false,
|
||||
);
|
||||
if (! $coverageManager->isActive()) {
|
||||
$this->output->writeln([
|
||||
'',
|
||||
' <fg=black;bg=yellow;options=bold> WARN </> No code coverage driver is available.</>',
|
||||
'',
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
$coverageMerger = new CoverageMerger($coverageManager->codeCoverage());
|
||||
foreach ($this->coverageFiles as $coverageFile) {
|
||||
$coverageMerger->addCoverageFromFile($coverageFile);
|
||||
|
||||
@ -22,6 +22,10 @@ final class Printer implements HandlesArguments
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
if (in_array('--no-output', $arguments, true)) {
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
return $this->pushArgument('--no-output', $arguments);
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ final class TestRepository
|
||||
private array $testCases = [];
|
||||
|
||||
/**
|
||||
* @var array<string, array{0: array<int, string>, 1: array<int, string>, 2: array<int, string|Closure>}>
|
||||
* @var array<string, array{0: array<int, string>, 1: array<int, string>, 2: array<int, array<int, string|Closure>>}>
|
||||
*/
|
||||
private array $uses = [];
|
||||
|
||||
@ -77,12 +77,17 @@ final class TestRepository
|
||||
throw new TestCaseClassOrTraitNotFound($classOrTrait);
|
||||
}
|
||||
|
||||
$hooks = array_map(fn (Closure $hook): array => [$hook], $hooks);
|
||||
|
||||
foreach ($paths as $path) {
|
||||
if (array_key_exists($path, $this->uses)) {
|
||||
$this->uses[$path] = [
|
||||
[...$this->uses[$path][0], ...$classOrTraits],
|
||||
[...$this->uses[$path][1], ...$groups],
|
||||
$this->uses[$path][2] + $hooks,
|
||||
array_map(
|
||||
fn (int $index): array => [...$this->uses[$path][2][$index] ?? [], ...($hooks[$index] ?? [])],
|
||||
range(0, 3),
|
||||
),
|
||||
];
|
||||
} else {
|
||||
$this->uses[$path] = [$classOrTraits, $groups, $hooks];
|
||||
@ -189,10 +194,11 @@ final class TestRepository
|
||||
$method->groups = [...$groups, ...$method->groups];
|
||||
}
|
||||
|
||||
$testCase->factoryProxies->add($testCase->filename, 0, '__addBeforeAll', [$hooks[0] ?? null]);
|
||||
$testCase->factoryProxies->add($testCase->filename, 0, '__addBeforeEach', [$hooks[1] ?? null]);
|
||||
$testCase->factoryProxies->add($testCase->filename, 0, '__addAfterEach', [$hooks[2] ?? null]);
|
||||
$testCase->factoryProxies->add($testCase->filename, 0, '__addAfterAll', [$hooks[3] ?? null]);
|
||||
foreach (['__addBeforeAll', '__addBeforeEach', '__addAfterEach', '__addAfterAll'] as $index => $name) {
|
||||
foreach ($hooks[$index] ?? [null] as $hook) {
|
||||
$testCase->factoryProxies->add($testCase->filename, 0, $name, [$hook]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -115,7 +115,11 @@ final class Backtrace
|
||||
continue;
|
||||
}
|
||||
|
||||
if (str_contains($trace['file'], 'pest'.DIRECTORY_SEPARATOR.'src')) {
|
||||
if (($GLOBALS['__PEST_INTERNAL_TEST_SUITE'] ?? false) && str_contains($trace['file'], 'pest'.DIRECTORY_SEPARATOR.'src')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (str_contains($trace['file'], DIRECTORY_SEPARATOR.'pestphp'.DIRECTORY_SEPARATOR.'pest'.DIRECTORY_SEPARATOR.'src')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@ -64,6 +64,8 @@ final class Exporter
|
||||
continue;
|
||||
}
|
||||
|
||||
assert(is_array($data));
|
||||
|
||||
$result[] = $context->contains($data[$key]) !== false
|
||||
? '*RECURSION*'
|
||||
: sprintf('[%s]', $this->shortenedRecursiveExport($data[$key], $context));
|
||||
|
||||
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Pest\Support;
|
||||
|
||||
use Closure;
|
||||
use InvalidArgumentException;
|
||||
use Pest\Exceptions\ShouldNotHappen;
|
||||
use Pest\TestSuite;
|
||||
use ReflectionClass;
|
||||
@ -66,9 +67,17 @@ final class Reflection
|
||||
{
|
||||
$test = TestSuite::getInstance()->test;
|
||||
|
||||
return $test instanceof \PHPUnit\Framework\TestCase
|
||||
? Closure::fromCallable($callable)->bindTo($test)(...$test->providedData())
|
||||
: self::bindCallable($callable);
|
||||
if (! $test instanceof \PHPUnit\Framework\TestCase) {
|
||||
return self::bindCallable($callable);
|
||||
}
|
||||
|
||||
foreach ($test->providedData() as $value) {
|
||||
if ($value instanceof Closure) {
|
||||
throw new InvalidArgumentException('Bound datasets are not supported while doing high order testing.');
|
||||
}
|
||||
}
|
||||
|
||||
return Closure::fromCallable($callable)->bindTo($test)(...$test->providedData());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
1
tests/.cache/test-results
Normal file
1
tests/.cache/test-results
Normal file
@ -0,0 +1 @@
|
||||
{"version":"pest_2.32.2","defects":[],"times":{"P\\Tests\\Playground::__pest_evaluable_basic":0.005}}
|
||||
@ -0,0 +1 @@
|
||||
<input type="hidden" name="_token" value="1" />
|
||||
@ -1,5 +1,5 @@
|
||||
|
||||
Pest Testing Framework 2.32.2.
|
||||
Pest Testing Framework 2.34.6.
|
||||
|
||||
USAGE: pest <file> [options]
|
||||
|
||||
@ -38,7 +38,6 @@
|
||||
EXECUTION OPTIONS:
|
||||
--parallel ........................................... Run tests in parallel
|
||||
--update-snapshots Update snapshots for tests using the "toMatchSnapshot" expectation
|
||||
--process-isolation ................ Run each test in a separate PHP process
|
||||
--globals-backup ................. Backup and restore $GLOBALS for each test
|
||||
--static-backup ......... Backup and restore static properties for each test
|
||||
--strict-coverage ................... Be strict about code coverage metadata
|
||||
@ -56,6 +55,7 @@
|
||||
--stop-on-notice ............. Stop after first test that triggered a notice
|
||||
--stop-on-skipped ............................ Stop after first skipped test
|
||||
--stop-on-incomplete ...................... Stop after first incomplete test
|
||||
--fail-on-empty-test-suite Signal failure using shell exit code when no tests were run
|
||||
--fail-on-warning Signal failure using shell exit code when a warning was triggered
|
||||
--fail-on-risky Signal failure using shell exit code when a test was considered risky
|
||||
--fail-on-deprecation Signal failure using shell exit code when a deprecation was triggered
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
|
||||
Pest Testing Framework 2.32.2.
|
||||
Pest Testing Framework 2.34.6.
|
||||
|
||||
|
||||
@ -154,6 +154,10 @@
|
||||
✓ it can correctly resolve a bound dataset that returns an array with (Closure)
|
||||
✓ it can correctly resolve a bound dataset that returns an array but wants to be spread with (Closure)
|
||||
↓ forbids to define tests in Datasets dirs and Datasets.php files
|
||||
✓ it may be used with high order with dataset "formal"
|
||||
✓ it may be used with high order with dataset "informal"
|
||||
✓ it may be used with high order even when bound with dataset "formal"
|
||||
✓ it may be used with high order even when bound with dataset "informal"
|
||||
|
||||
PASS Tests\Features\Depends
|
||||
✓ first
|
||||
@ -426,6 +430,7 @@
|
||||
PASS Tests\Features\Expect\toBeGreaterThan
|
||||
✓ passes
|
||||
✓ passes with DateTime and DateTimeImmutable
|
||||
✓ passes with strings
|
||||
✓ failures
|
||||
✓ failures with custom message
|
||||
✓ not failures
|
||||
@ -433,6 +438,7 @@
|
||||
PASS Tests\Features\Expect\toBeGreaterThanOrEqual
|
||||
✓ passes
|
||||
✓ passes with DateTime and DateTimeImmutable
|
||||
✓ passes with strings
|
||||
✓ failures
|
||||
✓ failures with custom message
|
||||
✓ not failures
|
||||
@ -461,6 +467,10 @@
|
||||
✓ failures with custom message
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Features\Expect\toBeIntBackedEnum
|
||||
✓ enum is backed by int
|
||||
✓ enum is not backed by int
|
||||
|
||||
PASS Tests\Features\Expect\toBeInvokable
|
||||
✓ class is invokable
|
||||
✓ opposite class is invokable
|
||||
@ -490,6 +500,7 @@
|
||||
PASS Tests\Features\Expect\toBeLessThan
|
||||
✓ passes
|
||||
✓ passes with DateTime and DateTimeImmutable
|
||||
✓ passes with strings
|
||||
✓ failures
|
||||
✓ failures with custom message
|
||||
✓ not failures
|
||||
@ -497,6 +508,7 @@
|
||||
PASS Tests\Features\Expect\toBeLessThanOrEqual
|
||||
✓ passes
|
||||
✓ passes with DateTime and DateTimeImmutable
|
||||
✓ passes with strings
|
||||
✓ failures
|
||||
✓ failures with custom message
|
||||
✓ not failures
|
||||
@ -567,6 +579,10 @@
|
||||
✓ failures with custom message
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Features\Expect\toBeStringBackedEnum
|
||||
✓ enum is backed by string
|
||||
✓ enum is not backed by string
|
||||
|
||||
PASS Tests\Features\Expect\toBeStudlyCase
|
||||
✓ pass
|
||||
✓ failures
|
||||
@ -637,6 +653,16 @@
|
||||
✓ failures with multiple needles (some failing)
|
||||
✓ not failures
|
||||
✓ not failures with multiple needles (all failing)
|
||||
✓ not failures with multiple needles (some failing)
|
||||
|
||||
PASS Tests\Features\Expect\toContainEqual
|
||||
✓ passes arrays
|
||||
✓ passes arrays with multiple needles
|
||||
✓ failures
|
||||
✓ failures with multiple needles (all failing)
|
||||
✓ failures with multiple needles (some failing)
|
||||
✓ not failures
|
||||
✓ not failures with multiple needles (all failing)
|
||||
✓ not failures with multiple needles (some failing)
|
||||
|
||||
PASS Tests\Features\Expect\toContainOnlyInstancesOf
|
||||
@ -830,6 +856,7 @@
|
||||
|
||||
PASS Tests\Features\Expect\toMatchSnapshot
|
||||
✓ pass
|
||||
✓ pass using pipes
|
||||
✓ pass with __toString
|
||||
✓ pass with toString
|
||||
✓ pass with dataset with ('my-datas-set-value')
|
||||
@ -1140,6 +1167,16 @@
|
||||
PASS Tests\Hooks\BeforeEachTest
|
||||
✓ global beforeEach execution order
|
||||
|
||||
PASS Tests\Overrides\VersionsTest
|
||||
✓ versions with dataset "Runner/Filter/NameFilterIterator.php"
|
||||
✓ versions with dataset "Runner/ResultCache/DefaultResultCache.php"
|
||||
✓ versions with dataset "Runner/TestSuiteLoader.php"
|
||||
✓ versions with dataset "TextUI/Command/Commands/WarmCodeCoverageCacheCommand.php"
|
||||
✓ versions with dataset "TextUI/Output/Default/ProgressPrinter/Subscriber/TestSkippedSubscriber.php"
|
||||
✓ versions with dataset "TextUI/TestSuiteFilterProcessor.php"
|
||||
✓ versions with dataset "Event/Value/ThrowableBuilder.php"
|
||||
✓ versions with dataset "Logging/JUnit/JunitXmlLogger.php"
|
||||
|
||||
PASS Tests\PHPUnit\CustomAffixes\InvalidTestName
|
||||
✓ it runs file names like @#$%^&()-_=+.php
|
||||
|
||||
@ -1352,6 +1389,10 @@
|
||||
PASS Tests\Visual\Help
|
||||
✓ visual snapshot of help command output
|
||||
|
||||
PASS Tests\Visual\JUnit
|
||||
✓ junit output
|
||||
✓ junit with parallel
|
||||
|
||||
PASS Tests\Visual\Parallel
|
||||
✓ parallel
|
||||
✓ a parallel test can extend another test with same name
|
||||
@ -1377,4 +1418,4 @@
|
||||
WARN Tests\Visual\Version
|
||||
- visual snapshot of help command output
|
||||
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 20 skipped, 978 passed (2304 assertions)
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 20 skipped, 1009 passed (2395 assertions)
|
||||
@ -361,3 +361,23 @@ it('can correctly resolve a bound dataset that returns an array but wants to be
|
||||
]);
|
||||
|
||||
todo('forbids to define tests in Datasets dirs and Datasets.php files');
|
||||
|
||||
dataset('greeting-string', [
|
||||
'formal' => 'Evening',
|
||||
'informal' => 'yo',
|
||||
]);
|
||||
|
||||
it('may be used with high order')
|
||||
->with('greeting-string')
|
||||
->expect(fn (string $greeting) => $greeting)
|
||||
->throwsNoExceptions();
|
||||
|
||||
dataset('greeting-bound', [
|
||||
'formal' => fn () => 'Evening',
|
||||
'informal' => fn () => 'yo',
|
||||
]);
|
||||
|
||||
it('may be used with high order even when bound')
|
||||
->with('greeting-bound')
|
||||
->expect(fn (string $greeting) => $greeting)
|
||||
->throws(InvalidArgumentException::class);
|
||||
|
||||
@ -16,6 +16,11 @@ test('passes with DateTime and DateTimeImmutable', function () {
|
||||
expect($past)->not->toBeGreaterThan($now);
|
||||
});
|
||||
|
||||
test('passes with strings', function () {
|
||||
expect('b')->toBeGreaterThan('a');
|
||||
expect('a')->not->toBeGreaterThan('a');
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect(4)->toBeGreaterThan(4);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@ -18,6 +18,11 @@ test('passes with DateTime and DateTimeImmutable', function () {
|
||||
expect($past)->not->toBeGreaterThanOrEqual($now);
|
||||
});
|
||||
|
||||
test('passes with strings', function () {
|
||||
expect('b')->toBeGreaterThanOrEqual('a');
|
||||
expect('a')->toBeGreaterThanOrEqual('a');
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect(4)->toBeGreaterThanOrEqual(4.1);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
9
tests/Features/Expect/toBeIntBackedEnum.php
Normal file
9
tests/Features/Expect/toBeIntBackedEnum.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
test('enum is backed by int')
|
||||
->expect('Tests\Fixtures\Arch\ToBeIntBackedEnum\HasIntBacking')
|
||||
->toBeIntBackedEnum();
|
||||
|
||||
test('enum is not backed by int')
|
||||
->expect('Tests\Fixtures\Arch\ToBeIntBackedEnum\HasStringBacking')
|
||||
->not->toBeIntBackedEnum();
|
||||
@ -16,6 +16,11 @@ test('passes with DateTime and DateTimeImmutable', function () {
|
||||
expect($now)->not->toBeLessThan($now);
|
||||
});
|
||||
|
||||
test('passes with strings', function () {
|
||||
expect('a')->toBeLessThan('b');
|
||||
expect('a')->not->toBeLessThan('a');
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect(4)->toBeLessThan(4);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@ -18,6 +18,11 @@ test('passes with DateTime and DateTimeImmutable', function () {
|
||||
expect($now)->not->toBeLessThanOrEqual($past);
|
||||
});
|
||||
|
||||
test('passes with strings', function () {
|
||||
expect('a')->toBeLessThanOrEqual('b');
|
||||
expect('a')->toBeLessThanOrEqual('a');
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect(4)->toBeLessThanOrEqual(3.9);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
9
tests/Features/Expect/toBeStringBackedEnum.php
Normal file
9
tests/Features/Expect/toBeStringBackedEnum.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
test('enum is backed by string')
|
||||
->expect('Tests\Fixtures\Arch\ToBeStringBackedEnum\HasStringBacking')
|
||||
->toBeStringBackedEnum();
|
||||
|
||||
test('enum is not backed by string')
|
||||
->expect('Tests\Fixtures\Arch\ToBeStringBackedEnum\HasIntBacking')
|
||||
->not->toBeStringBackedEnum();
|
||||
35
tests/Features/Expect/toContainEqual.php
Normal file
35
tests/Features/Expect/toContainEqual.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('passes arrays', function () {
|
||||
expect([1, 2, 42])->toContainEqual('42');
|
||||
});
|
||||
|
||||
test('passes arrays with multiple needles', function () {
|
||||
expect([1, 2, 42])->toContainEqual('42', '2');
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect([1, 2, 42])->toContainEqual('3');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with multiple needles (all failing)', function () {
|
||||
expect([1, 2, 42])->toContainEqual('3', '4');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with multiple needles (some failing)', function () {
|
||||
expect([1, 2, 42])->toContainEqual('1', '3', '4');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures', function () {
|
||||
expect([1, 2, 42])->not->toContainEqual('42');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures with multiple needles (all failing)', function () {
|
||||
expect([1, 2, 42])->not->toContainEqual('42', '2');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures with multiple needles (some failing)', function () {
|
||||
expect([1, 2, 42])->not->toContainEqual('42', '1');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
@ -21,6 +21,23 @@ test('pass', function () {
|
||||
expect($this->snapshotable)->toMatchSnapshot();
|
||||
});
|
||||
|
||||
expect()->pipe('toMatchSnapshot', function (Closure $next) {
|
||||
if (is_string($this->value)) {
|
||||
$this->value = preg_replace(
|
||||
'/name="_token" value=".*"/',
|
||||
'name="_token" value="1"',
|
||||
$this->value
|
||||
);
|
||||
}
|
||||
|
||||
return $next();
|
||||
});
|
||||
|
||||
test('pass using pipes', function () {
|
||||
expect('<input type="hidden" name="_token" value="'.random_int(1, 999).'" />')
|
||||
->toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('pass with `__toString`', function () {
|
||||
TestSuite::getInstance()->snapshots->save($this->snapshotable);
|
||||
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Fixtures\Arch\ToBeIntBackedEnum\HasIntBacking;
|
||||
|
||||
enum HasIntBackingEnum: int
|
||||
{
|
||||
case IntBacked = 1;
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Fixtures\Arch\ToBeIntBackedEnum\HasStringBacking;
|
||||
|
||||
enum HasStringBackingEnum: string
|
||||
{
|
||||
case StringBacked = 'Testing';
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Fixtures\Arch\ToBeStringBackedEnum\HasIntBacking;
|
||||
|
||||
enum HasIntBackingEnum: int
|
||||
{
|
||||
case IntBacked = 1;
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Fixtures\Arch\ToBeStringBackedEnum\HasStringBacking;
|
||||
|
||||
enum HasStringBackingEnum: string
|
||||
{
|
||||
case StringBacked = 'Testing';
|
||||
}
|
||||
@ -4,16 +4,16 @@ uses()->afterEach(function () {
|
||||
expect($this)
|
||||
->toHaveProperty('ith')
|
||||
->and($this->ith)
|
||||
->toBe(0);
|
||||
->toBe(1);
|
||||
|
||||
$this->ith = 1;
|
||||
$this->ith = 2;
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
expect($this)
|
||||
->toHaveProperty('ith')
|
||||
->and($this->ith)
|
||||
->toBe(1);
|
||||
->toBe(2);
|
||||
});
|
||||
|
||||
test('global afterEach execution order', function () {
|
||||
|
||||
@ -1,15 +1,6 @@
|
||||
<?php
|
||||
|
||||
uses()->beforeEach(function () {
|
||||
expect($this)
|
||||
->toHaveProperty('baz')
|
||||
->and($this->baz)
|
||||
->toBe(0);
|
||||
|
||||
$this->baz = 1;
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
expect($this)
|
||||
->toHaveProperty('baz')
|
||||
->and($this->baz)
|
||||
@ -18,9 +9,18 @@ beforeEach(function () {
|
||||
$this->baz = 2;
|
||||
});
|
||||
|
||||
test('global beforeEach execution order', function () {
|
||||
beforeEach(function () {
|
||||
expect($this)
|
||||
->toHaveProperty('baz')
|
||||
->and($this->baz)
|
||||
->toBe(2);
|
||||
|
||||
$this->baz = 3;
|
||||
});
|
||||
|
||||
test('global beforeEach execution order', function () {
|
||||
expect($this)
|
||||
->toHaveProperty('baz')
|
||||
->and($this->baz)
|
||||
->toBe(3);
|
||||
});
|
||||
|
||||
18
tests/Overrides/VersionsTest.php
Normal file
18
tests/Overrides/VersionsTest.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Pest\Bootstrappers\BootOverrides;
|
||||
|
||||
test('versions', function (string $vendorPath, string $expectedHash) {
|
||||
expect(hash_file('sha256', $vendorPath))->toBe($expectedHash);
|
||||
})->with(function () {
|
||||
foreach (BootOverrides::FILES as $hash => $file) {
|
||||
$path = implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__, 2),
|
||||
'vendor/phpunit/phpunit/src',
|
||||
$file,
|
||||
]);
|
||||
yield $file => [$path, $hash];
|
||||
}
|
||||
});
|
||||
@ -3,6 +3,8 @@
|
||||
use Tests\CustomTestCase\CustomTestCase;
|
||||
use Tests\CustomTestCaseInSubFolders\SubFolder\SubFolder\CustomTestCaseInSubFolder;
|
||||
|
||||
$GLOBALS['__PEST_INTERNAL_TEST_SUITE'] = true;
|
||||
|
||||
uses(CustomTestCaseInSubFolder::class)->in('PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder');
|
||||
|
||||
// test case for all the directories inside PHPUnit/GlobPatternTests/SubFolder/
|
||||
@ -33,9 +35,49 @@ uses()
|
||||
})
|
||||
->in('Hooks');
|
||||
|
||||
uses()
|
||||
->beforeEach(function () {
|
||||
expect($this)
|
||||
->toHaveProperty('baz')
|
||||
->and($this->baz)
|
||||
->toBe(0);
|
||||
|
||||
$this->baz = 1;
|
||||
})
|
||||
->beforeAll(function () {
|
||||
expect($_SERVER['globalHook'])
|
||||
->toHaveProperty('beforeAll')
|
||||
->and($_SERVER['globalHook']->beforeAll)
|
||||
->toBe(0);
|
||||
|
||||
$_SERVER['globalHook']->beforeAll = 1;
|
||||
})
|
||||
->afterEach(function () {
|
||||
expect($this)
|
||||
->toHaveProperty('ith')
|
||||
->and($this->ith)
|
||||
->toBe(0);
|
||||
|
||||
$this->ith = 1;
|
||||
})
|
||||
->afterAll(function () {
|
||||
expect($_SERVER['globalHook'])
|
||||
->toHaveProperty('afterAll')
|
||||
->and($_SERVER['globalHook']->afterAll)
|
||||
->toBe(0);
|
||||
|
||||
$_SERVER['globalHook']->afterAll = 1;
|
||||
})
|
||||
->in('Hooks');
|
||||
|
||||
function helper_returns_string()
|
||||
{
|
||||
return 'string';
|
||||
}
|
||||
|
||||
dataset('dataset_in_pest_file', ['A', 'B']);
|
||||
|
||||
function removeAnsiEscapeSequences(string $input): ?string
|
||||
{
|
||||
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $input);
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ test('collision', function (array $arguments) {
|
||||
|
||||
$process->run();
|
||||
|
||||
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
||||
return removeAnsiEscapeSequences($process->getOutput());
|
||||
};
|
||||
|
||||
$outputContent = explode("\n", $output());
|
||||
|
||||
@ -6,7 +6,7 @@ test('visual snapshot of help command output', function () {
|
||||
|
||||
$process->run();
|
||||
|
||||
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
||||
return removeAnsiEscapeSequences($process->getOutput());
|
||||
};
|
||||
|
||||
expect($output())->toMatchSnapshot();
|
||||
|
||||
79
tests/Visual/JUnit.php
Normal file
79
tests/Visual/JUnit.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
$run = function () {
|
||||
$junitLogFile = tempnam(sys_get_temp_dir(), 'junit');
|
||||
|
||||
$process = new Process(
|
||||
array_merge(['php', 'bin/pest', '--log-junit', $junitLogFile], func_get_args()),
|
||||
dirname(__DIR__, 2),
|
||||
['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true'],
|
||||
);
|
||||
|
||||
$process->run();
|
||||
|
||||
$rawXmlContent = file_get_contents($junitLogFile);
|
||||
unlink($junitLogFile);
|
||||
|
||||
// convert xml to array
|
||||
try {
|
||||
$xml = new SimpleXMLElement(preg_replace("/(<\/?)(\w+):([^>]*>)/", '$1$2$3', $rawXmlContent));
|
||||
|
||||
return json_decode(json_encode((array) $xml), true);
|
||||
} catch (Exception $exception) {
|
||||
throw new XmlParseException($exception->getMessage(), $exception->getCode(), $exception->getPrevious());
|
||||
}
|
||||
};
|
||||
|
||||
$normalizedPath = function (string $path) {
|
||||
return str_replace('/', DIRECTORY_SEPARATOR, $path);
|
||||
};
|
||||
|
||||
test('junit output', function () use ($normalizedPath, $run) {
|
||||
$result = $run('tests/.tests/SuccessOnly.php');
|
||||
|
||||
expect($result['testsuite']['@attributes'])
|
||||
->name->toBe('Tests\tests\SuccessOnly')
|
||||
->file->toBe($normalizedPath('tests/.tests/SuccessOnly.php'))
|
||||
->tests->toBe('2')
|
||||
->assertions->toBe('2')
|
||||
->errors->toBe('0')
|
||||
->failures->toBe('0')
|
||||
->skipped->toBe('0');
|
||||
|
||||
expect($result['testsuite']['testcase'])
|
||||
->toHaveCount(2);
|
||||
|
||||
expect($result['testsuite']['testcase'][0]['@attributes'])
|
||||
->name->toBe('it can pass with comparison')
|
||||
->file->toBe($normalizedPath('tests/.tests/SuccessOnly.php::it can pass with comparison'))
|
||||
->class->toBe('Tests\tests\SuccessOnly')
|
||||
->classname->toBe('Tests.tests.SuccessOnly')
|
||||
->assertions->toBe('1')
|
||||
->time->toStartWith('0.0');
|
||||
});
|
||||
|
||||
test('junit with parallel', function () use ($normalizedPath, $run) {
|
||||
$result = $run('tests/.tests/SuccessOnly.php', '--parallel', '--processes=1', '--filter', 'can pass with comparison');
|
||||
|
||||
expect($result['testsuite']['@attributes'])
|
||||
->name->toBe('Tests\tests\SuccessOnly')
|
||||
->file->toBe($normalizedPath('tests/.tests/SuccessOnly.php'))
|
||||
->tests->toBe('1')
|
||||
->assertions->toBe('1')
|
||||
->errors->toBe('0')
|
||||
->failures->toBe('0')
|
||||
->skipped->toBe('0');
|
||||
|
||||
expect($result['testsuite']['testcase'])
|
||||
->toHaveCount(1);
|
||||
|
||||
expect($result['testsuite']['testcase']['@attributes'])
|
||||
->name->toBe('it can pass with comparison')
|
||||
->file->toBe($normalizedPath('tests/.tests/SuccessOnly.php::it can pass with comparison'))
|
||||
->class->toBe('Tests\tests\SuccessOnly')
|
||||
->classname->toBe('Tests.tests.SuccessOnly')
|
||||
->assertions->toBe('1')
|
||||
->time->toStartWith('0.0');
|
||||
});
|
||||
@ -11,12 +11,12 @@ $run = function () {
|
||||
|
||||
$process->run();
|
||||
|
||||
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
||||
return removeAnsiEscapeSequences($process->getOutput());
|
||||
};
|
||||
|
||||
test('parallel', function () use ($run) {
|
||||
expect($run('--exclude-group=integration'))
|
||||
->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 16 skipped, 965 passed (2285 assertions)')
|
||||
->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 16 skipped, 994 passed (2348 assertions)')
|
||||
->toContain('Parallel: 3 processes');
|
||||
})->skipOnWindows();
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ $run = function (string $target, $decorated = false) {
|
||||
|
||||
$process->run();
|
||||
|
||||
return $decorated ? $process->getOutput() : preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
||||
return $decorated ? $process->getOutput() : removeAnsiEscapeSequences($process->getOutput());
|
||||
};
|
||||
|
||||
$snapshot = function ($name) {
|
||||
|
||||
@ -11,9 +11,7 @@ $run = function (string $target, bool $parallel) {
|
||||
|
||||
expect($process->getExitCode())->toBe(0);
|
||||
|
||||
$outputContent = preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
||||
|
||||
return $outputContent;
|
||||
return removeAnsiEscapeSequences($process->getOutput());
|
||||
};
|
||||
|
||||
$snapshot = function ($name) {
|
||||
|
||||
@ -6,7 +6,7 @@ test('visual snapshot of help command output', function () {
|
||||
|
||||
$process->run();
|
||||
|
||||
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
||||
return removeAnsiEscapeSequences($process->getOutput());
|
||||
};
|
||||
|
||||
expect($output())->toMatchSnapshot();
|
||||
|
||||
Reference in New Issue
Block a user