Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1660f8d

Browse filesBrowse files
committed
[Messenger] Use createMock instead of getMockBuilder
1 parent 301ceae commit 1660f8d
Copy full SHA for 1660f8d

File tree

5 files changed

+25
-50
lines changed
Filter options

5 files changed

+25
-50
lines changed

‎src/Symfony/Component/Messenger/Tests/Transport/Doctrine/ConnectionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Tests/Transport/Doctrine/ConnectionTest.php
+9-24Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,15 @@ public function testItThrowsATransportExceptionIfItCannotRejectMessage()
104104

105105
private function getDBALConnectionMock()
106106
{
107-
$driverConnection = $this->getMockBuilder(\Doctrine\DBAL\Connection::class)
108-
->disableOriginalConstructor()
109-
->getMock();
110-
$platform = $this->getMockBuilder(AbstractPlatform::class)
111-
->getMock();
107+
$driverConnection = $this->createMock(\Doctrine\DBAL\Connection::class);
108+
$platform = $this->createMock(AbstractPlatform::class);
112109
$platform->method('getWriteLockSQL')->willReturn('FOR UPDATE');
113-
$configuration = $this->getMockBuilder(\Doctrine\DBAL\Configuration::class)
114-
->getMock();
110+
$configuration = $this->createMock(\Doctrine\DBAL\Configuration::class);
115111
$driverConnection->method('getDatabasePlatform')->willReturn($platform);
116112
$driverConnection->method('getConfiguration')->willReturn($configuration);
117113

118-
$schemaManager = $this->getMockBuilder(AbstractSchemaManager::class)
119-
->disableOriginalConstructor()
120-
->getMock();
121-
$schemaConfig = $this->getMockBuilder(SchemaConfig::class)
122-
->disableOriginalConstructor()
123-
->getMock();
114+
$schemaManager = $this->createMock(AbstractSchemaManager::class);
115+
$schemaConfig = $this->createMock(SchemaConfig::class);
124116
$schemaConfig->method('getMaxIdentifierLength')->willReturn(63);
125117
$schemaConfig->method('getDefaultTableOptions')->willReturn([]);
126118
$schemaManager->method('createSchemaConfig')->willReturn($schemaConfig);
@@ -131,9 +123,7 @@ private function getDBALConnectionMock()
131123

132124
private function getQueryBuilderMock()
133125
{
134-
$queryBuilder = $this->getMockBuilder(QueryBuilder::class)
135-
->disableOriginalConstructor()
136-
->getMock();
126+
$queryBuilder = $this->createMock(QueryBuilder::class);
137127

138128
$queryBuilder->method('select')->willReturn($queryBuilder);
139129
$queryBuilder->method('update')->willReturn($queryBuilder);
@@ -151,9 +141,7 @@ private function getQueryBuilderMock()
151141

152142
private function getStatementMock($expectedResult)
153143
{
154-
$stmt = $this->getMockBuilder(Statement::class)
155-
->disableOriginalConstructor()
156-
->getMock();
144+
$stmt = $this->createMock(Statement::class);
157145
$stmt->expects($this->once())
158146
->method('fetch')
159147
->willReturn($expectedResult);
@@ -163,8 +151,7 @@ private function getStatementMock($expectedResult)
163151

164152
private function getSchemaSynchronizerMock()
165153
{
166-
return $this->getMockBuilder(SchemaSynchronizer::class)
167-
->getMock();
154+
return $this->createMock(SchemaSynchronizer::class);
168155
}
169156

170157
/**
@@ -320,9 +307,7 @@ public function testFindAll()
320307
'headers' => json_encode(['type' => DummyMessage::class]),
321308
];
322309

323-
$stmt = $this->getMockBuilder(Statement::class)
324-
->disableOriginalConstructor()
325-
->getMock();
310+
$stmt = $this->createMock(Statement::class);
326311
$stmt->expects($this->once())
327312
->method('fetchAll')
328313
->willReturn([$message1, $message2]);

‎src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineReceiverTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineReceiverTest.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testItReturnsTheDecodedMessageToTheHandler()
3232
$serializer = $this->createSerializer();
3333

3434
$doctrineEnvelope = $this->createDoctrineEnvelope();
35-
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
35+
$connection = $this->createMock(Connection::class);
3636
$connection->method('get')->willReturn($doctrineEnvelope);
3737

3838
$receiver = new DoctrineReceiver($connection, $serializer);
@@ -62,7 +62,7 @@ public function testItRejectTheMessageIfThereIsAMessageDecodingFailedException()
6262
$serializer->method('decode')->willThrowException(new MessageDecodingFailedException());
6363

6464
$doctrineEnvelop = $this->createDoctrineEnvelope();
65-
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
65+
$connection = $this->createMock(Connection::class);
6666
$connection->method('get')->willReturn($doctrineEnvelop);
6767
$connection->expects($this->once())->method('reject');
6868

‎src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineSenderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineSenderTest.php
+4-8Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ public function testSend()
2727
$envelope = new Envelope(new DummyMessage('Oy'));
2828
$encoded = ['body' => '...', 'headers' => ['type' => DummyMessage::class]];
2929

30-
$connection = $this->getMockBuilder(Connection::class)
31-
->disableOriginalConstructor()
32-
->getMock();
30+
$connection = $this->createMock(Connection::class);
3331
$connection->expects($this->once())->method('send')->with($encoded['body'], $encoded['headers'])->willReturn(15);
3432

35-
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock();
33+
$serializer = $this->createMock(SerializerInterface::class);
3634
$serializer->method('encode')->with($envelope)->willReturnOnConsecutiveCalls($encoded);
3735

3836
$sender = new DoctrineSender($connection, $serializer);
@@ -49,12 +47,10 @@ public function testSendWithDelay()
4947
$envelope = (new Envelope(new DummyMessage('Oy')))->with(new DelayStamp(500));
5048
$encoded = ['body' => '...', 'headers' => ['type' => DummyMessage::class]];
5149

52-
$connection = $this->getMockBuilder(Connection::class)
53-
->disableOriginalConstructor()
54-
->getMock();
50+
$connection = $this->createMock(Connection::class);
5551
$connection->expects($this->once())->method('send')->with($encoded['body'], $encoded['headers'], 500);
5652

57-
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock();
53+
$serializer = $this->createMock(SerializerInterface::class);
5854
$serializer->method('encode')->with($envelope)->willReturnOnConsecutiveCalls($encoded);
5955

6056
$sender = new DoctrineSender($connection, $serializer);

‎src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineTransportFactoryTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineTransportFactoryTest.php
+6-12Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class DoctrineTransportFactoryTest extends TestCase
2525
public function testSupports()
2626
{
2727
$factory = new DoctrineTransportFactory(
28-
$this->getMockBuilder(RegistryInterface::class)->getMock()
28+
$this->createMock(RegistryInterface::class)
2929
);
3030

3131
$this->assertTrue($factory->supports('doctrine://default', []));
@@ -34,18 +34,12 @@ public function testSupports()
3434

3535
public function testCreateTransport()
3636
{
37-
$driverConnection = $this->getMockBuilder(\Doctrine\DBAL\Connection::class)
38-
->disableOriginalConstructor()
39-
->getMock();
40-
$schemaManager = $this->getMockBuilder(AbstractSchemaManager::class)
41-
->disableOriginalConstructor()
42-
->getMock();
43-
$schemaConfig = $this->getMockBuilder(SchemaConfig::class)
44-
->disableOriginalConstructor()
45-
->getMock();
37+
$driverConnection = $this->createMock(\Doctrine\DBAL\Connection::class);
38+
$schemaManager = $this->createMock(AbstractSchemaManager::class);
39+
$schemaConfig = $this->createMock(SchemaConfig::class);
4640
$schemaManager->method('createSchemaConfig')->willReturn($schemaConfig);
4741
$driverConnection->method('getSchemaManager')->willReturn($schemaManager);
48-
$registry = $this->getMockBuilder(RegistryInterface::class)->getMock();
42+
$registry = $this->createMock(RegistryInterface::class);
4943
$registry->expects($this->once())
5044
->method('getConnection')
5145
->willReturn($driverConnection);
@@ -65,7 +59,7 @@ public function testCreateTransport()
6559
*/
6660
public function testCreateTransportMustThrowAnExceptionIfManagerIsNotFound()
6761
{
68-
$registry = $this->getMockBuilder(RegistryInterface::class)->getMock();
62+
$registry = $this->createMock(RegistryInterface::class);
6963
$registry->expects($this->once())
7064
->method('getConnection')
7165
->willReturnCallback(function () {

‎src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineTransportTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineTransportTest.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function testItIsATransport()
3131
public function testReceivesMessages()
3232
{
3333
$transport = $this->getTransport(
34-
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock(),
35-
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock()
34+
$serializer = $this->createMock(SerializerInterface::class),
35+
$connection = $this->createMock(Connection::class)
3636
);
3737

3838
$decodedMessage = new DummyMessage('Decoded.');
@@ -52,8 +52,8 @@ public function testReceivesMessages()
5252

5353
private function getTransport(SerializerInterface $serializer = null, Connection $connection = null)
5454
{
55-
$serializer = $serializer ?: $this->getMockBuilder(SerializerInterface::class)->getMock();
56-
$connection = $connection ?: $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
55+
$serializer = $serializer ?: $this->createMock(SerializerInterface::class);
56+
$connection = $connection ?: $this->createMock(Connection::class);
5757

5858
return new DoctrineTransport($connection, $serializer);
5959
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.