Skip to content

Commit

Permalink
Merge branch '1.12.x' into 2.0.x
Browse files Browse the repository at this point in the history
# By Gabriel Ostrolucký (2) and others
# Via GitHub (5) and Gabriel Ostrolucký (1)
* 1.12.x:
  Fix CS
  Fix dead link to DBAL docs
  Update deprecation messages to follow the Symfony convention
  Fix render controller when explaining a query
  Update namespace
  Document UOW reset introduced since 1.12.3/2.0.3

# Conflicts:
#	DependencyInjection/DoctrineExtension.php
#	Tests/TestCase.php
  • Loading branch information
ostrolucky committed Apr 23, 2020
1 parent 6926771 commit b0e0deb
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Resources/config/orm.xml
Expand Up @@ -29,7 +29,7 @@
<parameter key="doctrine.orm.cache.zenddata.class">Doctrine\Common\Cache\ZendDataCache</parameter>

<!-- metadata -->
<parameter key="doctrine.orm.metadata.driver_chain.class">Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain</parameter>
<parameter key="doctrine.orm.metadata.driver_chain.class">Doctrine\Persistence\Mapping\Driver\MappingDriverChain</parameter>
<parameter key="doctrine.orm.metadata.annotation.class">Doctrine\ORM\Mapping\Driver\AnnotationDriver</parameter>
<parameter key="doctrine.orm.metadata.xml.class">Doctrine\ORM\Mapping\Driver\SimplifiedXmlDriver</parameter>
<parameter key="doctrine.orm.metadata.yml.class">Doctrine\ORM\Mapping\Driver\SimplifiedYamlDriver</parameter>
Expand Down
2 changes: 1 addition & 1 deletion Resources/doc/configuration.rst
Expand Up @@ -1069,4 +1069,4 @@ which is the first one defined or the one configured via the
Each connection is also accessible via the ``doctrine.dbal.[name]_connection``
service where ``[name]`` is the name of the connection.

.. _DBAL documentation: http://www.doctrine-project.org/docs/dbal/2.0/en
.. _DBAL documentation: https://www.doctrine-project.org/projects/doctrine-dbal/en/2.10/index.html
2 changes: 1 addition & 1 deletion Resources/views/Collector/db.html.twig
Expand Up @@ -112,7 +112,7 @@
{% set profiler_markup_version = profiler_markup_version|default(1) %}

{% if 'explain' == page %}
{{ render(controller('DoctrineBundle:Profiler:explain', {
{{ render(controller('Doctrine\\Bundle\\DoctrineBundle\\Controller\\ProfilerController::explainAction', {
token: token,
panel: 'db',
connectionName: request.query.get('connection'),
Expand Down
13 changes: 7 additions & 6 deletions Tests/DependencyInjection/DoctrineExtensionTest.php
Expand Up @@ -257,7 +257,7 @@ public function testDependencyInjectionConfigurationDefaults() : void
$this->assertEquals('11211', $container->getParameter('doctrine.orm.cache.memcache_port'));
$this->assertEquals('Memcache', $container->getParameter('doctrine.orm.cache.memcache_instance.class'));
$this->assertEquals('Doctrine\Common\Cache\XcacheCache', $container->getParameter('doctrine.orm.cache.xcache.class'));
$this->assertEquals('Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain', $container->getParameter('doctrine.orm.metadata.driver_chain.class'));
$this->assertEquals('Doctrine\Persistence\Mapping\Driver\MappingDriverChain', $container->getParameter('doctrine.orm.metadata.driver_chain.class'));
$this->assertEquals('Doctrine\ORM\Mapping\Driver\AnnotationDriver', $container->getParameter('doctrine.orm.metadata.annotation.class'));
$this->assertEquals('Doctrine\ORM\Mapping\Driver\SimplifiedXmlDriver', $container->getParameter('doctrine.orm.metadata.xml.class'));
$this->assertEquals('Doctrine\ORM\Mapping\Driver\SimplifiedYamlDriver', $container->getParameter('doctrine.orm.metadata.yml.class'));
Expand Down Expand Up @@ -350,13 +350,14 @@ public function testUseSavePointsAddMethodCallToAddSavepointsToTheConnection() :
$container = $this->getContainer();
$extension = new DoctrineExtension();

$extension->load([[
'dbal' => [
'connections' => [
'default' => ['password' => 'foo', 'use_savepoints' => true],
$extension->load([
[
'dbal' => [
'connections' => [
'default' => ['password' => 'foo', 'use_savepoints' => true],
],
],
],
],
], $container);

$calls = $container->getDefinition('doctrine.dbal.default_connection')->getMethodCalls();
Expand Down
25 changes: 13 additions & 12 deletions Tests/ServiceRepositoryTest.php
Expand Up @@ -50,21 +50,22 @@ public function testRepositoryServiceWiring() : void

$extension = new DoctrineExtension();
$container->registerExtension($extension);
$extension->load([[
'dbal' => [
'driver' => 'pdo_sqlite',
'charset' => 'UTF8',
],
'orm' => [
'mappings' => [
'RepositoryServiceBundle' => [
'type' => 'annotation',
'dir' => __DIR__ . '/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Entity',
'prefix' => 'Fixtures\Bundles\RepositoryServiceBundle\Entity',
$extension->load([
[
'dbal' => [
'driver' => 'pdo_sqlite',
'charset' => 'UTF8',
],
'orm' => [
'mappings' => [
'RepositoryServiceBundle' => [
'type' => 'annotation',
'dir' => __DIR__ . '/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Entity',
'prefix' => 'Fixtures\Bundles\RepositoryServiceBundle\Entity',
],
],
],
],
],
], $container);

$def = $container->register(TestCustomServiceRepoRepository::class, TestCustomServiceRepoRepository::class)
Expand Down
48 changes: 25 additions & 23 deletions Tests/TestCase.php
Expand Up @@ -32,37 +32,39 @@ public function createXmlBundleTestContainer() : ContainerBuilder

$extension = new DoctrineExtension();
$container->registerExtension($extension);
$extension->load([[
'dbal' => [
'connections' => [
'default' => [
'driver' => 'pdo_mysql',
'charset' => 'UTF8',
'platform-service' => 'my.platform',
$extension->load([
[
'dbal' => [
'connections' => [
'default' => [
'driver' => 'pdo_mysql',
'charset' => 'UTF8',
'platform-service' => 'my.platform',
],
],
],
'default_connection' => 'default',
'types' => [
'test' => [
'class' => TestType::class,
'default_connection' => 'default',
'types' => [
'test' => [
'class' => TestType::class,
],
],
],
], 'orm' => [
'default_entity_manager' => 'default',
'entity_managers' => [
'default' => [
'mappings' => [
'XmlBundle' => [
'type' => 'xml',
'dir' => __DIR__ . '/DependencyInjection/Fixtures/Bundles/XmlBundle/Resources/config/doctrine',
'prefix' => 'Fixtures\Bundles\XmlBundle\Entity',
'orm' => [
'default_entity_manager' => 'default',
'entity_managers' => [
'default' => [
'mappings' => [
'XmlBundle' => [
'type' => 'xml',
'dir' => __DIR__ . '/DependencyInjection/Fixtures/Bundles/XmlBundle/Resources/config/doctrine',
'prefix' => 'Fixtures\Bundles\XmlBundle\Entity',
],
],
],
],
'resolve_target_entities' => ['Symfony\Component\Security\Core\User\UserInterface' => 'stdClass'],
],
'resolve_target_entities' => ['Symfony\Component\Security\Core\User\UserInterface' => 'stdClass'],
],
],
], $container);

$container->setDefinition('my.platform', new Definition('Doctrine\DBAL\Platforms\MySqlPlatform'))->setPublic(true);
Expand Down
28 changes: 28 additions & 0 deletions UPGRADE-1.12.md
Expand Up @@ -15,3 +15,31 @@ Service aliases

* Deprecated the `Symfony\Bridge\Doctrine\RegistryInterface` and `Doctrine\Bundle\DoctrineBundle\Registry` service alias, use `Doctrine\Common\Persistence\ManagerRegistry` instead.
* Deprecated the `Doctrine\Common\Persistence\ObjectManager` service alias, use `Doctrine\ORM\EntityManagerInterface` instead.

UnitOfWork cleared between each request
---------------------------------------
If all of these are true:
* You call `Symfony\Bundle\FrameworkBundle\Client::disableReboot()` in your test case
* Trigger multiple HTTP requests (via `Symfony\Bundle\FrameworkBundle\Client::request()` etc.) within your test case
* Your test case relies on Doctrine ORM keeping references to old entities between requests (this is most obvious when calling `Doctrine\Persistence\ObjectManager::refresh`)

Your test case will fail since `DoctrineBundle` 1.12.3, as identity map is now cleared between each request
to better simulate real requests and avoid memory leaks. You have two options to solve this:

1. Change your test cases with new behaviour in mind. In a lot of cases this just means to replace `ObjectManager::refresh($entity)` with `$entity = ObjectManager::find($entity->getId())`. This is the recommended solution.
2. Write a compiler pass which restores old behaviour, e.g. by adding the following to your `Kernel` class:
```php
protected function build(\Symfony\Component\DependencyInjection\ContainerBuilder $container)
{
parent::build($container);

if ($this->environment === 'test') {
$container->addCompilerPass(new class implements \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface {
public function process(\Symfony\Component\DependencyInjection\ContainerBuilder $container)
{
$container->getDefinition('doctrine')->clearTag('kernel.reset');
}
}, \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 1);
}
}
```
28 changes: 28 additions & 0 deletions UPGRADE-2.0.md
Expand Up @@ -61,3 +61,31 @@ Types
the type.
* The `commented` configuration option for types will be dropped in a future
release. You should not use it.

UnitOfWork cleared between each request
---------------------------------------
If all of these are true:
* You call `Symfony\Bundle\FrameworkBundle\Client::disableReboot()` in your test case
* Trigger multiple HTTP requests (via `Symfony\Bundle\FrameworkBundle\Client::request()` etc.) within your test case
* Your test case relies on Doctrine ORM keeping references to old entities between requests (this is most obvious when calling `Doctrine\Persistence\ObjectManager::refresh`)

Your test case will fail since `DoctrineBundle` 2.0.3, as identity map is now cleared between each request
to better simulate real requests and avoid memory leaks. You have two options to solve this:

1. Change your test cases with new behaviour in mind. In a lot of cases this just means to replace `ObjectManager::refresh($entity)` with `$entity = ObjectManager::find($entity->getId())`. This is the recommended solution.
2. Write a compiler pass which restores old behaviour, e.g. by adding the following to your `Kernel` class:
```php
protected function build(\Symfony\Component\DependencyInjection\ContainerBuilder $container)
{
parent::build($container);

if ($this->environment === 'test') {
$container->addCompilerPass(new class implements \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface {
public function process(\Symfony\Component\DependencyInjection\ContainerBuilder $container)
{
$container->getDefinition('doctrine')->clearTag('kernel.reset');
}
}, \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 1);
}
}
```

0 comments on commit b0e0deb

Please sign in to comment.