mirror of
https://github.com/pestphp/pest.git
synced 2026-12-03 22:45:06 +01:00
Compare commits
5 Commits
b75cf904b7
...
8d004b80d7
| Author | SHA1 | Date | |
|---|---|---|---|
| 8d004b80d7 | |||
| 12f3cd80de | |||
| dc73ec009e | |||
| 5bb349dcf2 | |||
| 1f60dc8f9a |
@@ -192,6 +192,7 @@ use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
|
||||
include_once $autoloadPath;
|
||||
|
||||
$GLOBALS['_composer_autoload_path'] = $autoloadPath;
|
||||
$GLOBALS['_composer_bin_dir'] ??= dirname($autoloadPath).'/bin';
|
||||
$rootPath = ComposerProject::rootPath($autoloadPath);
|
||||
|
||||
|
||||
@@ -43,9 +43,11 @@ $bootPest = (static function (string $rootPath): void {
|
||||
'testdox-columns:',
|
||||
'testdox-summary',
|
||||
'phpunit-argv:',
|
||||
'composer-autoload:',
|
||||
]);
|
||||
|
||||
$composerAutoloadFiles = [
|
||||
...(isset($getopt['composer-autoload']) && is_string($getopt['composer-autoload']) ? [$getopt['composer-autoload']] : []),
|
||||
dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'autoload.php',
|
||||
dirname(__DIR__, 2).DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'autoload.php',
|
||||
dirname(__DIR__).DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'autoload.php',
|
||||
|
||||
@@ -7,9 +7,7 @@ use Pest\Rector\Set\PestSetList;
|
||||
use Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector;
|
||||
use Rector\CodingStyle\Rector\ArrowFunction\ArrowFunctionDelegatingCallToFirstClassCallableRector;
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveDuplicatedReturnSelfDocblockRector;
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector;
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveParentDelegatingConstructorRector;
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveReturnTagIncompatibleWithNativeTypeRector;
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector;
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessUnionReturnDocblockRector;
|
||||
@@ -33,8 +31,6 @@ return RectorConfig::configure()
|
||||
ReturnNeverTypeRector::class,
|
||||
ArrowFunctionDelegatingCallToFirstClassCallableRector::class,
|
||||
NarrowObjectReturnTypeRector::class,
|
||||
RemoveParentDelegatingConstructorRector::class,
|
||||
RemoveDuplicatedReturnSelfDocblockRector::class,
|
||||
RemoveUselessUnionReturnDocblockRector::class,
|
||||
RemoveReturnTagIncompatibleWithNativeTypeRector::class => [
|
||||
__DIR__.'/src/Expectations/HigherOrderExpectation.php',
|
||||
|
||||
@@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins;
|
||||
|
||||
use Composer\InstalledVersions;
|
||||
use Pest\Console\Thanks;
|
||||
use Pest\Contracts\Plugins\HandlesArguments;
|
||||
use Pest\Support\InstalledPackages;
|
||||
use Pest\Support\View;
|
||||
use Pest\TestSuite;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
@@ -96,11 +96,11 @@ final readonly class Init implements HandlesArguments
|
||||
|
||||
View::render('components.new-line');
|
||||
|
||||
(new Thanks($this->input, $this->output))();
|
||||
new Thanks($this->input, $this->output)();
|
||||
}
|
||||
|
||||
private function isLaravelInstalled(): bool
|
||||
{
|
||||
return InstalledVersions::isInstalled('laravel/framework');
|
||||
return InstalledPackages::has('laravel/framework');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace Pest\Plugins\Parallel\Handlers;
|
||||
|
||||
use Closure;
|
||||
use Composer\InstalledVersions;
|
||||
use Illuminate\Testing\ParallelRunner;
|
||||
use Orchestra\Testbench\TestCase;
|
||||
use ParaTest\Options;
|
||||
@@ -13,6 +12,7 @@ use ParaTest\RunnerInterface;
|
||||
use Pest\Contracts\Plugins\HandlesArguments;
|
||||
use Pest\Plugins\Concerns\HandleArguments;
|
||||
use Pest\Plugins\Parallel\Paratest\WrapperRunner;
|
||||
use Pest\Support\InstalledPackages;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ final class Laravel implements HandlesArguments
|
||||
*/
|
||||
private function whenUsingLaravel(array $arguments, Closure $closure): array
|
||||
{
|
||||
$isLaravelApplication = InstalledVersions::isInstalled('laravel/framework', false);
|
||||
$isLaravelApplication = InstalledPackages::has('laravel/framework', false);
|
||||
$isLaravelPackage = class_exists(TestCase::class);
|
||||
|
||||
if ($isLaravelApplication && ! $isLaravelPackage) {
|
||||
|
||||
@@ -156,6 +156,10 @@ final class WrapperRunner implements RunnerInterface
|
||||
$parameters[] = $wrapper;
|
||||
$parameters[] = '--test-directory='.TestSuite::getInstance()->testPath;
|
||||
|
||||
if (is_string($GLOBALS['_composer_autoload_path'] ?? null)) {
|
||||
$parameters[] = '--composer-autoload='.$GLOBALS['_composer_autoload_path'];
|
||||
}
|
||||
|
||||
$this->parameters = $parameters;
|
||||
$this->codeCoverageFilterRegistry = new CodeCoverageFilterRegistry;
|
||||
}
|
||||
|
||||
@@ -105,13 +105,9 @@ abstract readonly class BaseRemote // @pest-arch-ignore-line
|
||||
return $configured;
|
||||
}
|
||||
|
||||
$process = new Process(['git', 'symbolic-ref', 'refs/remotes/origin/HEAD']);
|
||||
$process->setTimeout(5.0);
|
||||
$process->run();
|
||||
|
||||
if ($process->isSuccessful()) {
|
||||
$ref = trim($process->getOutput());
|
||||
$ref = new Git()->output(['symbolic-ref', 'refs/remotes/origin/HEAD']);
|
||||
|
||||
if ($ref !== null) {
|
||||
$branch = str_replace('refs/remotes/origin/', '', $ref);
|
||||
|
||||
if ($branch !== '') {
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace Pest\Plugins\Tia;
|
||||
use Pest\Plugins\Tia\Contracts\Lockfile;
|
||||
use Pest\Support\Git;
|
||||
use Symfony\Component\Process\Exception\ExceptionInterface as ProcessException;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@@ -302,16 +301,11 @@ final readonly class Fingerprint
|
||||
return $cache[$key] = true;
|
||||
}
|
||||
|
||||
$process = new Process(['git', 'check-ignore', '-q', '--', $relativePath], $projectRoot);
|
||||
$process->setTimeout(5.0);
|
||||
|
||||
try {
|
||||
$process->run();
|
||||
return $cache[$key] = ! new Git($projectRoot)->succeeds(['check-ignore', '-q', '--', $relativePath]);
|
||||
} catch (ProcessException) {
|
||||
return $cache[$key] = true;
|
||||
}
|
||||
|
||||
return $cache[$key] = $process->getExitCode() !== 0;
|
||||
}
|
||||
|
||||
private static function projectPrefix(string $projectRoot): string
|
||||
|
||||
@@ -127,16 +127,22 @@ final class ReadCapture
|
||||
|
||||
public function dir_closedir(): bool
|
||||
{
|
||||
closedir($this->resource());
|
||||
$this->forward('dir_closedir', function (mixed $resource): bool {
|
||||
closedir($resource);
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function dir_opendir(string $path): bool
|
||||
public function dir_opendir(string $path, int $options): bool
|
||||
{
|
||||
$handle = $this->withOriginalWrapper(fn () => opendir($path, $this->context));
|
||||
$handle = $this->withOriginalWrapper(fn (): mixed => self::$previousWrapper === null
|
||||
? opendir($path, $this->context)
|
||||
: $this->openDirectoryThroughPreviousWrapper(self::$previousWrapper, $path, $options));
|
||||
|
||||
if (! is_resource($handle)) {
|
||||
if ($handle === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -147,14 +153,18 @@ final class ReadCapture
|
||||
|
||||
public function dir_readdir(): string|false
|
||||
{
|
||||
return readdir($this->resource());
|
||||
$entry = $this->forward('dir_readdir', fn (mixed $resource): string|false => readdir($resource));
|
||||
|
||||
return is_string($entry) ? $entry : false;
|
||||
}
|
||||
|
||||
public function dir_rewinddir(): bool
|
||||
{
|
||||
rewinddir($this->resource());
|
||||
return $this->forward('dir_rewinddir', function (mixed $resource): bool {
|
||||
rewinddir($resource);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}) === true;
|
||||
}
|
||||
|
||||
public function mkdir(string $path, int $mode, int $options): bool
|
||||
@@ -320,7 +330,25 @@ final class ReadCapture
|
||||
$wrapper->context = $this->context;
|
||||
}
|
||||
|
||||
if (! method_exists($wrapper, 'stream_open') || $wrapper->stream_open($path, $mode, $options, $openedPath) !== true) {
|
||||
if (! is_callable([$wrapper, 'stream_open']) || $wrapper->stream_open($path, $mode, $options, $openedPath) !== true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $wrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string $wrapperClass
|
||||
*/
|
||||
private function openDirectoryThroughPreviousWrapper(string $wrapperClass, string $path, int $options): object|false
|
||||
{
|
||||
$wrapper = new $wrapperClass;
|
||||
|
||||
if (property_exists($wrapper, 'context')) {
|
||||
$wrapper->context = $this->context;
|
||||
}
|
||||
|
||||
if (! is_callable([$wrapper, 'dir_opendir']) || $wrapper->dir_opendir($path, $options) !== true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -336,16 +364,6 @@ final class ReadCapture
|
||||
return str_contains($mode, 'r') || str_contains($mode, '+');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return resource
|
||||
*/
|
||||
private function resource(): mixed
|
||||
{
|
||||
assert(is_resource($this->handle));
|
||||
|
||||
return $this->handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Closure(resource): mixed $native
|
||||
*/
|
||||
@@ -355,7 +373,7 @@ final class ReadCapture
|
||||
return $native($this->handle);
|
||||
}
|
||||
|
||||
if (! method_exists($this->handle, $method)) {
|
||||
if (! is_callable([$this->handle, $method])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins\Tia\WatchDefaults;
|
||||
|
||||
use Composer\InstalledVersions;
|
||||
use Pest\Browser\Support\BrowserTestIdentifier;
|
||||
use Pest\Factories\TestCaseFactory;
|
||||
use Pest\Plugins\Tia\Contracts\WatchDefault;
|
||||
use Pest\Support\InstalledPackages;
|
||||
use Pest\TestSuite;
|
||||
|
||||
/**
|
||||
@@ -17,8 +17,7 @@ final readonly class Browser implements WatchDefault
|
||||
{
|
||||
public function applicable(): bool
|
||||
{
|
||||
return class_exists(InstalledVersions::class)
|
||||
&& InstalledVersions::isInstalled('pestphp/pest-plugin-browser');
|
||||
return InstalledPackages::has('pestphp/pest-plugin-browser');
|
||||
}
|
||||
|
||||
public function defaults(string $projectRoot, string $testPath): array
|
||||
|
||||
@@ -4,8 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins\Tia\WatchDefaults;
|
||||
|
||||
use Composer\InstalledVersions;
|
||||
use Pest\Plugins\Tia\Contracts\WatchDefault;
|
||||
use Pest\Support\InstalledPackages;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@@ -14,9 +14,8 @@ final readonly class Inertia implements WatchDefault
|
||||
{
|
||||
public function applicable(): bool
|
||||
{
|
||||
return class_exists(InstalledVersions::class)
|
||||
&& (InstalledVersions::isInstalled('inertiajs/inertia-laravel')
|
||||
|| InstalledVersions::isInstalled('rompetomp/inertia-bundle'));
|
||||
return InstalledPackages::has('inertiajs/inertia-laravel')
|
||||
|| InstalledPackages::has('rompetomp/inertia-bundle');
|
||||
}
|
||||
|
||||
public function defaults(string $projectRoot, string $testPath): array
|
||||
|
||||
@@ -4,8 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins\Tia\WatchDefaults;
|
||||
|
||||
use Composer\InstalledVersions;
|
||||
use Pest\Plugins\Tia\Contracts\WatchDefault;
|
||||
use Pest\Support\InstalledPackages;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@@ -14,8 +14,7 @@ final readonly class Laravel implements WatchDefault
|
||||
{
|
||||
public function applicable(): bool
|
||||
{
|
||||
return class_exists(InstalledVersions::class)
|
||||
&& InstalledVersions::isInstalled('laravel/framework');
|
||||
return InstalledPackages::has('laravel/framework');
|
||||
}
|
||||
|
||||
public function defaults(string $projectRoot, string $testPath): array
|
||||
|
||||
@@ -4,8 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins\Tia\WatchDefaults;
|
||||
|
||||
use Composer\InstalledVersions;
|
||||
use Pest\Plugins\Tia\Contracts\WatchDefault;
|
||||
use Pest\Support\InstalledPackages;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@@ -14,8 +14,7 @@ final readonly class Livewire implements WatchDefault
|
||||
{
|
||||
public function applicable(): bool
|
||||
{
|
||||
return class_exists(InstalledVersions::class)
|
||||
&& InstalledVersions::isInstalled('livewire/livewire');
|
||||
return InstalledPackages::has('livewire/livewire');
|
||||
}
|
||||
|
||||
public function defaults(string $projectRoot, string $testPath): array
|
||||
|
||||
@@ -4,8 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins\Tia\WatchDefaults;
|
||||
|
||||
use Composer\InstalledVersions;
|
||||
use Pest\Plugins\Tia\Contracts\WatchDefault;
|
||||
use Pest\Support\InstalledPackages;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@@ -14,8 +14,7 @@ final readonly class Symfony implements WatchDefault
|
||||
{
|
||||
public function applicable(): bool
|
||||
{
|
||||
return class_exists(InstalledVersions::class)
|
||||
&& InstalledVersions::isInstalled('symfony/framework-bundle');
|
||||
return InstalledPackages::has('symfony/framework-bundle');
|
||||
}
|
||||
|
||||
public function defaults(string $projectRoot, string $testPath): array
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ final readonly class Git
|
||||
*/
|
||||
public function result(array $arguments, ?string $input = null): array
|
||||
{
|
||||
$process = new Process(['git', ...$arguments], $this->directory);
|
||||
$process = new Process(['git', ...$arguments], $this->directory, ['LC_ALL' => 'C', 'LANGUAGE' => '']);
|
||||
$process->setTimeout($this->timeout);
|
||||
|
||||
if ($input !== null) {
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Support;
|
||||
|
||||
use Composer\InstalledVersions;
|
||||
|
||||
final readonly class InstalledPackages
|
||||
{
|
||||
/**
|
||||
* @param array<int, array{root: array{install_path?: string}, versions: array<string, array{dev_requirement?: bool}>}> $installedSets
|
||||
*/
|
||||
public function __construct(private array $installedSets) {}
|
||||
|
||||
public static function fromComposer(): self
|
||||
{
|
||||
if (! class_exists(InstalledVersions::class)) {
|
||||
return new self([]);
|
||||
}
|
||||
|
||||
/** @var array<int, array{root: array{install_path?: string}, versions: array<string, array{dev_requirement?: bool}>}> $installedSets */
|
||||
$installedSets = InstalledVersions::getAllRawData();
|
||||
|
||||
return new self($installedSets);
|
||||
}
|
||||
|
||||
public static function has(string $package, bool $includeDevRequirements = true): bool
|
||||
{
|
||||
return self::fromComposer()->contains($package, $includeDevRequirements);
|
||||
}
|
||||
|
||||
public function contains(string $package, bool $includeDevRequirements = true): bool
|
||||
{
|
||||
foreach ($this->installedSets as $installedSet) {
|
||||
if ($this->isBundledInPhar($installedSet)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($installedSet['versions'][$package])) {
|
||||
return $includeDevRequirements || ($installedSet['versions'][$package]['dev_requirement'] ?? false) === false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{root: array{install_path?: string}} $installedSet
|
||||
*/
|
||||
private function isBundledInPhar(array $installedSet): bool
|
||||
{
|
||||
return str_starts_with($installedSet['root']['install_path'] ?? '', 'phar://');
|
||||
}
|
||||
}
|
||||
@@ -1326,6 +1326,7 @@
|
||||
✓ 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
|
||||
✓ init writes the plain stubs when only a tool bundled in a PHAR installs Laravel
|
||||
|
||||
PASS Tests\Features\Issue
|
||||
✓ it may be associated with an issue #1, #2
|
||||
@@ -2147,6 +2148,7 @@
|
||||
✓ 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
|
||||
✓ a __call wrapper already registered for file:// → it passes reads, includes and directory listings through it
|
||||
✓ 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
|
||||
@@ -2440,6 +2442,14 @@
|
||||
PASS Tests\Unit\Support\HigherOrderMessage
|
||||
✓ undefined method exceptions
|
||||
|
||||
PASS Tests\Unit\Support\InstalledPackages
|
||||
✓ it finds a package that the project installs
|
||||
✓ it ignores a package that only a tool bundled in a PHAR installs
|
||||
✓ it leaves out a development requirement when asked
|
||||
✓ it reads an installed set that has no install path
|
||||
✓ it reads the packages that Composer loaded
|
||||
✓ it is the only class of src that reads Composer packages
|
||||
|
||||
PASS Tests\Unit\Support\Reflection
|
||||
✓ it gets file name from closure
|
||||
✓ it gets property values
|
||||
@@ -2636,6 +2646,9 @@
|
||||
✓ 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\ParallelWorkerAutoload
|
||||
✓ loads the autoloader of the parent process in a parallel worker
|
||||
|
||||
PASS Tests\Visual\Shard
|
||||
✓ an empty shard runs no tests with dataset "sequential"
|
||||
✓ an empty shard runs no tests with dataset "parallel"
|
||||
@@ -2680,4 +2693,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, 1969 passed (4458 assertions)
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 39 skipped, 1978 passed (4476 assertions)
|
||||
+63
-1
@@ -74,6 +74,23 @@ test('a missing tests directory does not crash while resolving tia state', funct
|
||||
}
|
||||
});
|
||||
|
||||
test('init writes the plain stubs when only a tool bundled in a PHAR installs Laravel', function (): void {
|
||||
$root = makeInitProject();
|
||||
|
||||
try {
|
||||
$toolLoader = makeLaravelToolPhar($root);
|
||||
|
||||
$process = runInitProjectWithPhpOptions(['-d', 'auto_prepend_file='.$toolLoader], $root, '--init');
|
||||
|
||||
expect($process->getExitCode())->toBe(0)
|
||||
->and(file_get_contents($root.DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'Pest.php'))
|
||||
->toContain("require_once __DIR__.'/TestCase.php';")
|
||||
->not->toContain('RefreshDatabase');
|
||||
} finally {
|
||||
removeInitProject($root);
|
||||
}
|
||||
})->skipOnWindows();
|
||||
|
||||
function makeInitProject(): string
|
||||
{
|
||||
$root = sys_get_temp_dir().DIRECTORY_SEPARATOR.'pest-init-'.bin2hex(random_bytes(4));
|
||||
@@ -134,10 +151,55 @@ PHP);
|
||||
return $root;
|
||||
}
|
||||
|
||||
function makeLaravelToolPhar(string $root): string
|
||||
{
|
||||
$phar = $root.DIRECTORY_SEPARATOR.'tool.phar';
|
||||
|
||||
$build = new Process([
|
||||
PHP_BINARY,
|
||||
'-d',
|
||||
'phar.readonly=0',
|
||||
'-r',
|
||||
<<<'PHP'
|
||||
$phar = new Phar($argv[1]);
|
||||
$phar->addFromString('vendor/composer/installed.php', <<<'INSTALLED'
|
||||
<?php
|
||||
|
||||
return [
|
||||
'root' => ['name' => 'tool/dumper', 'install_path' => __DIR__.'/../../'],
|
||||
'versions' => ['laravel/framework' => ['pretty_version' => 'v12.0.0', 'version' => '12.0.0.0', 'dev_requirement' => false]],
|
||||
];
|
||||
INSTALLED);
|
||||
$phar->setStub('<?php __HALT_COMPILER();');
|
||||
PHP,
|
||||
$phar,
|
||||
]);
|
||||
|
||||
$build->mustRun();
|
||||
|
||||
$loader = $root.DIRECTORY_SEPARATOR.'tool-loader.php';
|
||||
|
||||
file_put_contents($loader, sprintf(
|
||||
"<?php\n\nrequire_once %s;\n\n(new Composer\\Autoload\\ClassLoader(%s))->register();\n",
|
||||
var_export(dirname(__DIR__, 2).DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'composer'.DIRECTORY_SEPARATOR.'ClassLoader.php', true),
|
||||
var_export('phar://'.$phar.'/vendor', true),
|
||||
));
|
||||
|
||||
return $loader;
|
||||
}
|
||||
|
||||
function runInitProject(string $root, string ...$command): Process
|
||||
{
|
||||
return runInitProjectWithPhpOptions([], $root, ...$command);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, string> $phpOptions
|
||||
*/
|
||||
function runInitProjectWithPhpOptions(array $phpOptions, string $root, string ...$command): Process
|
||||
{
|
||||
$process = new Process(
|
||||
[PHP_BINARY, 'run.php', ...$command],
|
||||
[PHP_BINARY, ...$phpOptions, 'run.php', ...$command],
|
||||
$root,
|
||||
[
|
||||
'PEST_NO_SUPPORT' => 'true',
|
||||
|
||||
@@ -179,6 +179,19 @@ test('tia still requires git', function (): void {
|
||||
->and($result->exitCode)->not->toBe(0);
|
||||
})->skipOnWindows();
|
||||
|
||||
test('tia still requires git when git speaks another language', function (): void {
|
||||
$project = Project::withoutGit();
|
||||
|
||||
$result = $project->pestWithEnvironment($project->path(), [
|
||||
'LC_ALL' => 'es_ES.UTF-8',
|
||||
'LANG' => 'es_ES.UTF-8',
|
||||
'LANGUAGE' => 'es',
|
||||
], '--tia');
|
||||
|
||||
expect($result->output)->toContain('The [Tia mode] feature requires [git].')
|
||||
->and($result->exitCode)->toBe(1, $result->describe());
|
||||
})->skipOnWindows();
|
||||
|
||||
test('a failing git shows its own error instead of asking for git', function (): void {
|
||||
$project = Project::make('master');
|
||||
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Fixtures\Tia;
|
||||
|
||||
use Closure;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class CallForwardingFileWrapper
|
||||
{
|
||||
/**
|
||||
* @var resource|null
|
||||
*/
|
||||
public mixed $context = null;
|
||||
|
||||
/**
|
||||
* @var resource
|
||||
*/
|
||||
private mixed $resource;
|
||||
|
||||
public static function enable(): void
|
||||
{
|
||||
stream_wrapper_unregister('file');
|
||||
stream_wrapper_register('file', self::class);
|
||||
}
|
||||
|
||||
public static function disable(): void
|
||||
{
|
||||
stream_wrapper_restore('file');
|
||||
}
|
||||
|
||||
public function stream_open(string $path, string $mode, int $options): bool
|
||||
{
|
||||
$resource = $this->native(fn (): mixed => @fopen($path, $mode, ($options & STREAM_USE_PATH) !== 0));
|
||||
|
||||
if ($resource === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->resource = $resource;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function dir_opendir(string $path): bool
|
||||
{
|
||||
$resource = $this->native(fn (): mixed => @opendir($path));
|
||||
|
||||
if ($resource === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->resource = $resource;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, mixed> $arguments
|
||||
*/
|
||||
public function __call(string $method, array $arguments): mixed
|
||||
{
|
||||
return match ($method) {
|
||||
'stream_read' => fread($this->resource, max(1, (int) $arguments[0])),
|
||||
'stream_write' => fwrite($this->resource, (string) $arguments[0]),
|
||||
'stream_eof' => feof($this->resource),
|
||||
'stream_close' => fclose($this->resource),
|
||||
'stream_stat' => fstat($this->resource),
|
||||
'dir_readdir' => readdir($this->resource),
|
||||
'dir_closedir' => closedir($this->resource) ?? true,
|
||||
'url_stat' => $this->native(fn (): mixed => @stat((string) $arguments[0])),
|
||||
'unlink' => $this->native(fn (): bool => @unlink((string) $arguments[0])),
|
||||
default => false,
|
||||
};
|
||||
}
|
||||
|
||||
private function native(Closure $callback): mixed
|
||||
{
|
||||
self::disable();
|
||||
|
||||
try {
|
||||
return $callback();
|
||||
} finally {
|
||||
self::enable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -423,29 +423,12 @@ final class Project
|
||||
|
||||
public function scaffoldVendor(string $directory): void
|
||||
{
|
||||
$pestRoot = dirname(__DIR__, 3);
|
||||
$pest = $directory.'/vendor/pestphp/pest';
|
||||
$this->scaffoldPest($directory.'/vendor/pestphp/pest', $directory.'/vendor', '/pestphp/pest/src');
|
||||
}
|
||||
|
||||
foreach (['src', 'overrides', 'resources', 'stubs'] as $tree) {
|
||||
self::mirror($pestRoot.'/'.$tree, $pest.'/'.$tree);
|
||||
}
|
||||
|
||||
foreach (['pest', 'worker.php'] as $binary) {
|
||||
self::mirror($pestRoot.'/bin/'.$binary, $pest.'/bin/'.$binary);
|
||||
}
|
||||
|
||||
self::mirror($pestRoot.'/composer.json', $pest.'/composer.json');
|
||||
|
||||
file_put_contents($directory.'/vendor/autoload.php', sprintf(
|
||||
"<?php\n\n\$loader = require %s;\n\$loader->addPsr4('Pest\\\\', __DIR__.'/pestphp/pest/src', true);\n\nreturn \$loader;\n",
|
||||
var_export($pestRoot.'/vendor/autoload.php', true),
|
||||
));
|
||||
|
||||
if (! is_dir($directory.'/vendor/bin') && ! @mkdir($directory.'/vendor/bin', 0755, true)) {
|
||||
throw new RuntimeException(sprintf('Unable to create [%s].', $directory.'/vendor/bin'));
|
||||
}
|
||||
|
||||
self::mirror($pestRoot.'/vendor/pest-plugins.json', $directory.'/vendor/pest-plugins.json');
|
||||
public function scaffoldCheckout(string $directory): void
|
||||
{
|
||||
$this->scaffoldPest($directory, $directory.'/vendor', '/../src');
|
||||
}
|
||||
|
||||
public function destroy(): void
|
||||
@@ -512,6 +495,33 @@ final class Project
|
||||
return $project;
|
||||
}
|
||||
|
||||
private function scaffoldPest(string $pest, string $vendor, string $sourceFromVendor): void
|
||||
{
|
||||
$pestRoot = dirname(__DIR__, 3);
|
||||
|
||||
foreach (['src', 'overrides', 'resources', 'stubs'] as $tree) {
|
||||
self::mirror($pestRoot.'/'.$tree, $pest.'/'.$tree);
|
||||
}
|
||||
|
||||
foreach (['pest', 'worker.php'] as $binary) {
|
||||
self::mirror($pestRoot.'/bin/'.$binary, $pest.'/bin/'.$binary);
|
||||
}
|
||||
|
||||
self::mirror($pestRoot.'/composer.json', $pest.'/composer.json');
|
||||
|
||||
if (! is_dir($vendor.'/bin') && ! @mkdir($vendor.'/bin', 0755, true)) {
|
||||
throw new RuntimeException(sprintf('Unable to create [%s].', $vendor.'/bin'));
|
||||
}
|
||||
|
||||
file_put_contents($vendor.'/autoload.php', sprintf(
|
||||
"<?php\n\n\$loader = require %s;\n\$loader->addPsr4('Pest\\\\', __DIR__.%s, true);\n\nreturn \$loader;\n",
|
||||
var_export($pestRoot.'/vendor/autoload.php', true),
|
||||
var_export($sourceFromVendor, true),
|
||||
));
|
||||
|
||||
self::mirror($pestRoot.'/vendor/pest-plugins.json', $vendor.'/pest-plugins.json');
|
||||
}
|
||||
|
||||
private static function mirror(string $from, string $to): void
|
||||
{
|
||||
if (is_dir($from)) {
|
||||
|
||||
@@ -7,6 +7,7 @@ use Pest\Plugins\Tia\ReadCapture;
|
||||
use Pest\Plugins\Tia\Recorder;
|
||||
use Pest\Plugins\Tia\WatchPatterns;
|
||||
use Pest\Support\Container;
|
||||
use Tests\Fixtures\Tia\CallForwardingFileWrapper;
|
||||
use Tests\Fixtures\Tia\LoggingFileWrapper;
|
||||
|
||||
/**
|
||||
@@ -403,6 +404,40 @@ describe('a wrapper already registered for file://', function (): void {
|
||||
});
|
||||
});
|
||||
|
||||
describe('a __call wrapper already registered for file://', function (): void {
|
||||
beforeEach(function (): void {
|
||||
CallForwardingFileWrapper::enable();
|
||||
});
|
||||
|
||||
afterEach(function (): void {
|
||||
CallForwardingFileWrapper::disable();
|
||||
});
|
||||
|
||||
it('passes reads, includes and directory listings through it', function (): void {
|
||||
$source = (string) realpath(dirname(__DIR__, 4).'/src/Plugins/Tia/ReadCapture.php');
|
||||
$path = __DIR__.'/read-capture-'.bin2hex(random_bytes(8)).'.php';
|
||||
file_put_contents($path, "<?php\n\nreturn 1;\n");
|
||||
|
||||
$results = [];
|
||||
|
||||
try {
|
||||
$links = tiaReadCaptureLinks(function () use ($source, $path, &$results): void {
|
||||
$results['read'] = file_get_contents($source) !== '';
|
||||
$results['include'] = require $path;
|
||||
$results['scandir'] = in_array(basename($path), (array) scandir(__DIR__), true);
|
||||
});
|
||||
} finally {
|
||||
@unlink($path);
|
||||
}
|
||||
|
||||
expect($results)->toBe([
|
||||
'read' => true,
|
||||
'include' => 1,
|
||||
'scandir' => true,
|
||||
])->and($links)->toBe([$source]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('withoutReadCapture()', function (): void {
|
||||
beforeEach(function (): void {
|
||||
Container::getInstance()->add(WatchPatterns::class, new WatchPatterns);
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Pest\Support\InstalledPackages;
|
||||
|
||||
$project = [
|
||||
'root' => ['install_path' => '/project/vendor/composer/../../'],
|
||||
'versions' => [
|
||||
'pestphp/pest' => ['dev_requirement' => true],
|
||||
'symfony/console' => ['dev_requirement' => false],
|
||||
],
|
||||
];
|
||||
|
||||
$pharTool = [
|
||||
'root' => ['install_path' => 'phar:///tools/dump.phar/vendor/composer/../../'],
|
||||
'versions' => [
|
||||
'laravel/framework' => ['dev_requirement' => false],
|
||||
],
|
||||
];
|
||||
|
||||
it('finds a package that the project installs', function () use ($project, $pharTool): void {
|
||||
$packages = new InstalledPackages([$pharTool, $project]);
|
||||
|
||||
expect($packages->contains('symfony/console'))->toBeTrue()
|
||||
->and($packages->contains('pestphp/pest'))->toBeTrue();
|
||||
});
|
||||
|
||||
it('ignores a package that only a tool bundled in a PHAR installs', function () use ($project, $pharTool): void {
|
||||
$packages = new InstalledPackages([$pharTool, $project]);
|
||||
|
||||
expect($packages->contains('laravel/framework'))->toBeFalse()
|
||||
->and($packages->contains('laravel/framework', false))->toBeFalse();
|
||||
});
|
||||
|
||||
it('leaves out a development requirement when asked', function () use ($project): void {
|
||||
$packages = new InstalledPackages([$project]);
|
||||
|
||||
expect($packages->contains('pestphp/pest', false))->toBeFalse()
|
||||
->and($packages->contains('symfony/console', false))->toBeTrue();
|
||||
});
|
||||
|
||||
it('reads an installed set that has no install path', function (): void {
|
||||
$packages = new InstalledPackages([
|
||||
['root' => [], 'versions' => ['laravel/framework' => ['dev_requirement' => false]]],
|
||||
]);
|
||||
|
||||
expect($packages->contains('laravel/framework'))->toBeTrue()
|
||||
->and($packages->contains('symfony/console'))->toBeFalse();
|
||||
});
|
||||
|
||||
it('reads the packages that Composer loaded', function (): void {
|
||||
expect(InstalledPackages::has('pestphp/pest'))->toBeTrue()
|
||||
->and(InstalledPackages::has('pestphp/pest-plugin-that-does-not-exist'))->toBeFalse();
|
||||
});
|
||||
|
||||
it('is the only class of src that reads Composer packages', function (): void {
|
||||
$source = dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'src';
|
||||
$readers = [];
|
||||
|
||||
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, FilesystemIterator::SKIP_DOTS)) as $file) {
|
||||
if ($file->getExtension() === 'php' && str_contains((string) file_get_contents($file->getPathname()), 'InstalledVersions')) {
|
||||
$readers[] = substr($file->getPathname(), strlen($source) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
expect($readers)->toBe(['Support'.DIRECTORY_SEPARATOR.'InstalledPackages.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, 1842 passed (3933 assertions)';
|
||||
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 31 skipped, 1850 passed (3949 assertions)';
|
||||
|
||||
expect($output)
|
||||
->toContain("Tests: {$expected}")
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
use Tests\Fixtures\Tia\Project;
|
||||
|
||||
test('loads the autoloader of the parent process in a parallel worker', function (): void {
|
||||
$project = Project::withoutGit();
|
||||
|
||||
try {
|
||||
$checkout = $project->path('checkout');
|
||||
$project->scaffoldCheckout($checkout);
|
||||
|
||||
$project->write('vendor/autoload.php', <<<'DECOY'
|
||||
<?php
|
||||
|
||||
fwrite(STDERR, 'decoy autoloader');
|
||||
|
||||
exit(1);
|
||||
DECOY);
|
||||
|
||||
$project->write('checkout/phpunit.xml', <<<'CONFIGURATION'
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit bootstrap="vendor/autoload.php" cacheDirectory=".phpunit.cache"/>
|
||||
CONFIGURATION);
|
||||
|
||||
$test = 'checkout/tests/WorkerAutoloadTest.php';
|
||||
$project->write($test, <<<'FIXTURE'
|
||||
<?php
|
||||
|
||||
test('runs in a worker with the autoloader of the checkout', function (): void {
|
||||
expect($_SERVER['PEST_PARALLEL'] ?? null)->toBe('1')
|
||||
->and(realpath((new ReflectionClass(Pest\TestSuite::class))->getFileName()))->toStartWith(dirname(__DIR__).DIRECTORY_SEPARATOR.'src');
|
||||
});
|
||||
FIXTURE);
|
||||
|
||||
$process = new Process(
|
||||
[PHP_BINARY, $checkout.'/bin/pest', '--configuration='.$project->path('checkout/phpunit.xml'), '--colors=never', $project->path($test), '--parallel', '--processes=2'],
|
||||
$checkout,
|
||||
['PARATEST' => '0', 'PAO_DISABLE' => '1'],
|
||||
);
|
||||
|
||||
expect($process->run())->toBe(0, $process->getOutput().$process->getErrorOutput())
|
||||
->and($process->getOutput())->toContain('1 passed (2 assertions)');
|
||||
} finally {
|
||||
Project::destroyAll();
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user