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

Skip to content

Commit af6c3c2

Browse files
authored
Merge pull request #2005 from greg0ire/phpunit-10
Phpunit 10
2 parents 2fa333d + da38461 commit af6c3c2

15 files changed

Lines changed: 79 additions & 51 deletions

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,11 @@
5252
"phpstan/phpstan": "2.1.1",
5353
"phpstan/phpstan-phpunit": "2.0.3",
5454
"phpstan/phpstan-strict-rules": "^2",
55-
"phpunit/phpunit": "^9.6.22",
55+
"phpunit/phpunit": "^10.5.53",
5656
"psr/log": "^1.1.4 || ^2.0 || ^3.0",
5757
"symfony/doctrine-messenger": "^6.4 || ^7.0",
5858
"symfony/expression-language": "^6.4 || ^7.0",
5959
"symfony/messenger": "^6.4 || ^7.0",
60-
"symfony/phpunit-bridge": "^7.2",
6160
"symfony/property-info": "^6.4 || ^7.0",
6261
"symfony/security-bundle": "^6.4 || ^7.0",
6362
"symfony/stopwatch": "^6.4 || ^7.0",

phpunit.xml.dist

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
colors="true"
44
bootstrap="tests/bootstrap.php"
5-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
5+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
6+
displayDetailsOnTestsThatTriggerDeprecations="true"
7+
failOnDeprecation="true"
68
>
79
<testsuites>
810
<testsuite name="DoctrineBundle for the Symfony Framework">
@@ -11,16 +13,12 @@
1113
</testsuites>
1214

1315
<php>
14-
<env name="SYMFONY_DEPRECATIONS_HELPER" value="ignoreFile=./tests/baseline-ignore"/>
16+
<env name="DOCTRINE_DEPRECATIONS" value="trigger"/>
1517
</php>
1618

17-
<coverage>
19+
<source ignoreSuppressionOfDeprecations="true">
1820
<include>
1921
<directory>src</directory>
2022
</include>
21-
</coverage>
22-
23-
<listeners>
24-
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
25-
</listeners>
23+
</source>
2624
</phpunit>

tests/CacheSchemaSubscriberTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\CacheSchemaSubscriberPass;
66
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension;
7+
use Doctrine\ORM\Configuration;
78
use Doctrine\ORM\EntityManagerInterface;
89
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
910
use Symfony\Component\DependencyInjection\Alias;
@@ -13,8 +14,11 @@
1314
use Symfony\Component\DependencyInjection\Reference;
1415

1516
use function interface_exists;
17+
use function method_exists;
1618
use function sys_get_temp_dir;
1719

20+
use const PHP_VERSION_ID;
21+
1822
class CacheSchemaSubscriberTest extends TestCase
1923
{
2024
public function testSchemaSubscriberWiring(): void
@@ -64,7 +68,12 @@ public function testSchemaSubscriberWiring(): void
6468
$extension->load([
6569
[
6670
'dbal' => [],
67-
'orm' => [],
71+
'orm' => [
72+
'controller_resolver' => ['auto_mapping' => false],
73+
/* @phpstan-ignore function.alreadyNarrowedType */
74+
] + (method_exists(Configuration::class, 'enableNativeLazyObjects') ? [
75+
'enable_native_lazy_objects' => PHP_VERSION_ID >= 80400,
76+
] : ['enable_lazy_ghost_objects' => true]),
6877
],
6978
], $container);
7079

tests/Command/ImportMappingDoctrineCommandTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Doctrine\ORM\EntityManagerInterface;
77
use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
88
use InvalidArgumentException;
9+
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
910
use PHPUnit\Framework\TestCase;
1011
use Symfony\Bundle\FrameworkBundle\Console\Application;
1112
use Symfony\Component\Console\Tester\CommandTester;
@@ -17,7 +18,6 @@
1718
use function interface_exists;
1819
use function sys_get_temp_dir;
1920

20-
/** @group legacy */
2121
class ImportMappingDoctrineCommandTest extends TestCase
2222
{
2323
private TestKernel $kernel;
@@ -66,6 +66,7 @@ protected function tearDown(): void
6666
unset($this->kernel, $this->commandTester);
6767
}
6868

69+
#[WithoutErrorHandler]
6970
public function testExecuteXmlWithBundle(): void
7071
{
7172
$this->commandTester->execute(['name' => 'ImportMappingTestFooBundle']);
@@ -79,6 +80,7 @@ public function testExecuteXmlWithBundle(): void
7980
);
8081
}
8182

83+
#[WithoutErrorHandler]
8284
public function testExecuteAnnotationsWithBundle(): void
8385
{
8486
$this->commandTester->execute([
@@ -95,13 +97,15 @@ public function testExecuteAnnotationsWithBundle(): void
9597
);
9698
}
9799

100+
#[WithoutErrorHandler]
98101
public function testExecuteThrowsExceptionWithNamespaceAndNoPath(): void
99102
{
100103
$this->expectException(InvalidArgumentException::class);
101104
$this->expectExceptionMessage('The --path option is required');
102105
$this->commandTester->execute(['name' => 'Some\Namespace']);
103106
}
104107

108+
#[WithoutErrorHandler]
105109
public function testExecuteXmlWithNamespace(): void
106110
{
107111
$this->commandTester->execute([
@@ -118,6 +122,7 @@ public function testExecuteXmlWithNamespace(): void
118122
);
119123
}
120124

125+
#[WithoutErrorHandler]
121126
public function testExecuteAnnotationsWithNamespace(): void
122127
{
123128
$this->commandTester->execute([

tests/ConnectionFactoryTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\DBAL\Driver;
99
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
1010
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
11+
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
1112

1213
use function array_intersect_key;
1314

@@ -61,7 +62,7 @@ public function testDefaultCollationMySql(): void
6162
);
6263
}
6364

64-
/** @group legacy */
65+
#[WithoutErrorHandler]
6566
public function testCollateMapsToCollationForMySql(): void
6667
{
6768
$factory = new ConnectionFactory([]);
@@ -85,7 +86,7 @@ public function testCollateMapsToCollationForMySql(): void
8586
);
8687
}
8788

88-
/** @group legacy */
89+
#[WithoutErrorHandler]
8990
public function testConnectionOverrideOptions(): void
9091
{
9192
$params = [

tests/DependencyInjection/AbstractDoctrineExtensionTestCase.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
use InvalidArgumentException;
2727
use LogicException;
2828
use PDO;
29+
use PHPUnit\Framework\Attributes\DataProvider;
30+
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
2931
use PHPUnit\Framework\TestCase;
3032
use Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterEventListenersAndSubscribersPass;
3133
use Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestHydrator;
@@ -143,7 +145,7 @@ public function testDbalLoadFromXmlSingleConnections(): void
143145
$this->assertEquals('9.4.0', $config['serverVersion']);
144146
}
145147

146-
/** @group legacy */
148+
#[WithoutErrorHandler]
147149
public function testDbalLoadUrlOverride(): void
148150
{
149151
$container = $this->loadContainer('dbal_allow_url_override');
@@ -164,7 +166,7 @@ public function testDbalLoadUrlOverride(): void
164166
$this->assertFalse(isset($config['override_url']));
165167
}
166168

167-
/** @group legacy */
169+
#[WithoutErrorHandler]
168170
public function testDbalLoadPartialUrlOverrideSetsDefaults(): void
169171
{
170172
$container = $this->loadContainer('dbal_allow_partial_url_override');
@@ -278,7 +280,7 @@ public function testDbalLoadDisableTypeComments(): void
278280
$this->assertCount(0, $calls);
279281
}
280282

281-
/** @group legacy */
283+
#[WithoutErrorHandler]
282284
public function testDbalSchemaManagerFactory(): void
283285
{
284286
$container = $this->loadContainer('dbal_schema_manager_factory');
@@ -717,10 +719,8 @@ public function testSetTypedFieldMapper(): void
717719
$this->assertDICDefinitionMethodCallOnce($definition, 'setTypedFieldMapper', [0 => new Reference('doctrine.orm.typed_field_mapper.default')]);
718720
}
719721

720-
/**
721-
* @dataProvider cacheConfigProvider
722-
* @group legacy
723-
*/
722+
#[DataProvider('cacheConfigProvider')]
723+
#[WithoutErrorHandler]
724724
public function testCacheConfig(string|null $expectedClass, string $entityManagerName, string|null $cacheGetter): void
725725
{
726726
if (! interface_exists(EntityManagerInterface::class)) {
@@ -1168,7 +1168,7 @@ public function testDbalSchemaFilterNewConfig(): void
11681168
}
11691169
}
11701170

1171-
/** @group legacy */
1171+
#[WithoutErrorHandler]
11721172
public function testWellKnownSchemaFilterDefaultTables(): void
11731173
{
11741174
$container = $this->getContainer([]);
@@ -1191,7 +1191,7 @@ public function testWellKnownSchemaFilterDefaultTables(): void
11911191
$this->assertTrue($filter->__invoke('anything_else'));
11921192
}
11931193

1194-
/** @group legacy */
1194+
#[WithoutErrorHandler]
11951195
public function testWellKnownSchemaFilterOverriddenTables(): void
11961196
{
11971197
$container = $this->getContainer([]);
@@ -1429,7 +1429,7 @@ public function testDisableSchemaValidation(): void
14291429
$this->assertFalse($collectorDefinition->getArguments()[1]);
14301430
}
14311431

1432-
/** @group legacy */
1432+
#[WithoutErrorHandler]
14331433
public function testNativeLazyObjectsWithoutConfig(): void
14341434
{
14351435
if (! interface_exists(EntityManagerInterface::class)) {
@@ -1470,7 +1470,7 @@ public function testNativeLazyObjectsWithConfigTrue(): void
14701470
$this->assertTrue($entityManager->getConfiguration()->isNativeLazyObjectsEnabled());
14711471
}
14721472

1473-
/** @group legacy */
1473+
#[WithoutErrorHandler]
14741474
public function testNativeLazyObjectsWithConfigFalse(): void
14751475
{
14761476
if (! interface_exists(EntityManagerInterface::class)) {

tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
99
use Doctrine\ORM\Cache\Region;
1010
use Doctrine\ORM\EntityManagerInterface;
11+
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
12+
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
1113
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1214
use Symfony\Component\Config\Loader\LoaderInterface;
1315
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -54,6 +56,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
5456
'doctrine',
5557
[
5658
'orm' => [
59+
'controller_resolver' => ['auto_mapping' => false],
5760
'query_cache_driver' => ['type' => 'service', 'id' => 'custom_cache_service'],
5861
'result_cache_driver' => ['type' => 'pool', 'pool' => 'doctrine.system_cache_pool'],
5962
'second_level_cache' => [
@@ -89,7 +92,12 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
8992
$loader->load(static function (ContainerBuilder $containerBuilder): void {
9093
$containerBuilder->loadFromExtension(
9194
'doctrine',
92-
['orm' => ['metadata_cache_driver' => ['type' => 'service', 'id' => 'custom_cache_service']]],
95+
[
96+
'orm' => [
97+
'controller_resolver' => ['auto_mapping' => false],
98+
'metadata_cache_driver' => ['type' => 'service', 'id' => 'custom_cache_service'],
99+
],
100+
],
93101
);
94102
$containerBuilder->setDefinition(
95103
'custom_cache_service',
@@ -100,7 +108,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
100108
})->boot();
101109
}
102110

103-
/** @group legacy */
111+
#[WithoutErrorHandler]
104112
public function testMetadataCacheConfigUsingNonPsr6ServiceDefinedByApplication(): void
105113
{
106114
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/DoctrineBundle/pull/1365');

tests/DependencyInjection/Compiler/EntityListenerPassTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use stdClass;
1313
use Symfony\Component\DependencyInjection\ContainerBuilder;
1414

15+
use function class_exists;
1516
use function interface_exists;
1617

1718
class EntityListenerPassTest extends TestCase
@@ -59,6 +60,13 @@ public function testEntityListenersAreRegistered(string|null $event, string|null
5960
/** @return iterable<array{0: ?string, 1: ?string, 2: ?string}> */
6061
public static function provideEvents(): iterable
6162
{
63+
if (! class_exists(Events::class)) {
64+
// If ORM is not available, return fake data to make the data provider valid
65+
yield 'Without ORM' => [null, null, null];
66+
67+
return;
68+
}
69+
6270
yield 'With event and matching method' => [Events::prePersist, null, null];
6371
yield 'Without event' => [null, null, null];
6472
yield 'With event and custom method' => [Events::postLoad, 'postLoadHandler', 'postLoadHandler'];

tests/DependencyInjection/DoctrineExtensionTest.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
3939
use InvalidArgumentException;
4040
use LogicException;
41+
use PHPUnit\Framework\Attributes\DataProvider;
42+
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
4143
use PHPUnit\Framework\TestCase;
4244
use ReflectionClass;
4345
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
@@ -66,10 +68,10 @@
6668
class DoctrineExtensionTest extends TestCase
6769
{
6870
/**
69-
* https://github.com/doctrine/orm/pull/7953 needed, otherwise ORM classes we define services for trigger deprecations
70-
*
71-
* @group legacy
71+
* https://github.com/doctrine/orm/pull/7953 needed, otherwise ORM classes
72+
* we define services for trigger deprecations
7273
*/
74+
#[WithoutErrorHandler]
7375
public function testAutowiringAlias(): void
7476
{
7577
if (! interface_exists(EntityManagerInterface::class)) {
@@ -656,7 +658,7 @@ public function testSingleEntityManagerWithDefaultSecondLevelCacheConfiguration(
656658
$this->assertEquals('%doctrine.orm.second_level_cache.default_cache_factory.class%', $slcDefinition->getClass());
657659
}
658660

659-
/** @group legacy */
661+
#[WithoutErrorHandler]
660662
public function testSingleEntityManagerWithCustomSecondLevelCacheConfiguration(): void
661663
{
662664
if (! interface_exists(EntityManagerInterface::class)) {
@@ -1019,7 +1021,7 @@ public function testMessengerIntegrationWithoutDoctrineTransport(): void
10191021
$this->assertNotContains('messenger.transport_factory', $container->findTags());
10201022
}
10211023

1022-
/** @group legacy */
1024+
#[WithoutErrorHandler]
10231025
public function testInvalidCacheConfiguration(): void
10241026
{
10251027
if (! interface_exists(EntityManagerInterface::class)) {
@@ -1066,12 +1068,9 @@ public function testCacheConfiguration(string $expectedAliasName, string $expect
10661068
$this->assertEquals($expectedTarget, (string) $alias);
10671069
}
10681070

1069-
/**
1070-
* @param array{type: ?string, pool?: string, id?: string} $cacheConfig
1071-
*
1072-
* @dataProvider legacyCacheConfigurationProvider
1073-
* @group legacy
1074-
*/
1071+
/** @param array{type: ?string, pool?: string, id?: string} $cacheConfig */
1072+
#[DataProvider('legacyCacheConfigurationProvider')]
1073+
#[WithoutErrorHandler]
10751074
public function testLegacyCacheConfiguration(string $expectedAliasName, string $expectedAliasTarget, string $cacheName, array $cacheConfig): void
10761075
{
10771076
$this->testCacheConfiguration($expectedAliasName, $expectedAliasTarget, $cacheName, $cacheConfig);

tests/DependencyInjection/Fixtures/TestKernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
5252
'schema_manager_factory' => 'doctrine.dbal.default_schema_manager_factory',
5353
],
5454
'orm' => [
55+
'controller_resolver' => ['auto_mapping' => false],
5556
'report_fields_where_declared' => true,
5657
'auto_generate_proxy_classes' => true,
5758
'enable_lazy_ghost_objects' => true,

0 commit comments

Comments
 (0)