Skip to content

Commit

Permalink
Add Symfony 7 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrolucky committed Aug 5, 2023
1 parent b5e9a1c commit 2b7916e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 64 deletions.
13 changes: 0 additions & 13 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -1095,19 +1095,6 @@ private function loadValidatorLoader(string $entityManagerName, ContainerBuilder
$validatorLoaderDefinition->addTag('validator.auto_mapper', ['priority' => -100]);
}

/**
* @param array<string, mixed> $objectManager
* @param string $cacheName
*
* @return void
*
* @psalm-suppress MoreSpecificImplementedParamType
*/
public function loadObjectManagerCacheDriver(array $objectManager, ContainerBuilder $container, $cacheName)
{
$this->loadCacheDriver($cacheName, $objectManager['name'], $objectManager[$cacheName . '_driver'], $container);
}

public function getXsdValidationBasePath(): string
{
return __DIR__ . '/../Resources/config/schema';
Expand Down
5 changes: 5 additions & 0 deletions Tests/DataCollector/DoctrineDataCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Bridge\Doctrine\Middleware\Debug\DebugDataHolder;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Kernel;

use function interface_exists;

Expand Down Expand Up @@ -132,6 +133,10 @@ public function testGetGroupedQueries(): void
/** @group legacy */
public function testGetGroupedQueriesWithDeprecatedDebugStackLogger(): void
{
if (Kernel::VERSION_ID >= 70000) {
$this->markTestSkipped('This test requires symfony < 7.0');
}

$logger = $this->getMockBuilder(DebugStack::class)->getMock();
$logger->queries = [];
$logger->queries[] = [
Expand Down
71 changes: 34 additions & 37 deletions Tests/RegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
use Fixtures\Bundles\RepositoryServiceBundle\Entity\TestCustomClassRepoEntity;
use Fixtures\Bundles\RepositoryServiceBundle\Repository\TestCustomClassRepoRepository;
use InvalidArgumentException;
use PHPUnit\Framework\MockObject\MockObject;
use ProxyManager\Proxy\ProxyInterface;
use stdClass;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\VarExporter\LazyObjectInterface;

use function assert;
Expand All @@ -24,54 +25,57 @@

class RegistryTest extends TestCase
{
/** @var MockObject&Container */
private MockObject $container;

protected function setUp(): void
{
$this->container = $this->createMock(Container::class);
}

public function testGetDefaultConnectionName(): void
{
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$registry = new Registry($container, [], [], 'default', 'default');
$registry = new Registry($this->container, [], [], 'default', 'default');

$this->assertEquals('default', $registry->getDefaultConnectionName());
}

public function testGetDefaultEntityManagerName(): void
{
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$registry = new Registry($container, [], [], 'default', 'default');
$registry = new Registry($this->container, [], [], 'default', 'default');

$this->assertEquals('default', $registry->getDefaultManagerName());
}

public function testGetDefaultConnection(): void
{
$conn = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$container->expects($this->once())
$conn = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
$this->container->expects($this->once())
->method('get')
->with($this->equalTo('doctrine.dbal.default_connection'))
->will($this->returnValue($conn));

$registry = new Registry($container, ['default' => 'doctrine.dbal.default_connection'], [], 'default', 'default');
$registry = new Registry($this->container, ['default' => 'doctrine.dbal.default_connection'], [], 'default', 'default');

$this->assertSame($conn, $registry->getConnection());
}

public function testGetConnection(): void
{
$conn = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$container->expects($this->once())
$conn = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
$this->container->expects($this->once())
->method('get')
->with($this->equalTo('doctrine.dbal.default_connection'))
->will($this->returnValue($conn));

$registry = new Registry($container, ['default' => 'doctrine.dbal.default_connection'], [], 'default', 'default');
$registry = new Registry($this->container, ['default' => 'doctrine.dbal.default_connection'], [], 'default', 'default');

$this->assertSame($conn, $registry->getConnection('default'));
}

public function testGetUnknownConnection(): void
{
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$registry = new Registry($container, [], [], 'default', 'default');
$registry = new Registry($this->container, [], [], 'default', 'default');

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Doctrine ORM Connection named "default" does not exist.');
Expand All @@ -80,44 +84,40 @@ public function testGetUnknownConnection(): void

public function testGetConnectionNames(): void
{
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$registry = new Registry($container, ['default' => 'doctrine.dbal.default_connection'], [], 'default', 'default');
$registry = new Registry($this->container, ['default' => 'doctrine.dbal.default_connection'], [], 'default', 'default');

$this->assertEquals(['default' => 'doctrine.dbal.default_connection'], $registry->getConnectionNames());
}

public function testGetDefaultEntityManager(): void
{
$em = new stdClass();
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$container->expects($this->once())
$em = new stdClass();
$this->container->expects($this->once())
->method('get')
->with($this->equalTo('doctrine.orm.default_entity_manager'))
->will($this->returnValue($em));

$registry = new Registry($container, [], ['default' => 'doctrine.orm.default_entity_manager'], 'default', 'default');
$registry = new Registry($this->container, [], ['default' => 'doctrine.orm.default_entity_manager'], 'default', 'default');

$this->assertSame($em, $registry->getManager());
}

public function testGetEntityManager(): void
{
$em = new stdClass();
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$container->expects($this->once())
$em = new stdClass();
$this->container->expects($this->once())
->method('get')
->with($this->equalTo('doctrine.orm.default_entity_manager'))
->will($this->returnValue($em));

$registry = new Registry($container, [], ['default' => 'doctrine.orm.default_entity_manager'], 'default', 'default');
$registry = new Registry($this->container, [], ['default' => 'doctrine.orm.default_entity_manager'], 'default', 'default');

$this->assertSame($em, $registry->getManager('default'));
}

public function testGetUnknownEntityManager(): void
{
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$registry = new Registry($container, [], [], 'default', 'default');
$registry = new Registry($this->container, [], [], 'default', 'default');

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage(
Expand All @@ -128,8 +128,7 @@ public function testGetUnknownEntityManager(): void

public function testResetUnknownEntityManager(): void
{
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$registry = new Registry($container, [], [], 'default', 'default');
$registry = new Registry($this->container, [], [], 'default', 'default');

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage(
Expand All @@ -153,13 +152,12 @@ public function testReset(): void
->method('setProxyInitializer')
->with($this->isInstanceOf(Closure::class));

$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$container->expects($this->any())
$this->container->expects($this->any())
->method('initialized')
->withConsecutive(['doctrine.orm.uninitialized_entity_manager'], ['doctrine.orm.noproxy_entity_manager'], ['doctrine.orm.proxy_entity_manager'])
->willReturnOnConsecutiveCalls(false, true, true, true);

$container->expects($this->any())
$this->container->expects($this->any())
->method('get')
->withConsecutive(['doctrine.orm.noproxy_entity_manager'], ['doctrine.orm.proxy_entity_manager'], ['doctrine.orm.proxy_entity_manager'], ['doctrine.orm.proxy_entity_manager'])
->willReturnOnConsecutiveCalls($noProxyManager, $proxyManager, $proxyManager, $proxyManager);
Expand All @@ -170,7 +168,7 @@ public function testReset(): void
'proxy' => 'doctrine.orm.proxy_entity_manager',
];

$registry = new Registry($container, [], $entityManagers, 'default', 'default');
$registry = new Registry($this->container, [], $entityManagers, 'default', 'default');
$registry->reset();
}

Expand All @@ -185,11 +183,10 @@ public function testResetLazyObject(): void
/** @psalm-suppress MissingDependency https://github.com/vimeo/psalm/issues/8258 */
$ghostManager->expects($this->once())->method('resetLazyObject')->willReturn(true);

$container = $this->createMock(ContainerInterface::class);
$container->method('initialized')
$this->container->method('initialized')
->withConsecutive(['doctrine.orm.uninitialized_entity_manager'], ['doctrine.orm.ghost_entity_manager'])
->willReturnOnConsecutiveCalls(false, true, true);
$container->method('get')
$this->container->method('get')
->withConsecutive(['doctrine.orm.ghost_entity_manager'], ['doctrine.orm.ghost_entity_manager'], ['doctrine.orm.ghost_entity_manager'])
->willReturnOnConsecutiveCalls($ghostManager, $ghostManager, $ghostManager);

Expand All @@ -198,7 +195,7 @@ public function testResetLazyObject(): void
'ghost' => 'doctrine.orm.ghost_entity_manager',
];

(new Registry($container, [], $entityManagers, 'default', 'default'))->reset();
(new Registry($this->container, [], $entityManagers, 'default', 'default'))->reset();
}

public function testIdentityMapsStayConsistentAfterReset(): void
Expand Down
28 changes: 14 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
"doctrine/dbal": "^3.6.0",
"doctrine/persistence": "^2.2 || ^3",
"doctrine/sql-formatter": "^1.0.1",
"symfony/cache": "^5.4 || ^6.0",
"symfony/config": "^5.4 || ^6.0",
"symfony/console": "^5.4 || ^6.0",
"symfony/dependency-injection": "^5.4 || ^6.0",
"symfony/cache": "^5.4 || ^6.0 || ^7.0",
"symfony/config": "^5.4 || ^6.0 || ^7.0",
"symfony/console": "^5.4 || ^6.0 || ^7.0",
"symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0",
"symfony/deprecation-contracts": "^2.1 || ^3",
"symfony/doctrine-bridge": "^5.4.19 || ^6.0.7",
"symfony/framework-bundle": "^5.4 || ^6.0",
"symfony/doctrine-bridge": "^5.4.19 || ^6.0.7 || ^7.0",
"symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0",
"symfony/service-contracts": "^1.1.1 || ^2.0 || ^3"
},
"require-dev": {
Expand All @@ -53,14 +53,14 @@
"psalm/plugin-phpunit": "^0.18.4",
"psalm/plugin-symfony": "^4",
"psr/log": "^1.1.4 || ^2.0 || ^3.0",
"symfony/phpunit-bridge": "^6.1",
"symfony/property-info": "^5.4 || ^6.0",
"symfony/proxy-manager-bridge": "^5.4 || ^6.0",
"symfony/security-bundle": "^5.4 || ^6.0",
"symfony/twig-bridge": "^5.4 || ^6.0",
"symfony/validator": "^5.4 || ^6.0",
"symfony/web-profiler-bundle": "^5.4 || ^6.0",
"symfony/yaml": "^5.4 || ^6.0",
"symfony/phpunit-bridge": "^6.1 || ^7.0",
"symfony/property-info": "^5.4 || ^6.0 || ^7.0",
"symfony/proxy-manager-bridge": "^5.4 || ^6.0 || ^7.0",
"symfony/security-bundle": "^5.4 || ^6.0 || ^7.0",
"symfony/twig-bridge": "^5.4 || ^6.0 || ^7.0",
"symfony/validator": "^5.4 || ^6.0 || ^7.0",
"symfony/web-profiler-bundle": "^5.4 || ^6.0 || ^7.0",
"symfony/yaml": "^5.4 || ^6.0 || ^7.0",
"twig/twig": "^1.34 || ^2.12 || ^3.0",
"vimeo/psalm": "^4.30"
},
Expand Down

0 comments on commit 2b7916e

Please sign in to comment.