[
+ static function(object $target, ...$args) {
+ return $target->executeStatement(...$args);
+ },
+ ],
+ 'executeQuery' => [
+ static function(object $target, ...$args): Result {
+ return $target->executeQuery(...$args);
+ },
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider provideExecuteMethod
+ */
+ public function testWithoutBinding(callable $executeMethod)
+ {
+ $this->init();
+
+ $executeMethod($this->conn, 'INSERT INTO products(name, price, stock) VALUES ("product1", 12.5, 5)');
+
+ $debug = $this->debugDataHolder->getData()['default'] ?? [];
+ $this->assertCount(2, $debug);
+ $this->assertSame('INSERT INTO products(name, price, stock) VALUES ("product1", 12.5, 5)', $debug[1]['sql']);
+ $this->assertSame([], $debug[1]['params']);
+ $this->assertSame([], $debug[1]['types']);
+ $this->assertGreaterThan(0, $debug[1]['executionMS']);
+ }
+
+ /**
+ * @dataProvider provideExecuteMethod
+ */
+ public function testWithValueBound(callable $executeMethod)
+ {
+ $this->init();
+
+ $stmt = $this->conn->prepare('INSERT INTO products(name, price, stock) VALUES (?, ?, ?)');
+ $stmt->bindValue(1, 'product1');
+ $stmt->bindValue(2, 12.5);
+ $stmt->bindValue(3, 5, ParameterType::INTEGER);
+
+ $executeMethod($stmt);
+
+ $debug = $this->debugDataHolder->getData()['default'] ?? [];
+ $this->assertCount(2, $debug);
+ $this->assertSame('INSERT INTO products(name, price, stock) VALUES (?, ?, ?)', $debug[1]['sql']);
+ $this->assertSame(['product1', 12.5, 5], $debug[1]['params']);
+ $this->assertSame([ParameterType::STRING, ParameterType::STRING, ParameterType::INTEGER], $debug[1]['types']);
+ $this->assertGreaterThan(0, $debug[1]['executionMS']);
+ }
+
+ /**
+ * @dataProvider provideExecuteMethod
+ */
+ public function testWithParamBound(callable $executeMethod)
+ {
+ $this->init();
+
+ $product = 'product1';
+ $price = 12.5;
+ $stock = 5;
+
+ $stmt = $this->conn->prepare('INSERT INTO products(name, price, stock) VALUES (?, ?, ?)');
+ $stmt->bindParam(1, $product);
+ $stmt->bindParam(2, $price);
+ $stmt->bindParam(3, $stock, ParameterType::INTEGER);
+
+ $executeMethod($stmt);
+
+ // Debug data should not be affected by these changes
+ $product = 'product2';
+ $price = 13.5;
+ $stock = 4;
+
+ $debug = $this->debugDataHolder->getData()['default'] ?? [];
+ $this->assertCount(2, $debug);
+ $this->assertSame('INSERT INTO products(name, price, stock) VALUES (?, ?, ?)', $debug[1]['sql']);
+ $this->assertSame(['product1', '12.5', 5], $debug[1]['params']);
+ $this->assertSame([ParameterType::STRING, ParameterType::STRING, ParameterType::INTEGER], $debug[1]['types']);
+ $this->assertGreaterThan(0, $debug[1]['executionMS']);
+ }
+
+ public function provideEndTransactionMethod(): array
+ {
+ return [
+ 'commit' => [
+ static function(Connection $conn): bool {
+ return $conn->commit();
+ },
+ '"COMMIT"',
+ ],
+ 'rollback' => [
+ static function(Connection $conn): bool {
+ return $conn->rollBack();
+ },
+ '"ROLLBACK"',
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider provideEndTransactionMethod
+ */
+ public function testTransaction(callable $endTransactionMethod, string $expectedEndTransactionDebug)
+ {
+ $this->init();
+
+ $this->conn->beginTransaction();
+ $this->conn->beginTransaction();
+ $this->conn->executeStatement('INSERT INTO products(name, price, stock) VALUES ("product1", 12.5, 5)');
+ $endTransactionMethod($this->conn);
+ $endTransactionMethod($this->conn);
+ $this->conn->beginTransaction();
+ $this->conn->executeStatement('INSERT INTO products(name, price, stock) VALUES ("product2", 15.5, 12)');
+ $endTransactionMethod($this->conn);
+
+ $debug = $this->debugDataHolder->getData()['default'] ?? [];
+ $this->assertCount(7, $debug);
+ $this->assertSame('"START TRANSACTION"', $debug[1]['sql']);
+ $this->assertGreaterThan(0, $debug[1]['executionMS']);
+ $this->assertSame('INSERT INTO products(name, price, stock) VALUES ("product1", 12.5, 5)', $debug[2]['sql']);
+ $this->assertGreaterThan(0, $debug[2]['executionMS']);
+ $this->assertSame($expectedEndTransactionDebug, $debug[3]['sql']);
+ $this->assertGreaterThan(0, $debug[3]['executionMS']);
+ $this->assertSame('"START TRANSACTION"', $debug[4]['sql']);
+ $this->assertGreaterThan(0, $debug[4]['executionMS']);
+ $this->assertSame('INSERT INTO products(name, price, stock) VALUES ("product2", 15.5, 12)', $debug[5]['sql']);
+ $this->assertGreaterThan(0, $debug[5]['executionMS']);
+ $this->assertSame($expectedEndTransactionDebug, $debug[6]['sql']);
+ $this->assertGreaterThan(0, $debug[6]['executionMS']);
+ }
+
+ public function provideExecuteAndEndTransactionMethods(): array
+ {
+ return [
+ 'commit and exec' => [
+ static function(Connection $conn, string $sql) {
+ return $conn->executeStatement($sql);
+ },
+ static function(Connection $conn): bool {
+ return $conn->commit();
+ },
+ ],
+ 'rollback and query' => [
+ static function(Connection $conn, string $sql): Result {
+ return $conn->executeQuery($sql);
+ },
+ static function(Connection $conn): bool {
+ return $conn->rollBack();
+ },
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider provideExecuteAndEndTransactionMethods
+ */
+ public function testGlobalDoctrineDuration(callable $sqlMethod, callable $endTransactionMethod)
+ {
+ $this->init();
+
+ $periods = $this->stopwatch->getEvent('doctrine')->getPeriods();
+ $this->assertCount(1, $periods);
+
+ $this->conn->beginTransaction();
+
+ $this->assertFalse($this->stopwatch->getEvent('doctrine')->isStarted());
+ $this->assertCount(2, $this->stopwatch->getEvent('doctrine')->getPeriods());
+
+ $sqlMethod($this->conn, 'SELECT * FROM products');
+
+ $this->assertFalse($this->stopwatch->getEvent('doctrine')->isStarted());
+ $this->assertCount(3, $this->stopwatch->getEvent('doctrine')->getPeriods());
+
+ $endTransactionMethod($this->conn);
+
+ $this->assertFalse($this->stopwatch->getEvent('doctrine')->isStarted());
+ $this->assertCount(4, $this->stopwatch->getEvent('doctrine')->getPeriods());
+ }
+
+ /**
+ * @dataProvider provideExecuteAndEndTransactionMethods
+ */
+ public function testWithoutStopwatch(callable $sqlMethod, callable $endTransactionMethod)
+ {
+ $this->init(false);
+
+ $this->conn->beginTransaction();
+ $sqlMethod($this->conn, 'SELECT * FROM products');
+ $endTransactionMethod($this->conn);
+ }
+}
diff --git a/src/Symfony/Bridge/Doctrine/composer.json b/src/Symfony/Bridge/Doctrine/composer.json
index 5d8e8485c73e9..dadb456cc2029 100644
--- a/src/Symfony/Bridge/Doctrine/composer.json
+++ b/src/Symfony/Bridge/Doctrine/composer.json
@@ -34,6 +34,7 @@
"symfony/http-kernel": "^5.0|^6.0",
"symfony/messenger": "^4.4|^5.0|^6.0",
"symfony/doctrine-messenger": "^5.1|^6.0",
+ "symfony/phpunit-bridge": "^4.4|^5.4|^6.0",
"symfony/property-access": "^4.4|^5.0|^6.0",
"symfony/property-info": "^5.0|^6.0",
"symfony/proxy-manager-bridge": "^4.4|^5.0|^6.0",
diff --git a/src/Symfony/Bridge/Doctrine/phpunit.xml.dist b/src/Symfony/Bridge/Doctrine/phpunit.xml.dist
index fa76fa9b500e7..31a2546b47ec4 100644
--- a/src/Symfony/Bridge/Doctrine/phpunit.xml.dist
+++ b/src/Symfony/Bridge/Doctrine/phpunit.xml.dist
@@ -28,4 +28,14 @@
+
+
+
+
+
+ Symfony\Bridge\Doctrine\Middleware\Debug
+
+
+
+
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