Skip to content

Commit 179088a

Browse files
committed
Run tests with MongoDB ODM using native laxy objects, fix other deprecations
1 parent eb53dfc commit 179088a

File tree

9 files changed

+50
-13
lines changed

9 files changed

+50
-13
lines changed

.php-cs-fixer.dist.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
3232
->setRules([
3333
'@DoctrineAnnotation' => true,
34-
'@PHP74Migration' => true,
35-
'@PHP74Migration:risky' => true,
36-
'@PHPUnit91Migration:risky' => true,
34+
'@PHP7x4Migration' => true,
35+
'@PHP7x4Migration:risky' => true,
36+
'@PHPUnit9x1Migration:risky' => true,
3737
'@PSR2' => true,
3838
'@Symfony' => true,
3939
'array_syntax' => ['syntax' => 'short'],

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@
5656
"doctrine/cache": "^1.11 || ^2.0",
5757
"doctrine/common": "^2.13 || ^3.0",
5858
"doctrine/dbal": "^3.7 || ^4.0",
59-
"doctrine/doctrine-bundle": "^2.3",
59+
"doctrine/doctrine-bundle": "^2.3 || ^3.0",
6060
"doctrine/mongodb-odm": "^2.3",
6161
"doctrine/orm": "^2.20 || ^3.3",
62-
"friendsofphp/php-cs-fixer": "^3.70",
62+
"friendsofphp/php-cs-fixer": "^3.89",
6363
"nesbot/carbon": "^2.71 || ^3.0",
64-
"phpstan/phpstan": "^2.1.1",
64+
"phpstan/phpstan": "^2.1.31",
6565
"phpstan/phpstan-doctrine": "^2.0.1",
6666
"phpstan/phpstan-phpunit": "^2.0.3",
6767
"phpunit/phpunit": "^9.6",
68-
"rector/rector": "^2.0.6",
68+
"rector/rector": "^2.2.6",
6969
"symfony/console": "^5.4 || ^6.0 || ^7.0",
7070
"symfony/doctrine-bridge": "^5.4 || ^6.0 || ^7.0",
7171
"symfony/phpunit-bridge": "^6.4 || ^7.0",

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ parameters:
1717
- '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is never written, only read\.$#'
1818
- '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is never read, only written\.$#'
1919
- '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is unused\.$#'
20+
- '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ (.*) is never assigned (.*) so it can be removed from the property type\.$#'
2021
- '#^Method Gedmo\\(?:[^\\]+\\)*Mapping\\Driver[^:]+::readExtendedMetadata\(\) with return type void returns [\w\|<>\s,]+ but should not return anything\.$#'
2122
- '#^Result of method Gedmo\\Mapping\\Driver::readExtendedMetadata\(\) \(void\) is used\.$#'
2223
excludePaths:

tests/Gedmo/Sortable/Fixture/Node.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Gedmo\Sortable\Entity\Repository\SortableRepository;
1616

1717
/**
18-
* @author Charles J. C. Elling, 2017-07-31
18+
* @author
1919
*
2020
* @ORM\Entity(repositoryClass="Gedmo\Sortable\Entity\Repository\SortableRepository")
2121
*/

tests/Gedmo/Sortable/Fixture/NotifyNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Gedmo\Sortable\Entity\Repository\SortableRepository;
1818

1919
/**
20-
* @author Charles J. C. Elling, 2017-07-31
20+
* @author
2121
*
2222
* @ORM\Entity(repositoryClass="Gedmo\Sortable\Entity\Repository\SortableRepository")
2323
* @ORM\ChangeTrackingPolicy("NOTIFY")

tests/Gedmo/Tool/BaseTestCaseMongoODM.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ protected function getMetadataDriverImplementation(): MappingDriver
112112
protected function getMockAnnotatedConfig(): Configuration
113113
{
114114
$config = new Configuration();
115+
116+
/** @phpstan-ignore-next-line function.alreadyNarrowedType */
117+
if (PHP_VERSION_ID >= 80400 && method_exists($config, 'setUseNativeLazyObject')) {
118+
$config->setUseNativeLazyObject(true);
119+
}
120+
115121
$config->addFilter('softdeleteable', SoftDeleteableFilter::class);
116122
$config->setProxyDir(TESTS_TEMP_DIR);
117123
$config->setHydratorDir(TESTS_TEMP_DIR);
@@ -129,6 +135,12 @@ protected function getMockAnnotatedConfig(): Configuration
129135
protected function getDefaultConfiguration(): Configuration
130136
{
131137
$config = new Configuration();
138+
139+
/** @phpstan-ignore-next-line function.alreadyNarrowedType */
140+
if (PHP_VERSION_ID >= 80400 && method_exists($config, 'setUseNativeLazyObject')) {
141+
$config->setUseNativeLazyObject(true);
142+
}
143+
132144
$config->addFilter('softdeleteable', SoftDeleteableFilter::class);
133145
$config->setProxyDir(TESTS_TEMP_DIR);
134146
$config->setHydratorDir(TESTS_TEMP_DIR);

tests/Gedmo/Tool/BaseTestCaseOM.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,14 @@ private function getMockODMMongoDBConfig(string $dbName, ?MappingDriver $mapping
170170
if (null === $mappingDriver) {
171171
$mappingDriver = $this->getMongoDBDriver();
172172
}
173+
173174
$config = new Configuration();
175+
176+
/** @phpstan-ignore-next-line function.alreadyNarrowedType */
177+
if (PHP_VERSION_ID >= 80400 && method_exists($config, 'setUseNativeLazyObject')) {
178+
$config->setUseNativeLazyObject(true);
179+
}
180+
174181
$config->addFilter('softdeleteable', SoftDeleteableFilter::class);
175182
$config->setProxyDir(TESTS_TEMP_DIR);
176183
$config->setHydratorDir(TESTS_TEMP_DIR);
@@ -191,10 +198,17 @@ private function getMockODMMongoDBConfig(string $dbName, ?MappingDriver $mapping
191198
private function getMockORMConfig(?MappingDriver $mappingDriver = null): \Doctrine\ORM\Configuration
192199
{
193200
$config = new \Doctrine\ORM\Configuration();
194-
$config->setProxyDir(TESTS_TEMP_DIR);
195-
$config->setProxyNamespace('Proxy');
201+
202+
/** @phpstan-ignore-next-line function.alreadyNarrowedType */
203+
if (PHP_VERSION_ID >= 80400 && method_exists($config, 'enableNativeLazyObjects')) {
204+
$config->enableNativeLazyObjects(true);
205+
} else {
206+
$config->setProxyDir(TESTS_TEMP_DIR);
207+
$config->setProxyNamespace('Proxy');
208+
$config->setAutoGenerateProxyClasses(true);
209+
}
210+
196211
$config->setDefaultQueryHints([]);
197-
$config->setAutoGenerateProxyClasses(true);
198212
$config->setClassMetadataFactoryName(ClassMetadataFactory::class);
199213
$config->setDefaultRepositoryClassName(EntityRepository::class);
200214
$config->setQuoteStrategy(new DefaultQuoteStrategy());

tests/Gedmo/Wrapper/MongoDocumentWrapperTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ public function testProxy(): void
5050
{
5151
$this->dm->clear();
5252
$test = $this->dm->getReference(Article::class, $this->articleId);
53-
static::assertStringStartsWith('Proxy', get_class($test));
53+
54+
if (method_exists($this->dm, 'isUninitializedObject')) {
55+
static::assertTrue($this->dm->isUninitializedObject($test));
56+
}
57+
5458
static::assertInstanceOf(Article::class, $test);
5559
$wrapped = new MongoDocumentWrapper($test, $this->dm);
5660

tests/bootstrap.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Doctrine\Common\Annotations\AnnotationReader;
1313
use Doctrine\Common\Annotations\PsrCachedReader;
1414
use Doctrine\DBAL\Types\Type;
15+
use Doctrine\Deprecations\Deprecation;
1516
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
1617
use Symfony\Bridge\Doctrine\Types\UuidType;
1718
use Symfony\Component\Cache\Adapter\ArrayAdapter;
@@ -45,3 +46,8 @@
4546
}
4647

4748
Type::addType('uuid', UuidType::class);
49+
50+
// Ignore unfixable deprecations
51+
Deprecation::ignoreDeprecations(
52+
'https://github.com/doctrine-extensions/DoctrineExtensions/pull/2772', // Ignore annotations deprecations from self
53+
);

0 commit comments

Comments
 (0)