Skip to content

Commit 65788a3

Browse files
committed
[DoctrineBridge] fix issue with missing stopwatch events
1 parent 01344e3 commit 65788a3

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public function prepare(string $sql): DriverStatement
4444
parent::prepare($sql),
4545
$this->debugDataHolder,
4646
$this->connectionName,
47-
$sql
47+
$sql,
48+
$this->stopwatch
4849
);
4950
}
5051

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\DBAL\Driver\Result as ResultInterface;
1616
use Doctrine\DBAL\Driver\Statement as StatementInterface;
1717
use Doctrine\DBAL\ParameterType;
18+
use Symfony\Component\Stopwatch\Stopwatch;
1819

1920
/**
2021
* @author Laurent VOULLEMIER <laurent.voullemier@gmail.com>
@@ -26,14 +27,16 @@ final class Statement extends AbstractStatementMiddleware
2627
private $debugDataHolder;
2728
private $connectionName;
2829
private $query;
30+
private $stopwatch;
2931

30-
public function __construct(StatementInterface $statement, DebugDataHolder $debugDataHolder, string $connectionName, string $sql)
32+
public function __construct(StatementInterface $statement, DebugDataHolder $debugDataHolder, string $connectionName, string $sql, ?Stopwatch $stopwatch = null)
3133
{
3234
parent::__construct($statement);
3335

3436
$this->debugDataHolder = $debugDataHolder;
3537
$this->connectionName = $connectionName;
3638
$this->query = new Query($sql);
39+
$this->stopwatch = $stopwatch;
3740
}
3841

3942
public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null): bool
@@ -59,12 +62,20 @@ public function execute($params = null): ResultInterface
5962
// clone to prevent variables by reference to change
6063
$this->debugDataHolder->addQuery($this->connectionName, $query = clone $this->query);
6164

65+
if (null !== $this->stopwatch) {
66+
$this->stopwatch->start('doctrine', 'doctrine');
67+
}
68+
6269
$query->start();
6370

6471
try {
6572
$result = parent::execute($params);
6673
} finally {
6774
$query->stop();
75+
76+
if (null !== $this->stopwatch) {
77+
$this->stopwatch->stop('doctrine');
78+
}
6879
}
6980

7081
return $result;

src/Symfony/Bridge/Doctrine/Tests/Middleware/Debug/MiddlewareTest.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,6 @@ public function testWithParamBound(callable $executeMethod)
161161
$executeMethod($stmt);
162162

163163
// Debug data should not be affected by these changes
164-
$product = 'product2';
165-
$price = 13.5;
166-
$stock = 4;
167-
168164
$debug = $this->debugDataHolder->getData()['default'] ?? [];
169165
$this->assertCount(2, $debug);
170166
$this->assertSame('INSERT INTO products(name, price, stock) VALUES (?, ?, ?)', $debug[1]['sql']);
@@ -242,6 +238,14 @@ static function (Connection $conn): bool {
242238
return $conn->rollBack();
243239
},
244240
],
241+
'prepared statement' => [
242+
static function (Connection $conn, string $sql): Result {
243+
return $conn->prepare($sql)->executeQuery();
244+
},
245+
static function (Connection $conn): bool {
246+
return $conn->commit();
247+
},
248+
],
245249
];
246250
}
247251

0 commit comments

Comments
 (0)