Skip to content

Commit 22b1eb4

Browse files
minor symfony#39941 Use createMock() and use import instead of FQCN (OskarStark)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- Use createMock() and use import instead of FQCN | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | --- | License | MIT | Doc PR | --- Commits ------- e7e61ee Use createMock() and use import instead of FQCN
2 parents c925f4c + e7e61ee commit 22b1eb4

File tree

622 files changed

+3640
-2845
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

622 files changed

+3640
-2845
lines changed

src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Tests\DataCollector;
1313

14+
use Doctrine\DBAL\Logging\DebugStack;
1415
use Doctrine\DBAL\Platforms\MySqlPlatform;
1516
use Doctrine\DBAL\Version;
1617
use Doctrine\Persistence\ManagerRegistry;
@@ -236,7 +237,7 @@ private function createCollector($queries)
236237
->method('getDatabasePlatform')
237238
->willReturn(new MySqlPlatform());
238239

239-
$registry = $this->getMockBuilder(ManagerRegistry::class)->getMock();
240+
$registry = $this->createMock(ManagerRegistry::class);
240241
$registry
241242
->expects($this->any())
242243
->method('getConnectionNames')
@@ -249,7 +250,7 @@ private function createCollector($queries)
249250
->method('getConnection')
250251
->willReturn($connection);
251252

252-
$logger = $this->getMockBuilder(\Doctrine\DBAL\Logging\DebugStack::class)->getMock();
253+
$logger = $this->createMock(DebugStack::class);
253254
$logger->queries = $queries;
254255

255256
$collector = new DoctrineDataCollector($registry);

src/Symfony/Bridge/Doctrine/Tests/DataFixtures/ContainerAwareLoaderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader;
1616
use Symfony\Bridge\Doctrine\Tests\Fixtures\ContainerAwareFixture;
17+
use Symfony\Component\DependencyInjection\ContainerInterface;
1718

1819
class ContainerAwareLoaderTest extends TestCase
1920
{
2021
public function testShouldSetContainerOnContainerAwareFixture()
2122
{
22-
$container = $this->getMockBuilder(\Symfony\Component\DependencyInjection\ContainerInterface::class)->getMock();
23+
$container = $this->createMock(ContainerInterface::class);
2324
$loader = new ContainerAwareLoader($container);
2425
$fixture = new ContainerAwareFixture();
2526

src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/DoctrineExtensionTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Doctrine\Tests\DependencyInjection;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\DependencyInjection\Definition;
1718
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@@ -22,7 +23,7 @@
2223
class DoctrineExtensionTest extends TestCase
2324
{
2425
/**
25-
* @var \Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension
26+
* @var AbstractDoctrineExtension
2627
*/
2728
private $extension;
2829

@@ -31,7 +32,7 @@ protected function setUp(): void
3132
parent::setUp();
3233

3334
$this->extension = $this
34-
->getMockBuilder(\Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension::class)
35+
->getMockBuilder(AbstractDoctrineExtension::class)
3536
->setMethods([
3637
'getMappingResourceConfigDirectory',
3738
'getObjectManagerElementName',

src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,17 @@ class DoctrineChoiceLoaderTest extends TestCase
7575

7676
protected function setUp(): void
7777
{
78-
$this->factory = $this->getMockBuilder(ChoiceListFactoryInterface::class)->getMock();
79-
$this->om = $this->getMockBuilder(ObjectManager::class)->getMock();
80-
$this->repository = $this->getMockBuilder(ObjectRepository::class)->getMock();
78+
$this->factory = $this->createMock(ChoiceListFactoryInterface::class);
79+
$this->om = $this->createMock(ObjectManager::class);
80+
$this->repository = $this->createMock(ObjectRepository::class);
8181
$this->class = 'stdClass';
82-
$this->idReader = $this->getMockBuilder(IdReader::class)
83-
->disableOriginalConstructor()
84-
->getMock();
82+
$this->idReader = $this->createMock(IdReader::class);
8583
$this->idReader->expects($this->any())
8684
->method('isSingleId')
8785
->willReturn(true)
8886
;
8987

90-
$this->objectLoader = $this->getMockBuilder(EntityLoaderInterface::class)->getMock();
88+
$this->objectLoader = $this->createMock(EntityLoaderInterface::class);
9189
$this->obj1 = (object) ['name' => 'A'];
9290
$this->obj2 = (object) ['name' => 'B'];
9391
$this->obj3 = (object) ['name' => 'C'];

src/Symfony/Bridge/Doctrine/Tests/Form/DataTransformer/CollectionToArrayTransformerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\Common\Collections\ArrayCollection;
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Bridge\Doctrine\Form\DataTransformer\CollectionToArrayTransformer;
17+
use Symfony\Component\Form\Exception\TransformationFailedException;
1718

1819
/**
1920
* @author Bernhard Schussek <bschussek@gmail.com>
@@ -64,7 +65,7 @@ public function testTransformNull()
6465

6566
public function testTransformExpectsArrayOrCollection()
6667
{
67-
$this->expectException(\Symfony\Component\Form\Exception\TransformationFailedException::class);
68+
$this->expectException(TransformationFailedException::class);
6869
$this->transformer->transform('Foo');
6970
}
7071

src/Symfony/Bridge/Doctrine/Tests/Form/DoctrineOrmTypeGuesserTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ public function requiredProvider()
3434
$return = [];
3535

3636
// Simple field, not nullable
37-
$classMetadata = $this->getMockBuilder(ClassMetadata::class)->disableOriginalConstructor()->getMock();
37+
$classMetadata = $this->createMock(ClassMetadata::class);
3838
$classMetadata->fieldMappings['field'] = true;
3939
$classMetadata->expects($this->once())->method('isNullable')->with('field')->willReturn(false);
4040

4141
$return[] = [$classMetadata, new ValueGuess(true, Guess::HIGH_CONFIDENCE)];
4242

4343
// Simple field, nullable
44-
$classMetadata = $this->getMockBuilder(ClassMetadata::class)->disableOriginalConstructor()->getMock();
44+
$classMetadata = $this->createMock(ClassMetadata::class);
4545
$classMetadata->fieldMappings['field'] = true;
4646
$classMetadata->expects($this->once())->method('isNullable')->with('field')->willReturn(true);
4747

4848
$return[] = [$classMetadata, new ValueGuess(false, Guess::MEDIUM_CONFIDENCE)];
4949

5050
// One-to-one, nullable (by default)
51-
$classMetadata = $this->getMockBuilder(ClassMetadata::class)->disableOriginalConstructor()->getMock();
51+
$classMetadata = $this->createMock(ClassMetadata::class);
5252
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(true);
5353

5454
$mapping = ['joinColumns' => [[]]];
@@ -57,7 +57,7 @@ public function requiredProvider()
5757
$return[] = [$classMetadata, new ValueGuess(false, Guess::HIGH_CONFIDENCE)];
5858

5959
// One-to-one, nullable (explicit)
60-
$classMetadata = $this->getMockBuilder(ClassMetadata::class)->disableOriginalConstructor()->getMock();
60+
$classMetadata = $this->createMock(ClassMetadata::class);
6161
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(true);
6262

6363
$mapping = ['joinColumns' => [['nullable' => true]]];
@@ -66,7 +66,7 @@ public function requiredProvider()
6666
$return[] = [$classMetadata, new ValueGuess(false, Guess::HIGH_CONFIDENCE)];
6767

6868
// One-to-one, not nullable
69-
$classMetadata = $this->getMockBuilder(ClassMetadata::class)->disableOriginalConstructor()->getMock();
69+
$classMetadata = $this->createMock(ClassMetadata::class);
7070
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(true);
7171

7272
$mapping = ['joinColumns' => [['nullable' => false]]];
@@ -75,7 +75,7 @@ public function requiredProvider()
7575
$return[] = [$classMetadata, new ValueGuess(true, Guess::HIGH_CONFIDENCE)];
7676

7777
// One-to-many, no clue
78-
$classMetadata = $this->getMockBuilder(ClassMetadata::class)->disableOriginalConstructor()->getMock();
78+
$classMetadata = $this->createMock(ClassMetadata::class);
7979
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(false);
8080

8181
$return[] = [$classMetadata, null];
@@ -85,10 +85,10 @@ public function requiredProvider()
8585

8686
private function getGuesser(ClassMetadata $classMetadata)
8787
{
88-
$em = $this->getMockBuilder(ObjectManager::class)->getMock();
88+
$em = $this->createMock(ObjectManager::class);
8989
$em->expects($this->once())->method('getClassMetaData')->with('TestEntity')->willReturn($classMetadata);
9090

91-
$registry = $this->getMockBuilder(ManagerRegistry::class)->getMock();
91+
$registry = $this->createMock(ManagerRegistry::class);
9292
$registry->expects($this->once())->method('getManagers')->willReturn([$em]);
9393

9494
return new DoctrineOrmTypeGuesser($registry);

src/Symfony/Bridge/Doctrine/Tests/Form/EventListener/MergeDoctrineCollectionListenerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Form\FormBuilder;
1919
use Symfony\Component\Form\FormEvent;
2020
use Symfony\Component\Form\FormEvents;
21+
use Symfony\Component\Form\FormFactoryInterface;
2122

2223
class MergeDoctrineCollectionListenerTest extends TestCase
2324
{
@@ -32,7 +33,7 @@ protected function setUp(): void
3233
{
3334
$this->collection = new ArrayCollection(['test']);
3435
$this->dispatcher = new EventDispatcher();
35-
$this->factory = $this->getMockBuilder(\Symfony\Component\Form\FormFactoryInterface::class)->getMock();
36+
$this->factory = $this->createMock(FormFactoryInterface::class);
3637
$this->form = $this->getBuilder()
3738
->getForm();
3839
}

src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class EntityTypePerformanceTest extends FormPerformanceTestCase
3535

3636
protected function getExtensions()
3737
{
38-
$manager = $this->getMockBuilder(ManagerRegistry::class)->getMock();
38+
$manager = $this->createMock(ManagerRegistry::class);
3939

4040
$manager->expects($this->any())
4141
->method('getManager')

src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@
2929
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity;
3030
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringCastableIdEntity;
3131
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity;
32+
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
3233
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
3334
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
35+
use Symfony\Component\Form\Exception\RuntimeException;
36+
use Symfony\Component\Form\Exception\UnexpectedTypeException;
3437
use Symfony\Component\Form\Forms;
3538
use Symfony\Component\Form\Tests\Extension\Core\Type\BaseTypeTest;
3639
use Symfony\Component\Form\Tests\Extension\Core\Type\FormTypeTest;
40+
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
41+
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
3742

3843
class EntityTypeTest extends BaseTypeTest
3944
{
@@ -118,13 +123,13 @@ protected function persist(array $entities)
118123

119124
public function testClassOptionIsRequired()
120125
{
121-
$this->expectException(\Symfony\Component\OptionsResolver\Exception\MissingOptionsException::class);
126+
$this->expectException(MissingOptionsException::class);
122127
$this->factory->createNamed('name', static::TESTED_TYPE);
123128
}
124129

125130
public function testInvalidClassOption()
126131
{
127-
$this->expectException(\Symfony\Component\Form\Exception\RuntimeException::class);
132+
$this->expectException(RuntimeException::class);
128133
$this->factory->createNamed('name', static::TESTED_TYPE, null, [
129134
'class' => 'foo',
130135
]);
@@ -219,7 +224,7 @@ public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder()
219224

220225
public function testConfigureQueryBuilderWithNonQueryBuilderAndNonClosure()
221226
{
222-
$this->expectException(\Symfony\Component\OptionsResolver\Exception\InvalidOptionsException::class);
227+
$this->expectException(InvalidOptionsException::class);
223228
$this->factory->createNamed('name', static::TESTED_TYPE, null, [
224229
'em' => 'default',
225230
'class' => self::SINGLE_IDENT_CLASS,
@@ -229,7 +234,7 @@ public function testConfigureQueryBuilderWithNonQueryBuilderAndNonClosure()
229234

230235
public function testConfigureQueryBuilderWithClosureReturningNonQueryBuilder()
231236
{
232-
$this->expectException(\Symfony\Component\Form\Exception\UnexpectedTypeException::class);
237+
$this->expectException(UnexpectedTypeException::class);
233238
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, [
234239
'em' => 'default',
235240
'class' => self::SINGLE_IDENT_CLASS,
@@ -1242,7 +1247,7 @@ public function testLoaderCaching()
12421247
$choiceLoader2 = $form->get('property2')->getConfig()->getOption('choice_loader');
12431248
$choiceLoader3 = $form->get('property3')->getConfig()->getOption('choice_loader');
12441249

1245-
$this->assertInstanceOf(\Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface::class, $choiceLoader1);
1250+
$this->assertInstanceOf(ChoiceLoaderInterface::class, $choiceLoader1);
12461251
$this->assertSame($choiceLoader1, $choiceLoader2);
12471252
$this->assertSame($choiceLoader1, $choiceLoader3);
12481253
}
@@ -1302,14 +1307,14 @@ public function testLoaderCachingWithParameters()
13021307
$choiceLoader2 = $form->get('property2')->getConfig()->getOption('choice_loader');
13031308
$choiceLoader3 = $form->get('property3')->getConfig()->getOption('choice_loader');
13041309

1305-
$this->assertInstanceOf(\Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface::class, $choiceLoader1);
1310+
$this->assertInstanceOf(ChoiceLoaderInterface::class, $choiceLoader1);
13061311
$this->assertSame($choiceLoader1, $choiceLoader2);
13071312
$this->assertSame($choiceLoader1, $choiceLoader3);
13081313
}
13091314

13101315
protected function createRegistryMock($name, $em)
13111316
{
1312-
$registry = $this->getMockBuilder(ManagerRegistry::class)->getMock();
1317+
$registry = $this->createMock(ManagerRegistry::class);
13131318
$registry->expects($this->any())
13141319
->method('getManager')
13151320
->with($this->equalTo($name))

src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Doctrine\Tests\Logger;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Psr\Log\LoggerInterface;
1516
use Symfony\Bridge\Doctrine\Logger\DbalLogger;
1617

1718
class DbalLoggerTest extends TestCase
@@ -21,7 +22,7 @@ class DbalLoggerTest extends TestCase
2122
*/
2223
public function testLog($sql, $params, $logParams)
2324
{
24-
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
25+
$logger = $this->createMock(LoggerInterface::class);
2526

2627
$dbalLogger = $this
2728
->getMockBuilder(DbalLogger::class)
@@ -53,7 +54,7 @@ public function getLogFixtures()
5354

5455
public function testLogNonUtf8()
5556
{
56-
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
57+
$logger = $this->createMock(LoggerInterface::class);
5758

5859
$dbalLogger = $this
5960
->getMockBuilder(DbalLogger::class)
@@ -76,7 +77,7 @@ public function testLogNonUtf8()
7677

7778
public function testLogNonUtf8Array()
7879
{
79-
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
80+
$logger = $this->createMock(LoggerInterface::class);
8081

8182
$dbalLogger = $this
8283
->getMockBuilder(DbalLogger::class)
@@ -107,7 +108,7 @@ public function testLogNonUtf8Array()
107108

108109
public function testLogLongString()
109110
{
110-
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
111+
$logger = $this->createMock(LoggerInterface::class);
111112

112113
$dbalLogger = $this
113114
->getMockBuilder(DbalLogger::class)
@@ -135,7 +136,7 @@ public function testLogLongString()
135136

136137
public function testLogUTF8LongString()
137138
{
138-
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
139+
$logger = $this->createMock(LoggerInterface::class);
139140

140141
$dbalLogger = $this
141142
->getMockBuilder(DbalLogger::class)

src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Tests\Security\User;
1313

14+
use Doctrine\ORM\EntityManager;
1415
use Doctrine\ORM\Tools\SchemaTool;
1516
use Doctrine\Persistence\ManagerRegistry;
1617
use Doctrine\Persistence\ObjectManager;
@@ -20,6 +21,7 @@
2021
use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
2122
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
2223
use Symfony\Bridge\Doctrine\Tests\Fixtures\User;
24+
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
2325
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
2426
use Symfony\Component\Security\Core\User\UserInterface;
2527

@@ -71,9 +73,7 @@ public function testLoadUserByUsernameWithUserLoaderRepositoryAndWithoutProperty
7173
->with('user1')
7274
->willReturn($user);
7375

74-
$em = $this->getMockBuilder(\Doctrine\ORM\EntityManager::class)
75-
->disableOriginalConstructor()
76-
->getMock();
76+
$em = $this->createMock(EntityManager::class);
7777
$em
7878
->expects($this->once())
7979
->method('getRepository')
@@ -125,7 +125,7 @@ public function testRefreshInvalidUser()
125125
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User', 'name');
126126

127127
$user2 = new User(1, 2, 'user2');
128-
$this->expectException(\Symfony\Component\Security\Core\Exception\UsernameNotFoundException::class);
128+
$this->expectException(UsernameNotFoundException::class);
129129
$this->expectExceptionMessage('User with id {"id1":1,"id2":2} not found');
130130

131131
$provider->refreshUser($user2);
@@ -155,7 +155,7 @@ public function testLoadUserByUserNameShouldLoadUserWhenProperInterfaceProvided(
155155
->method('loadUserByUsername')
156156
->with('name')
157157
->willReturn(
158-
$this->getMockBuilder(UserInterface::class)->getMock()
158+
$this->createMock(UserInterface::class)
159159
);
160160

161161
$provider = new EntityUserProvider(
@@ -198,7 +198,7 @@ public function testPasswordUpgrades()
198198

199199
private function getManager($em, $name = null)
200200
{
201-
$manager = $this->getMockBuilder(ManagerRegistry::class)->getMock();
201+
$manager = $this->createMock(ManagerRegistry::class);
202202
$manager->expects($this->any())
203203
->method('getManager')
204204
->with($this->equalTo($name))

0 commit comments

Comments
 (0)