mirror of
https://github.com/pestphp/pest.git
synced 2026-12-03 22:45:06 +01:00
Compare commits
5 Commits
fabc818ba9
...
f5c3687a68
| Author | SHA1 | Date | |
|---|---|---|---|
| f5c3687a68 | |||
| 41af35a3f2 | |||
| fdc57f77b7 | |||
| 67d3733eb2 | |||
| f80b3a89a0 |
@@ -129,6 +129,60 @@ use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
}
|
||||
}
|
||||
|
||||
$optionsWithSeparateValue = [
|
||||
'-c', '-d', '--atleast-version', '--bootstrap', '--cache-directory', '--columns', '--configuration',
|
||||
'--coverage-filter', '--coverage-clover', '--coverage-cobertura', '--coverage-crap4j', '--coverage-html',
|
||||
'--coverage-jsonl', '--coverage-openclover', '--coverage-php', '--coverage-xml', '--default-time-limit',
|
||||
'--diff-context', '--exclude-group', '--filter', '--exclude-filter', '--generate-baseline', '--use-baseline',
|
||||
'--group', '--covers', '--uses', '--requires-php-extension', '--include-path', '--list-tests-xml',
|
||||
'--log-junit', '--log-otr', '--log-teamcity', '--order-by', '--random-order-seed', '--repeat',
|
||||
'--timeout', '--testdox-html', '--testdox-text', '--test-suffix', '--testsuite', '--exclude-testsuite',
|
||||
'--test-files-file', '--test-id-filter-file', '--run-test-id', '--log-events-text',
|
||||
'--log-events-verbose-text', '--extension',
|
||||
];
|
||||
|
||||
$isOptionValue = false;
|
||||
|
||||
// Convert namespace-style arguments (e.g. Tests\Unit\TestName) to file paths.
|
||||
foreach ($arguments as $key => $value) {
|
||||
if ($isOptionValue) {
|
||||
$isOptionValue = false;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (str_starts_with($value, '-')) {
|
||||
$isOptionValue = in_array($value, $optionsWithSeparateValue, true);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! str_contains($value, '\\')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$path = str_replace('\\', DIRECTORY_SEPARATOR, $value);
|
||||
|
||||
if (! str_ends_with($path, '.php')) {
|
||||
$path .= '.php';
|
||||
}
|
||||
|
||||
if (file_exists($path)) {
|
||||
$arguments[$key] = $path;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Try lowercasing the first directory segment (e.g. Tests -> tests).
|
||||
$segments = explode(DIRECTORY_SEPARATOR, $path);
|
||||
$segments[0] = lcfirst($segments[0]);
|
||||
$lowercasedPath = implode(DIRECTORY_SEPARATOR, $segments);
|
||||
|
||||
if (file_exists($lowercasedPath)) {
|
||||
$arguments[$key] = $lowercasedPath;
|
||||
}
|
||||
}
|
||||
|
||||
// Used when Pest is required using composer.
|
||||
$autoloadPath = $GLOBALS['_composer_autoload_path'] ?? dirname(__DIR__, 3).'/autoload.php';
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ final class BootFiles implements Bootstrapper
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
if ($this->runningInit()) {
|
||||
if ($this->hasCliOption('--init')) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,10 @@ final class BootFiles implements Bootstrapper
|
||||
$testsPath = $rootPath.DIRECTORY_SEPARATOR.testDirectory();
|
||||
|
||||
if (! is_dir($testsPath)) {
|
||||
if ($this->hasCliOption('--help', '--version')) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new FatalException(sprintf('The test directory [%s] does not exist.', $testsPath));
|
||||
}
|
||||
|
||||
@@ -69,7 +73,7 @@ final class BootFiles implements Bootstrapper
|
||||
$this->bootDatasets($testsPath);
|
||||
}
|
||||
|
||||
private function runningInit(): bool
|
||||
private function hasCliOption(string ...$options): bool
|
||||
{
|
||||
$arguments = $_SERVER['argv'] ?? null;
|
||||
|
||||
@@ -78,7 +82,7 @@ final class BootFiles implements Bootstrapper
|
||||
}
|
||||
|
||||
/** @var array<int, string> $arguments */
|
||||
return $this->hasArgument('--init', $arguments);
|
||||
return array_any($options, fn (string $option): bool => $this->hasArgument($option, $arguments));
|
||||
}
|
||||
|
||||
private function load(string $filename): void
|
||||
|
||||
@@ -6,7 +6,6 @@ namespace Pest\PendingCalls;
|
||||
|
||||
use Closure;
|
||||
use Pest\PendingCalls\Concerns\Describable;
|
||||
use Pest\Support\Arr;
|
||||
use Pest\Support\Backtrace;
|
||||
use Pest\Support\ChainableClosure;
|
||||
use Pest\Support\HigherOrderMessageCollection;
|
||||
@@ -43,7 +42,7 @@ final class AfterEachCall
|
||||
$proxies = $this->proxies;
|
||||
|
||||
$afterEachTestCase = ChainableClosure::boundWhen(
|
||||
fn (): bool => $describing === [] || in_array(Arr::last($describing), $this->__describing, true),
|
||||
fn (): bool => $describing === [] || (count($describing) <= count($this->__describing) && array_slice($this->__describing, 0, count($describing)) === $describing),
|
||||
ChainableClosure::bound(fn () => $proxies->chain($this), $this->closure)->bindTo($this, self::class),
|
||||
)->bindTo($this, self::class);
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace Pest\PendingCalls;
|
||||
use Closure;
|
||||
use Pest\Exceptions\AfterBeforeTestFunction;
|
||||
use Pest\PendingCalls\Concerns\Describable;
|
||||
use Pest\Support\Arr;
|
||||
use Pest\Support\Backtrace;
|
||||
use Pest\Support\ChainableClosure;
|
||||
use Pest\Support\HigherOrderMessageCollection;
|
||||
@@ -50,11 +49,9 @@ final class BeforeEachCall
|
||||
$beforeEachTestCall = function (TestCall $testCall) use ($describing): void {
|
||||
|
||||
if ($this->describing !== []) {
|
||||
if (Arr::last($describing) !== Arr::last($this->describing)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! in_array(Arr::last($describing), $testCall->describing, true)) {
|
||||
$testCallDescribing = $testCall->describing;
|
||||
if (count($describing) > count($testCallDescribing) ||
|
||||
array_slice($testCallDescribing, 0, count($describing)) !== $describing) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -63,7 +60,7 @@ final class BeforeEachCall
|
||||
};
|
||||
|
||||
$beforeEachTestCase = ChainableClosure::boundWhen(
|
||||
fn (): bool => $describing === [] || in_array(Arr::last($describing), $this->__describing, true),
|
||||
fn (): bool => $describing === [] || (count($describing) <= count($this->__describing) && array_slice($this->__describing, 0, count($describing)) === $describing),
|
||||
ChainableClosure::bound(fn () => $testCaseProxies->chain($this), $this->closure)->bindTo($this, self::class),
|
||||
)->bindTo($this, self::class);
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ final class Retry implements HandlesArguments
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
if ($this->hasArgument('--parallel', $arguments)) {
|
||||
if ($this->hasArgument('--parallel', $arguments) || in_array('-p', $arguments, true)) {
|
||||
throw new InvalidOption('The [--retry] option is not supported when running in parallel.');
|
||||
}
|
||||
|
||||
|
||||
@@ -115,4 +115,17 @@ final class Configuration
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string>|null $patterns Project-relative globs to exclude, or null to disable read capture. Use watch() for excluded files that an existing watch pattern does not cover.
|
||||
* @return $this
|
||||
*/
|
||||
public function withoutReadCapture(?array $patterns = null): self
|
||||
{
|
||||
/** @var WatchPatterns $watchPatterns */
|
||||
$watchPatterns = Container::getInstance()->get(WatchPatterns::class);
|
||||
$watchPatterns->excludeReads($patterns);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins\Tia;
|
||||
|
||||
use Pest\Support\Container;
|
||||
use Pest\TestSuite;
|
||||
use ReflectionClass;
|
||||
|
||||
@@ -103,7 +104,9 @@ final class Recorder
|
||||
|
||||
$this->currentTestFile = $file;
|
||||
|
||||
ReadCapture::start($this);
|
||||
if ($this->watchPatterns()->isReadCaptureEnabled()) {
|
||||
ReadCapture::start($this);
|
||||
}
|
||||
|
||||
if ($this->classUsesDatabase($className)) {
|
||||
$this->perTestUsesDatabase[$file] = true;
|
||||
@@ -201,9 +204,34 @@ final class Recorder
|
||||
return;
|
||||
}
|
||||
|
||||
$relative = $this->projectRelative($real);
|
||||
|
||||
if ($relative !== null && $this->watchPatterns()->excludesRead($relative)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->linkSource($real);
|
||||
}
|
||||
|
||||
private function projectRelative(string $realPath): ?string
|
||||
{
|
||||
$root = rtrim(TestSuite::getInstance()->rootPath, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
|
||||
|
||||
if (! str_starts_with($realPath, $root)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return str_replace(DIRECTORY_SEPARATOR, '/', substr($realPath, strlen($root)));
|
||||
}
|
||||
|
||||
private function watchPatterns(): WatchPatterns
|
||||
{
|
||||
$watchPatterns = Container::getInstance()->get(WatchPatterns::class);
|
||||
assert($watchPatterns instanceof WatchPatterns);
|
||||
|
||||
return $watchPatterns;
|
||||
}
|
||||
|
||||
private function classUsesDatabase(string $className): bool
|
||||
{
|
||||
if (array_key_exists($className, $this->classUsesDatabaseCache)) {
|
||||
|
||||
@@ -43,6 +43,13 @@ final class WatchPatterns
|
||||
|
||||
private bool $defaultsEnabled = true;
|
||||
|
||||
/**
|
||||
* @var list<string>
|
||||
*/
|
||||
private array $excludedReadPatterns = [];
|
||||
|
||||
private bool $readCaptureEnabled = true;
|
||||
|
||||
/**
|
||||
* @var array<string, array{include: string, excludes: array<int, string>, allowDotfiles: bool}>
|
||||
*/
|
||||
@@ -110,6 +117,39 @@ final class WatchPatterns
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string>|null $patterns
|
||||
*/
|
||||
public function excludeReads(?array $patterns = null): void
|
||||
{
|
||||
if ($patterns === null) {
|
||||
$this->readCaptureEnabled = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->excludedReadPatterns = array_values(array_unique([
|
||||
...$this->excludedReadPatterns,
|
||||
...$patterns,
|
||||
]));
|
||||
}
|
||||
|
||||
public function isReadCaptureEnabled(): bool
|
||||
{
|
||||
return $this->readCaptureEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file Project-relative path.
|
||||
*/
|
||||
public function excludesRead(string $file): bool
|
||||
{
|
||||
return array_any(
|
||||
$this->excludedReadPatterns,
|
||||
fn (string $pattern): bool => $this->keyMatches($pattern, $file),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $projectRoot Absolute path.
|
||||
* @param array<int, string> $changedFiles Project-relative paths.
|
||||
@@ -279,6 +319,8 @@ final class WatchPatterns
|
||||
$this->defaultPatterns = [];
|
||||
$this->excludedDefaultPatterns = [];
|
||||
$this->defaultsEnabled = true;
|
||||
$this->excludedReadPatterns = [];
|
||||
$this->readCaptureEnabled = true;
|
||||
$this->parsed = [];
|
||||
$this->enabled = false;
|
||||
$this->locally = false;
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
✓ matching describe block names → outer → middle → it should not call afterEach functions for sibling describe blocks with the same name
|
||||
✓ matching describe block names → outer → inner → it does not get executed before the test
|
||||
✓ matching describe block names → outer → inner → it should not call afterEach functions for descendent of sibling describe blocks with the same name
|
||||
✓ hierarchical test naming → block one → the same name → it does not call afterEach from sibling describe with same name
|
||||
✓ hierarchical test naming → block two → the same name → it correctly calls afterEach from own describe hierarchy
|
||||
|
||||
PASS Tests\Features\Assignee
|
||||
✓ it may be associated with an assignee [@nunomaduro, @taylorotwell]
|
||||
@@ -56,6 +58,8 @@
|
||||
✓ matching name → it should not call the before each on the describe block with the same name
|
||||
✓ called on all tests → beforeEach should be called
|
||||
✓ called on all tests → beforeEach should be called for all tests
|
||||
✓ hierarchical test naming → block one → the same name → it does not call beforeEach from sibling describe with same name
|
||||
✓ hierarchical test naming → block two → the same name → it correctly calls beforeEach from own describe hierarchy
|
||||
|
||||
PASS Tests\Features\BeforeEachProxiesToTestCallWithExpectations
|
||||
✓ runs 1
|
||||
@@ -335,6 +339,8 @@
|
||||
✓ depends on describe using with → foo with (3)
|
||||
✓ depends on describe using with → bar with (3)
|
||||
✓ with test after describe → it should run the before each
|
||||
✓ sibling describes may share the same it() description → block one → it can be created
|
||||
✓ sibling describes may share the same it() description → block two → it can be created
|
||||
|
||||
PASS Tests\Features\DescriptionLess
|
||||
✓ get 'foo'
|
||||
@@ -1870,6 +1876,8 @@
|
||||
|
||||
PASS Tests\Unit\Plugins\Retry
|
||||
✓ it orders by defects and stop on defects if when --retry is used
|
||||
✓ it rejects retry with a parallel flag with ('--parallel')
|
||||
✓ it rejects retry with a parallel flag with ('-p')
|
||||
|
||||
PASS Tests\Unit\Plugins\Shard
|
||||
✓ getShard → it parses valid shard format with ('1/2', 1, 2)
|
||||
@@ -2067,6 +2075,13 @@
|
||||
✓ a wrapper already registered for file:// → it opens reads through it and still links them
|
||||
✓ a wrapper already registered for file:// → it keeps the include flag for the files a test includes
|
||||
✓ a wrapper already registered for file:// → it is registered again after the test
|
||||
✓ withoutReadCapture() → it does not link a file matching an excluded glob
|
||||
✓ withoutReadCapture() → it still links a file outside the excluded globs
|
||||
✓ withoutReadCapture() → it keeps the file wrapper registered while globs are excluded
|
||||
✓ withoutReadCapture() → it links every read when the list of globs is empty
|
||||
✓ withoutReadCapture() → it registers no wrapper and links no read when called without globs
|
||||
✓ withoutReadCapture() → it keeps the explicit links when called without globs
|
||||
✓ withoutReadCapture() → it leaves a wrapper already registered for file:// untouched when called without globs
|
||||
|
||||
PASS Tests\Unit\Plugins\Tia\Recorder
|
||||
✓ activateLinkTracking() → it tracks tables without a coverage driver
|
||||
@@ -2257,6 +2272,16 @@
|
||||
✓ it retains recorded Inertia dependencies when default watches are disabled
|
||||
✓ it retains recorded migration tables when default watches are disabled
|
||||
✓ it uses custom mappings for an unknown Vue page with defaults disabled
|
||||
✓ it captures every read by default
|
||||
✓ it excludes reads of files matching a glob
|
||||
✓ it matches read globs like watch patterns
|
||||
✓ it does not exclude a dotfile unless the glob names it
|
||||
✓ it accumulates read exclusions from repeated calls
|
||||
✓ it does not turn read capture off for an empty exclusion list
|
||||
✓ it turns read capture off without a list of globs
|
||||
✓ it keeps read capture off when globs are added afterwards
|
||||
✓ it captures reads again on reset
|
||||
✓ it does not change the default watch fallbacks of an excluded read
|
||||
|
||||
PASS Tests\Unit\Plugins\Tia\WorkerToken
|
||||
✓ prefers the per-process UNIQUE_TEST_TOKEN over the per-slot TEST_TOKEN, so two workers recycled into the same slot get different tokens
|
||||
@@ -2534,6 +2559,9 @@
|
||||
PASS Tests\Visual\SingleTestOrDirectory
|
||||
✓ allows to run a single test
|
||||
✓ allows to run a directory
|
||||
✓ allows to run a single test using its namespace
|
||||
✓ keeps namespace filters unchanged
|
||||
✓ converts a namespace after the retry flag
|
||||
✓ it disable decorating printer when colors is set to never
|
||||
|
||||
WARN Tests\Visual\Success
|
||||
@@ -2557,9 +2585,11 @@
|
||||
|
||||
WARN Tests\Visual\Version
|
||||
- visual snapshot of help command output
|
||||
✓ prints information when the tests directory is missing with dataset "help"
|
||||
✓ prints information when the tests directory is missing with dataset "version"
|
||||
|
||||
PASS Testsexternal\Features\Expect\toMatchSnapshot
|
||||
✓ 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, 1856 passed (4269 assertions)
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 38 skipped, 1886 passed (4325 assertions)
|
||||
@@ -100,3 +100,29 @@ describe('matching describe block names', function (): void {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('hierarchical test naming', function (): void {
|
||||
describe('block one', function (): void {
|
||||
describe('the same name', function (): void {
|
||||
it('does not call afterEach from sibling describe with same name', function (): void {
|
||||
expect($this)->not->toHaveProperty('example');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('block two', function (): void {
|
||||
describe('the same name', function (): void {
|
||||
beforeEach(function (): void {
|
||||
$this->example = false;
|
||||
});
|
||||
|
||||
afterEach(function (): void {
|
||||
expect($this->example)->toBeFalse();
|
||||
});
|
||||
|
||||
it('correctly calls afterEach from own describe hierarchy', function (): void {
|
||||
expect($this->example)->toBeFalse();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -126,3 +126,29 @@ describe('called on all tests', function (): void {
|
||||
expect($this->baz)->toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('hierarchical test naming', function (): void {
|
||||
describe('block one', function (): void {
|
||||
describe('the same name', function (): void {
|
||||
it('does not call beforeEach from sibling describe with same name', function (): void {
|
||||
expect($this)->not->toHaveProperty('example');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('block two', function (): void {
|
||||
beforeEach(function (): void {
|
||||
$this->example = false;
|
||||
});
|
||||
|
||||
describe('the same name', function (): void {
|
||||
beforeEach(function (): void {
|
||||
$this->result = $this->example;
|
||||
});
|
||||
|
||||
it('correctly calls beforeEach from own describe hierarchy', function (): void {
|
||||
expect($this->result)->toBeFalse();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -108,3 +108,17 @@ describe('with test after describe', function (): void {
|
||||
expect($this->count)->toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sibling describes may share the same it() description', function (): void {
|
||||
describe('block one', function (): void {
|
||||
it('can be created', function (): void {
|
||||
expect(true)->toBeTrue();
|
||||
});
|
||||
});
|
||||
|
||||
describe('block two', function (): void {
|
||||
it('can be created', function (): void {
|
||||
expect(true)->toBeTrue();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -63,7 +63,7 @@ test('a missing tests directory does not crash while resolving tia state', funct
|
||||
$root = makeInitProject();
|
||||
|
||||
try {
|
||||
$process = runInitProject($root, '--version');
|
||||
$process = runInitProject($root);
|
||||
|
||||
expect($process->getExitCode())->not->toBe(0)
|
||||
->and($process->getOutput())->toContain('does not exist')
|
||||
@@ -110,10 +110,6 @@ require {$autoload};
|
||||
|
||||
\$arguments = array_slice(\$argv, 1);
|
||||
|
||||
if (\$arguments === []) {
|
||||
\$arguments = ['--version'];
|
||||
}
|
||||
|
||||
\$GLOBALS['_composer_bin_dir'] = getcwd().'/vendor/bin';
|
||||
|
||||
\$_SERVER['argv'] = ['pest', ...\$arguments];
|
||||
|
||||
@@ -25,6 +25,19 @@ function tiaRecordWithSourceReadingTest(Project $project, string ...$arguments):
|
||||
$project->pest('--tia', ...$arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
function tiaEdgeFiles(Project $project, string $testFile): array
|
||||
{
|
||||
$graph = $project->graph() ?? [];
|
||||
|
||||
return array_map(
|
||||
fn (int $id): string => $graph['files'][$id],
|
||||
$graph['edges'][$testFile] ?? [],
|
||||
);
|
||||
}
|
||||
|
||||
test('a test that reads a file records an edge to it', function (array $arguments): void {
|
||||
$project = Project::make('master');
|
||||
|
||||
@@ -108,3 +121,68 @@ test('a file a test reads does not select it when another file changes', functio
|
||||
expect($result->affected())->toBe(4, $result->describe())
|
||||
->and($result->replayed())->toBe(3, $result->describe());
|
||||
})->skipOnWindows()->skip(! Coverage::isAvailable(), 'Coverage is not available');
|
||||
|
||||
test('a test that reads an excluded file records no edge to it', function (array $arguments): void {
|
||||
$project = Project::make('master');
|
||||
$project->write('tests/Pest.php', file_get_contents($project->path('tests/Pest.php')).
|
||||
"\npest()->tia()->withoutReadCapture(['app/Greeter.php']);\n");
|
||||
|
||||
tiaRecordWithSourceReadingTest($project, ...$arguments);
|
||||
|
||||
expect(tiaEdgeFiles($project, 'tests/Unit/GreeterTest.php'))->toContain('app/Greeter.php')
|
||||
->and(tiaEdgeFiles($project, 'tests/Unit/GreeterSourceTest.php'))->not->toContain('app/Greeter.php');
|
||||
})->with(Project::SEQUENTIAL_AND_PARALLEL)->skipOnWindows()->skip(! Coverage::isAvailable(), 'Coverage is not available');
|
||||
|
||||
test('a test that reads a file outside the excluded globs still records an edge to it', function (array $arguments): void {
|
||||
$project = Project::make('master');
|
||||
$project->write('tests/Pest.php', file_get_contents($project->path('tests/Pest.php')).
|
||||
"\npest()->tia()->withoutReadCapture(['lang/*.json']);\n");
|
||||
|
||||
tiaRecordWithSourceReadingTest($project, ...$arguments);
|
||||
|
||||
expect(tiaEdgeFiles($project, 'tests/Unit/GreeterSourceTest.php'))->toContain('app/Greeter.php');
|
||||
})->with(Project::SEQUENTIAL_AND_PARALLEL)->skipOnWindows()->skip(! Coverage::isAvailable(), 'Coverage is not available');
|
||||
|
||||
test('no read records an edge when read capture is off', function (array $arguments): void {
|
||||
$project = Project::make('master');
|
||||
$project->write('tests/Pest.php', file_get_contents($project->path('tests/Pest.php')).
|
||||
"\npest()->tia()->withoutReadCapture();\n");
|
||||
|
||||
tiaRecordWithSourceReadingTest($project, ...$arguments);
|
||||
|
||||
expect(tiaEdgeFiles($project, 'tests/Unit/GreeterTest.php'))->toContain('app/Greeter.php')
|
||||
->and(tiaEdgeFiles($project, 'tests/Unit/GreeterSourceTest.php'))->not->toContain('app/Greeter.php');
|
||||
})->with(Project::SEQUENTIAL_AND_PARALLEL)->skipOnWindows()->skip(! Coverage::isAvailable(), 'Coverage is not available');
|
||||
|
||||
test('a watch pattern reruns tests after an excluded file changes', function (array $arguments): void {
|
||||
$project = Project::make('master');
|
||||
|
||||
$project->write('tests/Pest.php', file_get_contents($project->path('tests/Pest.php')).<<<'PHP'
|
||||
|
||||
pest()->tia()
|
||||
->withoutReadCapture(['data/*.json'])
|
||||
->watch(['data/*.json' => 'tests/Unit/GreeterTest.php']);
|
||||
|
||||
PHP);
|
||||
$project->write('data/status.json', '"ready"');
|
||||
|
||||
$testFile = 'tests/Unit/GreeterTest.php';
|
||||
$project->write($testFile, str_replace(
|
||||
' expect((new Greeter)->greet(\'Nuno\'))->toBe(\'Hello, Nuno!\');',
|
||||
' expect(file_get_contents(__DIR__.\'/../../data/status.json\'))->toBe(\'"ready"\');',
|
||||
file_get_contents($project->path($testFile)),
|
||||
));
|
||||
|
||||
$project->git()->commit('add a watched JSON fixture');
|
||||
$project->seed('master');
|
||||
|
||||
$project->write('data/status.json', '"broken"');
|
||||
$project->git()->commit('change the watched fixture');
|
||||
|
||||
$result = $project->pest('--tia', ...$arguments);
|
||||
|
||||
expect($result->exitCode)->toBe(1, $result->describe())
|
||||
->and($result->affected())->toBe(2, $result->describe())
|
||||
->and($result->replayed())->toBe(4, $result->describe())
|
||||
->and($result->output)->toContain('greets a person', 'broken');
|
||||
})->with(Project::SEQUENTIAL_AND_PARALLEL)->skipOnWindows();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Pest\Exceptions\InvalidOption;
|
||||
use Pest\Plugins\Retry;
|
||||
|
||||
it('orders by defects and stop on defects if when --retry is used ', function (): void {
|
||||
@@ -12,3 +13,10 @@ it('orders by defects and stop on defects if when --retry is used ', function ()
|
||||
'--stop-on-failure',
|
||||
]);
|
||||
});
|
||||
|
||||
it('rejects retry with a parallel flag', function (string $parallelFlag): void {
|
||||
(new Retry)->handleArguments(['--retry', $parallelFlag]);
|
||||
})->with(['--parallel', '-p'])->throws(
|
||||
InvalidOption::class,
|
||||
'The [--retry] option is not supported when running in parallel.',
|
||||
);
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Pest\Plugins\Tia\Configuration;
|
||||
use Pest\Plugins\Tia\ReadCapture;
|
||||
use Pest\Plugins\Tia\Recorder;
|
||||
use Pest\Plugins\Tia\WatchPatterns;
|
||||
use Pest\Support\Container;
|
||||
use Tests\Fixtures\Tia\LoggingFileWrapper;
|
||||
|
||||
/**
|
||||
@@ -294,3 +297,100 @@ describe('a wrapper already registered for file://', function (): void {
|
||||
->and(tiaReadCaptureWrapperClass())->toBe(LoggingFileWrapper::class);
|
||||
});
|
||||
});
|
||||
|
||||
describe('withoutReadCapture()', function (): void {
|
||||
beforeEach(function (): void {
|
||||
Container::getInstance()->add(WatchPatterns::class, new WatchPatterns);
|
||||
|
||||
$this->excluded = (string) realpath(dirname(__DIR__, 4).'/src/Plugins/Tia/ReadCapture.php');
|
||||
$this->kept = (string) realpath(dirname(__DIR__, 4).'/src/Plugins/Tia/Recorder.php');
|
||||
});
|
||||
|
||||
afterEach(function (): void {
|
||||
Container::getInstance()->add(WatchPatterns::class, new WatchPatterns);
|
||||
});
|
||||
|
||||
it('does not link a file matching an excluded glob', function (): void {
|
||||
(new Configuration)->withoutReadCapture(['src/Plugins/Tia/Read*.php']);
|
||||
|
||||
expect(tiaReadCaptureLinks(fn (): string|false => file_get_contents($this->excluded)))->toBeEmpty();
|
||||
});
|
||||
|
||||
it('still links a file outside the excluded globs', function (): void {
|
||||
(new Configuration)->withoutReadCapture(['src/Plugins/Tia/Read*.php']);
|
||||
|
||||
$links = tiaReadCaptureLinks(function (): void {
|
||||
file_get_contents($this->excluded);
|
||||
file_get_contents($this->kept);
|
||||
});
|
||||
|
||||
expect($links)->toBe([$this->kept]);
|
||||
});
|
||||
|
||||
it('keeps the file wrapper registered while globs are excluded', function (): void {
|
||||
(new Configuration)->withoutReadCapture(['src/Plugins/Tia/Read*.php']);
|
||||
|
||||
$during = '';
|
||||
|
||||
tiaReadCaptureLinks(function () use (&$during): void {
|
||||
$during = tiaReadCaptureWrapperType();
|
||||
});
|
||||
|
||||
expect($during)->toBe('user-space');
|
||||
});
|
||||
|
||||
it('links every read when the list of globs is empty', function (): void {
|
||||
(new Configuration)->withoutReadCapture([]);
|
||||
|
||||
expect(tiaReadCaptureLinks(fn (): string|false => file_get_contents($this->excluded)))->toBe([$this->excluded]);
|
||||
});
|
||||
|
||||
it('registers no wrapper and links no read when called without globs', function (): void {
|
||||
(new Configuration)->withoutReadCapture();
|
||||
|
||||
$during = '';
|
||||
|
||||
$links = tiaReadCaptureLinks(function () use (&$during): void {
|
||||
$during = tiaReadCaptureWrapperType();
|
||||
file_get_contents($this->kept);
|
||||
});
|
||||
|
||||
expect($during)->toBe('plainfile')
|
||||
->and($links)->toBeEmpty()
|
||||
->and(tiaReadCaptureWrapperType())->toBe('plainfile');
|
||||
});
|
||||
|
||||
it('keeps the explicit links when called without globs', function (): void {
|
||||
(new Configuration)->withoutReadCapture();
|
||||
|
||||
$recorder = new Recorder;
|
||||
$recorder->activateLinkTracking();
|
||||
|
||||
$recorder->beginTest('Some\Missing\TestClass', 'it links', '/project/tests/Feature/LinksTest.php');
|
||||
$recorder->linkSource('/project/resources/views/welcome.blade.php');
|
||||
$recorder->endTest();
|
||||
|
||||
expect($recorder->perTestFiles())
|
||||
->toBe(['/project/tests/Feature/LinksTest.php' => ['/project/resources/views/welcome.blade.php']]);
|
||||
});
|
||||
|
||||
it('leaves a wrapper already registered for file:// untouched when called without globs', function (): void {
|
||||
(new Configuration)->withoutReadCapture();
|
||||
|
||||
LoggingFileWrapper::enable();
|
||||
|
||||
try {
|
||||
$during = null;
|
||||
|
||||
$links = tiaReadCaptureLinks(function () use (&$during): void {
|
||||
$during = tiaReadCaptureWrapperClass();
|
||||
file_get_contents($this->kept);
|
||||
});
|
||||
} finally {
|
||||
LoggingFileWrapper::disable();
|
||||
}
|
||||
|
||||
expect($during)->toBe(LoggingFileWrapper::class)
|
||||
->and($links)->toBeEmpty();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -181,3 +181,88 @@ it('uses custom mappings for an unknown Vue page with defaults disabled', functi
|
||||
|
||||
expect($graph->affected(['resources/js/Pages/Enroll.vue']))->toBe(['tests/Unit/CalculatorTest.php']);
|
||||
});
|
||||
|
||||
it('captures every read by default', function (): void {
|
||||
expect($this->watchPatterns->isReadCaptureEnabled())->toBeTrue()
|
||||
->and($this->watchPatterns->excludesRead('lang/fr.json'))->toBeFalse();
|
||||
});
|
||||
|
||||
it('excludes reads of files matching a glob', function (): void {
|
||||
$configuration = new Configuration;
|
||||
|
||||
expect($configuration->withoutReadCapture(['lang/*.json']))->toBe($configuration)
|
||||
->and($this->watchPatterns->isReadCaptureEnabled())->toBeTrue()
|
||||
->and($this->watchPatterns->excludesRead('lang/fr.json'))->toBeTrue()
|
||||
->and($this->watchPatterns->excludesRead('lang/vendor/package/fr.json'))->toBeFalse()
|
||||
->and($this->watchPatterns->excludesRead('resources/lang/fr.json'))->toBeFalse()
|
||||
->and($this->watchPatterns->excludesRead('lang/fr.php'))->toBeFalse();
|
||||
});
|
||||
|
||||
it('matches read globs like watch patterns', function (): void {
|
||||
(new Configuration)->withoutReadCapture([
|
||||
'lang/**/*.json !lang/vendor/keep/**',
|
||||
'tests/Fixtures/*.csv',
|
||||
'.env.testing',
|
||||
]);
|
||||
|
||||
expect($this->watchPatterns->excludesRead('lang/vendor/package/fr.json'))->toBeTrue()
|
||||
->and($this->watchPatterns->excludesRead('lang/vendor/keep/fr.json'))->toBeFalse()
|
||||
->and($this->watchPatterns->excludesRead('tests/Fixtures/orders.csv'))->toBeTrue()
|
||||
->and($this->watchPatterns->excludesRead('tests/Fixtures/nested/orders.csv'))->toBeFalse()
|
||||
->and($this->watchPatterns->excludesRead('.env.testing'))->toBeTrue()
|
||||
->and($this->watchPatterns->excludesRead('.env.local'))->toBeFalse();
|
||||
});
|
||||
|
||||
it('does not exclude a dotfile unless the glob names it', function (): void {
|
||||
(new Configuration)->withoutReadCapture(['**']);
|
||||
|
||||
expect($this->watchPatterns->excludesRead('lang/fr.json'))->toBeTrue()
|
||||
->and($this->watchPatterns->excludesRead('.env.testing'))->toBeFalse();
|
||||
});
|
||||
|
||||
it('accumulates read exclusions from repeated calls', function (): void {
|
||||
(new Configuration)
|
||||
->withoutReadCapture(['lang/*.json'])
|
||||
->withoutReadCapture(['resources/lang/*.json']);
|
||||
|
||||
expect($this->watchPatterns->excludesRead('lang/fr.json'))->toBeTrue()
|
||||
->and($this->watchPatterns->excludesRead('resources/lang/fr.json'))->toBeTrue();
|
||||
});
|
||||
|
||||
it('does not turn read capture off for an empty exclusion list', function (): void {
|
||||
(new Configuration)->withoutReadCapture([]);
|
||||
|
||||
expect($this->watchPatterns->isReadCaptureEnabled())->toBeTrue()
|
||||
->and($this->watchPatterns->excludesRead('lang/fr.json'))->toBeFalse();
|
||||
});
|
||||
|
||||
it('turns read capture off without a list of globs', function (): void {
|
||||
(new Configuration)->withoutReadCapture();
|
||||
|
||||
expect($this->watchPatterns->isReadCaptureEnabled())->toBeFalse();
|
||||
});
|
||||
|
||||
it('keeps read capture off when globs are added afterwards', function (): void {
|
||||
(new Configuration)
|
||||
->withoutReadCapture()
|
||||
->withoutReadCapture(['lang/*.json']);
|
||||
|
||||
expect($this->watchPatterns->isReadCaptureEnabled())->toBeFalse();
|
||||
});
|
||||
|
||||
it('captures reads again on reset', function (): void {
|
||||
(new Configuration)
|
||||
->withoutReadCapture()
|
||||
->withoutReadCapture(['lang/*.json']);
|
||||
|
||||
$this->watchPatterns->reset();
|
||||
|
||||
expect($this->watchPatterns->isReadCaptureEnabled())->toBeTrue()
|
||||
->and($this->watchPatterns->excludesRead('lang/fr.json'))->toBeFalse();
|
||||
});
|
||||
|
||||
it('does not change the default watch fallbacks of an excluded read', function (): void {
|
||||
(new Configuration)->withoutReadCapture(['.env.testing']);
|
||||
|
||||
expect($this->watchPatterns->matchedDirectories(getcwd(), ['.env.testing']))->toBe(['tests']);
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@ use Symfony\Component\Process\Process;
|
||||
|
||||
$run = function (): ?string {
|
||||
$process = new Process(
|
||||
array_merge(['php', 'bin/pest', '--parallel', '--processes=3'], func_get_args()),
|
||||
array_merge(['php', '-d', 'memory_limit=512M', 'bin/pest', '--parallel', '--processes=3', '--passthru-php=-d memory_limit=512M'], func_get_args()),
|
||||
dirname(__DIR__, 2),
|
||||
['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1'],
|
||||
);
|
||||
@@ -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 (3752 assertions)';
|
||||
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 30 skipped, 1759 passed (3800 assertions)';
|
||||
|
||||
expect($output)
|
||||
->toContain("Tests: {$expected}")
|
||||
|
||||
@@ -30,6 +30,44 @@ test('allows to run a directory', function () use ($run, $snapshot): void {
|
||||
expect($run('tests/Fixtures/DirectoryWithTests'))->toContain($snapshot('allows-to-run-a-directory'));
|
||||
})->skipOnWindows();
|
||||
|
||||
test('allows to run a single test using its namespace', function () use ($run, $snapshot): void {
|
||||
expect($run('Tests\\Fixtures\\DirectoryWithTests\\ExampleTest'))->toContain($snapshot('allows-to-run-a-single-test'));
|
||||
})->skipOnWindows();
|
||||
|
||||
test('keeps namespace filters unchanged', function () use ($snapshot): void {
|
||||
$process = new Process([
|
||||
'php',
|
||||
'bin/pest',
|
||||
'tests/Fixtures/DirectoryWithTests',
|
||||
'--filter',
|
||||
'Tests\\\\Fixtures\\\\DirectoryWithTests\\\\ExampleTest',
|
||||
'--colors=never',
|
||||
], dirname(__DIR__, 2),
|
||||
['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1'],
|
||||
);
|
||||
|
||||
$process->run();
|
||||
|
||||
expect(removeAnsiEscapeSequences($process->getOutput()))->toContain($snapshot('allows-to-run-a-single-test'));
|
||||
})->skipOnWindows();
|
||||
|
||||
test('converts a namespace after the retry flag', function () use ($snapshot): void {
|
||||
$process = new Process([
|
||||
'php',
|
||||
'bin/pest',
|
||||
'--retry',
|
||||
'Tests\\Fixtures\\DirectoryWithTests\\ExampleTest',
|
||||
'--colors=never',
|
||||
], dirname(__DIR__, 2),
|
||||
['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1'],
|
||||
);
|
||||
|
||||
$process->run();
|
||||
|
||||
expect($process->getExitCode())->toBe(0)
|
||||
->and(removeAnsiEscapeSequences($process->getOutput()))->toContain($snapshot('allows-to-run-a-single-test'));
|
||||
})->skipOnWindows();
|
||||
|
||||
it('disable decorating printer when colors is set to never', function () use ($snapshot): void {
|
||||
$process = new Process([
|
||||
'php',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
use Tests\Fixtures\Tia\Project;
|
||||
|
||||
test('visual snapshot of help command output', function (): void {
|
||||
$output = function (): ?string {
|
||||
@@ -13,3 +14,22 @@ test('visual snapshot of help command output', function (): void {
|
||||
|
||||
expect($output())->toMatchSnapshot();
|
||||
})->skipOnWindows()->skip(! getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE'));
|
||||
|
||||
test('prints information when the tests directory is missing', function (string $option, string $expected): void {
|
||||
$project = Project::withoutGit();
|
||||
|
||||
try {
|
||||
rename($project->path('tests'), $project->path('fixtures'));
|
||||
unlink($project->path('phpunit.xml'));
|
||||
|
||||
$result = $project->pest($option);
|
||||
|
||||
expect($result->exitCode)->toBe(0, $result->describe())
|
||||
->and($result->output)->toContain($expected);
|
||||
} finally {
|
||||
Project::destroyAll();
|
||||
}
|
||||
})->with([
|
||||
'help' => ['--help', '--init'],
|
||||
'version' => ['--version', 'Pest Testing Framework'],
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user