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 d3072e6

Browse filesBrowse files
committed
Fix tests failing with DBAL 3
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent 460fd35 commit d3072e6
Copy full SHA for d3072e6

File tree

Expand file treeCollapse file tree

6 files changed

+56
-25
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+56
-25
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php
+19-17Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

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

14+
use Doctrine\DBAL\Connection;
1415
use Doctrine\DBAL\Logging\DebugStack;
15-
use Doctrine\DBAL\Platforms\MySqlPlatform;
16-
use Doctrine\DBAL\Version;
16+
use Doctrine\DBAL\Platforms\MySQLPlatform;
1717
use Doctrine\Persistence\ManagerRegistry;
1818
use PHPUnit\Framework\TestCase;
1919
use Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector;
@@ -22,6 +22,9 @@
2222
use Symfony\Component\VarDumper\Cloner\Data;
2323
use Symfony\Component\VarDumper\Dumper\CliDumper;
2424

25+
// Doctrine DBAL 2 compatibility
26+
class_exists('Doctrine\DBAL\Platforms\MySqlPlatform');
27+
2528
class DoctrineDataCollectorTest extends TestCase
2629
{
2730
public function testCollectConnections()
@@ -93,6 +96,8 @@ public function testCollectQueries($param, $types, $expected, $explainable, bool
9396
$dumper->setColors(false);
9497
$collectedParam->dump($dumper);
9598
$this->assertStringMatchesFormat($expected, print_r(stream_get_contents($out, -1, 0), true));
99+
} elseif (\is_string($expected)) {
100+
$this->assertStringMatchesFormat($expected, $collectedParam);
96101
} else {
97102
$this->assertEquals($expected, $collectedParam);
98103
}
@@ -150,7 +155,7 @@ public function testReset()
150155
/**
151156
* @dataProvider paramProvider
152157
*/
153-
public function testSerialization($param, $types, $expected, $explainable, bool $runnable = true)
158+
public function testSerialization($param, array $types, $expected, $explainable, bool $runnable = true)
154159
{
155160
$queries = [
156161
['sql' => 'SELECT * FROM table1 WHERE field1 = ?1', 'params' => [$param], 'types' => $types, 'executionMS' => 1],
@@ -167,6 +172,8 @@ public function testSerialization($param, $types, $expected, $explainable, bool
167172
$dumper->setColors(false);
168173
$collectedParam->dump($dumper);
169174
$this->assertStringMatchesFormat($expected, print_r(stream_get_contents($out, -1, 0), true));
175+
} elseif (\is_string($expected)) {
176+
$this->assertStringMatchesFormat($expected, $collectedParam);
170177
} else {
171178
$this->assertEquals($expected, $collectedParam);
172179
}
@@ -175,9 +182,9 @@ public function testSerialization($param, $types, $expected, $explainable, bool
175182
$this->assertSame($runnable, $collectedQueries['default'][0]['runnable']);
176183
}
177184

178-
public function paramProvider()
185+
public function paramProvider(): array
179186
{
180-
$tests = [
187+
return [
181188
['some value', [], 'some value', true],
182189
[1, [], 1, true],
183190
[true, [], true, true],
@@ -207,30 +214,25 @@ public function paramProvider()
207214
,
208215
false,
209216
],
210-
];
211-
212-
if (version_compare(Version::VERSION, '2.6', '>=')) {
213-
$tests[] = ['this is not a date', ['date'], "⚠ Could not convert PHP value 'this is not a date' of type 'string' to type 'date'. Expected one of the following types: null, DateTime", false, false];
214-
$tests[] = [
217+
['this is not a date', ['date'], "⚠ Could not convert PHP value 'this is not a date'%S to type %Sdate%S. Expected one of the following types: null, DateTime", false, false],
218+
[
215219
new \stdClass(),
216220
['date'],
217221
<<<EOTXT
218222
{#%d
219-
⚠: "Could not convert PHP value of type 'stdClass' to type 'date'. Expected one of the following types: null, DateTime"
223+
⚠: "Could not convert PHP value of type %SstdClass%S to type %Sdate%S. Expected one of the following types: null, DateTime"
220224
}
221225
EOTXT
222226
,
223227
false,
224228
false,
225-
];
226-
}
227-
228-
return $tests;
229+
],
230+
];
229231
}
230232

231-
private function createCollector($queries)
233+
private function createCollector(array $queries): DoctrineDataCollector
232234
{
233-
$connection = $this->getMockBuilder(\Doctrine\DBAL\Connection::class)
235+
$connection = $this->getMockBuilder(Connection::class)
234236
->disableOriginalConstructor()
235237
->getMock();
236238
$connection->expects($this->any())

‎src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,12 @@ public function testInvalidEntityManagerThrowsException()
103103

104104
public function testMiddlewareNoPingInNonWorkerContext()
105105
{
106-
$this->connection->expects($this->never())
107-
->method('ping')
108-
->willReturn(false);
106+
// This method has been removed in DBAL 3.0
107+
if (method_exists(Connection::class, 'ping')) {
108+
$this->connection->expects($this->never())
109+
->method('ping')
110+
->willReturn(false);
111+
}
109112

110113
$this->connection->expects($this->never())
111114
->method('close')

‎src/Symfony/Bridge/Doctrine/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/composer.json
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
"doctrine/orm": "^2.6.3"
4848
},
4949
"conflict": {
50+
"doctrine/dbal": "<2.6",
51+
"doctrine/orm": "<2.6.3",
5052
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
5153
"symfony/dependency-injection": "<3.4",
5254
"symfony/form": "<4.4",

‎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
+10-2Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ private function getDBALConnectionMock()
140140
$schemaConfig->method('getMaxIdentifierLength')->willReturn(63);
141141
$schemaConfig->method('getDefaultTableOptions')->willReturn([]);
142142
$schemaManager->method('createSchemaConfig')->willReturn($schemaConfig);
143-
$driverConnection->method('getSchemaManager')->willReturn($schemaManager);
143+
if (method_exists(DBALConnection::class, 'createSchemaManager')) {
144+
$driverConnection->method('createSchemaManager')->willReturn($schemaManager);
145+
} else {
146+
$driverConnection->method('getSchemaManager')->willReturn($schemaManager);
147+
}
144148

145149
return $driverConnection;
146150
}
@@ -428,7 +432,11 @@ public function testSetupIndices(string $platformClass, array $expectedIndices)
428432
$expectedTable->addIndex($indexColumns);
429433
}
430434
$schemaManager->method('createSchema')->willReturn($schema);
431-
$driverConnection->method('getSchemaManager')->willReturn($schemaManager);
435+
if (method_exists(DBALConnection::class, 'createSchemaManager')) {
436+
$driverConnection->method('createSchemaManager')->willReturn($schemaManager);
437+
} else {
438+
$driverConnection->method('getSchemaManager')->willReturn($schemaManager);
439+
}
432440

433441
$platformMock = $this->createMock($platformClass);
434442
$platformMock

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineIntegrationTest.php
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\DBAL\Driver\Result as DriverResult;
1515
use Doctrine\DBAL\DriverManager;
1616
use Doctrine\DBAL\Result;
17+
use Doctrine\DBAL\Schema\AbstractSchemaManager;
1718
use PHPUnit\Framework\TestCase;
1819
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
1920
use Symfony\Component\Messenger\Transport\Doctrine\Connection;
@@ -175,7 +176,7 @@ public function testItRetrieveTheMessageThatIsOlderThanRedeliverTimeout()
175176

176177
public function testTheTransportIsSetupOnGet()
177178
{
178-
$this->assertFalse($this->driverConnection->getSchemaManager()->tablesExist('messenger_messages'));
179+
$this->assertFalse($this->createSchemaManager()->tablesExist('messenger_messages'));
179180
$this->assertNull($this->connection->get());
180181

181182
$this->connection->send('the body', ['my' => 'header']);
@@ -187,4 +188,11 @@ private function formatDateTime(\DateTime $dateTime)
187188
{
188189
return $dateTime->format($this->driverConnection->getDatabasePlatform()->getDateTimeFormatString());
189190
}
191+
192+
private function createSchemaManager(): AbstractSchemaManager
193+
{
194+
return method_exists($this->driverConnection, 'createSchemaManager')
195+
? $this->driverConnection->createSchemaManager()
196+
: $this->driverConnection->getSchemaManager();
197+
}
190198
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php
+10-2Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Doctrine\DBAL\Platforms\MySqlPlatform;
2121
use Doctrine\DBAL\Query\QueryBuilder;
2222
use Doctrine\DBAL\Result;
23+
use Doctrine\DBAL\Schema\AbstractSchemaManager;
2324
use Doctrine\DBAL\Schema\Comparator;
2425
use Doctrine\DBAL\Schema\Schema;
2526
use Doctrine\DBAL\Schema\Synchronizer\SchemaSynchronizer;
@@ -377,7 +378,7 @@ private function executeStatement(string $sql, array $parameters = [], array $ty
377378

378379
private function getSchema(): Schema
379380
{
380-
$schema = new Schema([], [], $this->driverConnection->getSchemaManager()->createSchemaConfig());
381+
$schema = new Schema([], [], $this->createSchemaManager()->createSchemaConfig());
381382
$table = $schema->createTable($this->configuration['table_name']);
382383
$table->addColumn('id', self::$useDeprecatedConstants ? Type::BIGINT : Types::BIGINT)
383384
->setAutoincrement(true)
@@ -421,7 +422,7 @@ private function updateSchema(): void
421422
}
422423

423424
$comparator = new Comparator();
424-
$schemaDiff = $comparator->compare($this->driverConnection->getSchemaManager()->createSchema(), $this->getSchema());
425+
$schemaDiff = $comparator->compare($this->createSchemaManager()->createSchema(), $this->getSchema());
425426

426427
foreach ($schemaDiff->toSaveSql($this->driverConnection->getDatabasePlatform()) as $sql) {
427428
if (method_exists($this->driverConnection, 'executeStatement')) {
@@ -431,4 +432,11 @@ private function updateSchema(): void
431432
}
432433
}
433434
}
435+
436+
private function createSchemaManager(): AbstractSchemaManager
437+
{
438+
return method_exists($this->driverConnection, 'createSchemaManager')
439+
? $this->driverConnection->createSchemaManager()
440+
: $this->driverConnection->getSchemaManager();
441+
}
434442
}

0 commit comments

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