Skip to content

Commit

Permalink
Fix tests under PHP 8
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrolucky committed Nov 14, 2021
1 parent c7d1ac1 commit ae07283
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
38 changes: 24 additions & 14 deletions Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\HttpKernel\Kernel;

use function array_filter;
use function array_intersect_key;
Expand All @@ -44,6 +45,7 @@
use function uniqid;

use const DIRECTORY_SEPARATOR;
use const PHP_VERSION_ID;

/** @psalm-import-type Params from DriverManager */
abstract class AbstractDoctrineExtensionTest extends TestCase
Expand Down Expand Up @@ -508,12 +510,16 @@ public function testSingleEntityManagerMultipleMappingBundleDefinitions(): void
self::markTestSkipped('This test requires ORM');
}

if (PHP_VERSION_ID < 80000 || Kernel::VERSION_ID < 50400) {
self::markTestSkipped('This test requires PHP 8 and Symfony 5.4+');
}

$container = $this->loadContainer('orm_single_em_bundle_mappings', ['YamlBundle', 'AnnotationsBundle', 'XmlBundle', 'AttributesBundle']);

$definition = $container->getDefinition('doctrine.orm.default_metadata_driver');

$this->assertDICDefinitionMethodCallAt(0, $definition, 'addDriver', [
new Reference('doctrine.orm.default_annotation_metadata_driver'),
new Reference('doctrine.orm.default_attribute_metadata_driver'),
'Fixtures\Bundles\AnnotationsBundle\Entity',
]);

Expand All @@ -532,15 +538,12 @@ public function testSingleEntityManagerMultipleMappingBundleDefinitions(): void
'Fixtures\Bundles\XmlBundle',
]);

$annDef = $container->getDefinition('doctrine.orm.default_annotation_metadata_driver');
$this->assertDICConstructorArguments($annDef, [
new Reference('doctrine.orm.metadata.annotation_reader'),
[__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'AnnotationsBundle' . DIRECTORY_SEPARATOR . 'Entity'],
]);

$attrDef = $container->getDefinition('doctrine.orm.default_attribute_metadata_driver');
$this->assertDICConstructorArguments($attrDef, [
[__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'AttributesBundle' . DIRECTORY_SEPARATOR . 'Entity'],
[
__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'AnnotationsBundle' . DIRECTORY_SEPARATOR . 'Entity',
__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'AttributesBundle' . DIRECTORY_SEPARATOR . 'Entity',
],
]);

$ymlDef = $container->getDefinition('doctrine.orm.default_yml_metadata_driver');
Expand All @@ -560,16 +563,21 @@ public function testMultipleEntityManagersMappingBundleDefinitions(): void
self::markTestSkipped('This test requires ORM');
}

if (PHP_VERSION_ID < 80000 || Kernel::VERSION_ID < 50400) {
self::markTestSkipped('This test requires PHP 8 and Symfony 5.4+');
}

$container = $this->loadContainer('orm_multiple_em_bundle_mappings', ['YamlBundle', 'AnnotationsBundle', 'XmlBundle', 'AttributesBundle']);

$this->assertEquals(['em1' => 'doctrine.orm.em1_entity_manager', 'em2' => 'doctrine.orm.em2_entity_manager'], $container->getParameter('doctrine.entity_managers'), 'Set of the existing EntityManagers names is incorrect.');
$this->assertEquals('%doctrine.entity_managers%', $container->getDefinition('doctrine')->getArgument(2), 'Set of the existing EntityManagers names is incorrect.');

$def1 = $container->getDefinition('doctrine.orm.em1_metadata_driver');
$def2 = $container->getDefinition('doctrine.orm.em2_metadata_driver');
$def1 = $container->getDefinition('doctrine.orm.em1_metadata_driver');
$def2 = $container->getDefinition('doctrine.orm.em2_metadata_driver');
$def1Id = sprintf('doctrine.orm.em1_%s_metadata_driver', PHP_VERSION_ID >= 80000 && Kernel::VERSION_ID >= 50400 ? 'attribute' : 'annotation');

$this->assertDICDefinitionMethodCallAt(0, $def1, 'addDriver', [
new Reference('doctrine.orm.em1_annotation_metadata_driver'),
new Reference($def1Id),
'Fixtures\Bundles\AnnotationsBundle\Entity',
]);

Expand All @@ -588,10 +596,12 @@ public function testMultipleEntityManagersMappingBundleDefinitions(): void
'Fixtures\Bundles\XmlBundle',
]);

$annDef = $container->getDefinition('doctrine.orm.em1_annotation_metadata_driver');
$annDef = $container->getDefinition($def1Id);
$this->assertDICConstructorArguments($annDef, [
new Reference('doctrine.orm.metadata.annotation_reader'),
[__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'AnnotationsBundle' . DIRECTORY_SEPARATOR . 'Entity'],
[
__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'AnnotationsBundle' . DIRECTORY_SEPARATOR . 'Entity',
__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'AttributesBundle' . DIRECTORY_SEPARATOR . 'Entity',
],
]);

$ymlDef = $container->getDefinition('doctrine.orm.em2_yml_metadata_driver');
Expand Down
10 changes: 7 additions & 3 deletions Tests/DependencyInjection/DoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Messenger\MessageBusInterface;

use function array_values;
Expand Down Expand Up @@ -736,7 +737,7 @@ public function testAnnotationsBundleMappingDetection(): void

$definition = $container->getDefinition('doctrine.orm.default_metadata_driver');
$this->assertDICDefinitionMethodCallOnce($definition, 'addDriver', [
new Reference('doctrine.orm.default_annotation_metadata_driver'),
new Reference(sprintf('doctrine.orm.default_%s_metadata_driver', PHP_VERSION_ID >= 80000 && Kernel::VERSION_ID >= 50400 ? 'attribute' : 'annotation')),
'Fixtures\Bundles\AnnotationsBundle\Entity',
]);
}
Expand Down Expand Up @@ -821,7 +822,7 @@ public function testOrmMergeConfigs(): void

$definition = $container->getDefinition('doctrine.orm.default_metadata_driver');
$this->assertDICDefinitionMethodCallAt(0, $definition, 'addDriver', [
new Reference('doctrine.orm.default_annotation_metadata_driver'),
new Reference(sprintf('doctrine.orm.default_%s_metadata_driver', PHP_VERSION_ID >= 80000 && Kernel::VERSION_ID >= 50400 ? 'attribute' : 'annotation')),
'Fixtures\Bundles\AnnotationsBundle\Entity',
]);
$this->assertDICDefinitionMethodCallAt(1, $definition, 'addDriver', [
Expand Down Expand Up @@ -871,7 +872,10 @@ public function testAnnotationsBundleMappingDetectionWithVendorNamespace(): void
$extension->load([$config], $container);

$calls = $container->getDefinition('doctrine.orm.default_metadata_driver')->getMethodCalls();
$this->assertEquals('doctrine.orm.default_annotation_metadata_driver', (string) $calls[0][1][0]);
$this->assertEquals(
sprintf('doctrine.orm.default_%s_metadata_driver', PHP_VERSION_ID >= 80000 && Kernel::VERSION_ID >= 50400 ? 'attribute' : 'annotation'),
(string) $calls[0][1][0]
);
$this->assertEquals('Fixtures\Bundles\Vendor\AnnotationsBundle\Entity', $calls[0][1][1]);
}

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
"doctrine/coding-standard": "^9.0",
"doctrine/orm": "^2.9",
"friendsofphp/proxy-manager-lts": "^1.0",
"phpunit/phpunit": "^7.5 || ^8.0 || ^9.3",
"psalm/plugin-phpunit": "^0.15.1",
"phpunit/phpunit": "^7.5 || ^8.0 || ^9.3 || ^10.0",
"psalm/plugin-phpunit": "^0.16.1",
"psalm/plugin-symfony": "^3",
"symfony/phpunit-bridge": "^5.2|^6.0",
"symfony/property-info": "^4.3.3|^5.0|^6.0",
Expand Down

0 comments on commit ae07283

Please sign in to comment.