-
-
Notifications
You must be signed in to change notification settings - Fork 290
Don't Generate Set or Unset on Proxy of Readonly Public Properties #957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 3.2.x
Are you sure you want to change the base?
Changes from 3 commits
629cdb6
830786e
d189500
1521aa8
306a5ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?php | ||
|
|
||
| namespace Doctrine\Tests\Common\Proxy; | ||
|
|
||
| class Php81ReadonlyPublicPropertyType | ||
| { | ||
| public readonly string $readable; | ||
| public string $writeable = 'default'; | ||
|
|
||
| public function __construct( | ||
| public readonly string $id, | ||
| string $readable = 'readable-default' | ||
| ) { | ||
| $this->readable = $readable; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -525,6 +525,41 @@ public function testPhp81NeverType() | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @requires PHP >= 8.1.0 | ||
| */ | ||
| public function testPhp81ReadonlyPublicProperties() | ||
| { | ||
| $className = Php81ReadonlyPublicPropertyType::class; | ||
| $proxyClassName = 'Doctrine\Tests\Common\ProxyProxy\__CG__\Php81ReadonlyPublicPropertyType'; | ||
|
|
||
| if ( ! class_exists($proxyClassName, false)) { | ||
| $metadata = $this->createClassMetadata($className, ['id']); | ||
|
|
||
| $metadata | ||
| ->expects($this->any()) | ||
| ->method('hasField') | ||
| ->will($this->returnCallback(static function ($fieldName) { | ||
| return in_array($fieldName, ['id', 'readable', 'writeable']); | ||
| })); | ||
|
|
||
| $proxyGenerator = new ProxyGenerator(__DIR__ . '/generated', __NAMESPACE__ . 'Proxy'); | ||
| $this->generateAndRequire($proxyGenerator, $metadata); | ||
| } | ||
|
|
||
| // Readonly properties are removed from unset. | ||
| self::assertStringContainsString( | ||
| 'unset($this->writeable);', | ||
| file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPhp81ReadonlyPublicPropertyType.php') | ||
| ); | ||
|
|
||
| // But remain in property listings. | ||
| self::assertStringContainsString( | ||
| "'readable' => NULL", | ||
| file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPhp81ReadonlyPublicPropertyType.php') | ||
| ); | ||
|
||
| } | ||
|
|
||
| /** | ||
| * @requires PHP >= 8.1.0 | ||
| */ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.