Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge 2.10.x into 2.11.x #1702

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ public function testAddCustomHydrationMode(): void
$this->assertDICDefinitionMethodCallOnce($definition, 'addCustomHydrationMode', ['test_hydrator', TestHydrator::class]);
}

/** @requires PHP 8.1 */
public function testAddFilter(): void
{
if (! interface_exists(EntityManagerInterface::class)) {
Expand Down
5 changes: 3 additions & 2 deletions Tests/DependencyInjection/Compiler/IdGeneratorPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ public function testRepositoryServiceWiring(): void
'framework' => [
'http_method_override' => false,
'annotations' => [
'enabled' => class_exists(AnnotationReader::class) && Kernel::VERSION_ID < 64000,
'enabled' => class_exists(AnnotationReader::class) && Kernel::VERSION_ID < 60400,
],
'php_errors' => ['log' => true],
] + (Kernel::VERSION_ID >= 62000 ? ['handle_all_throwables' => true] : []),
] + (Kernel::VERSION_ID >= 60200 ? ['handle_all_throwables' => true] : []),
], $container);

$extension = new DoctrineExtension();
Expand All @@ -111,6 +111,7 @@ public function testRepositoryServiceWiring(): void
'orm' => [
'mappings' => $mappings,
'report_fields_where_declared' => true,
'enable_lazy_ghost_objects' => PHP_VERSION_ID >= 80100,
],
],
], $container);
Expand Down
5 changes: 3 additions & 2 deletions Tests/DependencyInjection/Fixtures/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
$container->loadFromExtension('framework', [
'secret' => 'F00',
'http_method_override' => false,
'annotations' => class_exists(Annotation::class) && Kernel::VERSION_ID <= 64000,
'annotations' => class_exists(Annotation::class) && Kernel::VERSION_ID <= 60400,
'php_errors' => ['log' => true],
] + (Kernel::VERSION_ID >= 62000 ? ['handle_all_throwables' => true] : []));
] + (Kernel::VERSION_ID >= 60200 ? ['handle_all_throwables' => true] : []));
$container->loadFromExtension('doctrine', [
'dbal' => [
'driver' => 'pdo_sqlite',
Expand All @@ -53,6 +53,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
'orm' => [
'report_fields_where_declared' => true,
'auto_generate_proxy_classes' => true,
'enable_lazy_ghost_objects' => PHP_VERSION_ID >= 80100,
'mappings' => [
'RepositoryServiceBundle' => [
'type' => PHP_VERSION_ID >= 80000 ? 'attribute' : 'annotation',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<connection name="default" dbname="db" />
</dbal>

<orm>
<orm enable-lazy-ghost-objects="true">
<filter name="soft_delete" enabled="true" >Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\TestFilter</filter>
<filter name="myFilter" enabled="true" class="Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\TestFilter">
<parameter name="myParameter">myValue</parameter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ doctrine:
dbname: db

orm:
enable_lazy_ghost_objects: true
filters:
soft_delete:
class: Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\TestFilter
Expand Down
2 changes: 1 addition & 1 deletion Tests/LockStoreSchemaListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testLockStoreSchemaSubscriberWiring(array $config, int $expected
$extension->load(
[
'framework' => ['http_method_override' => false, 'php_errors' => ['log' => true]]
+ (Kernel::VERSION_ID >= 62000 ? ['handle_all_throwables' => true] : []) + $config,
+ (Kernel::VERSION_ID >= 60200 ? ['handle_all_throwables' => true] : []) + $config,
],
$container
);
Expand Down
24 changes: 4 additions & 20 deletions Tests/Mapping/ContainerEntityListenerResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@
use Doctrine\Bundle\DoctrineBundle\Mapping\ContainerEntityListenerResolver;
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use RuntimeException;
use Symfony\Component\DependencyInjection\Container;

use function interface_exists;

class ContainerEntityListenerResolverTest extends TestCase
{
private ContainerEntityListenerResolver $resolver;

/** @var ContainerInterface&MockObject */
private ContainerInterface $container;
private Container $container;

public static function setUpBeforeClass(): void
{
Expand All @@ -32,7 +30,7 @@ protected function setUp(): void
{
parent::setUp();

$this->container = $this->createMock(ContainerInterface::class);
$this->container = new Container();
$this->resolver = new ContainerEntityListenerResolver($this->container);
}

Expand Down Expand Up @@ -62,16 +60,7 @@ public function testRegisterServiceAndResolve(): void
$object = new $className();

$this->resolver->registerService($className, $serviceId);
$this->container
->expects($this->any())
->method('has')
->with($serviceId)
->will($this->returnValue(true));
$this->container
->expects($this->any())
->method('get')
->with($serviceId)
->will($this->returnValue($object));
$this->container->set($serviceId, $object);

$this->assertInstanceOf($className, $this->resolver->resolve($className));
$this->assertSame($object, $this->resolver->resolve($className));
Expand All @@ -83,11 +72,6 @@ public function testRegisterMissingServiceAndResolve(): void
$serviceId = 'app.entity_listener';

$this->resolver->registerService($className, $serviceId);
$this->container
->expects($this->any())
->method('has')
->with($serviceId)
->will($this->returnValue(false));

$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('There is no service named');
Expand Down
70 changes: 20 additions & 50 deletions Tests/RegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use InvalidArgumentException;
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 @@ -26,28 +26,23 @@ class RegistryTest extends TestCase
{
public function testGetDefaultConnectionName(): void
{
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$registry = new Registry($container, [], [], 'default', 'default');
$registry = new Registry(new 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(new 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())
->method('get')
->with($this->equalTo('doctrine.dbal.default_connection'))
->will($this->returnValue($conn));
$container = new Container();
$container->set('doctrine.dbal.default_connection', $conn);

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

Expand All @@ -57,11 +52,8 @@ public function testGetDefaultConnection(): void
public function testGetConnection(): void
{
$conn = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$container->expects($this->once())
->method('get')
->with($this->equalTo('doctrine.dbal.default_connection'))
->will($this->returnValue($conn));
$container = new Container();
$container->set('doctrine.dbal.default_connection', $conn);

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

Expand All @@ -70,8 +62,7 @@ public function testGetConnection(): void

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

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Doctrine ORM Connection named "default" does not exist.');
Expand All @@ -80,20 +71,16 @@ 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(new 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())
->method('get')
->with($this->equalTo('doctrine.orm.default_entity_manager'))
->will($this->returnValue($em));
$container = new Container();
$container->set('doctrine.orm.default_entity_manager', $em);

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

Expand All @@ -103,11 +90,8 @@ public function testGetDefaultEntityManager(): void
public function testGetEntityManager(): void
{
$em = new stdClass();
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$container->expects($this->once())
->method('get')
->with($this->equalTo('doctrine.orm.default_entity_manager'))
->will($this->returnValue($em));
$container = new Container();
$container->set('doctrine.orm.default_entity_manager', $em);

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

Expand All @@ -116,8 +100,7 @@ public function testGetEntityManager(): void

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

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

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

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

$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$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())
->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);
$container = new Container();
$container->set('doctrine.orm.noproxy_entity_manager', $noProxyManager);
$container->set('doctrine.orm.proxy_entity_manager', $proxyManager);

$entityManagers = [
'uninitialized' => 'doctrine.orm.uninitialized_entity_manager',
Expand All @@ -185,13 +160,8 @@ 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')
->withConsecutive(['doctrine.orm.uninitialized_entity_manager'], ['doctrine.orm.ghost_entity_manager'])
->willReturnOnConsecutiveCalls(false, true, true);
$container->method('get')
->withConsecutive(['doctrine.orm.ghost_entity_manager'], ['doctrine.orm.ghost_entity_manager'], ['doctrine.orm.ghost_entity_manager'])
->willReturnOnConsecutiveCalls($ghostManager, $ghostManager, $ghostManager);
$container = new Container();
$container->set('doctrine.orm.ghost_entity_manager', $ghostManager);

$entityManagers = [
'uninitialized' => 'doctrine.orm.uninitialized_entity_manager',
Expand Down
20 changes: 7 additions & 13 deletions Tests/Repository/ContainerRepositoryFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectRepository;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use RuntimeException;
use stdClass;
use Symfony\Component\DependencyInjection\Container;

use function interface_exists;

Expand Down Expand Up @@ -127,19 +127,13 @@ public function testCustomRepositoryIsNotAValidClass(): void
}

/** @param array<string, object> $services */
private function createContainer(array $services): ContainerInterface
private function createContainer(array $services): Container
{
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$container->expects($this->any())
->method('has')
->willReturnCallback(static function ($id) use ($services) {
return isset($services[$id]);
});
$container->expects($this->any())
->method('get')
->willReturnCallback(static function ($id) use ($services) {
return $services[$id];
});
$container = new Container();

foreach ($services as $id => $service) {
$container->set($id, $service);
}

return $container;
}
Expand Down
5 changes: 3 additions & 2 deletions Tests/ServiceRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public function testRepositoryServiceWiring(): void
'http_method_override' => false,
'php_errors' => ['log' => true],
'annotations' => [
'enabled' => class_exists(AnnotationReader::class) && Kernel::VERSION_ID < 64000,
'enabled' => class_exists(AnnotationReader::class) && Kernel::VERSION_ID < 60400,
],
] + (Kernel::VERSION_ID >= 62000 ? ['handle_all_throwables' => true] : []),
] + (Kernel::VERSION_ID >= 60200 ? ['handle_all_throwables' => true] : []),
], $container);

$extension = new DoctrineExtension();
Expand All @@ -90,6 +90,7 @@ public function testRepositoryServiceWiring(): void
],
'orm' => [
'report_fields_where_declared' => true,
'enable_lazy_ghost_objects' => PHP_VERSION_ID >= 80100,
'mappings' => [
'RepositoryServiceBundle' => [
'type' => PHP_VERSION_ID >= 80000 ? 'attribute' : 'annotation',
Expand Down
1 change: 0 additions & 1 deletion Tests/baseline-ignore

This file was deleted.

1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"symfony/string": "^5.4 || ^6.0",
"symfony/twig-bridge": "^5.4 || ^6.0",
"symfony/validator": "^5.4 || ^6.0",
"symfony/var-exporter": "^5.4 || ^6.2 || ^7.0",
"symfony/web-profiler-bundle": "^5.4 || ^6.0",
"symfony/yaml": "^5.4 || ^6.0",
"twig/twig": "^1.34 || ^2.12 || ^3.0",
Expand Down
4 changes: 0 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
</testsuite>
</testsuites>

<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="ignoreFile=./Tests/baseline-ignore"/>
</php>

<filter>
<whitelist>
<directory>.</directory>
Expand Down