mirror of
https://github.com/pestphp/pest.git
synced 2026-12-03 22:45:06 +01:00
Compare commits
3 Commits
a6a919c32c
...
d314fc0540
| Author | SHA1 | Date | |
|---|---|---|---|
| d314fc0540 | |||
| 093ca57693 | |||
| cf21b7cd64 |
@@ -66,14 +66,14 @@ final class Laravel implements HandlesArguments
|
||||
*/
|
||||
private function ensureEnvironmentVariables(array $arguments): array
|
||||
{
|
||||
$_ENV['LARAVEL_PARALLEL_TESTING'] = 1;
|
||||
$_SERVER['LARAVEL_PARALLEL_TESTING'] = $_ENV['LARAVEL_PARALLEL_TESTING'] = 1;
|
||||
|
||||
if ($this->hasArgument('--recreate-databases', $arguments)) {
|
||||
$_ENV['LARAVEL_PARALLEL_TESTING_RECREATE_DATABASES'] = 1;
|
||||
$_SERVER['LARAVEL_PARALLEL_TESTING_RECREATE_DATABASES'] = $_ENV['LARAVEL_PARALLEL_TESTING_RECREATE_DATABASES'] = 1;
|
||||
}
|
||||
|
||||
if ($this->hasArgument('--drop-databases', $arguments)) {
|
||||
$_ENV['LARAVEL_PARALLEL_TESTING_DROP_DATABASES'] = 1;
|
||||
$_SERVER['LARAVEL_PARALLEL_TESTING_DROP_DATABASES'] = $_ENV['LARAVEL_PARALLEL_TESTING_DROP_DATABASES'] = 1;
|
||||
}
|
||||
|
||||
$arguments = $this->popArgument('--recreate-databases', $arguments);
|
||||
|
||||
+2
-1
@@ -36,6 +36,7 @@ use Pest\Plugins\Tia\SourceScope;
|
||||
use Pest\Plugins\Tia\Storage;
|
||||
use Pest\Plugins\Tia\TableExtractor;
|
||||
use Pest\Plugins\Tia\WatchPatterns;
|
||||
use Pest\Support\Arr;
|
||||
use Pest\Support\Ci;
|
||||
use Pest\Support\Container;
|
||||
use Pest\Support\Git;
|
||||
@@ -1765,7 +1766,7 @@ final class Tia implements AddsOutput, HandlesArguments, HandlesOriginalArgument
|
||||
return [
|
||||
array_map(array_keys(...), $merged['files']),
|
||||
array_map(static fn (array $tables): array => array_map(strval(...), array_keys($tables)), $merged['tables']),
|
||||
array_map(array_keys(...), $merged['inertia']),
|
||||
array_map(Arr::stringKeys(...), $merged['inertia']),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace Pest\Plugins\Tia;
|
||||
|
||||
use Pest\Exceptions\MissingDependency;
|
||||
use Pest\Exceptions\TiaGitFailed;
|
||||
use Pest\Support\Arr;
|
||||
use Pest\Support\Git;
|
||||
use Symfony\Component\Process\ExecutableFinder;
|
||||
|
||||
@@ -78,7 +79,7 @@ final class ChangedFiles
|
||||
*/
|
||||
public function outsideProject(): array
|
||||
{
|
||||
return array_map(strval(...), array_keys($this->outsideProject));
|
||||
return Arr::stringKeys($this->outsideProject);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,7 +87,7 @@ final class ChangedFiles
|
||||
*/
|
||||
public function outsideProjectDirty(): array
|
||||
{
|
||||
return array_map(strval(...), array_keys($this->outsideProjectDirty));
|
||||
return Arr::stringKeys($this->outsideProjectDirty);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,13 +103,13 @@ final class ChangedFiles
|
||||
|
||||
$candidates = array_fill_keys($files, true);
|
||||
|
||||
foreach (array_keys($lastRunTree) as $snapshotted) {
|
||||
foreach (Arr::stringKeys($lastRunTree) as $snapshotted) {
|
||||
$candidates[$snapshotted] = true;
|
||||
}
|
||||
|
||||
$remaining = [];
|
||||
|
||||
foreach (array_keys($candidates) as $file) {
|
||||
foreach (Arr::stringKeys($candidates) as $file) {
|
||||
$snapshot = $lastRunTree[$file] ?? null;
|
||||
$current = $this->currentHash($file);
|
||||
|
||||
@@ -189,7 +190,7 @@ final class ChangedFiles
|
||||
$unique[$file] = true;
|
||||
}
|
||||
|
||||
$candidates = array_keys($this->filterIgnored($unique));
|
||||
$candidates = Arr::stringKeys($this->filterIgnored($unique));
|
||||
|
||||
$this->filterIgnoredOutsideProject();
|
||||
|
||||
@@ -374,7 +375,7 @@ final class ChangedFiles
|
||||
}
|
||||
}
|
||||
|
||||
return array_keys($names);
|
||||
return Arr::stringKeys($names);
|
||||
}
|
||||
|
||||
public function hasRemote(): bool
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Pest\Plugins\Tia;
|
||||
use JsonException;
|
||||
use Pest\Factories\TestCaseFactory;
|
||||
use Pest\Factories\TestCaseMethodFactory;
|
||||
use Pest\Support\Arr;
|
||||
use Pest\Support\Container;
|
||||
use Pest\Support\View;
|
||||
use Pest\TestSuite;
|
||||
@@ -594,7 +595,7 @@ final class Graph
|
||||
{
|
||||
$generated = [];
|
||||
|
||||
foreach ($this->fileIds as $path => $id) {
|
||||
foreach ($this->files as $id => $path) {
|
||||
$hash = $this->livewireGeneratedHash($path);
|
||||
|
||||
if ($hash === null) {
|
||||
@@ -1131,7 +1132,7 @@ final class Graph
|
||||
}
|
||||
}
|
||||
|
||||
$names = array_keys($normalised);
|
||||
$names = Arr::stringKeys($normalised);
|
||||
sort($names);
|
||||
|
||||
$this->testInertiaComponents[$testRel] = $names;
|
||||
@@ -1161,7 +1162,7 @@ final class Graph
|
||||
continue;
|
||||
}
|
||||
|
||||
$keys = array_keys($names);
|
||||
$keys = Arr::stringKeys($names);
|
||||
sort($keys);
|
||||
$out[$path] = $keys;
|
||||
}
|
||||
@@ -1645,7 +1646,7 @@ final class Graph
|
||||
{
|
||||
$survivors = array_fill_keys($keep, true);
|
||||
|
||||
foreach (array_keys($this->baselines) as $branch) {
|
||||
foreach (Arr::stringKeys($this->baselines) as $branch) {
|
||||
if (str_starts_with($branch, self::WORKSPACE_BRANCH_PREFIX)) {
|
||||
continue;
|
||||
}
|
||||
@@ -1711,8 +1712,8 @@ final class Graph
|
||||
|
||||
$branches = [];
|
||||
|
||||
foreach (array_keys($data['baselines']) as $branch) {
|
||||
if (is_string($branch) && $branch !== '') {
|
||||
foreach (Arr::stringKeys($data['baselines']) as $branch) {
|
||||
if ($branch !== '') {
|
||||
$branches[] = $branch;
|
||||
}
|
||||
}
|
||||
@@ -1847,8 +1848,8 @@ final class Graph
|
||||
|
||||
if (is_array($baseline['tree'] ?? null)) {
|
||||
foreach ($baseline['tree'] as $path => $hash) {
|
||||
if (is_string($path) && is_string($hash)) {
|
||||
$tree[$path] = $hash;
|
||||
if (is_string($hash)) {
|
||||
$tree[(string) $path] = $hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ final class ReadCapture
|
||||
*/
|
||||
private function openNatively(string $path, string $mode, int $options): mixed
|
||||
{
|
||||
return ($options & STREAM_REPORT_ERRORS) !== 0
|
||||
return ($options & (STREAM_REPORT_ERRORS | self::STREAM_OPEN_FOR_INCLUDE)) !== 0
|
||||
? fopen($path, $mode, ($options & STREAM_USE_PATH) !== 0, $this->context)
|
||||
: @fopen($path, $mode, ($options & STREAM_USE_PATH) !== 0, $this->context);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins\Tia;
|
||||
|
||||
use Pest\Support\Arr;
|
||||
use Pest\Support\Container;
|
||||
use Pest\TestSuite;
|
||||
use ReflectionClass;
|
||||
@@ -329,7 +330,7 @@ final class Recorder
|
||||
$out = [];
|
||||
|
||||
foreach ($this->perTestInertiaComponents as $testFile => $components) {
|
||||
$names = array_keys($components);
|
||||
$names = Arr::stringKeys($components);
|
||||
sort($names);
|
||||
$out[$testFile] = $names;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Pest\Plugins\Tia;
|
||||
|
||||
use Pest\Plugins\Tia\Contracts\WatchDefault;
|
||||
use Pest\Support\Arr;
|
||||
use Pest\TestSuite;
|
||||
|
||||
/**
|
||||
@@ -173,7 +174,7 @@ final class WatchPatterns
|
||||
}
|
||||
}
|
||||
|
||||
return array_keys($matched);
|
||||
return Arr::stringKeys($matched);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,17 +185,17 @@ final class WatchPatterns
|
||||
{
|
||||
$matched = [];
|
||||
|
||||
foreach ($patterns as $key => $dirs) {
|
||||
foreach (Arr::stringKeys($patterns) as $key) {
|
||||
if (! $this->keyMatches($key, $file)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($dirs as $dir) {
|
||||
foreach ($patterns[$key] as $dir) {
|
||||
$matched[$dir] = true;
|
||||
}
|
||||
}
|
||||
|
||||
return array_keys($matched);
|
||||
return Arr::stringKeys($matched);
|
||||
}
|
||||
|
||||
private function usesDefaultsFor(string $file): bool
|
||||
|
||||
@@ -9,6 +9,15 @@ namespace Pest\Support;
|
||||
*/
|
||||
final class Arr
|
||||
{
|
||||
/**
|
||||
* @param array<array-key, mixed> $array
|
||||
* @return list<string>
|
||||
*/
|
||||
public static function stringKeys(array $array): array
|
||||
{
|
||||
return array_map(strval(...), array_keys($array));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<array-key, mixed> $array
|
||||
*/
|
||||
|
||||
@@ -2002,6 +2002,10 @@
|
||||
✓ it keeps a tracked outside change and drops an untracked ignored one
|
||||
✓ it keeps a tracked project change that the ignore rules match
|
||||
✓ it reads committed paths from the repository root even when git is told to be relative
|
||||
✓ it keeps a changed file whose name is a number as a string
|
||||
✓ it keeps a changed file outside the project whose name is a number as a string
|
||||
✓ it keeps a snapshotted file whose name is a number as a string
|
||||
✓ it keeps a branch whose name is a number as a string
|
||||
|
||||
PASS Tests\Unit\Plugins\Tia\ConfigurationFile
|
||||
✓ it fingerprints the path and the content of the configuration file
|
||||
@@ -2111,6 +2115,8 @@
|
||||
✓ Laravel boot files → it watches the config and bootstrap files in the Laravel defaults
|
||||
✓ clearResults() → it drops the results of the fallback branch too
|
||||
✓ branch baseline over the fallback → it reads results written after an earlier read
|
||||
✓ pruneMissingBranches() → it keeps a branch whose name is a number
|
||||
✓ decode() → it keeps a file of the last run tree whose name is a number
|
||||
✓ encode() and decode() → it round-trips paths that are not valid UTF-8
|
||||
✓ encode() and decode() → it lists a branch whose name is not valid UTF-8
|
||||
✓ legacy schema → it reads a graph of the previous schema without unescaping its strings
|
||||
@@ -2142,12 +2148,26 @@
|
||||
✓ it detects an added or removed non-platform dependency
|
||||
✓ it is independent of package ordering
|
||||
|
||||
PASS Tests\Unit\Plugins\Tia\NumericInertiaPages
|
||||
✓ it selects the tests of a changed Inertia page whose name is a number
|
||||
✓ it keeps an Inertia page whose name is a number after the graph is decoded
|
||||
✓ it records an Inertia page whose name is a number as a string
|
||||
✓ it selects the tests of a shared module of an Inertia page whose name is a number
|
||||
|
||||
PASS Tests\Unit\Plugins\Tia\NumericSourceFileNames
|
||||
✓ it selects the tests of a changed source file whose name is a number
|
||||
✓ it selects the tests of a numeric source file after the graph is decoded
|
||||
|
||||
PASS Tests\Unit\Plugins\Tia\NumericTableDependencies
|
||||
✓ it exports numeric table dependencies from the recorder as strings
|
||||
✓ it persists numeric tables as JSON strings and selects only their migration readers after reload
|
||||
✓ it preserves numeric worker tables through payload cleaning union and graph reload
|
||||
✓ it preserves observed and migration added numeric tables when augmenting database tests
|
||||
|
||||
PASS Tests\Unit\Plugins\Tia\NumericWatchPatterns
|
||||
✓ it matches a watch pattern whose key is a number
|
||||
✓ it selects the tests under a watch target whose name is a number
|
||||
|
||||
PASS Tests\Unit\Plugins\Tia\ReadCapture
|
||||
✓ reads → it links a project file the test reads with dataset "file_get_contents"
|
||||
✓ reads → it links a project file the test reads with dataset "file"
|
||||
@@ -2163,6 +2183,7 @@
|
||||
✓ the file wrapper → it passes filesystem operations through while a test records
|
||||
✓ the file wrapper → it writes with LOCK_EX while a test records
|
||||
✓ the file wrapper → it reports a missing path to the error handler as plain PHP does while a test records
|
||||
✓ the file wrapper → it reports why an include failed as plain PHP does while a test records
|
||||
✓ the file wrapper → it keeps no memory for each filesystem call while a test records
|
||||
✓ the file wrapper → it keeps no memory for each test it records
|
||||
✓ the file wrapper → it is restored quietly when the test already restored it
|
||||
@@ -2415,6 +2436,7 @@
|
||||
✓ last → it should return the last element for an array without changing the internal pointer
|
||||
✓ last → it should return the last element for an associative array without changing the internal pointer
|
||||
✓ last → it should return the last element for an mixed key array without changing the internal pointer
|
||||
✓ stringKeys → it returns every key as a string
|
||||
|
||||
PASS Tests\Unit\Support\Backtrace
|
||||
✓ it gets file name from called file
|
||||
@@ -2588,6 +2610,9 @@
|
||||
✓ a parallel test can extend another test with same name
|
||||
✓ parallel reports invalid datasets as failures
|
||||
✓ parallel lets extensions register event subscribers
|
||||
✓ sets Laravel parallel flags with dataset "without database options"
|
||||
✓ sets Laravel parallel flags with dataset "recreate databases"
|
||||
✓ sets Laravel parallel flags with dataset "drop databases"
|
||||
✓ parallel can have multiple exclude-groups
|
||||
✓ parallel can have multiple groups
|
||||
✓ parallel accepts the options that the workers ignore with ('--no-results')
|
||||
@@ -2717,4 +2742,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, 39 skipped, 2000 passed (4505 assertions)
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 39 skipped, 2019 passed (4528 assertions)
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Composer\InstalledVersions;
|
||||
use Pest\Plugins\Parallel\Handlers\Laravel;
|
||||
|
||||
require dirname(__DIR__, 3).'/vendor/autoload.php';
|
||||
|
||||
final class ParallelRunnerStub
|
||||
{
|
||||
public static function resolveRunnerUsing(Closure $resolver): void {}
|
||||
}
|
||||
|
||||
class_alias(ParallelRunnerStub::class, 'Illuminate\\Testing\\ParallelRunner');
|
||||
|
||||
$installed = InstalledVersions::getAllRawData()[0];
|
||||
$installed['versions']['laravel/framework'] = ['dev_requirement' => false];
|
||||
InstalledVersions::reload($installed);
|
||||
|
||||
(new Laravel)->handleArguments($argv);
|
||||
|
||||
$flags = array_flip([
|
||||
'LARAVEL_PARALLEL_TESTING',
|
||||
'LARAVEL_PARALLEL_TESTING_RECREATE_DATABASES',
|
||||
'LARAVEL_PARALLEL_TESTING_DROP_DATABASES',
|
||||
]);
|
||||
|
||||
echo json_encode([
|
||||
'server' => array_keys(array_filter(array_intersect_key($_SERVER, $flags))),
|
||||
'env' => array_keys(array_filter(array_intersect_key($_ENV, $flags))),
|
||||
], JSON_THROW_ON_ERROR);
|
||||
@@ -6,6 +6,7 @@ use Pest\Plugins\Tia\ChangedFiles;
|
||||
use Pest\Plugins\Tia\Fingerprint;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Tests\Fixtures\Tia\GitRepo;
|
||||
use Tests\Fixtures\Tia\Project;
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
@@ -51,6 +52,8 @@ afterEach(function (): void {
|
||||
foreach (tiaMonorepoRoots() as $root) {
|
||||
new Process(['rm', '-rf', $root])->run();
|
||||
}
|
||||
|
||||
Project::destroyAll();
|
||||
});
|
||||
|
||||
it('resolves the project prefix inside the repository', function (): void {
|
||||
@@ -285,3 +288,41 @@ it('reads committed paths from the repository root even when git is told to be r
|
||||
expect($changedFiles->since($monorepo['sha']))->toBe(['app/Service.php'])
|
||||
->and($changedFiles->outsideProject())->toBe(['frontend/widget.php']);
|
||||
})->skipOnWindows();
|
||||
|
||||
it('keeps a changed file whose name is a number as a string', function (): void {
|
||||
$project = Project::make();
|
||||
$sha = $project->git()->sha();
|
||||
|
||||
file_put_contents($project->path('123'), "changed\n");
|
||||
$project->git()->commit('add a file with a numeric name');
|
||||
|
||||
expect(new ChangedFiles($project->path())->since($sha))->toBe(['123']);
|
||||
})->skipOnWindows();
|
||||
|
||||
it('keeps a changed file outside the project whose name is a number as a string', function (): void {
|
||||
$monorepo = tiaMonorepoRepository();
|
||||
|
||||
file_put_contents($monorepo['root'].'/123', "outside\n");
|
||||
file_put_contents($monorepo['project'].'/123', "inside\n");
|
||||
$monorepo['repo']->commit('add files with a numeric name');
|
||||
|
||||
$changedFiles = new ChangedFiles($monorepo['project']);
|
||||
|
||||
expect($changedFiles->since($monorepo['sha']))->toBe(['123'])
|
||||
->and($changedFiles->outsideProject())->toBe(['123']);
|
||||
})->skipOnWindows();
|
||||
|
||||
it('keeps a snapshotted file whose name is a number as a string', function (): void {
|
||||
$project = Project::make();
|
||||
|
||||
file_put_contents($project->path('123'), "changed\n");
|
||||
|
||||
expect(new ChangedFiles($project->path())->filterUnchangedSinceLastRun([], ['123' => 'stale']))->toBe(['123']);
|
||||
});
|
||||
|
||||
it('keeps a branch whose name is a number as a string', function (): void {
|
||||
$project = Project::make();
|
||||
$project->git()->switchTo('123', new: true);
|
||||
|
||||
expect(new ChangedFiles($project->path())->branchNames())->toBe(['123', 'master']);
|
||||
});
|
||||
|
||||
@@ -410,6 +410,32 @@ describe('branch baseline over the fallback', function (): void {
|
||||
});
|
||||
});
|
||||
|
||||
describe('pruneMissingBranches()', function (): void {
|
||||
it('keeps a branch whose name is a number', function (): void {
|
||||
$graph = new Graph(sys_get_temp_dir());
|
||||
$graph->setRecordedAtSha('123', 'abc');
|
||||
$graph->setRecordedAtSha('gone', 'def');
|
||||
|
||||
$graph->pruneMissingBranches(['123']);
|
||||
|
||||
expect($graph->recordedAtSha('123'))->toBe('abc')
|
||||
->and($graph->recordedAtSha('gone'))->toBeNull()
|
||||
->and(Graph::branchesIn($graph->encode()))->toBe(['123']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('decode()', function (): void {
|
||||
it('keeps a file of the last run tree whose name is a number', function (): void {
|
||||
$graph = new Graph(sys_get_temp_dir());
|
||||
$graph->setRecordedAtSha('master', 'abc');
|
||||
$graph->setLastRunTree('master', ['123' => 'hash']);
|
||||
|
||||
$decoded = Graph::decode($graph->encode(), sys_get_temp_dir());
|
||||
|
||||
expect($decoded?->lastRunTree('master'))->toBe([123 => 'hash']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('encode() and decode()', function (): void {
|
||||
it('round-trips paths that are not valid UTF-8', function (): void {
|
||||
$root = sys_get_temp_dir();
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Pest\Plugins\Tia\Graph;
|
||||
use Pest\Plugins\Tia\Recorder;
|
||||
use Pest\Plugins\Tia\WatchPatterns;
|
||||
use Pest\Support\Container;
|
||||
|
||||
beforeEach(function (): void {
|
||||
Container::getInstance()->add(WatchPatterns::class, new WatchPatterns);
|
||||
});
|
||||
|
||||
afterEach(function (): void {
|
||||
Container::getInstance()->add(WatchPatterns::class, new WatchPatterns);
|
||||
});
|
||||
|
||||
it('selects the tests of a changed Inertia page whose name is a number', function (): void {
|
||||
$root = (string) realpath(sys_get_temp_dir());
|
||||
$graph = new Graph($root);
|
||||
$graph->replaceTestInertiaComponents([
|
||||
$root.'/tests/Feature/NumericPageTest.php' => ['123'],
|
||||
$root.'/tests/Feature/DashboardTest.php' => ['Dashboard'],
|
||||
]);
|
||||
|
||||
expect($graph->affected(['resources/js/Pages/123.vue']))->toBe(['tests/Feature/NumericPageTest.php']);
|
||||
});
|
||||
|
||||
it('keeps an Inertia page whose name is a number after the graph is decoded', function (): void {
|
||||
$root = (string) realpath(sys_get_temp_dir());
|
||||
$graph = new Graph($root);
|
||||
$graph->replaceTestInertiaComponents([
|
||||
$root.'/tests/Feature/NumericPageTest.php' => ['123'],
|
||||
]);
|
||||
|
||||
$decoded = Graph::decode($graph->encode(), $root);
|
||||
|
||||
expect($decoded?->affected(['resources/js/Pages/123.vue']))->toBe(['tests/Feature/NumericPageTest.php']);
|
||||
});
|
||||
|
||||
it('records an Inertia page whose name is a number as a string', function (): void {
|
||||
$recorder = new Recorder;
|
||||
$recorder->activateLinkTracking();
|
||||
|
||||
$recorder->beginTest('Some\Missing\TestClass', 'it renders', '/project/tests/Feature/NumericPageTest.php');
|
||||
$recorder->linkInertiaComponent('123');
|
||||
$recorder->endTest();
|
||||
|
||||
expect($recorder->perTestInertiaComponents())->toBe(['/project/tests/Feature/NumericPageTest.php' => ['123']]);
|
||||
});
|
||||
|
||||
it('selects the tests of a shared module of an Inertia page whose name is a number', function (): void {
|
||||
$root = (string) realpath(sys_get_temp_dir());
|
||||
$graph = new Graph($root);
|
||||
$graph->replaceTestInertiaComponents([
|
||||
$root.'/tests/Feature/NumericPageTest.php' => ['123'],
|
||||
]);
|
||||
$graph->replaceJsFileToComponents(['resources/js/Components/Chart.vue' => ['123']]);
|
||||
|
||||
expect($graph->affected(['resources/js/Components/Chart.vue']))->toBe(['tests/Feature/NumericPageTest.php']);
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Pest\Plugins\Tia\Graph;
|
||||
use Pest\Plugins\Tia\WatchPatterns;
|
||||
use Pest\Support\Container;
|
||||
|
||||
beforeEach(function (): void {
|
||||
Container::getInstance()->add(WatchPatterns::class, new WatchPatterns);
|
||||
});
|
||||
|
||||
afterEach(function (): void {
|
||||
Container::getInstance()->add(WatchPatterns::class, new WatchPatterns);
|
||||
});
|
||||
|
||||
it('selects the tests of a changed source file whose name is a number', function (): void {
|
||||
$graph = new Graph(sys_get_temp_dir());
|
||||
$graph->link('tests/Feature/NumericTest.php', '123');
|
||||
$graph->link('tests/Feature/OtherTest.php', 'app/Other.php');
|
||||
|
||||
expect($graph->affected(['123']))->toBe(['tests/Feature/NumericTest.php']);
|
||||
});
|
||||
|
||||
it('selects the tests of a numeric source file after the graph is decoded', function (): void {
|
||||
$graph = new Graph(sys_get_temp_dir());
|
||||
$graph->link('tests/Feature/NumericTest.php', '123');
|
||||
|
||||
$decoded = Graph::decode($graph->encode(), sys_get_temp_dir());
|
||||
|
||||
expect($decoded?->affected(['123']))->toBe(['tests/Feature/NumericTest.php']);
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Pest\Plugins\Tia\WatchPatterns;
|
||||
|
||||
it('matches a watch pattern whose key is a number', function (): void {
|
||||
$watchPatterns = new WatchPatterns;
|
||||
$watchPatterns->add(['123' => 'tests/Feature']);
|
||||
|
||||
expect($watchPatterns->matchedDirectories(sys_get_temp_dir(), ['123']))->toBe(['tests/Feature']);
|
||||
});
|
||||
|
||||
it('selects the tests under a watch target whose name is a number', function (): void {
|
||||
$watchPatterns = new WatchPatterns;
|
||||
$watchPatterns->add(['config.txt' => '123']);
|
||||
|
||||
$directories = $watchPatterns->matchedDirectories(sys_get_temp_dir(), ['config.txt']);
|
||||
|
||||
expect($directories)->toBe(['123'])
|
||||
->and($watchPatterns->testsUnderDirectories($directories, ['123/ConfigTest.php', 'tests/OtherTest.php']))
|
||||
->toBe(['123/ConfigTest.php']);
|
||||
});
|
||||
@@ -239,6 +239,40 @@ describe('the file wrapper', function (): void {
|
||||
]);
|
||||
});
|
||||
|
||||
it('reports why an include failed as plain PHP does while a test records', function (): void {
|
||||
$missing = sys_get_temp_dir().DIRECTORY_SEPARATOR.'pest-read-capture-missing-'.bin2hex(random_bytes(8)).'.php';
|
||||
$results = [];
|
||||
$errorReporting = error_reporting(E_ALL);
|
||||
|
||||
set_error_handler(function (int $level, string $message, string $file, int $line): bool {
|
||||
if ((error_reporting() & $level) === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new ErrorException($message, 0, $level, $file, $line);
|
||||
});
|
||||
|
||||
try {
|
||||
tiaReadCaptureLinks(function () use ($missing, &$results): void {
|
||||
try {
|
||||
include $missing;
|
||||
} catch (ErrorException $exception) {
|
||||
$results['include'] = str_contains($exception->getMessage(), 'No such file or directory');
|
||||
}
|
||||
|
||||
$results['silenced include'] = @include $missing;
|
||||
});
|
||||
} finally {
|
||||
restore_error_handler();
|
||||
error_reporting($errorReporting);
|
||||
}
|
||||
|
||||
expect($results)->toBe([
|
||||
'include' => true,
|
||||
'silenced include' => false,
|
||||
]);
|
||||
});
|
||||
|
||||
it('keeps no memory for each filesystem call while a test records', function (): void {
|
||||
$growth = 0;
|
||||
|
||||
|
||||
@@ -49,3 +49,9 @@ describe('last', function (): void {
|
||||
->and(current($array))->toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('stringKeys', function (): void {
|
||||
it('returns every key as a string', function (): void {
|
||||
expect(Arr::stringKeys(['123' => true, 'app/Service.php' => true]))->toBe(['123', 'app/Service.php']);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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, 31 skipped, 1872 passed (3978 assertions)';
|
||||
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 31 skipped, 1888 passed (3998 assertions)';
|
||||
|
||||
expect($output)
|
||||
->toContain("Tests: {$expected}")
|
||||
@@ -59,6 +59,31 @@ test('parallel lets extensions register event subscribers', function (): void {
|
||||
->toContain('Parallel: 2 processes');
|
||||
})->skipOnWindows();
|
||||
|
||||
test('sets Laravel parallel flags', function (array $options, array $databaseFlags): void {
|
||||
$process = new Process(
|
||||
[PHP_BINARY, '-d', 'auto_prepend_file=', 'tests/Fixtures/Suites/ParallelLaravelFlags.php', '--parallel', ...$options],
|
||||
dirname(__DIR__, 2),
|
||||
[
|
||||
'LARAVEL_PARALLEL_TESTING' => false,
|
||||
'LARAVEL_PARALLEL_TESTING_RECREATE_DATABASES' => false,
|
||||
'LARAVEL_PARALLEL_TESTING_DROP_DATABASES' => false,
|
||||
],
|
||||
);
|
||||
|
||||
$process->mustRun();
|
||||
|
||||
$expectedFlags = ['LARAVEL_PARALLEL_TESTING', ...$databaseFlags];
|
||||
|
||||
expect(json_decode($process->getOutput(), true, flags: JSON_THROW_ON_ERROR))->toBe([
|
||||
'server' => $expectedFlags,
|
||||
'env' => $expectedFlags,
|
||||
]);
|
||||
})->with([
|
||||
'without database options' => [[], []],
|
||||
'recreate databases' => [['--recreate-databases'], ['LARAVEL_PARALLEL_TESTING_RECREATE_DATABASES']],
|
||||
'drop databases' => [['--drop-databases'], ['LARAVEL_PARALLEL_TESTING_DROP_DATABASES']],
|
||||
]);
|
||||
|
||||
test('parallel can have multiple exclude-groups', function () use ($run): void {
|
||||
$singleExclude = $run('--exclude-group=integration');
|
||||
$doubleExclude = $run('--exclude-group=integration', '--exclude-group=container');
|
||||
|
||||
Reference in New Issue
Block a user