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.12k stars 319 forks source link

[Bug]: toExtend returns turn for non-existent classes #1052

Open tmbenhura opened 6 months ago

tmbenhura commented 6 months ago

What Happened

When I use expect(RectangleBuilder::class)->toExtend(ShapeBuilder::class);

it returns true, when the class for RectangleBuilder does not yet exist. Upon creating a plain class for RectangleBuilder (without the extends clause) it will now return false.

In my tracing, in the Pest\Expectation class' toExtend method, none of its callbacks are invoked when the class doesn't exist. But, they are called if the class does exist.

How to Reproduce

Existing code:

namespace Builders;
abstract class ShapeBuilder { }

Test:

use Builders\RectangleBuilder; // Exists
use Builders\ShapeBuilder; // File and class do NOT EXIST yet

test('rectangle builder extends shape builder', function () {
    expect(RectangleBuilder::class)->toExtend(ShapeBuilder::class); // True
    expect("")->toExtend(ShapeBuilder::class); // True
})->only();

Sample Repository

No response

Pest Version

2.30.0

PHP Version

8.1.2

Operation System

Windows

Notes

No response