Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit5ee3ad4

Browse files
committed
Fix tests failing with DBAL 3
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent460fd35 commit5ee3ad4

File tree

8 files changed

+98
-54
lines changed

8 files changed

+98
-54
lines changed

‎src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php‎

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

1414
useDoctrine\DBAL\Connection;
1515
useDoctrine\DBAL\Driver\ResultasDriverResult;
16+
useDoctrine\DBAL\ParameterType;
1617
useDoctrine\DBAL\Result;
1718
useDoctrine\DBAL\Types\Type;
1819
useDoctrine\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' =>class_exists(ParameterType::class) ? ParameterType::STRING :\PDO::PARAM_STR];
6768
$stmt =$this->conn->executeQuery($sql,$paramValues,$paramTypes);
6869
$row =$stmtinstanceof Result ||$stmtinstanceof 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' =>class_exists(ParameterType::class) ? ParameterType::STRING :\PDO::PARAM_STR];
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' =>class_exists(ParameterType::class) ? ParameterType::STRING :\PDO::PARAM_STR,
106107
'lastUsed' =>self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE,
107-
'series' => \PDO::PARAM_STR,
108+
'series' =>class_exists(ParameterType::class) ? ParameterType::STRING :\PDO::PARAM_STR,
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' =>class_exists(ParameterType::class) ? ParameterType::STRING :\PDO::PARAM_STR,
137+
'username' =>class_exists(ParameterType::class) ? ParameterType::STRING :\PDO::PARAM_STR,
138+
'series' =>class_exists(ParameterType::class) ? ParameterType::STRING :\PDO::PARAM_STR,
139+
'value' =>class_exists(ParameterType::class) ? ParameterType::STRING :\PDO::PARAM_STR,
139140
'lastUsed' =>self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE,
140141
];
141142
if (method_exists($this->conn,'executeStatement')) {

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
namespaceSymfony\Bridge\Doctrine\Tests\DataCollector;
1313

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

25+
// Doctrine DBAL 2 compatibility
26+
class_exists('Doctrine\DBAL\Platforms\MySqlPlatform');
27+
2528
class DoctrineDataCollectorTestextends TestCase
2629
{
2730
publicfunctiontestCollectConnections()
@@ -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-
publicfunctiontestSerialization($param,$types,$expected,$explainable,bool$runnable =true)
158+
publicfunctiontestSerialization($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-
publicfunctionparamProvider()
185+
publicfunctionparamProvider():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-
privatefunctioncreateCollector($queries)
233+
privatefunctioncreateCollector(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‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,12 @@ public function testInvalidEntityManagerThrowsException()
103103

104104
publicfunctiontestMiddlewareNoPingInNonWorkerContext()
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‎

Lines 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/Cache/Traits/PdoTrait.php‎

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
useDoctrine\DBAL\DriverManager;
1818
useDoctrine\DBAL\Exception;
1919
useDoctrine\DBAL\Exception\TableNotFoundException;
20+
useDoctrine\DBAL\ParameterType;
2021
useDoctrine\DBAL\Schema\Schema;
2122
useSymfony\Component\Cache\Exception\InvalidArgumentException;
2223
useSymfony\Component\Cache\Marshaller\DefaultMarshaller;
@@ -166,17 +167,20 @@ public function prune()
166167
$deleteSql .=" AND$this->idCol LIKE :namespace";
167168
}
168169

170+
$connection =$this->getConnection();
171+
$useDbalConstants =$connectioninstanceof Connection &&class_exists(ParameterType::class);
172+
169173
try {
170-
$delete =$this->getConnection()->prepare($deleteSql);
174+
$delete =$connection->prepare($deleteSql);
171175
}catch (TableNotFoundException$e) {
172176
returntrue;
173177
}catch (\PDOException$e) {
174178
returntrue;
175179
}
176-
$delete->bindValue(':time',time(), \PDO::PARAM_INT);
180+
$delete->bindValue(':time',time(),$useDbalConstants ? ParameterType::INTEGER :\PDO::PARAM_INT);
177181

178182
if ('' !==$this->namespace) {
179-
$delete->bindValue(':namespace',sprintf('%s%%',$this->namespace), \PDO::PARAM_STR);
183+
$delete->bindValue(':namespace',sprintf('%s%%',$this->namespace),$useDbalConstants ? ParameterType::STRING :\PDO::PARAM_STR);
180184
}
181185
try {
182186
return$delete->execute();
@@ -192,13 +196,16 @@ public function prune()
192196
*/
193197
protectedfunctiondoFetch(array$ids)
194198
{
199+
$connection =$this->getConnection();
200+
$useDbalConstants =$connectioninstanceof Connection &&class_exists(ParameterType::class);
201+
195202
$now =time();
196203
$expired = [];
197204

198205
$sql =str_pad('', (\count($ids) <<1) -1,'?,');
199206
$sql ="SELECT$this->idCol, CASE WHEN$this->lifetimeCol IS NULL OR$this->lifetimeCol +$this->timeCol > ? THEN$this->dataCol ELSE NULL END FROM$this->table WHERE$this->idCol IN ($sql)";
200-
$stmt =$this->getConnection()->prepare($sql);
201-
$stmt->bindValue($i =1,$now, \PDO::PARAM_INT);
207+
$stmt =$connection->prepare($sql);
208+
$stmt->bindValue($i =1,$now,$useDbalConstants ? ParameterType::INTEGER :\PDO::PARAM_INT);
202209
foreach ($idsas$id) {
203210
$stmt->bindValue(++$i,$id);
204211
}
@@ -222,8 +229,8 @@ protected function doFetch(array $ids)
222229
if ($expired) {
223230
$sql =str_pad('', (\count($expired) <<1) -1,'?,');
224231
$sql ="DELETE FROM$this->table WHERE$this->lifetimeCol +$this->timeCol <= ? AND$this->idCol IN ($sql)";
225-
$stmt =$this->getConnection()->prepare($sql);
226-
$stmt->bindValue($i =1,$now, \PDO::PARAM_INT);
232+
$stmt =$connection->prepare($sql);
233+
$stmt->bindValue($i =1,$now,$useDbalConstants ? ParameterType::INTEGER :\PDO::PARAM_INT);
227234
foreach ($expiredas$id) {
228235
$stmt->bindValue(++$i,$id);
229236
}
@@ -236,11 +243,14 @@ protected function doFetch(array $ids)
236243
*/
237244
protectedfunctiondoHave($id)
238245
{
246+
$connection =$this->getConnection();
247+
$useDbalConstants =$connectioninstanceof Connection &&class_exists(ParameterType::class);
248+
239249
$sql ="SELECT 1 FROM$this->table WHERE$this->idCol = :id AND ($this->lifetimeCol IS NULL OR$this->lifetimeCol +$this->timeCol > :time)";
240-
$stmt =$this->getConnection()->prepare($sql);
250+
$stmt =$connection->prepare($sql);
241251

242252
$stmt->bindValue(':id',$id);
243-
$stmt->bindValue(':time',time(), \PDO::PARAM_INT);
253+
$stmt->bindValue(':time',time(),$useDbalConstants ? ParameterType::INTEGER :\PDO::PARAM_INT);
244254
$result =$stmt->execute();
245255

246256
return (bool) (\is_object($result) ?$result->fetchOne() :$stmt->fetchColumn());
@@ -303,6 +313,8 @@ protected function doSave(array $values, int $lifetime)
303313
}
304314

305315
$conn =$this->getConnection();
316+
$useDbalConstants =$conninstanceof Connection &&class_exists(ParameterType::class);
317+
306318
$driver =$this->driver;
307319
$insertSql ="INSERT INTO$this->table ($this->idCol,$this->dataCol,$this->lifetimeCol,$this->timeCol) VALUES (:id, :data, :lifetime, :time)";
308320

@@ -354,25 +366,25 @@ protected function doSave(array $values, int $lifetime)
354366
if ('sqlsrv' ===$driver ||'oci' ===$driver) {
355367
$stmt->bindParam(1,$id);
356368
$stmt->bindParam(2,$id);
357-
$stmt->bindParam(3,$data, \PDO::PARAM_LOB);
358-
$stmt->bindValue(4,$lifetime, \PDO::PARAM_INT);
359-
$stmt->bindValue(5,$now, \PDO::PARAM_INT);
360-
$stmt->bindParam(6,$data, \PDO::PARAM_LOB);
361-
$stmt->bindValue(7,$lifetime, \PDO::PARAM_INT);
362-
$stmt->bindValue(8,$now, \PDO::PARAM_INT);
369+
$stmt->bindParam(3,$data,$useDbalConstants ? ParameterType::LARGE_OBJECT :\PDO::PARAM_LOB);
370+
$stmt->bindValue(4,$lifetime,$useDbalConstants ? ParameterType::INTEGER :\PDO::PARAM_INT);
371+
$stmt->bindValue(5,$now,$useDbalConstants ? ParameterType::INTEGER :\PDO::PARAM_INT);
372+
$stmt->bindParam(6,$data,$useDbalConstants ? ParameterType::LARGE_OBJECT :\PDO::PARAM_LOB);
373+
$stmt->bindValue(7,$lifetime,$useDbalConstants ? ParameterType::INTEGER :\PDO::PARAM_INT);
374+
$stmt->bindValue(8,$now,$useDbalConstants ? ParameterType::INTEGER :\PDO::PARAM_INT);
363375
}else {
364376
$stmt->bindParam(':id',$id);
365-
$stmt->bindParam(':data',$data, \PDO::PARAM_LOB);
366-
$stmt->bindValue(':lifetime',$lifetime, \PDO::PARAM_INT);
367-
$stmt->bindValue(':time',$now, \PDO::PARAM_INT);
377+
$stmt->bindParam(':data',$data,$useDbalConstants ? ParameterType::LARGE_OBJECT :\PDO::PARAM_LOB);
378+
$stmt->bindValue(':lifetime',$lifetime,$useDbalConstants ? ParameterType::INTEGER :\PDO::PARAM_INT);
379+
$stmt->bindValue(':time',$now,$useDbalConstants ? ParameterType::INTEGER :\PDO::PARAM_INT);
368380
}
369381
if (null ===$driver) {
370382
$insertStmt =$conn->prepare($insertSql);
371383

372384
$insertStmt->bindParam(':id',$id);
373-
$insertStmt->bindParam(':data',$data, \PDO::PARAM_LOB);
374-
$insertStmt->bindValue(':lifetime',$lifetime, \PDO::PARAM_INT);
375-
$insertStmt->bindValue(':time',$now, \PDO::PARAM_INT);
385+
$insertStmt->bindParam(':data',$data,$useDbalConstants ? ParameterType::LARGE_OBJECT :\PDO::PARAM_LOB);
386+
$insertStmt->bindValue(':lifetime',$lifetime,$useDbalConstants ? ParameterType::INTEGER :\PDO::PARAM_INT);
387+
$insertStmt->bindValue(':time',$now,$useDbalConstants ? ParameterType::INTEGER :\PDO::PARAM_INT);
376388
}
377389

378390
foreach ($valuesas$id =>$data) {

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

Lines 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‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
useDoctrine\DBAL\Driver\ResultasDriverResult;
1515
useDoctrine\DBAL\DriverManager;
1616
useDoctrine\DBAL\Result;
17+
useDoctrine\DBAL\Schema\AbstractSchemaManager;
1718
usePHPUnit\Framework\TestCase;
1819
useSymfony\Component\Messenger\Tests\Fixtures\DummyMessage;
1920
useSymfony\Component\Messenger\Transport\Doctrine\Connection;
@@ -175,7 +176,7 @@ public function testItRetrieveTheMessageThatIsOlderThanRedeliverTimeout()
175176

176177
publicfunctiontestTheTransportIsSetupOnGet()
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+
privatefunctioncreateSchemaManager():AbstractSchemaManager
193+
{
194+
returnmethod_exists($this->driverConnection,'createSchemaManager')
195+
?$this->driverConnection->createSchemaManager()
196+
:$this->driverConnection->getSchemaManager();
197+
}
190198
}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
useDoctrine\DBAL\Platforms\MySqlPlatform;
2121
useDoctrine\DBAL\Query\QueryBuilder;
2222
useDoctrine\DBAL\Result;
23+
useDoctrine\DBAL\Schema\AbstractSchemaManager;
2324
useDoctrine\DBAL\Schema\Comparator;
2425
useDoctrine\DBAL\Schema\Schema;
2526
useDoctrine\DBAL\Schema\Synchronizer\SchemaSynchronizer;
@@ -377,7 +378,7 @@ private function executeStatement(string $sql, array $parameters = [], array $ty
377378

378379
privatefunctiongetSchema():Schema
379380
{
380-
$schema =newSchema([], [],$this->driverConnection->getSchemaManager()->createSchemaConfig());
381+
$schema =newSchema([], [],$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 =newComparator();
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+
privatefunctioncreateSchemaManager():AbstractSchemaManager
437+
{
438+
returnmethod_exists($this->driverConnection,'createSchemaManager')
439+
?$this->driverConnection->createSchemaManager()
440+
:$this->driverConnection->getSchemaManager();
441+
}
434442
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp