mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
Merge branch 'pestphp:2.x' into 2.x
This commit is contained in:
@ -21,7 +21,7 @@
|
||||
"nunomaduro/collision": "^7.0.5",
|
||||
"nunomaduro/termwind": "^1.15.1",
|
||||
"pestphp/pest-plugin": "^2.0.0",
|
||||
"phpunit/phpunit": "^10.0.11"
|
||||
"phpunit/phpunit": "^10.0.12"
|
||||
},
|
||||
"conflict": {
|
||||
"brianium/paratest": "<7.0.6"
|
||||
@ -71,7 +71,7 @@
|
||||
"test:types": "phpstan analyse --ansi --memory-limit=-1 --debug",
|
||||
"test:unit": "php bin/pest --colors=always --exclude-group=integration --compact",
|
||||
"test:inline": "php bin/pest --colors=always --configuration=phpunit.inline.xml",
|
||||
"test:parallel": "php bin/pest --colors=always --exclude-group=integration --parallel",
|
||||
"test:parallel": "php bin/pest --colors=always --exclude-group=integration --parallel --processes=10",
|
||||
"test:integration": "php bin/pest --colors=always --group=integration -v",
|
||||
"update:snapshots": "REBUILD_SNAPSHOTS=true php bin/pest --colors=always",
|
||||
"test": [
|
||||
|
||||
@ -79,6 +79,11 @@ final class DefaultResultCache implements ResultCache
|
||||
*/
|
||||
private array $defects = [];
|
||||
|
||||
/**
|
||||
* @psalm-var array<string, TestStatus>
|
||||
*/
|
||||
private array $currentDefects = [];
|
||||
|
||||
/**
|
||||
* @psalm-var array<string, float>
|
||||
*/
|
||||
@ -96,6 +101,7 @@ final class DefaultResultCache implements ResultCache
|
||||
public function setStatus(string $id, TestStatus $status): void
|
||||
{
|
||||
if ($status->isFailure() || $status->isError()) {
|
||||
$this->currentDefects[$id] = $status;
|
||||
$this->defects[$id] = $status;
|
||||
}
|
||||
}
|
||||
@ -107,6 +113,10 @@ final class DefaultResultCache implements ResultCache
|
||||
|
||||
public function setTime(string $id, float $time): void
|
||||
{
|
||||
if (! isset($this->currentDefects[$id])) {
|
||||
unset($this->defects[$id]);
|
||||
}
|
||||
|
||||
$this->times[$id] = $time;
|
||||
}
|
||||
|
||||
|
||||
@ -4,11 +4,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins;
|
||||
|
||||
use Composer\InstalledVersions;
|
||||
use Pest\Console\Thanks;
|
||||
use Pest\Contracts\Plugins\HandlesArguments;
|
||||
use Pest\Support\View;
|
||||
use Pest\TestSuite;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@ -26,7 +28,9 @@ final class Init implements HandlesArguments
|
||||
private const STUBS = [
|
||||
'phpunit.xml' => 'phpunit.xml',
|
||||
'Pest.php' => 'tests/Pest.php',
|
||||
'ExampleTest.php' => 'tests/ExampleTest.php',
|
||||
'TestCase.php' => 'tests/TestCase.php',
|
||||
'Unit/ExampleTest.php' => 'tests/Unit/ExampleTest.php',
|
||||
'Feature/ExampleTest.php' => 'tests/Feature/ExampleTest.php',
|
||||
];
|
||||
|
||||
/**
|
||||
@ -59,16 +63,19 @@ final class Init implements HandlesArguments
|
||||
|
||||
private function init(): void
|
||||
{
|
||||
if ($this->isLaravelInstalled()) {
|
||||
exit($this->initLaravel());
|
||||
}
|
||||
|
||||
$testsBaseDir = "{$this->testSuite->rootPath}/tests";
|
||||
|
||||
if (! is_dir($testsBaseDir)) {
|
||||
mkdir($testsBaseDir);
|
||||
}
|
||||
|
||||
$this->output->writeln([
|
||||
'',
|
||||
' <fg=white;bg=blue;options=bold> INFO </> Preparing tests directory.</>',
|
||||
'',
|
||||
View::render('components.badge', [
|
||||
'type' => 'INFO',
|
||||
'content' => 'Preparing tests directory.',
|
||||
]);
|
||||
|
||||
foreach (self::STUBS as $from => $to) {
|
||||
@ -98,4 +105,43 @@ final class Init implements HandlesArguments
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
private function initLaravel(): int
|
||||
{
|
||||
$command = [
|
||||
'composer', 'require',
|
||||
'pestphp/pest-plugin-laravel 2.x-dev',
|
||||
'--dev',
|
||||
];
|
||||
|
||||
$result = (new Process($command, $this->testSuite->rootPath, ['COMPOSER_MEMORY_LIMIT' => '-1']))
|
||||
->setTimeout(null)
|
||||
->run(function ($type, $output): void {
|
||||
$this->output->write($output);
|
||||
});
|
||||
|
||||
if ($result > 0) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$command = [
|
||||
'php', 'artisan',
|
||||
'pest:install',
|
||||
'--ansi', '--no-interaction',
|
||||
];
|
||||
|
||||
return (new Process($command, $this->testSuite->rootPath, ['COMPOSER_MEMORY_LIMIT' => '-1']))
|
||||
->setTimeout(null)
|
||||
->run(function ($type, $output): void {
|
||||
$this->output->write($output);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if laravel is installed through Composer
|
||||
*/
|
||||
private function isLaravelInstalled(): bool
|
||||
{
|
||||
return InstalledVersions::isInstalled('laravel/laravel');
|
||||
}
|
||||
}
|
||||
|
||||
@ -296,6 +296,30 @@ final class WrapperRunner implements RunnerInterface
|
||||
);
|
||||
}
|
||||
|
||||
$testResultSum = new TestResult(
|
||||
$testResultSum->numberOfTests(),
|
||||
$testResultSum->numberOfTestsRun(),
|
||||
$testResultSum->numberOfAssertions(),
|
||||
$testResultSum->testErroredEvents(),
|
||||
$testResultSum->testFailedEvents(),
|
||||
$testResultSum->testConsideredRiskyEvents(),
|
||||
$testResultSum->testSuiteSkippedEvents(),
|
||||
$testResultSum->testSkippedEvents(),
|
||||
$testResultSum->testMarkedIncompleteEvents(),
|
||||
$testResultSum->testTriggeredDeprecationEvents(),
|
||||
$testResultSum->testTriggeredPhpDeprecationEvents(),
|
||||
$testResultSum->testTriggeredPhpunitDeprecationEvents(),
|
||||
$testResultSum->testTriggeredErrorEvents(),
|
||||
$testResultSum->testTriggeredNoticeEvents(),
|
||||
$testResultSum->testTriggeredPhpNoticeEvents(),
|
||||
$testResultSum->testTriggeredWarningEvents(),
|
||||
$testResultSum->testTriggeredPhpWarningEvents(),
|
||||
$testResultSum->testTriggeredPhpunitErrorEvents(),
|
||||
$testResultSum->testTriggeredPhpunitWarningEvents(),
|
||||
$testResultSum->testRunnerTriggeredDeprecationEvents(),
|
||||
array_values(array_filter($testResultSum->testRunnerTriggeredWarningEvents(), fn ($event): bool => ! str_contains($event->message(), 'No tests found'))),
|
||||
);
|
||||
|
||||
$this->printer->printResults(
|
||||
$testResultSum,
|
||||
$this->teamcityFiles,
|
||||
@ -305,7 +329,7 @@ final class WrapperRunner implements RunnerInterface
|
||||
$this->generateCodeCoverageReports();
|
||||
$this->generateLogs();
|
||||
|
||||
$exitcode = (new ShellExitCodeCalculator())->calculate(
|
||||
$exitCode = (new ShellExitCodeCalculator())->calculate(
|
||||
$this->options->configuration->failOnEmptyTestSuite(),
|
||||
$this->options->configuration->failOnRisky(),
|
||||
$this->options->configuration->failOnWarning(),
|
||||
@ -320,7 +344,7 @@ final class WrapperRunner implements RunnerInterface
|
||||
$this->clearFiles($this->teamcityFiles);
|
||||
$this->clearFiles($this->testdoxFiles);
|
||||
|
||||
return $exitcode;
|
||||
return $exitCode;
|
||||
}
|
||||
|
||||
private function generateCodeCoverageReports(): void
|
||||
|
||||
10
stubs/init/TestCase.php
Normal file
10
stubs/init/TestCase.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase as BaseTestCase;
|
||||
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
//
|
||||
}
|
||||
5
stubs/init/Unit/ExampleTest.php
Normal file
5
stubs/init/Unit/ExampleTest.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
test('example', function () {
|
||||
expect(true)->toBeTrue();
|
||||
});
|
||||
@ -917,4 +917,4 @@
|
||||
PASS Tests\Visual\Version
|
||||
✓ visual snapshot of help command output
|
||||
|
||||
Tests: 4 incomplete, 4 todos, 18 skipped, 634 passed (1559 assertions)
|
||||
Tests: 4 incomplete, 4 todos, 18 skipped, 634 passed (1560 assertions)
|
||||
@ -9,6 +9,8 @@ $run = function () {
|
||||
|
||||
$process->run();
|
||||
|
||||
expect($process->getExitCode())->toBe(0);
|
||||
|
||||
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user