Skip to content

Commit 5129c19

Browse files
derrabusfabpot
authored andcommitted
Fix tests failing with DBAL 3
1 parent d44e0b7 commit 5129c19

File tree

4 files changed

+37
-29
lines changed

4 files changed

+37
-29
lines changed

Security/RememberMe/DoctrineTokenProvider.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\DBAL\Connection;
1515
use Doctrine\DBAL\Driver\Result as DriverResult;
16+
use Doctrine\DBAL\ParameterType;
1617
use Doctrine\DBAL\Result;
1718
use Doctrine\DBAL\Types\Type;
1819
use Doctrine\DBAL\Types\Types;
@@ -63,7 +64,7 @@ public function loadTokenBySeries($series)
6364
$sql = 'SELECT class, username, value, lastUsed AS last_used'
6465
.' FROM rememberme_token WHERE series=:series';
6566
$paramValues = ['series' => $series];
66-
$paramTypes = ['series' => \PDO::PARAM_STR];
67+
$paramTypes = ['series' => ParameterType::STRING];
6768
$stmt = $this->conn->executeQuery($sql, $paramValues, $paramTypes);
6869
$row = $stmt instanceof Result || $stmt instanceof DriverResult ? $stmt->fetchAssociative() : $stmt->fetch(\PDO::FETCH_ASSOC);
6970

@@ -81,7 +82,7 @@ public function deleteTokenBySeries($series)
8182
{
8283
$sql = 'DELETE FROM rememberme_token WHERE series=:series';
8384
$paramValues = ['series' => $series];
84-
$paramTypes = ['series' => \PDO::PARAM_STR];
85+
$paramTypes = ['series' => ParameterType::STRING];
8586
if (method_exists($this->conn, 'executeStatement')) {
8687
$this->conn->executeStatement($sql, $paramValues, $paramTypes);
8788
} else {
@@ -102,9 +103,9 @@ public function updateToken($series, $tokenValue, \DateTime $lastUsed)
102103
'series' => $series,
103104
];
104105
$paramTypes = [
105-
'value' => \PDO::PARAM_STR,
106+
'value' => ParameterType::STRING,
106107
'lastUsed' => self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE,
107-
'series' => \PDO::PARAM_STR,
108+
'series' => ParameterType::STRING,
108109
];
109110
if (method_exists($this->conn, 'executeStatement')) {
110111
$updated = $this->conn->executeStatement($sql, $paramValues, $paramTypes);
@@ -132,10 +133,10 @@ public function createNewToken(PersistentTokenInterface $token)
132133
'lastUsed' => $token->getLastUsed(),
133134
];
134135
$paramTypes = [
135-
'class' => \PDO::PARAM_STR,
136-
'username' => \PDO::PARAM_STR,
137-
'series' => \PDO::PARAM_STR,
138-
'value' => \PDO::PARAM_STR,
136+
'class' => ParameterType::STRING,
137+
'username' => ParameterType::STRING,
138+
'series' => ParameterType::STRING,
139+
'value' => ParameterType::STRING,
139140
'lastUsed' => self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE,
140141
];
141142
if (method_exists($this->conn, 'executeStatement')) {

Tests/DataCollector/DoctrineDataCollectorTest.php

Lines 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::class);
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())

Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php

Lines 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')

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@
4343
"doctrine/annotations": "^1.10.4",
4444
"doctrine/collections": "~1.0",
4545
"doctrine/data-fixtures": "^1.1",
46-
"doctrine/dbal": "^2.6|^3.0",
46+
"doctrine/dbal": "^2.7|^3.0",
4747
"doctrine/orm": "^2.6.3"
4848
},
4949
"conflict": {
50+
"doctrine/dbal": "<2.7",
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",

0 commit comments

Comments
 (0)