mirror of
https://github.com/pestphp/pest.git
synced 2026-12-03 22:45:06 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 425cd93e27 | |||
| 5b2293f67a | |||
| 7d49828491 | |||
| 3223d50607 |
@@ -235,8 +235,8 @@ final class TestCaseMethodFactory
|
||||
$attributesCode
|
||||
public function $methodName(...\$arguments)
|
||||
{
|
||||
if (count(\$arguments) === 1 && \$arguments[0] instanceof __PestDatasetProviderError) {
|
||||
throw \$arguments[0]->getPrevious() ?? \$arguments[0];
|
||||
if (count(\$arguments) === 1 && \$arguments[array_key_first(\$arguments)] instanceof __PestDatasetProviderError) {
|
||||
throw \$arguments[array_key_first(\$arguments)]->getPrevious() ?? \$arguments[array_key_first(\$arguments)];
|
||||
}
|
||||
|
||||
return \$this->__runTest(
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ namespace Pest;
|
||||
|
||||
function version(): string
|
||||
{
|
||||
return '4.7.7';
|
||||
return '4.7.8';
|
||||
}
|
||||
|
||||
function testDirectory(string $file = ''): string
|
||||
|
||||
+38
-10
@@ -50,12 +50,14 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
*/
|
||||
public bool $showOnlyCovered = false;
|
||||
|
||||
private string $coveragePath;
|
||||
|
||||
/**
|
||||
* Creates a new Plugin instance.
|
||||
*/
|
||||
public function __construct(private readonly OutputInterface $output)
|
||||
{
|
||||
// ..
|
||||
$this->coveragePath = \Pest\Support\Coverage::getPath();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,12 +79,6 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
return false;
|
||||
}))];
|
||||
|
||||
$originals = array_flip($originals);
|
||||
foreach ($arguments as $argument) {
|
||||
unset($originals[$argument]);
|
||||
}
|
||||
$originals = array_flip($originals);
|
||||
|
||||
$inputs = [];
|
||||
$inputs[] = new InputOption(self::COVERAGE_OPTION, null, InputOption::VALUE_NONE);
|
||||
$inputs[] = new InputOption(self::MIN_OPTION, null, InputOption::VALUE_REQUIRED);
|
||||
@@ -90,10 +86,26 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
$inputs[] = new InputOption(self::ONLY_COVERED_OPTION, null, InputOption::VALUE_NONE);
|
||||
|
||||
$input = new ArgvInput($arguments, new InputDefinition($inputs));
|
||||
$coveragePathProvided = false;
|
||||
|
||||
if ((bool) $input->getOption(self::COVERAGE_OPTION)) {
|
||||
$this->coverage = true;
|
||||
$originals[] = '--coverage-php';
|
||||
$originals[] = \Pest\Support\Coverage::getPath();
|
||||
|
||||
foreach ($originals as $index => $original) {
|
||||
if (Str::startsWith($original, '--coverage-php=')) {
|
||||
$this->coveragePath = Str::after($original, '--coverage-php=');
|
||||
$coveragePathProvided = true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if ($original === '--coverage-php' && isset($originals[$index + 1])) {
|
||||
$this->coveragePath = $originals[$index + 1];
|
||||
$coveragePathProvided = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (! \Pest\Support\Coverage::isAvailable()) {
|
||||
if (\Pest\Support\Coverage::usingXdebug()) {
|
||||
@@ -114,6 +126,17 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
}
|
||||
}
|
||||
|
||||
$originals = array_flip($originals);
|
||||
foreach ($arguments as $argument) {
|
||||
unset($originals[$argument]);
|
||||
}
|
||||
$originals = array_flip($originals);
|
||||
|
||||
if ((bool) $input->getOption(self::COVERAGE_OPTION) && ! $coveragePathProvided) {
|
||||
$originals[] = '--coverage-php';
|
||||
$originals[] = $this->coveragePath;
|
||||
}
|
||||
|
||||
if ($input->getOption(self::MIN_OPTION) !== null) {
|
||||
/** @var int|float $minOption */
|
||||
$minOption = $input->getOption(self::MIN_OPTION);
|
||||
@@ -156,7 +179,12 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$coverage = \Pest\Support\Coverage::report($this->output, $this->compact, $this->showOnlyCovered);
|
||||
$coverage = \Pest\Support\Coverage::report($this->output, $this->compact, $this->showOnlyCovered, $this->coveragePath);
|
||||
|
||||
if ($this->coveragePath === \Pest\Support\Coverage::getPath()) {
|
||||
unlink($this->coveragePath);
|
||||
}
|
||||
|
||||
$exitCode = (int) ($coverage < $this->coverageMin);
|
||||
|
||||
if ($exitCode === 0 && $this->coverageExactly !== null) {
|
||||
|
||||
@@ -74,9 +74,9 @@ final class Coverage
|
||||
* Reports the code coverage report to the
|
||||
* console and returns the result in float.
|
||||
*/
|
||||
public static function report(OutputInterface $output, bool $compact = false, bool $showOnlyCovered = false): float
|
||||
public static function report(OutputInterface $output, bool $compact, bool $showOnlyCovered, string $reportPath): float
|
||||
{
|
||||
if (! file_exists($reportPath = self::getPath())) {
|
||||
if (! file_exists($reportPath)) {
|
||||
if (self::usingXdebug()) {
|
||||
$output->writeln(
|
||||
" <fg=black;bg=yellow;options=bold> WARN </> Unable to get coverage using Xdebug. Did you set <href=https://xdebug.org/docs/code_coverage#mode>Xdebug's coverage mode</>?</>",
|
||||
@@ -90,7 +90,6 @@ final class Coverage
|
||||
|
||||
/** @var CodeCoverage $codeCoverage */
|
||||
$codeCoverage = require $reportPath;
|
||||
unlink($reportPath);
|
||||
|
||||
$totalCoverage = $codeCoverage->getReport()->percentageOfExecutedLines();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
Pest Testing Framework 4.7.7.
|
||||
Pest Testing Framework 4.7.8.
|
||||
|
||||
USAGE: pest <file> [options]
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
|
||||
Pest Testing Framework 4.7.7.
|
||||
Pest Testing Framework 4.7.8.
|
||||
|
||||
|
||||
@@ -76,6 +76,7 @@
|
||||
WARN Tests\Features\Coverage
|
||||
✓ it has plugin
|
||||
- it adds coverage if --coverage exist → Coverage is not available
|
||||
- it keeps the explicit coverage path when --coverage exists → Coverage is not available
|
||||
✓ it adds coverage if --min exist
|
||||
✓ it generates coverage based on file input
|
||||
|
||||
@@ -275,6 +276,7 @@
|
||||
✓ dataset items can mix named and sequential styles with ('Taylor', 'taylor@laravel.com')
|
||||
✓ dataset items can mix named and sequential styles with ('James', 'james@laravel.com') #1
|
||||
✓ dataset items can mix named and sequential styles with ('James', 'james@laravel.com') #2
|
||||
✓ named parameters work with a single argument with ('Taylor')
|
||||
|
||||
PASS Tests\Features\Depends
|
||||
✓ first
|
||||
@@ -1904,5 +1906,4 @@
|
||||
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, 35 skipped, 1296 passed (2979 assertions)
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 36 skipped, 1297 passed (2980 assertions)
|
||||
|
||||
@@ -19,6 +19,26 @@ it('adds coverage if --coverage exist', function () {
|
||||
->and($plugin->coverage)->toBeTrue();
|
||||
})->skip(! Coverage::isAvailable() || ! function_exists('xdebug_info') || ! in_array('coverage', xdebug_info('mode'), true), 'Coverage is not available');
|
||||
|
||||
it('keeps the explicit coverage path when --coverage exists', function () {
|
||||
foreach ([
|
||||
['--coverage-php=test.cov'],
|
||||
['--coverage-php', 'test.cov'],
|
||||
] as $coverageArguments) {
|
||||
$plugin = new CoveragePlugin(new ConsoleOutput);
|
||||
|
||||
$arguments = $plugin->handleArguments([
|
||||
'--coverage',
|
||||
'--coverage-text',
|
||||
...$coverageArguments,
|
||||
]);
|
||||
|
||||
expect(array_values($arguments))->toEqual([
|
||||
'--coverage-text',
|
||||
...$coverageArguments,
|
||||
]);
|
||||
}
|
||||
})->skip(! Coverage::isAvailable() || ! function_exists('xdebug_info') || ! in_array('coverage', xdebug_info('mode'), true), 'Coverage is not available');
|
||||
|
||||
it('adds coverage if --min exist', function () {
|
||||
$plugin = new CoveragePlugin(new ConsoleOutput);
|
||||
expect($plugin->coverageMin)->toEqual(0.0)
|
||||
|
||||
@@ -542,3 +542,9 @@ test('dataset items can mix named and sequential styles', function (string $name
|
||||
['James', 'james@laravel.com'],
|
||||
['James', 'email' => 'james@laravel.com'],
|
||||
]);
|
||||
|
||||
test('named parameters work with a single argument', function (string $name) {
|
||||
expect($name)->toBe('Taylor');
|
||||
})->with([
|
||||
['name' => 'Taylor'],
|
||||
]);
|
||||
|
||||
@@ -24,13 +24,13 @@ test('parallel', function () use ($run) {
|
||||
$file = file_get_contents(__FILE__);
|
||||
$file = preg_replace(
|
||||
'/\$expected = \'.*?\';/',
|
||||
"\$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1280 passed (2928 assertions)';",
|
||||
"\$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1281 passed (2929 assertions)';",
|
||||
$file,
|
||||
);
|
||||
file_put_contents(__FILE__, $file);
|
||||
}
|
||||
|
||||
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1280 passed (2928 assertions)';
|
||||
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1281 passed (2929 assertions)';
|
||||
|
||||
expect($output)
|
||||
->toContain("Tests: {$expected}")
|
||||
|
||||
Reference in New Issue
Block a user