Skip to content

[DoctrineBridge] Removed legacy code related to DoctrineChoiceLoader #31887

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

Merged
merged 1 commit into from
Jun 6, 2019
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
6 changes: 6 additions & 0 deletions src/Symfony/Bridge/Doctrine/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
CHANGELOG
=========

5.0.0
-----

* passing an `IdReader` to the `DoctrineChoiceLoader` when the query cannot be optimized with single id field, throws an exception; pass `null` instead
* not explicitly passing an instance of `IdReader` to `DoctrineChoiceLoader` when it can optimize single id field, will not apply any optimization

4.4.0
-----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,7 @@ public function __construct(ObjectManager $manager, string $class, IdReader $idR
$classMetadata = $manager->getClassMetadata($class);

if ($idReader && !$idReader->isSingleId()) {
@trigger_error(sprintf('Passing an instance of "%s" to "%s" with an entity class "%s" that has a composite id is deprecated since Symfony 4.3 and will throw an exception in 5.0.', IdReader::class, __CLASS__, $class), E_USER_DEPRECATED);

// In Symfony 5.0
// throw new \InvalidArgumentException(sprintf('The second argument `$idReader` of "%s" must be null when the query cannot be optimized because of composite id fields.', __METHOD__));
}

if ((5 > \func_num_args() || false !== func_get_arg(4)) && null === $idReader) {
$idReader = new IdReader($manager, $classMetadata);

if ($idReader->isSingleId()) {
@trigger_error(sprintf('Not explicitly passing an instance of "%s" to "%s" when it can optimize single id entity "%s" has been deprecated in 4.3 and will not apply any optimization in 5.0.', IdReader::class, __CLASS__, $class), E_USER_DEPRECATED);
} else {
$idReader = null;
}
throw new \InvalidArgumentException(sprintf('The second argument `$idReader` of "%s" must be null when the query cannot be optimized because of composite id fields.', __METHOD__));
}

$this->manager = $manager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader;
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface;
use Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader;
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity;
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface;

Expand Down Expand Up @@ -377,70 +376,8 @@ public function testLoadChoicesForValuesLoadsOnlyChoicesIfValueIsIdReader()
}

/**
* @group legacy
*
* @expectedDeprecation Not explicitly passing an instance of "Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader" to "Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader" when it can optimize single id entity "%s" has been deprecated in 4.3 and will not apply any optimization in 5.0.
*/
public function testLoaderWithoutIdReaderCanBeOptimized()
{
$obj1 = new SingleIntIdEntity('1', 'one');
$obj2 = new SingleIntIdEntity('2', 'two');

$metadata = $this->createMock(ClassMetadata::class);
$metadata->expects($this->once())
->method('getIdentifierFieldNames')
->willReturn(['idField'])
;
$metadata->expects($this->any())
->method('getIdentifierValues')
->willReturnCallback(function ($obj) use ($obj1, $obj2) {
if ($obj === $obj1) {
return ['idField' => '1'];
}
if ($obj === $obj2) {
return ['idField' => '2'];
}

return null;
})
;

$this->om = $this->createMock(ObjectManager::class);
$this->om->expects($this->once())
->method('getClassMetadata')
->with(SingleIntIdEntity::class)
->willReturn($metadata)
;
$this->om->expects($this->any())
->method('contains')
->with($this->isInstanceOf(SingleIntIdEntity::class))
->willReturn(true)
;

$loader = new DoctrineChoiceLoader(
$this->om,
SingleIntIdEntity::class,
null,
$this->objectLoader
);

$choices = [$obj1, $obj2];

$this->repository->expects($this->never())
->method('findAll');

$this->objectLoader->expects($this->once())
->method('getEntitiesByIds')
->with('idField', ['1'])
->willReturn($choices);

$this->assertSame([$obj1], $loader->loadChoicesForValues(['1']));
}

/**
* @group legacy
*
* @deprecationMessage Passing an instance of "Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader" to "Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader" with an entity class "stdClass" that has a composite id is deprecated since Symfony 4.3 and will throw an exception in 5.0.
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The second argument `$idReader` of "Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader::__construct" must be null when the query cannot be optimized because of composite id fields.
*/
public function testPassingIdReaderWithoutSingleIdEntity()
{
Expand All @@ -450,13 +387,6 @@ public function testPassingIdReaderWithoutSingleIdEntity()
->willReturn(false)
;

$loader = new DoctrineChoiceLoader(
$this->om,
$this->class,
$idReader,
$this->objectLoader
);

$this->assertInstanceOf(DoctrineChoiceLoader::class, $loader);
new DoctrineChoiceLoader($this->om, $this->class, $idReader, $this->objectLoader);
}
}