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 93d0dc8

Browse filesBrowse files
vincenttouzetTobion
authored andcommitted
[Messenger] Retrieve table default options from the SchemaManager
1 parent 327fb95 commit 93d0dc8
Copy full SHA for 93d0dc8

File tree

6 files changed

+39
-41
lines changed
Filter options

6 files changed

+39
-41
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
+16-18Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Doctrine\DBAL\Driver\Statement;
1616
use Doctrine\DBAL\Platforms\AbstractPlatform;
1717
use Doctrine\DBAL\Query\QueryBuilder;
18+
use Doctrine\DBAL\Schema\AbstractSchemaManager;
19+
use Doctrine\DBAL\Schema\SchemaConfig;
1820
use Doctrine\DBAL\Schema\Synchronizer\SchemaSynchronizer;
1921
use PHPUnit\Framework\TestCase;
2022
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
@@ -102,25 +104,26 @@ public function testItThrowsATransportExceptionIfItCannotRejectMessage()
102104

103105
private function getDBALConnectionMock()
104106
{
105-
$driverConnection = $this->getMockBuilder(\Doctrine\DBAL\Connection::class)
106-
->disableOriginalConstructor()
107-
->getMock();
108-
$platform = $this->getMockBuilder(AbstractPlatform::class)
109-
->getMock();
107+
$driverConnection = $this->createMock(\Doctrine\DBAL\Connection::class);
108+
$platform = $this->createMock(AbstractPlatform::class);
110109
$platform->method('getWriteLockSQL')->willReturn('FOR UPDATE');
111-
$configuration = $this->getMockBuilder(\Doctrine\DBAL\Configuration::class)
112-
->getMock();
110+
$configuration = $this->createMock(\Doctrine\DBAL\Configuration::class);
113111
$driverConnection->method('getDatabasePlatform')->willReturn($platform);
114112
$driverConnection->method('getConfiguration')->willReturn($configuration);
115113

114+
$schemaManager = $this->createMock(AbstractSchemaManager::class);
115+
$schemaConfig = $this->createMock(SchemaConfig::class);
116+
$schemaConfig->method('getMaxIdentifierLength')->willReturn(63);
117+
$schemaConfig->method('getDefaultTableOptions')->willReturn([]);
118+
$schemaManager->method('createSchemaConfig')->willReturn($schemaConfig);
119+
$driverConnection->method('getSchemaManager')->willReturn($schemaManager);
120+
116121
return $driverConnection;
117122
}
118123

119124
private function getQueryBuilderMock()
120125
{
121-
$queryBuilder = $this->getMockBuilder(QueryBuilder::class)
122-
->disableOriginalConstructor()
123-
->getMock();
126+
$queryBuilder = $this->createMock(QueryBuilder::class);
124127

125128
$queryBuilder->method('select')->willReturn($queryBuilder);
126129
$queryBuilder->method('update')->willReturn($queryBuilder);
@@ -138,9 +141,7 @@ private function getQueryBuilderMock()
138141

139142
private function getStatementMock($expectedResult)
140143
{
141-
$stmt = $this->getMockBuilder(Statement::class)
142-
->disableOriginalConstructor()
143-
->getMock();
144+
$stmt = $this->createMock(Statement::class);
144145
$stmt->expects($this->once())
145146
->method('fetch')
146147
->willReturn($expectedResult);
@@ -150,8 +151,7 @@ private function getStatementMock($expectedResult)
150151

151152
private function getSchemaSynchronizerMock()
152153
{
153-
return $this->getMockBuilder(SchemaSynchronizer::class)
154-
->getMock();
154+
return $this->createMock(SchemaSynchronizer::class);
155155
}
156156

157157
/**
@@ -307,9 +307,7 @@ public function testFindAll()
307307
'headers' => json_encode(['type' => DummyMessage::class]),
308308
];
309309

310-
$stmt = $this->getMockBuilder(Statement::class)
311-
->disableOriginalConstructor()
312-
->getMock();
310+
$stmt = $this->createMock(Statement::class);
313311
$stmt->expects($this->once())
314312
->method('fetchAll')
315313
->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
+12-8Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Messenger\Tests\Transport\Doctrine;
1313

14+
use Doctrine\DBAL\Schema\AbstractSchemaManager;
15+
use Doctrine\DBAL\Schema\SchemaConfig;
1416
use PHPUnit\Framework\TestCase;
1517
use Symfony\Bridge\Doctrine\RegistryInterface;
1618
use Symfony\Component\Messenger\Transport\Doctrine\Connection;
@@ -23,7 +25,7 @@ class DoctrineTransportFactoryTest extends TestCase
2325
public function testSupports()
2426
{
2527
$factory = new DoctrineTransportFactory(
26-
$this->getMockBuilder(RegistryInterface::class)->getMock()
28+
$this->createMock(RegistryInterface::class)
2729
);
2830

2931
$this->assertTrue($factory->supports('doctrine://default', []));
@@ -32,19 +34,21 @@ public function testSupports()
3234

3335
public function testCreateTransport()
3436
{
35-
$connection = $this->getMockBuilder(\Doctrine\DBAL\Connection::class)
36-
->disableOriginalConstructor()
37-
->getMock();
38-
$registry = $this->getMockBuilder(RegistryInterface::class)->getMock();
37+
$driverConnection = $this->createMock(\Doctrine\DBAL\Connection::class);
38+
$schemaManager = $this->createMock(AbstractSchemaManager::class);
39+
$schemaConfig = $this->createMock(SchemaConfig::class);
40+
$schemaManager->method('createSchemaConfig')->willReturn($schemaConfig);
41+
$driverConnection->method('getSchemaManager')->willReturn($schemaManager);
42+
$registry = $this->createMock(RegistryInterface::class);
3943
$registry->expects($this->once())
4044
->method('getConnection')
41-
->willReturn($connection);
45+
->willReturn($driverConnection);
4246

4347
$factory = new DoctrineTransportFactory($registry);
4448
$serializer = $this->createMock(SerializerInterface::class);
4549

4650
$this->assertEquals(
47-
new DoctrineTransport(new Connection(Connection::buildConfiguration('doctrine://default'), $connection), $serializer),
51+
new DoctrineTransport(new Connection(Connection::buildConfiguration('doctrine://default'), $driverConnection), $serializer),
4852
$factory->createTransport('doctrine://default', [], $serializer)
4953
);
5054
}
@@ -55,7 +59,7 @@ public function testCreateTransport()
5559
*/
5660
public function testCreateTransportMustThrowAnExceptionIfManagerIsNotFound()
5761
{
58-
$registry = $this->getMockBuilder(RegistryInterface::class)->getMock();
62+
$registry = $this->createMock(RegistryInterface::class);
5963
$registry->expects($this->once())
6064
->method('getConnection')
6165
->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
}

‎src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ private function executeQuery(string $sql, array $parameters = [])
304304

305305
private function getSchema(): Schema
306306
{
307-
$schema = new Schema();
307+
$schema = new Schema([], [], $this->driverConnection->getSchemaManager()->createSchemaConfig());
308308
$table = $schema->createTable($this->configuration['table_name']);
309309
$table->addColumn('id', Type::BIGINT)
310310
->setAutoincrement(true)

0 commit comments

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