Skip to content

Commit 8d348d3

Browse files
committed
Replace deprecated ObjectManager
1 parent 6c06b69 commit 8d348d3

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

form/data_transformers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ First, create the custom field type class::
342342
namespace AppBundle\Form;
343343

344344
use AppBundle\Form\DataTransformer\IssueToNumberTransformer;
345-
use Doctrine\Common\Persistence\ObjectManager;
345+
use Doctrine\Persistence\ManagerRegistry;
346346
use Symfony\Component\Form\AbstractType;
347347
use Symfony\Component\Form\Extension\Core\Type\TextType;
348348
use Symfony\Component\Form\FormBuilderInterface;

form/unit_testing.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,27 +135,27 @@ make sure the ``FormRegistry`` uses the created instance::
135135
namespace Tests\AppBundle\Form\Type;
136136

137137
use AppBundle\Form\Type\TestedType;
138-
use Doctrine\Common\Persistence\ObjectManager;
138+
use Doctrine\Persistence\ManagerRegistry;
139139
use Symfony\Component\Form\PreloadedExtension;
140140
use Symfony\Component\Form\Test\TypeTestCase;
141141
// ...
142142

143143
class TestedTypeTest extends TypeTestCase
144144
{
145-
private $objectManager;
145+
private $managerRegistry;
146146

147147
protected function setUp()
148148
{
149149
// mock any dependencies
150-
$this->objectManager = $this->createMock(ObjectManager::class);
150+
$this->managerRegistry = $this->createMock(ManagerRegistry::class);
151151

152152
parent::setUp();
153153
}
154154

155155
protected function getExtensions()
156156
{
157157
// create a type instance with the mocked dependencies
158-
$type = new TestedType($this->objectManager);
158+
$type = new TestedType($this->managerRegistry);
159159

160160
return [
161161
// register the type instances with the PreloadedExtension

reference/forms/types/entity.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ or the short alias name (as shown prior).
193193
``em``
194194
~~~~~~
195195

196-
**type**: ``string`` | ``Doctrine\Common\Persistence\ObjectManager`` **default**: the default entity manager
196+
**type**: ``string`` | ``Doctrine\Persistence\ManagerRegistry`` **default**: the default entity manager
197197

198198
If specified, this entity manager will be used to load the choices
199199
instead of the ``default`` entity manager.

service_container/parent_services.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ you may have multiple repository classes which need the
1212
// src/AppBundle/Repository/BaseDoctrineRepository.php
1313
namespace AppBundle\Repository;
1414

15-
use Doctrine\Common\Persistence\ObjectManager;
15+
use Doctrine\Persistence\ManagerRegistry;
1616
use Psr\Log\LoggerInterface;
1717

1818
// ...
1919
abstract class BaseDoctrineRepository
2020
{
21-
protected $objectManager;
21+
protected $managerRegistry;
2222
protected $logger;
2323

24-
public function __construct(ObjectManager $objectManager)
24+
public function __construct(ManagerRegistry $managerRegistry)
2525
{
26-
$this->objectManager = $objectManager;
26+
$this->managerRegistry = $managerRegistry;
2727
}
2828

2929
public function setLogger(LoggerInterface $logger)

testing/database.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,20 @@ Suppose the class you want to test looks like this::
4545
namespace AppBundle\Salary;
4646

4747
use AppBundle\Entity\Employee;
48-
use Doctrine\Common\Persistence\ObjectManager;
48+
use Doctrine\Persistence\ManagerRegistry;
4949

5050
class SalaryCalculator
5151
{
52-
private $objectManager;
52+
private $managerRegistry;
5353

54-
public function __construct(ObjectManager $objectManager)
54+
public function __construct(ManagerRegistry $managerRegistry)
5555
{
56-
$this->objectManager = $objectManager;
56+
$this->managerRegistry = $managerRegistry;
5757
}
5858

5959
public function calculateTotalSalary($id)
6060
{
61-
$employeeRepository = $this->objectManager
61+
$employeeRepository = $this->managerRegistry
6262
->getRepository(Employee::class);
6363
$employee = $employeeRepository->find($id);
6464

@@ -74,7 +74,7 @@ it's easy to pass a mock object within a test::
7474

7575
use AppBundle\Entity\Employee;
7676
use AppBundle\Salary\SalaryCalculator;
77-
use Doctrine\Common\Persistence\ObjectManager;
77+
use Doctrine\Persistence\ManagerRegistry;
7878
use Doctrine\Common\Persistence\ObjectRepository;
7979
use PHPUnit\Framework\TestCase;
8080

@@ -95,14 +95,14 @@ it's easy to pass a mock object within a test::
9595
->willReturn($employee);
9696

9797
// Last, mock the EntityManager to return the mock of the repository
98-
$objectManager = $this->createMock(ObjectManager::class);
98+
$managerRegistry = $this->createMock(ManagerRegistry::class);
9999
// use getMock() on PHPUnit 5.3 or below
100-
// $objectManager = $this->getMock(ObjectManager::class);
101-
$objectManager->expects($this->any())
100+
// $managerRegistry = $this->getMock(ManagerRegistry::class);
101+
$managerRegistry->expects($this->any())
102102
->method('getRepository')
103103
->willReturn($employeeRepository);
104104

105-
$salaryCalculator = new SalaryCalculator($objectManager);
105+
$salaryCalculator = new SalaryCalculator($managerRegistry);
106106
$this->assertEquals(2100, $salaryCalculator->calculateTotalSalary(1));
107107
}
108108
}

0 commit comments

Comments
 (0)