Skip to content

Commit 6c883aa

Browse files
authored
Merge pull request #5 from thimarsola/test/non-final-class-higher-order-regression
test: cover non-final class branch of the higher-order property crash
2 parents 0b7e3ce + 5415122 commit 6c883aa

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Type\Fixtures;
6+
7+
abstract class NonFinalObject
8+
{
9+
public string $title = '';
10+
}

tests/Type/data/higher-order-expectations.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace HigherOrderExpectations;
66

77
use Tests\Type\Fixtures\MagicPropertyObject;
8+
use Tests\Type\Fixtures\NonFinalObject;
89
use Tests\Type\Fixtures\Post;
910

1011
use function PHPStan\Testing\assertType;
@@ -123,6 +124,24 @@ function testMagicPropertyChainDoesNotCrash(): void
123124
assertType('Pest\Expectations\HigherOrderExpectation<Pest\Expectation<Tests\Type\Fixtures\MagicPropertyObject>, Tests\Type\Fixtures\MagicPropertyObject>', $result);
124125
}
125126

127+
function testNonFinalClassMissingPropertyDoesNotCrash(NonFinalObject $object): void
128+
{
129+
$result = expect($object)->name;
130+
assertType('Pest\Expectations\HigherOrderExpectation<Pest\Expectation<Tests\Type\Fixtures\NonFinalObject>, mixed>', $result);
131+
}
132+
133+
function testNonFinalClassMissingPropertyChainDoesNotCrash(NonFinalObject $object): void
134+
{
135+
$result = expect($object)->name->toBe('Nuno');
136+
assertType('Pest\Expectations\HigherOrderExpectation<Pest\Expectation<Tests\Type\Fixtures\NonFinalObject>, Tests\Type\Fixtures\NonFinalObject>', $result);
137+
}
138+
139+
function testNonFinalClassRealPropertyStillResolves(NonFinalObject $object): void
140+
{
141+
$result = expect($object)->title;
142+
assertType('Pest\Expectations\HigherOrderExpectation<Pest\Expectation<Tests\Type\Fixtures\NonFinalObject>, string>', $result);
143+
}
144+
126145
function testUnionWithoutClassPropertyDoesNotCrash(): void
127146
{
128147
/** @var array<string, mixed>|object|null $payload */

0 commit comments

Comments
 (0)