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 1629b59

Browse filesBrowse files
committed
Merge branch '5.3' into 5.4
* 5.3: fix tests Fix tests failing with DBAL 3 Fix circular reference in autowired decorators
2 parents 6e4758e + 6faae75 commit 1629b59
Copy full SHA for 1629b59

File tree

12 files changed

+130
-63
lines changed
Filter options

12 files changed

+130
-63
lines changed

‎src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function getTypes(string $class, string $property, array $context = [])
166166
case Type::BUILTIN_TYPE_ARRAY:
167167
switch ($typeOfField) {
168168
case Types::ARRAY:
169-
case Types::JSON_ARRAY:
169+
case 'json_array':
170170
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true)];
171171

172172
case Types::SIMPLE_ARRAY:
@@ -280,7 +280,7 @@ private function getPhpType(string $doctrineType): ?string
280280

281281
case Types::ARRAY:
282282
case Types::SIMPLE_ARRAY:
283-
case Types::JSON_ARRAY:
283+
case 'json_array':
284284
return Type::BUILTIN_TYPE_ARRAY;
285285
}
286286

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php
+9-8Lines 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\Schema\Schema;
1819
use Doctrine\DBAL\Types\Types;
@@ -57,7 +58,7 @@ public function loadTokenBySeries(string $series)
5758
// the alias for lastUsed works around case insensitivity in PostgreSQL
5859
$sql = 'SELECT class, username, value, lastUsed AS last_used FROM rememberme_token WHERE series=:series';
5960
$paramValues = ['series' => $series];
60-
$paramTypes = ['series' => \PDO::PARAM_STR];
61+
$paramTypes = ['series' => ParameterType::STRING];
6162
$stmt = $this->conn->executeQuery($sql, $paramValues, $paramTypes);
6263
$row = $stmt instanceof Result || $stmt instanceof DriverResult ? $stmt->fetchAssociative() : $stmt->fetch(\PDO::FETCH_ASSOC);
6364

@@ -75,7 +76,7 @@ public function deleteTokenBySeries(string $series)
7576
{
7677
$sql = 'DELETE FROM rememberme_token WHERE series=:series';
7778
$paramValues = ['series' => $series];
78-
$paramTypes = ['series' => \PDO::PARAM_STR];
79+
$paramTypes = ['series' => ParameterType::STRING];
7980
if (method_exists($this->conn, 'executeStatement')) {
8081
$this->conn->executeStatement($sql, $paramValues, $paramTypes);
8182
} else {
@@ -95,9 +96,9 @@ public function updateToken(string $series, string $tokenValue, \DateTime $lastU
9596
'series' => $series,
9697
];
9798
$paramTypes = [
98-
'value' => \PDO::PARAM_STR,
99+
'value' => ParameterType::STRING,
99100
'lastUsed' => Types::DATETIME_MUTABLE,
100-
'series' => \PDO::PARAM_STR,
101+
'series' => ParameterType::STRING,
101102
];
102103
if (method_exists($this->conn, 'executeStatement')) {
103104
$updated = $this->conn->executeStatement($sql, $paramValues, $paramTypes);
@@ -124,10 +125,10 @@ public function createNewToken(PersistentTokenInterface $token)
124125
'lastUsed' => $token->getLastUsed(),
125126
];
126127
$paramTypes = [
127-
'class' => \PDO::PARAM_STR,
128-
'username' => \PDO::PARAM_STR,
129-
'series' => \PDO::PARAM_STR,
130-
'value' => \PDO::PARAM_STR,
128+
'class' => ParameterType::STRING,
129+
'username' => ParameterType::STRING,
130+
'series' => ParameterType::STRING,
131+
'value' => ParameterType::STRING,
131132
'lastUsed' => Types::DATETIME_MUTABLE,
132133
];
133134
if (method_exists($this->conn, 'executeStatement')) {

‎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::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())

‎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
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
},
5353
"conflict": {
5454
"doctrine/dbal": "<2.10",
55+
"doctrine/orm": "<2.7.3",
5556
"phpunit/phpunit": "<5.4.3",
5657
"symfony/dependency-injection": "<4.4",
5758
"symfony/form": "<5.1",

‎src/Symfony/Component/Cache/Adapter/PdoAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/PdoAdapter.php
+33-21Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Doctrine\DBAL\DriverManager;
1818
use Doctrine\DBAL\Exception;
1919
use Doctrine\DBAL\Exception\TableNotFoundException;
20+
use Doctrine\DBAL\ParameterType;
2021
use Doctrine\DBAL\Schema\Schema;
2122
use Symfony\Component\Cache\Exception\InvalidArgumentException;
2223
use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
@@ -191,17 +192,20 @@ public function prune()
191192
$deleteSql .= " AND $this->idCol LIKE :namespace";
192193
}
193194

195+
$connection = $this->getConnection();
196+
$useDbalConstants = $connection instanceof Connection;
197+
194198
try {
195-
$delete = $this->getConnection()->prepare($deleteSql);
199+
$delete = $connection->prepare($deleteSql);
196200
} catch (TableNotFoundException $e) {
197201
return true;
198202
} catch (\PDOException $e) {
199203
return true;
200204
}
201-
$delete->bindValue(':time', time(), \PDO::PARAM_INT);
205+
$delete->bindValue(':time', time(), $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
202206

203207
if ('' !== $this->namespace) {
204-
$delete->bindValue(':namespace', sprintf('%s%%', $this->namespace), \PDO::PARAM_STR);
208+
$delete->bindValue(':namespace', sprintf('%s%%', $this->namespace), $useDbalConstants ? ParameterType::STRING : \PDO::PARAM_STR);
205209
}
206210
try {
207211
return $delete->execute();
@@ -217,13 +221,16 @@ public function prune()
217221
*/
218222
protected function doFetch(array $ids)
219223
{
224+
$connection = $this->getConnection();
225+
$useDbalConstants = $connection instanceof Connection;
226+
220227
$now = time();
221228
$expired = [];
222229

223230
$sql = str_pad('', (\count($ids) << 1) - 1, '?,');
224231
$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)";
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 ($ids as $id) {
228235
$stmt->bindValue(++$i, $id);
229236
}
@@ -247,8 +254,8 @@ protected function doFetch(array $ids)
247254
if ($expired) {
248255
$sql = str_pad('', (\count($expired) << 1) - 1, '?,');
249256
$sql = "DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol <= ? AND $this->idCol IN ($sql)";
250-
$stmt = $this->getConnection()->prepare($sql);
251-
$stmt->bindValue($i = 1, $now, \PDO::PARAM_INT);
257+
$stmt = $connection->prepare($sql);
258+
$stmt->bindValue($i = 1, $now, $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
252259
foreach ($expired as $id) {
253260
$stmt->bindValue(++$i, $id);
254261
}
@@ -261,11 +268,14 @@ protected function doFetch(array $ids)
261268
*/
262269
protected function doHave(string $id)
263270
{
271+
$connection = $this->getConnection();
272+
$useDbalConstants = $connection instanceof Connection;
273+
264274
$sql = "SELECT 1 FROM $this->table WHERE $this->idCol = :id AND ($this->lifetimeCol IS NULL OR $this->lifetimeCol + $this->timeCol > :time)";
265-
$stmt = $this->getConnection()->prepare($sql);
275+
$stmt = $connection->prepare($sql);
266276

267277
$stmt->bindValue(':id', $id);
268-
$stmt->bindValue(':time', time(), \PDO::PARAM_INT);
278+
$stmt->bindValue(':time', time(), $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
269279
$result = $stmt->execute();
270280

271281
return (bool) (\is_object($result) ? $result->fetchOne() : $stmt->fetchColumn());
@@ -328,6 +338,8 @@ protected function doSave(array $values, int $lifetime)
328338
}
329339

330340
$conn = $this->getConnection();
341+
$useDbalConstants = $conn instanceof Connection;
342+
331343
$driver = $this->driver;
332344
$insertSql = "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, :data, :lifetime, :time)";
333345

@@ -379,25 +391,25 @@ protected function doSave(array $values, int $lifetime)
379391
if ('sqlsrv' === $driver || 'oci' === $driver) {
380392
$stmt->bindParam(1, $id);
381393
$stmt->bindParam(2, $id);
382-
$stmt->bindParam(3, $data, \PDO::PARAM_LOB);
383-
$stmt->bindValue(4, $lifetime, \PDO::PARAM_INT);
384-
$stmt->bindValue(5, $now, \PDO::PARAM_INT);
385-
$stmt->bindParam(6, $data, \PDO::PARAM_LOB);
386-
$stmt->bindValue(7, $lifetime, \PDO::PARAM_INT);
387-
$stmt->bindValue(8, $now, \PDO::PARAM_INT);
394+
$stmt->bindParam(3, $data, $useDbalConstants ? ParameterType::LARGE_OBJECT : \PDO::PARAM_LOB);
395+
$stmt->bindValue(4, $lifetime, $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
396+
$stmt->bindValue(5, $now, $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
397+
$stmt->bindParam(6, $data, $useDbalConstants ? ParameterType::LARGE_OBJECT : \PDO::PARAM_LOB);
398+
$stmt->bindValue(7, $lifetime, $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
399+
$stmt->bindValue(8, $now, $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
388400
} else {
389401
$stmt->bindParam(':id', $id);
390-
$stmt->bindParam(':data', $data, \PDO::PARAM_LOB);
391-
$stmt->bindValue(':lifetime', $lifetime, \PDO::PARAM_INT);
392-
$stmt->bindValue(':time', $now, \PDO::PARAM_INT);
402+
$stmt->bindParam(':data', $data, $useDbalConstants ? ParameterType::LARGE_OBJECT : \PDO::PARAM_LOB);
403+
$stmt->bindValue(':lifetime', $lifetime, $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
404+
$stmt->bindValue(':time', $now, $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
393405
}
394406
if (null === $driver) {
395407
$insertStmt = $conn->prepare($insertSql);
396408

397409
$insertStmt->bindParam(':id', $id);
398-
$insertStmt->bindParam(':data', $data, \PDO::PARAM_LOB);
399-
$insertStmt->bindValue(':lifetime', $lifetime, \PDO::PARAM_INT);
400-
$insertStmt->bindValue(':time', $now, \PDO::PARAM_INT);
410+
$insertStmt->bindParam(':data', $data, $useDbalConstants ? ParameterType::LARGE_OBJECT : \PDO::PARAM_LOB);
411+
$insertStmt->bindValue(':lifetime', $lifetime, $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
412+
$insertStmt->bindValue(':time', $now, $useDbalConstants ? ParameterType::INTEGER : \PDO::PARAM_INT);
401413
}
402414

403415
foreach ($values as $id => $data) {

‎src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ private function autowireCalls(\ReflectionClass $reflectionClass, bool $isRoot,
153153
$this->decoratedClass = null;
154154
$this->getPreviousValue = null;
155155

156-
if ($isRoot && ($definition = $this->container->getDefinition($this->currentId)) && null !== ($this->decoratedId = $definition->innerServiceId) && $this->container->has($this->decoratedId)) {
157-
$this->decoratedClass = $this->container->findDefinition($this->decoratedId)->getClass();
156+
if ($isRoot && ($definition = $this->container->getDefinition($this->currentId)) && ($decoratedDefinition = $definition->getDecoratedService()) && null !== ($innerId = $decoratedDefinition[0]) && $this->container->has($innerId)) {
157+
// If the class references to itself and is decorated, provide the inner service id and class to not get a circular reference
158+
$this->decoratedClass = $this->container->findDefinition($innerId)->getClass();
159+
$this->decoratedId = $decoratedDefinition[1] ?? $this->currentId.'.inner';
158160
}
159161

160162
foreach ($this->methodCalls as $i => $call) {

0 commit comments

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