Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2b31429

Browse files
authored
chore: test with SF7.3 (#891)
1 parent 50350cb commit 2b31429

9 files changed

Lines changed: 111 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
php: [ 8.2, 8.3, 8.4 ]
17-
symfony: [ 6.4.*, 7.1.*, 7.2.* ]
17+
symfony: [ 6.4.*, 7.2.*, 7.3.* ]
1818
database: [ mysql|mongo ]
1919
phpunit: [ 11, 12 ]
2020

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"doctrine/common": "^3.2.2",
3535
"doctrine/doctrine-bundle": "^2.10",
3636
"doctrine/doctrine-migrations-bundle": "^2.2|^3.0",
37-
"doctrine/mongodb-odm-bundle": "^4.6|^5.0",
3837
"doctrine/mongodb-odm": "^2.4",
38+
"doctrine/mongodb-odm-bundle": "^4.6|^5.0",
3939
"doctrine/orm": "^2.16|^3.0",
4040
"phpunit/phpunit": "^9.5.0 || ^10.0 || ^11.0 || ^12.0",
4141
"symfony/console": "^6.4|^7.0",

src/Persistence/ProxyGenerator.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,32 @@ private static function generateClassFor(object $object): string
114114
$proxyCode,
115115
[
116116
'implements \Symfony\Component\VarExporter\LazyObjectInterface' => \sprintf('implements \%s, \Symfony\Component\VarExporter\LazyObjectInterface', Proxy::class),
117+
'use \Symfony\Component\VarExporter\Internal\LazyDecoratorTrait' => \sprintf("use \\%s;\n use \\%s", IsProxy::class, LazyProxyTrait::class),
117118
'use \Symfony\Component\VarExporter\LazyProxyTrait' => \sprintf("use \\%s;\n use \\%s", IsProxy::class, LazyProxyTrait::class),
118-
'if (isset($this->lazyObjectState)) {' => "\$this->_autoRefresh();\n\n if (isset(\$this->lazyObjectReal)) {",
119119
'\func_get_args()' => '$this->unproxyArgs(\func_get_args())',
120120
],
121121
);
122122

123+
/**
124+
* Add `$this->_autoRefresh();` after every method declaration.
125+
*
126+
* (\s* # 1. Optional indentation
127+
* (?:public|protected|private)?\s* # 2. Optional visibility
128+
* function\s+ # 3. The "function" keyword followed by space
129+
* (?!__) # 4. Negative lookahead to exclude magic methods (like __serialize)
130+
* \w+ # 5. Method name
131+
* \s*\([^\)]*\)\s* # 6. Parameters inside parentheses (not captured)
132+
* ):?\s*\??[\w\\\\]* # 7. Optional return type, can be nullable (starts with `?`), supports namespaced types (`\Foo\Bar`)
133+
* \s*\{\s*$ # 8. Opening brace `{` at the end of the line, with optional spaces before
134+
*/
135+
$proxyCode = preg_replace_callback(
136+
'/^(\s*(?:public|protected|private)?\s*function\s+(?!__)\w+\s*\([^\)]*\)\s*):?\s*\??[\w\\\\]*\s*\{\s*$/m',
137+
function ($matches) {
138+
return rtrim($matches[0]) . "\n \$this->_autoRefresh();";
139+
},
140+
$proxyCode
141+
);
142+
123143
eval($proxyCode); // @phpstan-ignore-line
124144

125145
return $proxyClass;

tests/Fixture/FoundryTestKernel.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,25 @@ public static function usesDamaDoctrineTestBundle(): bool
7272

7373
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader): void
7474
{
75-
$c->loadFromExtension('framework', [
75+
$frameworkConfiguration = [
7676
'http_method_override' => false,
7777
'secret' => 'S3CRET',
7878
'router' => ['utf8' => true],
7979
'test' => true,
80-
]);
80+
'uid' => ['default_uuid_version' => 7, 'time_based_uuid_version' => 7],
81+
];
82+
83+
if (\str_starts_with(self::VERSION, '6.4')) {
84+
// prevent a deprecation notice in Symfony 6.4
85+
$frameworkConfiguration['handle_all_throwables'] = true;
86+
}
87+
88+
if (\str_starts_with(self::VERSION, '7.3')) {
89+
// prevent a deprecation notice in Symfony 7.3
90+
$frameworkConfiguration['property_info']['with_constructor_extractor'] = true;
91+
}
92+
93+
$c->loadFromExtension('framework', $frameworkConfiguration);
8194

8295
if (self::hasORM()) {
8396
$c->loadFromExtension('doctrine', [

tests/Integration/DataProvider/GenericEntityProxyFactoryTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Zenstruck\Foundry\Tests\Integration\DataProvider;
1313

14+
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
1415
use PHPUnit\Framework\Attributes\RequiresPhpunit;
1516
use PHPUnit\Framework\Attributes\RequiresPhpunitExtension;
1617
use Zenstruck\Foundry\PHPUnit\FoundryExtension;
@@ -23,6 +24,7 @@
2324
*/
2425
#[RequiresPhpunit('>=11.4')]
2526
#[RequiresPhpunitExtension(FoundryExtension::class)]
27+
#[IgnoreDeprecations]
2628
final class GenericEntityProxyFactoryTest extends DataProviderWithProxyFactoryInKernelTestCase
2729
{
2830
use RequiresORM;

tests/Integration/ORM/EntityRelationship/ProxyEntityFactoryRelationshipTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Doctrine\Persistence\Proxy as DoctrineProxy;
1818
use PHPUnit\Framework\AssertionFailedError;
1919
use PHPUnit\Framework\Attributes\DataProvider;
20+
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
2021
use PHPUnit\Framework\Attributes\RequiresPhpunit;
2122
use PHPUnit\Framework\Attributes\Test;
2223
use Zenstruck\Assert;
@@ -33,6 +34,7 @@
3334
* @author Nicolas PHILIPPE <[email protected]>
3435
*/
3536
#[RequiresPhpunit('>=11.4')]
37+
#[IgnoreDeprecations]
3638
final class ProxyEntityFactoryRelationshipTest extends EntityFactoryRelationshipTestCase
3739
{
3840
/** @test */

tests/Integration/ORM/GenericEntityProxyFactoryTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Zenstruck\Foundry\Tests\Integration\ORM;
1313

14+
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
1415
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
1516
use Zenstruck\Foundry\Tests\Fixture\Entity\EdgeCases\EntityWithReadonly\EntityWithReadonly;
1617
use Zenstruck\Foundry\Tests\Fixture\Factories\Entity\GenericProxyEntityFactory;
@@ -21,7 +22,9 @@
2122

2223
/**
2324
* @author Kevin Bond <[email protected]>
25+
* @group legacy
2426
*/
27+
#[IgnoreDeprecations]
2528
final class GenericEntityProxyFactoryTest extends GenericProxyFactoryTestCase
2629
{
2730
use RequiresORM;

tests/Integration/ORM/ProxyGenericEntityRepositoryDecoratorTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@
1313

1414
namespace Zenstruck\Foundry\Tests\Integration\ORM;
1515

16+
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
1617
use Zenstruck\Foundry\Tests\Fixture\Factories\Entity\GenericProxyEntityFactory;
1718
use Zenstruck\Foundry\Tests\Integration\Persistence\GenericRepositoryDecoratorTestCase;
1819
use Zenstruck\Foundry\Tests\Integration\RequiresORM;
1920

21+
/**
22+
* @group legacy
23+
*/
24+
#[IgnoreDeprecations]
2025
final class ProxyGenericEntityRepositoryDecoratorTest extends GenericRepositoryDecoratorTestCase
2126
{
2227
use RequiresORM;

tests/Unit/Persistence/ProxyGeneratorTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,21 @@
1414
namespace Zenstruck\Foundry\Tests\Unit\Persistence;
1515

1616
use PHPUnit\Framework\Attributes\DataProvider;
17+
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
1718
use PHPUnit\Framework\Attributes\Test;
1819
use PHPUnit\Framework\TestCase;
1920
use Zenstruck\Foundry\Persistence\ProxyGenerator;
21+
use Zenstruck\Foundry\Test\Factories;
2022

2123
/**
2224
* @author Nicolas PHILIPPE <[email protected]>
25+
* @group legacy
2326
*/
27+
#[IgnoreDeprecations]
2428
final class ProxyGeneratorTest extends TestCase
2529
{
30+
use Factories;
31+
2632
/**
2733
* @test
2834
* @dataProvider classWithUnserializeMagicMethodProvider
@@ -40,6 +46,37 @@ public static function classWithUnserializeMagicMethodProvider(): iterable
4046
yield 'not type hinted __unserialize method' => [new ClassWithNoTypeHintInUnserialize()];
4147
yield 'type hinted __unserialize method' => [new ClassWithTypeHintedUnserialize()];
4248
}
49+
50+
/**
51+
* @test
52+
*/
53+
#[Test]
54+
public function it_can_generate_proxy_for_class_with_self_return_type(): void
55+
{
56+
$proxyfiedObj = ProxyGenerator::wrap($obj = new ClassWithSelfReturnType());
57+
self::assertSame($obj, $proxyfiedObj->returnsSelf()->_real()); // @phpstan-ignore method.notFound
58+
}
59+
60+
/**
61+
* @test
62+
*/
63+
#[Test]
64+
public function it_can_generate_proxy_for_class_with_method_with_nullable_return_type(): void
65+
{
66+
$proxyfiedObj = ProxyGenerator::wrap(new ClassWithNullableReturnType());
67+
self::assertNull($proxyfiedObj->returnsNullable(null));
68+
self::assertSame(1, $proxyfiedObj->returnsNullable(1));
69+
}
70+
71+
/**
72+
* @test
73+
*/
74+
#[Test]
75+
public function it_can_generate_proxy_for_class_with_method_with_no_return_type(): void
76+
{
77+
$proxyfiedObj = ProxyGenerator::wrap(new ClassWithoutReturnType());
78+
self::assertSame(1, $proxyfiedObj->returnsSeomthing());
79+
}
4380
}
4481

4582
class ClassWithNoTypeHintInUnserialize
@@ -55,3 +92,27 @@ public function __unserialize(array $array)
5592
{
5693
}
5794
}
95+
96+
class ClassWithNullableReturnType
97+
{
98+
public function returnsNullable(?int $int): ?int
99+
{
100+
return $int;
101+
}
102+
}
103+
104+
class ClassWithoutReturnType
105+
{
106+
public function returnsSeomthing() // @phpstan-ignore missingType.return
107+
{
108+
return 1;
109+
}
110+
}
111+
112+
class ClassWithSelfReturnType
113+
{
114+
public function returnsSelf(): self
115+
{
116+
return $this;
117+
}
118+
}

0 commit comments

Comments
 (0)