Skip to content

Commit a18116a

Browse files
committed
Run tests with ORM 3 and DBAL 4
1 parent 2b77ae3 commit a18116a

21 files changed

+381
-114
lines changed

.github/patch-types.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
}
2424
// no break;
2525
case false !== strpos($file, '/vendor/'):
26+
case false !== strpos($file, '/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php'):
27+
case false !== strpos($file, '/src/Symfony/Bridge/Doctrine/Middleware/Debug/DBAL3'):
2628
case false !== strpos($file, '/src/Symfony/Bridge/PhpUnit/'):
2729
case false !== strpos($file, '/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Validation/Article.php'):
2830
case false !== strpos($file, '/src/Symfony/Component/Cache/Tests/Fixtures/DriverWrapper.php'):

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@
131131
"doctrine/annotations": "^1.13.1|^2",
132132
"doctrine/collections": "^1.0|^2.0",
133133
"doctrine/data-fixtures": "^1.1",
134-
"doctrine/dbal": "^2.13.1|^3.0",
135-
"doctrine/orm": "^2.12",
134+
"doctrine/dbal": "^2.13.1|^3|^4",
135+
"doctrine/orm": "^2.12|^3",
136136
"dragonmantank/cron-expression": "^3.1",
137137
"egulias/email-validator": "^2.1.10|^3.1|^4",
138138
"guzzlehttp/promises": "^1.4",

src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function guessType(string $class, string $property): ?TypeGuess
6060
}
6161

6262
return match ($metadata->getTypeOfField($property)) {
63-
Types::ARRAY,
63+
'array',
6464
Types::SIMPLE_ARRAY => new TypeGuess(CollectionType::class, [], Guess::MEDIUM_CONFIDENCE),
6565
Types::BOOLEAN => new TypeGuess(CheckboxType::class, [], Guess::HIGH_CONFIDENCE),
6666
Types::DATETIME_MUTABLE,

src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Messenger;
1313

14+
use Doctrine\DBAL\Connection;
1415
use Doctrine\DBAL\Exception as DBALException;
1516
use Doctrine\ORM\EntityManagerInterface;
1617
use Symfony\Component\Messenger\Envelope;
@@ -38,14 +39,23 @@ private function pingConnection(EntityManagerInterface $entityManager): void
3839
$connection = $entityManager->getConnection();
3940

4041
try {
41-
$connection->executeQuery($connection->getDatabasePlatform()->getDummySelectSQL());
42+
$this->executeDummySql($connection);
4243
} catch (DBALException) {
4344
$connection->close();
44-
$connection->connect();
45+
// Attempt to reestablish the lazy connection by sending another query.
46+
$this->executeDummySql($connection);
4547
}
4648

4749
if (!$entityManager->isOpen()) {
4850
$this->managerRegistry->resetManager($this->entityManagerName);
4951
}
5052
}
53+
54+
/**
55+
* @throws DBALException
56+
*/
57+
private function executeDummySql(Connection $connection): void
58+
{
59+
$connection->executeQuery($connection->getDatabasePlatform()->getDummySelectSQL());
60+
}
5161
}

src/Symfony/Bridge/Doctrine/Middleware/Debug/Connection.php

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,16 @@
1414
use Doctrine\DBAL\Driver\Connection as ConnectionInterface;
1515
use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware;
1616
use Doctrine\DBAL\Driver\Result;
17-
use Doctrine\DBAL\Driver\Statement as DriverStatement;
1817
use Symfony\Component\Stopwatch\Stopwatch;
1918

2019
/**
2120
* @author Laurent VOULLEMIER <laurent.voullemier@gmail.com>
21+
* @author Alexander M. Turek <me@derrabus.de>
2222
*
2323
* @internal
2424
*/
2525
final class Connection extends AbstractConnectionMiddleware
2626
{
27-
private int $nestingLevel = 0;
28-
2927
public function __construct(
3028
ConnectionInterface $connection,
3129
private DebugDataHolder $debugDataHolder,
@@ -35,7 +33,7 @@ public function __construct(
3533
parent::__construct($connection);
3634
}
3735

38-
public function prepare(string $sql): DriverStatement
36+
public function prepare(string $sql): Statement
3937
{
4038
return new Statement(
4139
parent::prepare($sql),
@@ -54,13 +52,11 @@ public function query(string $sql): Result
5452
$query->start();
5553

5654
try {
57-
$result = parent::query($sql);
55+
return parent::query($sql);
5856
} finally {
5957
$query->stop();
6058
$this->stopwatch?->stop('doctrine');
6159
}
62-
63-
return $result;
6460
}
6561

6662
public function exec(string $sql): int
@@ -80,63 +76,51 @@ public function exec(string $sql): int
8076
return $affectedRows;
8177
}
8278

83-
public function beginTransaction(): bool
79+
public function beginTransaction(): void
8480
{
85-
$query = null;
86-
if (1 === ++$this->nestingLevel) {
87-
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query('"START TRANSACTION"'));
88-
}
81+
$query = new Query('"START TRANSACTION"');
82+
$this->debugDataHolder->addQuery($this->connectionName, $query);
8983

9084
$this->stopwatch?->start('doctrine', 'doctrine');
91-
$query?->start();
85+
$query->start();
9286

9387
try {
94-
$ret = parent::beginTransaction();
88+
parent::beginTransaction();
9589
} finally {
96-
$query?->stop();
90+
$query->stop();
9791
$this->stopwatch?->stop('doctrine');
9892
}
99-
100-
return $ret;
10193
}
10294

103-
public function commit(): bool
95+
public function commit(): void
10496
{
105-
$query = null;
106-
if (1 === $this->nestingLevel--) {
107-
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query('"COMMIT"'));
108-
}
97+
$query = new Query('"COMMIT"');
98+
$this->debugDataHolder->addQuery($this->connectionName, $query);
10999

110100
$this->stopwatch?->start('doctrine', 'doctrine');
111-
$query?->start();
101+
$query->start();
112102

113103
try {
114-
$ret = parent::commit();
104+
parent::commit();
115105
} finally {
116-
$query?->stop();
106+
$query->stop();
117107
$this->stopwatch?->stop('doctrine');
118108
}
119-
120-
return $ret;
121109
}
122110

123-
public function rollBack(): bool
111+
public function rollBack(): void
124112
{
125-
$query = null;
126-
if (1 === $this->nestingLevel--) {
127-
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query('"ROLLBACK"'));
128-
}
113+
$query = new Query('"ROLLBACK"');
114+
$this->debugDataHolder->addQuery($this->connectionName, $query);
129115

130116
$this->stopwatch?->start('doctrine', 'doctrine');
131-
$query?->start();
117+
$query->start();
132118

133119
try {
134-
$ret = parent::rollBack();
120+
parent::rollBack();
135121
} finally {
136-
$query?->stop();
122+
$query->stop();
137123
$this->stopwatch?->stop('doctrine');
138124
}
139-
140-
return $ret;
141125
}
142126
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\Middleware\Debug\DBAL3;
13+
14+
use Doctrine\DBAL\Driver\Connection as ConnectionInterface;
15+
use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware;
16+
use Doctrine\DBAL\Driver\Result;
17+
use Symfony\Bridge\Doctrine\Middleware\Debug\DebugDataHolder;
18+
use Symfony\Bridge\Doctrine\Middleware\Debug\Query;
19+
use Symfony\Component\Stopwatch\Stopwatch;
20+
21+
/**
22+
* @author Laurent VOULLEMIER <laurent.voullemier@gmail.com>
23+
*
24+
* @internal
25+
*/
26+
final class Connection extends AbstractConnectionMiddleware
27+
{
28+
private int $nestingLevel = 0;
29+
30+
public function __construct(
31+
ConnectionInterface $connection,
32+
private DebugDataHolder $debugDataHolder,
33+
private ?Stopwatch $stopwatch,
34+
private string $connectionName,
35+
) {
36+
parent::__construct($connection);
37+
}
38+
39+
public function prepare(string $sql): Statement
40+
{
41+
return new Statement(
42+
parent::prepare($sql),
43+
$this->debugDataHolder,
44+
$this->connectionName,
45+
$sql,
46+
$this->stopwatch,
47+
);
48+
}
49+
50+
public function query(string $sql): Result
51+
{
52+
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query($sql));
53+
54+
$this->stopwatch?->start('doctrine', 'doctrine');
55+
$query->start();
56+
57+
try {
58+
return parent::query($sql);
59+
} finally {
60+
$query->stop();
61+
$this->stopwatch?->stop('doctrine');
62+
}
63+
}
64+
65+
public function exec(string $sql): int
66+
{
67+
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query($sql));
68+
69+
$this->stopwatch?->start('doctrine', 'doctrine');
70+
$query->start();
71+
72+
try {
73+
return parent::exec($sql);
74+
} finally {
75+
$query->stop();
76+
$this->stopwatch?->stop('doctrine');
77+
}
78+
}
79+
80+
public function beginTransaction(): bool
81+
{
82+
$query = null;
83+
if (1 === ++$this->nestingLevel) {
84+
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query('"START TRANSACTION"'));
85+
}
86+
87+
$this->stopwatch?->start('doctrine', 'doctrine');
88+
$query?->start();
89+
90+
try {
91+
return parent::beginTransaction();
92+
} finally {
93+
$query?->stop();
94+
$this->stopwatch?->stop('doctrine');
95+
}
96+
}
97+
98+
public function commit(): bool
99+
{
100+
$query = null;
101+
if (1 === $this->nestingLevel--) {
102+
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query('"COMMIT"'));
103+
}
104+
105+
$this->stopwatch?->start('doctrine', 'doctrine');
106+
$query?->start();
107+
108+
try {
109+
return parent::commit();
110+
} finally {
111+
$query?->stop();
112+
$this->stopwatch?->stop('doctrine');
113+
}
114+
}
115+
116+
public function rollBack(): bool
117+
{
118+
$query = null;
119+
if (1 === $this->nestingLevel--) {
120+
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query('"ROLLBACK"'));
121+
}
122+
123+
$this->stopwatch?->start('doctrine', 'doctrine');
124+
$query?->start();
125+
126+
try {
127+
return parent::rollBack();
128+
} finally {
129+
$query?->stop();
130+
$this->stopwatch?->stop('doctrine');
131+
}
132+
}
133+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\Middleware\Debug\DBAL3;
13+
14+
use Doctrine\DBAL\Driver\Middleware\AbstractStatementMiddleware;
15+
use Doctrine\DBAL\Driver\Result as ResultInterface;
16+
use Doctrine\DBAL\Driver\Statement as StatementInterface;
17+
use Doctrine\DBAL\ParameterType;
18+
use Symfony\Bridge\Doctrine\Middleware\Debug\DebugDataHolder;
19+
use Symfony\Bridge\Doctrine\Middleware\Debug\Query;
20+
use Symfony\Component\Stopwatch\Stopwatch;
21+
22+
/**
23+
* @author Laurent VOULLEMIER <laurent.voullemier@gmail.com>
24+
*
25+
* @internal
26+
*/
27+
final class Statement extends AbstractStatementMiddleware
28+
{
29+
private Query $query;
30+
31+
public function __construct(
32+
StatementInterface $statement,
33+
private DebugDataHolder $debugDataHolder,
34+
private string $connectionName,
35+
string $sql,
36+
private ?Stopwatch $stopwatch = null,
37+
) {
38+
parent::__construct($statement);
39+
40+
$this->query = new Query($sql);
41+
}
42+
43+
public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null): bool
44+
{
45+
$this->query->setParam($param, $variable, $type);
46+
47+
return parent::bindParam($param, $variable, $type, ...\array_slice(\func_get_args(), 3));
48+
}
49+
50+
public function bindValue($param, $value, $type = ParameterType::STRING): bool
51+
{
52+
$this->query->setValue($param, $value, $type);
53+
54+
return parent::bindValue($param, $value, $type);
55+
}
56+
57+
public function execute($params = null): ResultInterface
58+
{
59+
if (null !== $params) {
60+
$this->query->setValues($params);
61+
}
62+
63+
// clone to prevent variables by reference to change
64+
$this->debugDataHolder->addQuery($this->connectionName, $query = clone $this->query);
65+
66+
$this->stopwatch?->start('doctrine', 'doctrine');
67+
$query->start();
68+
69+
try {
70+
return parent::execute($params);
71+
} finally {
72+
$query->stop();
73+
$this->stopwatch?->stop('doctrine');
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy