Skip to content

Commit

Permalink
Merge pull request #1401 from doctrine/2.4.x
Browse files Browse the repository at this point in the history
Merge 2.4.x into 2.5.x
  • Loading branch information
derrabus authored Sep 11, 2021
2 parents afe36ab + ed09522 commit 148df5a
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 46 deletions.
9 changes: 9 additions & 0 deletions .symfony.bundle.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
branches:
- "1.12.x"
- "2.4.x"
- "2.5.x"
maintained_branches:
- "2.4.x"
- "2.5.x"
doc_dir: "Resources/doc/"
dev_branch: "2.5.x"
5 changes: 1 addition & 4 deletions Command/CreateDatabaseDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ protected function configure()
);
}

/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$connectionName = $input->getOption('connection');
if (empty($connectionName)) {
Expand Down
5 changes: 1 addition & 4 deletions Command/DropDatabaseDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ protected function configure()
);
}

/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$connectionName = $input->getOption('connection');
if (empty($connectionName)) {
Expand Down
5 changes: 1 addition & 4 deletions Command/ImportMappingDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ protected function configure()
);
}

/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$type = $input->getArgument('mapping-type') ?: 'xml';
if ($type === 'yaml') {
Expand Down
6 changes: 5 additions & 1 deletion Command/Proxy/DoctrineCommandHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Bundle\FrameworkBundle\Console\Application;

use function assert;
use function class_exists;

/**
* Provides some helper and convenience methods to configure doctrine commands in the context of bundles
Expand All @@ -25,7 +26,10 @@ public static function setApplicationEntityManager(Application $application, $em
$em = $application->getKernel()->getContainer()->get('doctrine')->getManager($emName);
assert($em instanceof EntityManagerInterface);
$helperSet = $application->getHelperSet();
$helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
if (class_exists(ConnectionHelper::class)) {
$helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
}

$helperSet->set(new EntityManagerHelper($em), 'em');
}

Expand Down
5 changes: 1 addition & 4 deletions Command/Proxy/ImportDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ protected function configure()
->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The connection to use for this command');
}

/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
trigger_deprecation(
'doctrine/doctrine-bundle',
Expand Down
5 changes: 1 addition & 4 deletions Command/Proxy/RunSqlDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ protected function configure()
$this->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The connection to use for this command');
}

/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
trigger_deprecation(
'doctrine/doctrine-bundle',
Expand Down
13 changes: 13 additions & 0 deletions DependencyInjection/Compiler/CacheCompatibilityPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ private function updateSecondLevelCache(ContainerBuilder $container, Definition
assert($factoryDefinition instanceof Definition);
$aliasId = (string) $factoryDefinition->getArgument(1);
$this->wrapIfNecessary($container, $aliasId, (string) $container->getAlias($aliasId), false);
foreach ($factoryDefinition->getMethodCalls() as $factoryMethodCall) {
if ($factoryMethodCall[0] !== 'setRegion') {
continue;
}

$driverId = (string) $container->getDefinition($factoryMethodCall[1][0])->getArgument(1);
if (! $container->hasAlias($driverId)) {
continue;
}

$this->wrapIfNecessary($container, $driverId, (string) $container->getAlias($driverId), false);
}

break;
}
}
Expand Down
5 changes: 5 additions & 0 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransportFactory;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;

use function array_intersect_key;
use function array_keys;
Expand Down Expand Up @@ -498,6 +499,10 @@ protected function ormLoad(array $config, ContainerBuilder $container)
$this->loadPropertyInfoExtractor($name, $container);
}

if (! interface_exists(LoaderInterface::class)) {
continue;
}

$this->loadValidatorLoader($name, $container);
}

Expand Down
41 changes: 29 additions & 12 deletions Resources/doc/entity-listeners.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,39 @@ which entity manager it should be registered with.

Full example:

.. code-block:: php
.. configuration-block::

.. code-block:: annotation
<?php
// User.php
<?php
// User.php
use Doctrine\ORM\Mapping as ORM;
use App\UserListener;
/**
* @ORM\Entity
* @ORM\EntityListeners({UserListener::class})
*/
class User
{
// ....
}
.. code-block:: attribute
use Doctrine\ORM\Mapping as ORM;
<?php
// User.php
/**
* @ORM\Entity
* @ORM\EntityListeners({"App\UserListener"})
*/
class User
{
// ....
}
use Doctrine\ORM\Mapping as ORM;
use App\UserListener;
#[ORM\Entity]
#[ORM\EntityListeners([UserListener::class])]
class User
{
// ....
}
.. configuration-block::

Expand Down
3 changes: 1 addition & 2 deletions Resources/doc/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ adding the following line in the ``config/bundles.php`` file of your project::
// ...
];


If you don't have a ``config/bundles.php`` file in your project, chances are that
you're using an older Symfony version. In this case, you should have an
you're using an older Symfony version. In this case, you should have an
``app/AppKernel.php`` file instead. Edit such file::

<?php
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/Collector/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 30 additions & 4 deletions Tests/ConnectionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\Exception as InternalDriverException;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Exception;
use Throwable;
Expand All @@ -19,6 +21,9 @@
use function class_exists;
use function strpos;

// Compatibility with DBAL < 3
class_exists(\Doctrine\DBAL\Platforms\MySqlPlatform::class);

class ConnectionFactoryTest extends TestCase
{
public function testContainer(): void
Expand All @@ -29,9 +34,10 @@ public function testContainer(): void
$config = null;
$eventManager = null;
$mappingTypes = ['' => ''];
$exception = class_exists(Driver\AbstractDriverException::class) ?
/** @psalm-suppress InvalidArgument */
$exception = class_exists(Driver\AbstractDriverException::class) ?
new DriverException('', $this->createMock(Driver\AbstractDriverException::class)) :
new DriverException('', $this->createMock(Driver\AbstractException::class));
new DriverException($this->createMock(InternalDriverException::class), null);

// put the mock into the fake driver
FakeDriver::$exception = $exception;
Expand Down Expand Up @@ -139,14 +145,18 @@ class FakeDriver implements Driver
* So we have to fake the exception a driver would normally throw.
*
* @link https://github.com/doctrine/DoctrineBundle/issues/673
*
* @psalm-suppress InvalidReturnStatement
* @psalm-suppress InvalidReturnType
* @psalm-suppress UndefinedClass
*/
public function getDatabasePlatform(): AbstractPlatform
{
if (self::$exception !== null) {
throw self::$exception;
}

return static::$platform ?? new MySqlPlatform();
return static::$platform ?? new MySQLPlatform();
}

// ----- below this line follow only dummy methods to satisfy the interface requirements ----
Expand All @@ -169,6 +179,22 @@ public function getSchemaManager(Connection $conn, ?AbstractPlatform $platform =
throw new Exception('not implemented');
}

/**
* @psalm-suppress InvalidReturnStatement
* @psalm-suppress InvalidReturnType
* @psalm-suppress MissingDependency
* @psalm-suppress UndefinedClass
*/
public function getExceptionConverter(): ExceptionConverter
{
return new class implements ExceptionConverter {
public function convert(InternalDriverException $exception, ?Query $query): DriverException
{
return new DriverException($exception, $query);
}
};
}

public function getName(): string
{
return 'FakeDriver';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class CacheCompatibilityPassTest extends TestCase

public function testCacheConfigUsingServiceDefinedByApplication(): void
{
$this->expectNotToPerformAssertions();
(new class () extends TestKernel {
public function registerContainerConfiguration(LoaderInterface $loader): void
{
Expand All @@ -36,6 +35,12 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
'orm' => [
'query_cache_driver' => ['type' => 'service', 'id' => 'custom_cache_service'],
'result_cache_driver' => ['type' => 'pool', 'pool' => 'doctrine.system_cache_pool'],
'second_level_cache' => [
'enabled' => true,
'regions' => [
'lifelong' => ['lifetime' => 0, 'cache_driver' => ['type' => 'pool', 'pool' => 'doctrine.system_cache_pool']],
],
],
],
]
);
Expand All @@ -48,6 +53,8 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
});
}
})->boot();

$this->addToAssertionCount(1);
}

/** @group legacy */
Expand Down
9 changes: 7 additions & 2 deletions Tests/ProfilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public function setUp(): void
{
$this->logger = new DebugStack();
$registry = $this->getMockBuilder(ManagerRegistry::class)->getMock();
$registry->expects($this->once())->method('getManagers')->willReturn([]);
$registry->method('getConnectionNames')->willReturn([]);
$registry->method('getManagerNames')->willReturn([]);
$registry->method('getManagers')->willReturn([]);
$this->collector = new DoctrineDataCollector($registry);
$this->collector->addLogger('foo', $this->logger);

Expand All @@ -62,7 +64,10 @@ public function setUp(): void
$this->twig->addExtension(new CodeExtension('', '', ''));
$this->twig->addExtension(new RoutingExtension($urlGenerator));
$this->twig->addExtension(new HttpKernelExtension());
/** @psalm-suppress InternalClass */
/**
* @psalm-suppress InternalClass
* @psalm-suppress InternalMethod
*/
$this->twig->addExtension(new WebProfilerExtension());
$this->twig->addExtension(new DoctrineExtension());

Expand Down
4 changes: 2 additions & 2 deletions Tests/RegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ public function testReset(): void

$container->expects($this->any())
->method('get')
->withConsecutive(['doctrine.orm.noproxy_entity_manager'], ['doctrine.orm.proxy_entity_manager'], ['doctrine.orm.proxy_entity_manager'])
->willReturnOnConsecutiveCalls($noProxyManager, $proxyManager, $proxyManager);
->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);

$entityManagers = [
'uninitialized' => 'doctrine.orm.uninitialized_entity_manager',
Expand Down
14 changes: 13 additions & 1 deletion Tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension;
use Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\TestType;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use PHPUnit\Framework\TestCase as BaseTestCase;
use ReflectionClass;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;

use function class_exists;
use function sys_get_temp_dir;
use function uniqid;

// Compatibility with DBAL < 3
class_exists(\Doctrine\DBAL\Platforms\MySqlPlatform::class);

class TestCase extends BaseTestCase
{
/**
* @psalm-suppress InvalidClass
* @psalm-suppress UndefinedClass
*/
public function createXmlBundleTestContainer(): ContainerBuilder
{
$container = new ContainerBuilder(new ParameterBag([
Expand Down Expand Up @@ -69,7 +79,9 @@ public function createXmlBundleTestContainer(): ContainerBuilder
],
], $container);

$container->setDefinition('my.platform', new Definition('Doctrine\DBAL\Platforms\MySqlPlatform'))->setPublic(true);
// Fix casing: The class is named MySqlPlatform on DBAL 2.
$platformClassName = (new ReflectionClass(MySQLPlatform::class))->getName();
$container->setDefinition('my.platform', new Definition($platformClassName))->setPublic(true);

// Register dummy cache services so we don't have to load the FrameworkExtension
$container->setDefinition('cache.system', (new Definition(ArrayAdapter::class))->setPublic(true));
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
],
"require": {
"php": "^7.1 || ^8.0",
"doctrine/annotations": "^1",
"doctrine/cache": "^1.11 || ^2.0",
"doctrine/dbal": "^2.9.0|^3.0",
"doctrine/persistence": "^1.3.3|^2.0",
Expand Down

0 comments on commit 148df5a

Please sign in to comment.