pestphp / pest

Pest is an elegant PHP testing Framework with a focus on simplicity, meticulously designed to bring back the joy of testing in PHP.
https://pestphp.com
MIT License
9.6k stars 357 forks source link

[Bug]: Multiple covers calls do not work on a `describe` block #937

Closed tminich closed 2 months ago

tminich commented 1 year ago

What Happened

Chaining multiple ->coversClass calls work fine on an it block, but only one works on a describe block. Even worse, as soon as you chain more than one, none work.

How to Reproduce

describe('Test', function (): void {
    it('should work', function (): void {
        expect(value: true)->toBeTrue();
    });
})->coversClass(\PHPUnit\Framework\TestCase::class)
  ->coversClass(\Orchestra\Testbench\TestCase::class)
;

describe('Other', function (): void {
    it('should work', function (): void {
        expect(value: true)->toBeTrue();
    });
})->coversClass(\Tests\TestCase::class)
;

describe('Third', function (): void {
    it('should work', function (): void {
        expect(value: true)->toBeTrue();
    });
})->coversClass(\Laravel\Dusk\TestCase::class)
;

Dumping the generated test class gives this (abbreviated):

namespace P\Tests\php\Unit\Test;

use Pest\Repositories\DatasetsRepository as __PestDatasets;
use Pest\TestSuite as __PestTestSuite;

/**
 * @testdox C:\devel\module-laravel-app\tests\php\Unit\Test\BTest.php
 */

#[\PHPUnit\Framework\Attributes\CoversClass(\Tests\TestCase::class)]
#[\PHPUnit\Framework\Attributes\CoversClass(\Laravel\Dusk\TestCase::class)]
#[\AllowDynamicProperties]
final class BTest extends \PHPUnit\Framework\TestCase implements \Pest\Contracts\HasPrintableTestCaseName {
    use \Pest\Concerns\Testable, \Pest\Concerns\Expectable, \Pest\Arch\Concerns\Architectable;
    // ...
}

As can be seen the chained calls are ignored while the single calls work fine and get accumulated properly.

Sample Repository

No response

Pest Version

2.16.0

PHP Version

8.2.9

Operation System

Windows

Notes

No response

nunomaduro commented 2 months ago

this is fixed on Pest 3. Not sure if should be fixed on Pest 2. Sorry!