Merge branch '2.x' into improve_types

This commit is contained in:
Nuno Maduro
2023-03-21 20:30:29 +00:00
committed by GitHub
16 changed files with 325 additions and 11 deletions

View File

@ -23,6 +23,7 @@ final class BootOverrides implements Bootstrapper
'Runner/TestSuiteLoader.php',
'TextUI/Command/WarmCodeCoverageCacheCommand.php',
'TextUI/Output/Default/ProgressPrinter/TestSkippedSubscriber.php',
'TextUI/TestSuiteFilterProcessor.php',
];
/**

View File

@ -64,7 +64,7 @@ final class Expectation
*/
public function and(mixed $value): Expectation
{
return $value instanceof static ? $value : new self($value);
return $value instanceof self ? $value : new self($value);
}
/**

View File

@ -10,6 +10,7 @@ use Pest\Factories\Covers\CoversClass;
use Pest\Factories\Covers\CoversFunction;
use Pest\Factories\Covers\CoversNothing;
use Pest\Factories\TestCaseMethodFactory;
use Pest\Plugins\Only;
use Pest\Support\Backtrace;
use Pest\Support\Exporter;
use Pest\Support\HigherOrderCallables;
@ -134,6 +135,16 @@ final class TestCall
return $this;
}
/**
* Filters the test suite by "only" tests.
*/
public function only(): self
{
Only::enable($this);
return $this;
}
/**
* Skips the current test.
*/

View File

@ -6,7 +6,7 @@ namespace Pest;
function version(): string
{
return '2.0.2';
return '2.1.0';
}
function testDirectory(string $file = ''): string

61
src/Plugins/Only.php Normal file
View File

@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
namespace Pest\Plugins;
use Pest\Contracts\Plugins\Shutdownable;
use Pest\PendingCalls\TestCall;
/**
* @internal
*/
final class Only implements Shutdownable
{
/**
* The temporary folder.
*/
private const TEMPORARY_FOLDER = __DIR__
.DIRECTORY_SEPARATOR
.'..'
.DIRECTORY_SEPARATOR
.'..'
.DIRECTORY_SEPARATOR
.'.temp';
/**
* {@inheritDoc}
*/
public function shutdown(): void
{
$lockFile = self::TEMPORARY_FOLDER.DIRECTORY_SEPARATOR.'only.lock';
if (file_exists($lockFile)) {
unlink($lockFile);
}
}
/**
* Creates the lock file.
*/
public static function enable(TestCall $testCall): void
{
$testCall->group('__pest_only');
$lockFile = self::TEMPORARY_FOLDER.DIRECTORY_SEPARATOR.'only.lock';
if (! file_exists($lockFile)) {
touch($lockFile);
}
}
/**
* Checks if "only" mode is enabled.
*/
public static function isEnabled(): bool
{
$lockFile = self::TEMPORARY_FOLDER.DIRECTORY_SEPARATOR.'only.lock';
return file_exists($lockFile);
}
}

View File

@ -73,7 +73,7 @@ final class Arr
foreach ($array as $key => $value) {
if (is_array($value) && $value !== []) {
$results = array_merge($results, static::dot($value, $prepend.$key.'.'));
$results = array_merge($results, self::dot($value, $prepend.$key.'.'));
} else {
$results[$prepend.$value] = $value;
}

View File

@ -42,7 +42,7 @@ final class Reflection
}
if (is_callable($method)) {
return static::bindCallable($method, $args);
return self::bindCallable($method, $args);
}
throw $exception;
@ -72,7 +72,7 @@ final class Reflection
return $test instanceof \PHPUnit\Framework\TestCase
? Closure::fromCallable($callable)->bindTo($test)(...$test->providedData())
: static::bindCallable($callable);
: self::bindCallable($callable);
}
/**

View File

@ -61,7 +61,8 @@ final class Str
{
$code = self::PREFIX.str_replace(' ', '_', $code);
return (string) preg_replace('/[^A-Z_a-z0-9]/', '_', $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);
}
/**