mirror of
https://github.com/pestphp/pest.git
synced 2026-12-03 22:45:06 +01:00
Compare commits
9 Commits
fcd408b895
...
fabc818ba9
| Author | SHA1 | Date | |
|---|---|---|---|
| fabc818ba9 | |||
| a865244b92 | |||
| d65b04a389 | |||
| a07f68bc54 | |||
| 989c08008f | |||
| a1a902dbc7 | |||
| 4a66e6888d | |||
| 9990d0ee36 | |||
| bb91916d0d |
@@ -6,6 +6,7 @@ declare(strict_types=1);
|
||||
use Pest\Contracts\Restarter;
|
||||
use Pest\Kernel;
|
||||
use Pest\Panic;
|
||||
use Pest\Support\ComposerProject;
|
||||
use Pest\Support\Container;
|
||||
use Pest\TestCaseFilters\GitDirtyTestCaseFilter;
|
||||
use Pest\TestCaseMethodFilters\AssigneeTestCaseFilter;
|
||||
@@ -129,21 +130,16 @@ use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
}
|
||||
|
||||
// Used when Pest is required using composer.
|
||||
$vendorPath = dirname(__DIR__, 4).'/vendor/autoload.php';
|
||||
$autoloadPath = $GLOBALS['_composer_autoload_path'] ?? dirname(__DIR__, 3).'/autoload.php';
|
||||
|
||||
// Used when Pest maintainers are running Pest tests.
|
||||
$localPath = dirname(__DIR__).'/vendor/autoload.php';
|
||||
|
||||
if (file_exists($vendorPath)) {
|
||||
include_once $vendorPath;
|
||||
$autoloadPath = $vendorPath;
|
||||
} else {
|
||||
include_once $localPath;
|
||||
$autoloadPath = $localPath;
|
||||
if (! is_file($autoloadPath)) {
|
||||
$autoloadPath = dirname(__DIR__).'/vendor/autoload.php';
|
||||
}
|
||||
|
||||
// Get $rootPath based on $autoloadPath
|
||||
$rootPath = dirname($autoloadPath, 2);
|
||||
include_once $autoloadPath;
|
||||
|
||||
$GLOBALS['_composer_bin_dir'] ??= dirname($autoloadPath).'/bin';
|
||||
$rootPath = ComposerProject::rootPath($autoloadPath);
|
||||
|
||||
$input = new ArgvInput;
|
||||
|
||||
|
||||
+5
-4
@@ -7,6 +7,7 @@ use ParaTest\WrapperRunner\WrapperWorker;
|
||||
use Pest\Kernel;
|
||||
use Pest\Plugins\Actions\CallsHandleArguments;
|
||||
use Pest\Plugins\Parallel\Paratest\StopConditions;
|
||||
use Pest\Support\ComposerProject;
|
||||
use Pest\Support\Container;
|
||||
use Pest\TestSuite;
|
||||
use PHPUnit\TextUI\Configuration\Registry as ConfigurationRegistry;
|
||||
@@ -14,10 +15,9 @@ use Symfony\Component\Console\Input\ArgvInput;
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
$bootPest = (static function (): void {
|
||||
$bootPest = (static function (string $rootPath): void {
|
||||
$workerArgv = new ArgvInput;
|
||||
|
||||
$rootPath = dirname(PHPUNIT_COMPOSER_INSTALL, 2);
|
||||
$testSuite = TestSuite::getInstance($rootPath, $workerArgv->getParameterOption(
|
||||
'--test-directory',
|
||||
'tests'
|
||||
@@ -56,13 +56,14 @@ $bootPest = (static function (): void {
|
||||
if (file_exists($file)) {
|
||||
require_once $file;
|
||||
define('PHPUNIT_COMPOSER_INSTALL', $file);
|
||||
$GLOBALS['_composer_bin_dir'] ??= dirname($file).'/bin';
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$container = Container::getInstance();
|
||||
$rootPath = dirname(PHPUNIT_COMPOSER_INSTALL, 2);
|
||||
$rootPath = ComposerProject::rootPath(PHPUNIT_COMPOSER_INSTALL);
|
||||
|
||||
foreach (Kernel::RESTARTERS as $restarterClass) {
|
||||
$restarter = $container->get($restarterClass);
|
||||
@@ -85,7 +86,7 @@ $bootPest = (static function (): void {
|
||||
$phpunitArgv = unserialize($getopt['phpunit-argv'], ['allowed_classes' => false]);
|
||||
assert(is_array($phpunitArgv));
|
||||
|
||||
$bootPest();
|
||||
$bootPest($rootPath);
|
||||
|
||||
$phpunitArgv = CallsHandleArguments::execute($phpunitArgv);
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ use Pest\Plugins\Concerns\HandleArguments;
|
||||
use PHPUnit\Event\Facade as EventFacade;
|
||||
use PHPUnit\TextUI\CliArguments\Builder as CliConfigurationBuilder;
|
||||
use PHPUnit\TextUI\CliArguments\XmlConfigurationFileFinder;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@@ -27,6 +28,9 @@ final class Configuration implements HandlesArguments, Terminable
|
||||
.DIRECTORY_SEPARATOR
|
||||
.'resources/base-phpunit.xml';
|
||||
|
||||
/** @var array{path: string, dev: int, ino: int}|null */
|
||||
private ?array $generatedConfiguration = null;
|
||||
|
||||
public function handleArguments(array $arguments): array
|
||||
{
|
||||
if ($this->hasArgument('--configuration', $arguments) || $this->hasArgument('-c', $arguments) || $this->hasCustomConfigurationFile()) {
|
||||
@@ -40,19 +44,50 @@ final class Configuration implements HandlesArguments, Terminable
|
||||
|
||||
private function fromGeneratedConfigurationFile(): string
|
||||
{
|
||||
$path = $this->getTempPhpunitXmlPath();
|
||||
if (file_exists($path)) {
|
||||
unlink($path);
|
||||
$directory = getcwd();
|
||||
|
||||
if ($directory === false) {
|
||||
throw new RuntimeException('Unable to determine the working directory.');
|
||||
}
|
||||
|
||||
$doc = new DOMDocument;
|
||||
$doc->load(self::BASE_PHPUNIT_FILE);
|
||||
|
||||
$contents = $doc->saveXML();
|
||||
assert(is_string($contents));
|
||||
|
||||
assert(is_int(file_put_contents($path, $contents)));
|
||||
foreach (['.pest.xml', '.pest-fallback.xml', null] as $filename) {
|
||||
$filename ??= '.pest-'.bin2hex(random_bytes(8)).'.xml';
|
||||
$path = $directory.DIRECTORY_SEPARATOR.$filename;
|
||||
$file = @fopen($path, 'xb');
|
||||
|
||||
return $path;
|
||||
if ($file === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$stat = @fstat($file);
|
||||
|
||||
if ($stat === false) {
|
||||
throw new RuntimeException('Unable to identify the temporary PHPUnit configuration file.');
|
||||
}
|
||||
|
||||
$this->generatedConfiguration = ['path' => $path, 'dev' => $stat['dev'], 'ino' => $stat['ino']];
|
||||
$written = @fwrite($file, $contents);
|
||||
} finally {
|
||||
fclose($file);
|
||||
}
|
||||
|
||||
if ($written !== strlen($contents)) {
|
||||
$this->terminate();
|
||||
|
||||
throw new RuntimeException('Unable to write the temporary PHPUnit configuration file.');
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
throw new RuntimeException('Unable to create a temporary PHPUnit configuration file.');
|
||||
}
|
||||
|
||||
private function hasCustomConfigurationFile(): bool
|
||||
@@ -63,17 +98,20 @@ final class Configuration implements HandlesArguments, Terminable
|
||||
return is_string($configurationFile);
|
||||
}
|
||||
|
||||
private function getTempPhpunitXmlPath(): string
|
||||
{
|
||||
return getcwd().'/.pest.xml';
|
||||
}
|
||||
|
||||
public function terminate(): void
|
||||
{
|
||||
$path = $this->getTempPhpunitXmlPath();
|
||||
$configuration = $this->generatedConfiguration;
|
||||
$this->generatedConfiguration = null;
|
||||
|
||||
if (file_exists($path)) {
|
||||
unlink($path);
|
||||
if ($configuration === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
clearstatcache();
|
||||
$stat = @lstat($configuration['path']);
|
||||
|
||||
if ($stat !== false && $stat['dev'] === $configuration['dev'] && $stat['ino'] === $configuration['ino']) {
|
||||
unlink($configuration['path']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+38
-39
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins;
|
||||
|
||||
use Pest\Contracts\Plugins\HandlesArguments;
|
||||
use Pest\Contracts\Plugins\Terminable;
|
||||
use Pest\Factories\Attribute;
|
||||
use Pest\Factories\TestCaseMethodFactory;
|
||||
@@ -13,17 +14,24 @@ use PHPUnit\Framework\Attributes\Group;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Only implements Terminable
|
||||
final class Only implements HandlesArguments, Terminable
|
||||
{
|
||||
private const string TEMPORARY_FOLDER = __DIR__
|
||||
.DIRECTORY_SEPARATOR
|
||||
.'..'
|
||||
.DIRECTORY_SEPARATOR
|
||||
.'..'
|
||||
.DIRECTORY_SEPARATOR
|
||||
.'.temp';
|
||||
private const string DEFAULT_GROUP = '__pest_only';
|
||||
|
||||
public static function enable(TestCall|TestCaseMethodFactory $testCall, string $group = '__pest_only'): void
|
||||
private const string WORKER_GROUP = 'ONLY_GROUP';
|
||||
|
||||
private static ?string $group = null;
|
||||
|
||||
public function handleArguments(array $arguments): array
|
||||
{
|
||||
if (! Parallel::isWorker()) {
|
||||
self::shareGroupWithWorkers();
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
public static function enable(TestCall|TestCaseMethodFactory $testCall, string $group = self::DEFAULT_GROUP): void
|
||||
{
|
||||
if ($testCall instanceof TestCall) {
|
||||
$testCall->group($group);
|
||||
@@ -38,52 +46,43 @@ final class Only implements Terminable
|
||||
return;
|
||||
}
|
||||
|
||||
$lockFile = self::TEMPORARY_FOLDER.DIRECTORY_SEPARATOR.'only.lock';
|
||||
|
||||
if (file_exists($lockFile) && $group === '__pest_only') {
|
||||
file_put_contents($lockFile, $group);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (! file_exists($lockFile)) {
|
||||
touch($lockFile);
|
||||
|
||||
file_put_contents($lockFile, $group);
|
||||
if (self::$group === null || $group === self::DEFAULT_GROUP) {
|
||||
self::$group = $group;
|
||||
self::shareGroupWithWorkers();
|
||||
}
|
||||
}
|
||||
|
||||
public static function isEnabled(): bool
|
||||
{
|
||||
$lockFile = self::TEMPORARY_FOLDER.DIRECTORY_SEPARATOR.'only.lock';
|
||||
|
||||
return file_exists($lockFile);
|
||||
return self::selectedGroup() !== null;
|
||||
}
|
||||
|
||||
public static function group(): string
|
||||
{
|
||||
$lockFile = self::TEMPORARY_FOLDER.DIRECTORY_SEPARATOR.'only.lock';
|
||||
|
||||
if (! file_exists($lockFile)) {
|
||||
return '__pest_only';
|
||||
}
|
||||
|
||||
return file_get_contents($lockFile) ?: '__pest_only'; // @phpstan-ignore-line
|
||||
return self::selectedGroup() ?: self::DEFAULT_GROUP;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function terminate(): void
|
||||
{
|
||||
if (Parallel::isWorker()) {
|
||||
return;
|
||||
self::$group = null;
|
||||
self::shareGroupWithWorkers();
|
||||
}
|
||||
|
||||
private static function selectedGroup(): ?string
|
||||
{
|
||||
if (! Parallel::isWorker()) {
|
||||
return self::$group;
|
||||
}
|
||||
|
||||
$lockFile = self::TEMPORARY_FOLDER.DIRECTORY_SEPARATOR.'only.lock';
|
||||
$group = Parallel::getGlobal(self::WORKER_GROUP);
|
||||
|
||||
if (file_exists($lockFile)) {
|
||||
unlink($lockFile);
|
||||
return is_string($group) ? base64_decode($group) : null;
|
||||
}
|
||||
|
||||
private static function shareGroupWithWorkers(): void
|
||||
{
|
||||
if (Parallel::isEnabled()) {
|
||||
Parallel::setGlobal(self::WORKER_GROUP, self::$group === null ? false : base64_encode(self::$group));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,10 +124,6 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
|
||||
'testsCount' => count($tests),
|
||||
];
|
||||
|
||||
if ($testsToRun === []) {
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
$filter = $this->buildFilterArgument($testsToRun);
|
||||
|
||||
$this->ensureFilterLengthIsSafe($filter);
|
||||
@@ -175,7 +171,7 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
|
||||
private function allTests(array $arguments): array
|
||||
{
|
||||
$command = $this->buildListTestsCommand(
|
||||
$arguments,
|
||||
$this->popArgument('--list-tests', $arguments),
|
||||
TestSuite::getInstance()->testPath,
|
||||
);
|
||||
|
||||
@@ -247,7 +243,7 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
|
||||
private function buildFilterArgument(array $testsToRun): string
|
||||
{
|
||||
if ($testsToRun === []) {
|
||||
return '';
|
||||
return '(?!)';
|
||||
}
|
||||
|
||||
/** @var array<string, mixed> $tree */
|
||||
|
||||
@@ -655,13 +655,7 @@ final class Graph
|
||||
if (isset($handledBlade[$rel])) {
|
||||
continue;
|
||||
}
|
||||
if (! isset($this->fileIds[$rel])) {
|
||||
if (! is_file($this->projectRoot.'/'.$rel)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$watchedPaths[] = $rel;
|
||||
} elseif ($this->isFrameworkBootPath($rel)) {
|
||||
if (! isset($this->fileIds[$rel]) || $this->isFrameworkBootPath($rel)) {
|
||||
$watchedPaths[] = $rel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Pest\Repositories;
|
||||
|
||||
use Pest\Exceptions\ShouldNotHappen;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@@ -48,7 +49,9 @@ final readonly class Snapshot
|
||||
@mkdir($directory, 0755, true);
|
||||
}
|
||||
|
||||
file_put_contents($this->filename, $contents);
|
||||
if (@file_put_contents($this->filename, $contents) !== strlen($contents)) {
|
||||
throw new RuntimeException(sprintf('Unable to write snapshot at [%s].', $this->path()));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ use Pest\TestSuite;
|
||||
*/
|
||||
final class SnapshotRepository
|
||||
{
|
||||
private const int MAX_FILENAME_BYTES = 255;
|
||||
|
||||
private static ?string $key = null;
|
||||
|
||||
private static int $ordinal = 0;
|
||||
@@ -95,15 +97,18 @@ final class SnapshotRepository
|
||||
$relativePath = substr($testFile, strlen($startPath));
|
||||
$relativePath = substr($relativePath, 0, (int) strrpos($relativePath, '.'));
|
||||
|
||||
return new Snapshot(
|
||||
sprintf(
|
||||
'%s/%s%s.snap',
|
||||
$this->testsPath.'/'.$this->snapshotsPath.$relativePath,
|
||||
TestSuite::getInstance()->getDescription(),
|
||||
$suffix,
|
||||
),
|
||||
dirname($this->testsPath).'/',
|
||||
);
|
||||
$directory = $this->testsPath.'/'.$this->snapshotsPath.$relativePath;
|
||||
$description = TestSuite::getInstance()->getDescription().$suffix;
|
||||
$extension = '.snap';
|
||||
$filename = $description.$extension;
|
||||
|
||||
if (strlen($filename) > self::MAX_FILENAME_BYTES && ! is_file($directory.'/'.$filename)) {
|
||||
$digest = '__'.hash('xxh128', $description);
|
||||
$prefix = mb_strcut($description, 0, self::MAX_FILENAME_BYTES - strlen($digest.$extension), 'UTF-8');
|
||||
$filename = $prefix.$digest.$extension;
|
||||
}
|
||||
|
||||
return new Snapshot($directory.'/'.$filename, dirname($this->testsPath).'/');
|
||||
}
|
||||
|
||||
private function synchronize(): void
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Support;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class ComposerProject
|
||||
{
|
||||
public static function rootPath(string $autoloadPath): string
|
||||
{
|
||||
$vendorPath = dirname($autoloadPath);
|
||||
$vendorPath = realpath($vendorPath) ?: $vendorPath;
|
||||
$rootPath = dirname($vendorPath);
|
||||
$metadataPath = $vendorPath.'/composer/installed.php';
|
||||
|
||||
if (! is_file($metadataPath)) {
|
||||
return $rootPath;
|
||||
}
|
||||
|
||||
/** @var array{root: array{install_path: string}} $installed */
|
||||
$installed = require $metadataPath;
|
||||
|
||||
return realpath($installed['root']['install_path']) ?: $rootPath;
|
||||
}
|
||||
}
|
||||
@@ -46,33 +46,31 @@ final class GitDirtyTestCaseFilter implements TestCaseFilter
|
||||
|
||||
private function loadChangedFiles(): void
|
||||
{
|
||||
$status = new Git(timeout: 60.0)->raw(['status', '--short', '--', '*.php']);
|
||||
$git = new Git($this->projectRoot, timeout: 60.0);
|
||||
$status = $git->raw(['status', '--porcelain=v1', '-z', '--no-renames', '--', '*.php']);
|
||||
$prefix = $git->raw(['rev-parse', '--show-prefix']);
|
||||
|
||||
if ($status === null) {
|
||||
if ($status === null || $prefix === null) {
|
||||
throw new MissingDependency('Filter by dirty files', 'git');
|
||||
}
|
||||
|
||||
$output = preg_split('/\R+/', $status, flags: PREG_SPLIT_NO_EMPTY);
|
||||
assert(is_array($output));
|
||||
|
||||
$pathOffset = 3 + strlen(rtrim($prefix, "\r\n"));
|
||||
$dirtyFiles = [];
|
||||
|
||||
foreach ($output as $dirtyFile) {
|
||||
$dirtyFiles[substr($dirtyFile, 3)] = trim(substr($dirtyFile, 0, 3));
|
||||
foreach (explode("\0", $status) as $entry) {
|
||||
if ($entry === '' || trim(substr($entry, 0, 2)) === 'D') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$dirtyFiles[] = substr($entry, $pathOffset);
|
||||
}
|
||||
|
||||
$dirtyFiles = array_filter($dirtyFiles, fn (string $status): bool => $status !== 'D');
|
||||
|
||||
$dirtyFiles = array_map(
|
||||
fn (string $file, string $status): string => in_array($status, ['R', 'RM'], true)
|
||||
? explode(' -> ', $file)[1]
|
||||
: $file, array_keys($dirtyFiles), $dirtyFiles,
|
||||
);
|
||||
|
||||
$dirtyFiles = array_filter(
|
||||
$dirtyFiles,
|
||||
fn (string $file): bool => str_starts_with('.'.DIRECTORY_SEPARATOR.$file, TestSuite::getInstance()->testPath)
|
||||
fn (string $file): bool => (
|
||||
str_starts_with('.'.DIRECTORY_SEPARATOR.$file, TestSuite::getInstance()->testPath)
|
||||
|| str_starts_with($file, TestSuite::getInstance()->testPath)
|
||||
) && is_file($this->projectRoot.DIRECTORY_SEPARATOR.$file)
|
||||
);
|
||||
|
||||
$dirtyFiles = array_values($dirtyFiles);
|
||||
|
||||
@@ -13,6 +13,10 @@ use Tests\TestCase;
|
||||
|
|
||||
*/
|
||||
|
||||
if (! class_exists(TestCase::class)) {
|
||||
require_once __DIR__.'/TestCase.php';
|
||||
}
|
||||
|
||||
pest()->extend(TestCase::class)->in('Feature');
|
||||
|
||||
/*
|
||||
|
||||
@@ -73,6 +73,14 @@
|
||||
↓ is marked as todo 3
|
||||
↓ shouldBeMarkedAsTodo
|
||||
|
||||
PASS Tests\Features\Configuration
|
||||
✓ preserves an existing .pest.xml file with dataset "explicit configuration"
|
||||
✓ preserves an existing .pest.xml file with dataset "discovered configuration"
|
||||
✓ preserves an existing .pest.xml file with dataset "generated configuration"
|
||||
✓ removes the generated configuration when it finishes with dataset "sequential"
|
||||
✓ removes the generated configuration when it finishes with dataset "parallel"
|
||||
✓ preserves a replacement for the generated configuration
|
||||
|
||||
WARN Tests\Features\Coverage
|
||||
✓ it has plugin
|
||||
- it adds coverage if --coverage exist → Coverage is not available
|
||||
@@ -401,6 +409,12 @@
|
||||
✓ it works with nested properties
|
||||
✓ it works with higher order tests
|
||||
|
||||
PASS Tests\Features\Expect\LongSnapshotNames
|
||||
✓ creates and matches snapshots with long dataset labels
|
||||
|
||||
PASS Tests\Features\Expect\SnapshotWriteFailure
|
||||
✓ reports a missing snapshot that cannot be written
|
||||
|
||||
PASS Tests\Features\Expect\each
|
||||
✓ an exception is thrown if the the type is not iterable
|
||||
✓ it expects on each item
|
||||
@@ -1302,7 +1316,7 @@
|
||||
… a "describe" group of tests → it is incompleted
|
||||
|
||||
PASS Tests\Features\Init
|
||||
✓ init creates a suite when the tests directory is missing
|
||||
✓ init creates a runnable suite when the tests directory is missing
|
||||
✓ init creates a suite when --init is not the first argument
|
||||
✓ init creates a suite when --init is passed with a value
|
||||
✓ a missing tests directory does not crash while resolving tia state
|
||||
@@ -1380,6 +1394,10 @@
|
||||
! notice → This is a notice description // tests/Features/Notices.php:6
|
||||
! a "describe" group of tests → notice → This is a notice description // tests/Features/Notices.php:13
|
||||
|
||||
PASS Tests\Features\Only
|
||||
✓ limits focus to the invocation that discovers it with dataset "sequential"
|
||||
✓ limits focus to the invocation that discovers it with dataset "parallel"
|
||||
|
||||
PASS Tests\Features\Pr
|
||||
✓ it may be associated with an pr #1, #2
|
||||
✓ nested → it may be associated with an pr #1, #4, #5, #6, #3
|
||||
@@ -1874,7 +1892,7 @@
|
||||
✓ buildFilterArgument → it generates compact filter for single test
|
||||
✓ buildFilterArgument → it generates compact filter for multiple tests with common prefix
|
||||
✓ buildFilterArgument → it generates compact filter for tests with different namespaces
|
||||
✓ buildFilterArgument → it returns empty string for empty test list
|
||||
✓ buildFilterArgument → it generates a filter that selects no tests for an empty test list
|
||||
✓ buildFilterArgument → it generates compact filter for deeply nested namespaces
|
||||
✓ buildFilterArgument → it handles mix of nested and flat namespaces
|
||||
✓ buildFilterArgument → it does not match a class outside of the shard when another class name is its prefix
|
||||
@@ -2395,6 +2413,14 @@
|
||||
PASS Tests\Visual\Collision
|
||||
✓ collision with ([''])
|
||||
|
||||
PASS Tests\Visual\Dirty
|
||||
✓ dirty selects paths with spaces and Unicode with dataset "repository root"
|
||||
✓ dirty selects paths with spaces and Unicode with dataset "project subdirectory"
|
||||
✓ dirty selects paths with spaces and Unicode with dataset "subdirectory with leading space"
|
||||
✓ dirty ignores a test removed after staging a modification with dataset "sequential"
|
||||
✓ dirty ignores a test removed after staging a modification with dataset "parallel"
|
||||
✓ dirty selects an unresolved test only while its file exists
|
||||
|
||||
PASS Tests\Visual\FailingBoot
|
||||
✓ a failure in the boot files renders only that failure
|
||||
|
||||
@@ -2405,6 +2431,11 @@
|
||||
✓ junit output
|
||||
✓ junit with parallel
|
||||
|
||||
PASS Tests\Visual\NestedVendorDirectory
|
||||
✓ runs with a nested Composer vendor directory with dataset "Composer proxy"
|
||||
✓ runs with a nested Composer vendor directory with dataset "Composer proxy with workers"
|
||||
✓ runs with a nested Composer vendor directory with dataset "direct execution with workers"
|
||||
|
||||
PASS Tests\Visual\Parallel
|
||||
✓ parallel
|
||||
✓ a parallel test can extend another test with same name
|
||||
@@ -2492,6 +2523,14 @@
|
||||
✓ parallel counts a shared issue only once across recycled workers with ('notice', 'shares notice', 'notice')
|
||||
✓ parallel combines stop-on counts from different workers and cleans up their files
|
||||
|
||||
PASS Tests\Visual\Shard
|
||||
✓ an empty shard runs no tests with dataset "sequential"
|
||||
✓ an empty shard runs no tests with dataset "parallel"
|
||||
✓ an empty shard runs no tests with dataset "sequential with fail-on-empty-test-suite"
|
||||
✓ an empty shard runs no tests with dataset "parallel with fail-on-empty-test-suite"
|
||||
✓ an empty shard lists no tests
|
||||
✓ a non-empty shard runs its assigned test
|
||||
|
||||
PASS Tests\Visual\SingleTestOrDirectory
|
||||
✓ allows to run a single test
|
||||
✓ allows to run a directory
|
||||
@@ -2523,4 +2562,4 @@
|
||||
✓ pass with dataset with ('my-datas-set-value')
|
||||
✓ within describe → pass with dataset with ('my-datas-set-value')
|
||||
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 38 skipped, 1831 passed (4150 assertions)
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 38 skipped, 1856 passed (4269 assertions)
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Tests\Fixtures\Tia\Project;
|
||||
|
||||
afterEach(function (): void {
|
||||
Project::destroyAll();
|
||||
});
|
||||
|
||||
test('preserves an existing .pest.xml file', function (array $arguments, bool $hasDefaultConfiguration): void {
|
||||
$project = Project::withoutGit();
|
||||
$configuration = $project->path('.pest.xml');
|
||||
$contents = $arguments === [] ? 'An existing project file.' : (string) file_get_contents($project->path('phpunit.xml'));
|
||||
$project->write('.pest.xml', $contents);
|
||||
|
||||
if (! $hasDefaultConfiguration) {
|
||||
unlink($project->path('phpunit.xml'));
|
||||
}
|
||||
|
||||
$result = $project->pest('tests/Unit/GreeterTest.php', '--cache-directory', $project->path('.phpunit.cache'), ...$arguments);
|
||||
|
||||
expect($result->exitCode)->toBe(0, $result->describe())
|
||||
->and($result->tally())->toContain('2 passed')
|
||||
->and(glob($project->path('.pest*.xml')))->toHaveCount(1)
|
||||
->and($configuration)->toBeFile()
|
||||
->and(file_get_contents($configuration))->toBe($contents);
|
||||
})->with([
|
||||
'explicit configuration' => [['--configuration=.pest.xml'], false],
|
||||
'discovered configuration' => [[], true],
|
||||
'generated configuration' => [[], false],
|
||||
])->group('integration');
|
||||
|
||||
test('removes the generated configuration when it finishes', function (array $arguments): void {
|
||||
$project = Project::withoutGit();
|
||||
unlink($project->path('phpunit.xml'));
|
||||
|
||||
$result = $project->pest('tests/Unit/GreeterTest.php', '--cache-directory', $project->path('.phpunit.cache'), ...$arguments);
|
||||
|
||||
expect($result->exitCode)->toBe(0, $result->describe())
|
||||
->and($result->tally())->toContain('2 passed')
|
||||
->and(glob($project->path('.pest*.xml')))->toBe([]);
|
||||
})->with(Project::SEQUENTIAL_AND_PARALLEL)->group('integration');
|
||||
|
||||
test('preserves a replacement for the generated configuration', function (): void {
|
||||
$project = Project::withoutGit();
|
||||
unlink($project->path('phpunit.xml'));
|
||||
$project->write('replacement.xml', 'A replacement project file.');
|
||||
$project->write('tests/Unit/ReplaceConfigurationTest.php', <<<'PHP'
|
||||
<?php
|
||||
|
||||
test('replaces the configuration', function (): void {
|
||||
expect(rename('replacement.xml', '.pest.xml'))->toBeTrue();
|
||||
});
|
||||
PHP);
|
||||
|
||||
$result = $project->pest('tests/Unit/ReplaceConfigurationTest.php', '--cache-directory', $project->path('.phpunit.cache'));
|
||||
|
||||
expect($result->exitCode)->toBe(0, $result->describe())
|
||||
->and($project->path('.pest.xml'))->toBeFile()
|
||||
->and(file_get_contents($project->path('.pest.xml')))->toBe('A replacement project file.');
|
||||
})->group('integration');
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Tests\Fixtures\Tia\Project;
|
||||
|
||||
afterEach(function (): void {
|
||||
Project::destroyAll();
|
||||
});
|
||||
|
||||
test('creates and matches snapshots with long dataset labels', function (): void {
|
||||
$project = Project::withoutGit();
|
||||
$testFile = 'tests/Unit/SnapshotNamesTest.php';
|
||||
$snapshotDirectory = $project->path('tests/.pest/snapshots/Unit/SnapshotNamesTest');
|
||||
|
||||
$project->write($testFile, <<<'FIXTURE'
|
||||
<?php
|
||||
|
||||
$prefix = str_repeat('日本', 135);
|
||||
|
||||
test('stores a snapshot', function (string $value): void {
|
||||
expect($value)->toMatchSnapshot()
|
||||
->and(strtoupper($value))->toMatchSnapshot(as: 'upper');
|
||||
})->with([
|
||||
'short' => ['short'],
|
||||
$prefix.' one' => ['one'],
|
||||
$prefix.' two' => ['two'],
|
||||
]);
|
||||
FIXTURE);
|
||||
|
||||
$first = $project->pest($testFile, '--update-snapshots');
|
||||
$snapshots = glob($snapshotDirectory.'/*.snap');
|
||||
|
||||
expect($first->exitCode)->toBe(0, $first->describe())
|
||||
->and($snapshots)->toHaveCount(6)
|
||||
->and(array_map(file_get_contents(...), $snapshots))->toEqualCanonicalizing(['short', 'SHORT', 'one', 'ONE', 'two', 'TWO'])
|
||||
->and($snapshotDirectory.'/stores_a_snapshot_with_data_set__dataset__short__.snap')->toBeFile()
|
||||
->and($snapshotDirectory.'/stores_a_snapshot_with_data_set__dataset__short____upper.snap')->toBeFile();
|
||||
|
||||
foreach ($snapshots as $snapshot) {
|
||||
$filename = basename($snapshot);
|
||||
|
||||
expect(strlen($filename))->toBeLessThanOrEqual(255)
|
||||
->and(mb_check_encoding($filename, 'UTF-8'))->toBeTrue();
|
||||
}
|
||||
|
||||
$second = $project->pestWithEnvironment($project->path(), ['CI' => 'true'], $testFile);
|
||||
|
||||
expect($second->exitCode)->toBe(0, $second->describe())
|
||||
->and($second->tally())->toContain('3 passed');
|
||||
})->group('integration');
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Tests\Fixtures\Tia\Project;
|
||||
|
||||
afterEach(function (): void {
|
||||
Project::destroyAll();
|
||||
});
|
||||
|
||||
test('reports a missing snapshot that cannot be written', function (): void {
|
||||
$project = Project::withoutGit();
|
||||
$testFile = 'tests/Unit/BlockedSnapshotTest.php';
|
||||
$directory = 'tests/.pest/snapshots/Unit/BlockedSnapshotTest';
|
||||
|
||||
$project->write($directory, 'An existing file.');
|
||||
$project->write($testFile, <<<'PHP'
|
||||
<?php
|
||||
|
||||
test('stores a snapshot', function (): void {
|
||||
expect('content')->toMatchSnapshot();
|
||||
});
|
||||
PHP);
|
||||
|
||||
$run = $project->pest($testFile, '--update-snapshots');
|
||||
|
||||
expect($run->exitCode)->toBe(2, $run->describe())
|
||||
->and(str_replace('\\', '/', $run->output))->toContain("Unable to write snapshot at [$directory/stores_a_snapshot.snap].")
|
||||
->not->toContain('Snapshot created at')
|
||||
->and(file_get_contents($project->path($directory)))->toBe('An existing file.');
|
||||
})->group('integration');
|
||||
+11
-1
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
test('init creates a suite when the tests directory is missing', function (): void {
|
||||
test('init creates a runnable suite when the tests directory is missing', function (): void {
|
||||
$root = makeInitProject();
|
||||
|
||||
try {
|
||||
@@ -17,6 +17,11 @@ test('init creates a suite when the tests directory is missing', function (): vo
|
||||
->and($root.DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'Pest.php')->toBeFile()
|
||||
->and($root.DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'TestCase.php')->toBeFile()
|
||||
->and($root.DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'Unit'.DIRECTORY_SEPARATOR.'ExampleTest.php')->toBeFile();
|
||||
|
||||
$suite = runInitProject($root, '--colors=never');
|
||||
|
||||
expect($suite->getExitCode())->toBe(0)
|
||||
->and($suite->getOutput())->toContain('2 passed (2 assertions)');
|
||||
} finally {
|
||||
removeInitProject($root);
|
||||
}
|
||||
@@ -85,6 +90,11 @@ function makeInitProject(): string
|
||||
true,
|
||||
);
|
||||
|
||||
file_put_contents(
|
||||
$root.DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'autoload.php',
|
||||
"<?php\n\nreturn require_once {$autoload};\n",
|
||||
);
|
||||
|
||||
file_put_contents($root.DIRECTORY_SEPARATOR.'run.php', <<<PHP
|
||||
<?php
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Tests\Fixtures\Tia\Project;
|
||||
|
||||
afterEach(function (): void {
|
||||
Project::destroyAll();
|
||||
});
|
||||
|
||||
test('limits focus to the invocation that discovers it', function (array $arguments): void {
|
||||
$project = Project::withoutGit();
|
||||
$testFile = 'tests/Unit/FocusTest.php';
|
||||
$project->write('vendor/pestphp/pest/.temp/.gitkeep', '');
|
||||
$project->write($testFile, <<<'FIXTURE'
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
test('runs with a named focus group in CI', function (): void {
|
||||
expect(true)->toBeTrue();
|
||||
})->only('named-focus');
|
||||
|
||||
test('runs an independent Pest invocation', function (): void {
|
||||
foreach ([[], ['--parallel', '--processes=2']] as $arguments) {
|
||||
$process = new Process(
|
||||
[PHP_BINARY, 'vendor/pestphp/pest/bin/pest', 'tests/Unit/GreeterTest.php', '--cache-directory', '.home/nested', ...$arguments],
|
||||
env: ['PARATEST' => '0'],
|
||||
);
|
||||
$process->mustRun();
|
||||
|
||||
expect($process->getOutput())->toContain('2 passed');
|
||||
}
|
||||
})->only();
|
||||
|
||||
test('runs without focus in CI', function (): void {
|
||||
expect(true)->toBeTrue();
|
||||
});
|
||||
FIXTURE);
|
||||
|
||||
$focused = $project->pest($testFile, '--cache-directory', $project->path('.home/focused'), ...$arguments);
|
||||
|
||||
expect($focused->exitCode)->toBe(0, $focused->describe())
|
||||
->and($focused->tally())->toContain('1 passed (2 assertions)');
|
||||
|
||||
$ci = $project->pest($testFile, '--ci', '--cache-directory', $project->path('.home/ci'), ...$arguments);
|
||||
|
||||
expect($ci->exitCode)->toBe(0, $ci->describe())
|
||||
->and($ci->tally())->toContain('3 passed');
|
||||
})->with(Project::SEQUENTIAL_AND_PARALLEL)->group('integration');
|
||||
@@ -63,3 +63,31 @@ test('still runs every test without a baseline when defaults are disabled', func
|
||||
expect($result->exitCode)->toBe(0, $result->describe())
|
||||
->and($result->tally())->toContain(Project::TOTAL_TESTS.' passed');
|
||||
})->with(Project::SEQUENTIAL_AND_PARALLEL)->skipOnWindows();
|
||||
|
||||
test('runs dependent tests when a watched path is removed', function (array $gitArguments, array $arguments): void {
|
||||
$project = Project::make('master');
|
||||
$project->write('schema/api.graphql', "type Query { status: String }\n");
|
||||
$project->write('tests/Pest.php', file_get_contents($project->path('tests/Pest.php')).
|
||||
"\npest()->tia()->withoutDefaultWatchPatterns()->watch(['schema/*.graphql' => 'tests/Unit/GreeterTest.php']);\n");
|
||||
|
||||
$test = 'tests/Unit/GreeterTest.php';
|
||||
$project->write($test, str_replace(
|
||||
"test('greets a person', function (): void {",
|
||||
"test('greets a person', function (): void {\n expect('schema/api.graphql')->toBeFile();",
|
||||
file_get_contents($project->path($test)),
|
||||
));
|
||||
|
||||
$project->git()->commit('add a watched schema and its test');
|
||||
$project->seed('master');
|
||||
$project->git()->run($gitArguments);
|
||||
$project->git()->commit('remove the watched path');
|
||||
|
||||
$result = $project->pest('--tia', '--filtered', ...$arguments);
|
||||
|
||||
expect($result->exitCode)->toBe(1, $result->describe())
|
||||
->and($result->affected())->toBe(2, $result->describe())
|
||||
->and($result->output)->toContain('greets a person', 'schema/api.graphql');
|
||||
})->with([
|
||||
'deleted' => [['rm', '--', 'schema/api.graphql']],
|
||||
'renamed' => [['mv', '--', 'schema/api.graphql', 'moved.graphql']],
|
||||
])->with(Project::SEQUENTIAL_AND_PARALLEL)->skipOnWindows();
|
||||
|
||||
@@ -94,7 +94,7 @@ describe('buildFilterArgument', function (): void {
|
||||
expect($filter)->toBe('Tests\\\\(Unit\\\\FooTest::|Feature\\\\BarTest::)');
|
||||
});
|
||||
|
||||
it('returns empty string for empty test list', function (): void {
|
||||
it('generates a filter that selects no tests for an empty test list', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -103,7 +103,7 @@ describe('buildFilterArgument', function (): void {
|
||||
|
||||
$filter = $method->invoke($shard, []);
|
||||
|
||||
expect($filter)->toBeEmpty();
|
||||
expect('Tests\\Unit\\ExampleTest::testExample')->not->toMatch('/'.$filter.'/');
|
||||
});
|
||||
|
||||
it('generates compact filter for deeply nested namespaces', function (): void {
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
use Tests\Fixtures\Tia\GitRepo;
|
||||
use Tests\Fixtures\Tia\Project;
|
||||
|
||||
afterEach(function (): void {
|
||||
Project::destroyAll();
|
||||
});
|
||||
|
||||
test('dirty selects paths with spaces and Unicode', function (string $directory): void {
|
||||
$project = Project::make();
|
||||
$root = $directory === '' ? $project->path() : $project->nested($directory);
|
||||
$testDirectory = $directory === '' ? 'tests/Unit' : $directory.'/tests/Unit';
|
||||
$project->git()->run(['config', 'core.quotePath', 'true']);
|
||||
|
||||
foreach (['RegularTest', 'Before Rename Test', 'UnchangedTest', 'DeletedTest'] as $file) {
|
||||
$project->write($testDirectory.'/'.$file.'.php', "<?php\n\nit('runs $file')->assertTrue(true);\n");
|
||||
}
|
||||
|
||||
$project->git()->commit('add dirty test fixtures');
|
||||
$project->git()->run(['mv', $testDirectory.'/Before Rename Test.php', $testDirectory.'/After Rename Test.php']);
|
||||
$project->write($testDirectory.'/RegularTest.php', "<?php\n\nit('runs modified test')->assertTrue(true);\n");
|
||||
$project->write($testDirectory.'/Café Test.php', "<?php\n\nit('runs new test')->assertTrue(true);\n");
|
||||
unlink($project->path($testDirectory.'/DeletedTest.php'));
|
||||
|
||||
$result = $project->pestIn($root, '--dirty');
|
||||
|
||||
expect($result->exitCode)->toBe(0, $result->describe())
|
||||
->and($result->output)->toContain('3 passed (3 assertions)', 'runs modified test', 'runs Before Rename Test', 'runs new test')
|
||||
->not->toContain('runs UnchangedTest', 'runs DeletedTest');
|
||||
})->with([
|
||||
'repository root' => [''],
|
||||
'project subdirectory' => ['backend'],
|
||||
'subdirectory with leading space' => [' backend'],
|
||||
])->skipOnWindows();
|
||||
|
||||
test('dirty ignores a test removed after staging a modification', function (array $arguments): void {
|
||||
$project = Project::make();
|
||||
$testFile = 'tests/Unit/GreeterTest.php';
|
||||
$project->write($testFile, "<?php\n\nit('runs staged test')->assertTrue(true);\n");
|
||||
$project->git()->run(['add', '--', $testFile]);
|
||||
unlink($project->path($testFile));
|
||||
|
||||
$result = $project->pest('--dirty', '--fail-on-empty-test-suite', '--cache-directory', $project->path('.home/cache'), ...$arguments);
|
||||
|
||||
expect($result->exitCode)->toBe(0, $result->describe())
|
||||
->and($result->output)->toContain('No "dirty" tests found.');
|
||||
})->with(Project::SEQUENTIAL_AND_PARALLEL)->skipOnWindows();
|
||||
|
||||
test('dirty selects an unresolved test only while its file exists', function (): void {
|
||||
$project = Project::make();
|
||||
$testFile = 'tests/Unit/GreeterTest.php';
|
||||
$project->git()->switchTo('modified', true);
|
||||
$project->write($testFile, "<?php\n\nit('runs the unresolved test')->assertTrue(true);\n");
|
||||
$project->git()->commit('modify the test');
|
||||
$project->git()->switchTo('master');
|
||||
unlink($project->path($testFile));
|
||||
$project->git()->commit('remove the test');
|
||||
|
||||
$merge = new Process(['git', 'merge', '--no-edit', 'modified'], $project->path(), GitRepo::ENV);
|
||||
expect($merge->run())->toBe(1);
|
||||
|
||||
$present = $project->pest('--dirty', '--fail-on-empty-test-suite');
|
||||
|
||||
expect($present->exitCode)->toBe(0, $present->describe())
|
||||
->and($present->output)->toContain('1 passed (1 assertions)', 'runs the unresolved test');
|
||||
|
||||
unlink($project->path($testFile));
|
||||
$missing = $project->pest('--dirty', '--fail-on-empty-test-suite');
|
||||
|
||||
expect($missing->exitCode)->toBe(0, $missing->describe())
|
||||
->and($missing->output)->toContain('No "dirty" tests found.');
|
||||
})->skipOnWindows();
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
use Tests\Fixtures\Tia\Project;
|
||||
|
||||
test('runs with a nested Composer vendor directory', function (string $binary, array $arguments, int $assertions): void {
|
||||
$project = Project::withoutGit();
|
||||
|
||||
try {
|
||||
$vendor = 'build/dependencies';
|
||||
mkdir($project->path('build'));
|
||||
rename($project->path('vendor'), $project->path($vendor));
|
||||
|
||||
$project->write($vendor.'/composer/installed.php', <<<'METADATA'
|
||||
<?php
|
||||
|
||||
return ['root' => ['install_path' => __DIR__.'/../../..']];
|
||||
METADATA);
|
||||
|
||||
$project->write($vendor.'/bin/pest', <<<'PROXY'
|
||||
<?php
|
||||
|
||||
$GLOBALS['_composer_bin_dir'] = __DIR__;
|
||||
$GLOBALS['_composer_autoload_path'] = __DIR__.'/../autoload.php';
|
||||
|
||||
return include __DIR__.'/../pestphp/pest/bin/pest';
|
||||
PROXY);
|
||||
|
||||
$project->write($vendor.'/pestphp/pest/.temp/.gitkeep', '');
|
||||
$project->write('phpunit.xml', <<<'CONFIGURATION'
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit bootstrap="build/dependencies/autoload.php" cacheDirectory=".phpunit.cache"/>
|
||||
CONFIGURATION);
|
||||
|
||||
$test = 'tests/NestedVendorTest.php';
|
||||
$project->write($test, <<<'FIXTURE'
|
||||
<?php
|
||||
|
||||
test('uses the project root', function (): void {
|
||||
expect(Pest\TestSuite::getInstance()->rootPath)->toBe(realpath(__DIR__.'/..'));
|
||||
|
||||
if (($_SERVER['PARATEST'] ?? null) === '1') {
|
||||
expect($_SERVER['PEST_PARALLEL'] ?? null)->toBe('1');
|
||||
}
|
||||
});
|
||||
FIXTURE);
|
||||
|
||||
$process = new Process(
|
||||
[PHP_BINARY, $project->path($vendor.'/'.$binary), '--configuration='.$project->path('phpunit.xml'), '--colors=never', $project->path($test), ...$arguments],
|
||||
dirname($project->path),
|
||||
['PARATEST' => '0', 'PAO_DISABLE' => '1'],
|
||||
);
|
||||
|
||||
expect($process->run())->toBe(0)
|
||||
->and($process->getOutput())->toContain("1 passed ($assertions assertions)");
|
||||
} finally {
|
||||
Project::destroyAll();
|
||||
}
|
||||
})->with([
|
||||
'Composer proxy' => ['bin/pest', [], 1],
|
||||
'Composer proxy with workers' => ['bin/pest', ['--parallel', '--processes=2'], 2],
|
||||
'direct execution with workers' => ['pestphp/pest/bin/pest', ['--parallel', '--processes=2'], 2],
|
||||
]);
|
||||
@@ -21,7 +21,7 @@ test('parallel', function () use ($run): void {
|
||||
$output = implode("\n", array_slice(explode("\n", (string) $output), -10));
|
||||
$profileOutput = $run('tests/Fixtures/Suites/SuccessOnly.php', '--profile');
|
||||
|
||||
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 30 skipped, 1734 passed (3750 assertions)';
|
||||
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 30 skipped, 1734 passed (3752 assertions)';
|
||||
|
||||
expect($output)
|
||||
->toContain("Tests: {$expected}")
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
test('an empty shard runs no tests', function (int $exitCode, string ...$arguments): void {
|
||||
$process = new Process([
|
||||
PHP_BINARY, 'bin/pest', 'tests/Fixtures/DirectoryWithTests/ExampleTest.php',
|
||||
'--colors=never', '--shard=2/2', ...$arguments,
|
||||
], dirname(__DIR__, 2));
|
||||
|
||||
$process->run();
|
||||
|
||||
expect($process->getExitCode())->toBe($exitCode)
|
||||
->and(removeAnsiEscapeSequences($process->getOutput()))
|
||||
->toContain('No tests found.', '2 of 2 — 0 files ran, out of 1.')
|
||||
->not->toContain('example 1');
|
||||
})->with([
|
||||
'sequential' => [0],
|
||||
'parallel' => [0, '--parallel', '--processes=2'],
|
||||
'sequential with fail-on-empty-test-suite' => [1, '--fail-on-empty-test-suite'],
|
||||
'parallel with fail-on-empty-test-suite' => [1, '--parallel', '--processes=2', '--fail-on-empty-test-suite'],
|
||||
]);
|
||||
|
||||
test('an empty shard lists no tests', function (): void {
|
||||
$process = new Process([
|
||||
PHP_BINARY, 'bin/pest', 'tests/Fixtures/DirectoryWithTests/ExampleTest.php',
|
||||
'--colors=never', '--shard=2/2', '--list-tests',
|
||||
], dirname(__DIR__, 2));
|
||||
|
||||
$process->run();
|
||||
|
||||
expect($process->getExitCode())->toBe(0)
|
||||
->and($process->getOutput())->toContain('Available test')
|
||||
->not->toContain('__pest_evaluable_it_example_1', 'example 1');
|
||||
});
|
||||
|
||||
test('a non-empty shard runs its assigned test', function (): void {
|
||||
$process = new Process([
|
||||
PHP_BINARY, 'bin/pest', 'tests/Fixtures/DirectoryWithTests/ExampleTest.php',
|
||||
'--colors=never', '--shard=1/2',
|
||||
], dirname(__DIR__, 2));
|
||||
|
||||
$process->run();
|
||||
|
||||
expect($process->getExitCode())->toBe(0)
|
||||
->and($process->getOutput())->toContain('1 passed', '1 of 2 — 1 file ran, out of 1.');
|
||||
});
|
||||
Reference in New Issue
Block a user