Skip to content

Commit 826292d

Browse files
committed
[DoctrineBridge] Fix value type on Query::setValue (middlewares)
1 parent 0235a07 commit 826292d

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function setParam(string|int $param, null|string|int|float|bool &$variabl
5252
$this->types[$idx] = $type;
5353
}
5454

55-
public function setValue(string|int $param, null|string|int|float|bool $value, int $type): void
55+
public function setValue(string|int $param, mixed $value, int $type): void
5656
{
5757
// Numeric indexes start at 0 in profiler
5858
$idx = \is_int($param) ? $param - 1 : $param;

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Doctrine\DBAL\DriverManager;
1818
use Doctrine\DBAL\ParameterType;
1919
use Doctrine\DBAL\Statement;
20+
use Doctrine\DBAL\Types\Types;
2021
use PHPUnit\Framework\TestCase;
2122
use Symfony\Bridge\Doctrine\Middleware\Debug\DebugDataHolder;
2223
use Symfony\Bridge\Doctrine\Middleware\Debug\Middleware;
@@ -61,11 +62,22 @@ private function init(bool $withStopwatch = true): void
6162
id INTEGER PRIMARY KEY,
6263
name TEXT NOT NULL,
6364
price REAL NOT NULL,
64-
stock INTEGER NOT NULL
65+
stock INTEGER NOT NULL,
66+
picture BLOB NULL,
67+
tags TEXT NULL,
68+
created_at TEXT NULL
6569
);
6670
EOT);
6771
}
6872

73+
private function getResourceFromString(string $str)
74+
{
75+
$res = fopen('php://temp', 'r+');
76+
fwrite($res, $str);
77+
78+
return $res;
79+
}
80+
6981
public function provideExecuteMethod(): array
7082
{
7183
return [
@@ -102,18 +114,26 @@ public function testWithValueBound(callable $executeMethod)
102114
{
103115
$this->init();
104116

105-
$stmt = $this->conn->prepare('INSERT INTO products(name, price, stock) VALUES (?, ?, ?)');
117+
$sql = <<<EOT
118+
INSERT INTO products(name, price, stock, picture, tags, created_at)
119+
VALUES (?, ?, ?, ?, ?, ?)
120+
EOT;
121+
122+
$stmt = $this->conn->prepare($sql);
106123
$stmt->bindValue(1, 'product1');
107124
$stmt->bindValue(2, 12.5);
108125
$stmt->bindValue(3, 5, ParameterType::INTEGER);
126+
$stmt->bindValue(4, $res = $this->getResourceFromString('mydata'), ParameterType::BINARY);
127+
$stmt->bindValue(5, ['foo', 'bar'], Types::SIMPLE_ARRAY);
128+
$stmt->bindValue(6, new \DateTime('2022-06-12 11:00:00'), Types::DATETIME_MUTABLE);
109129

110130
$executeMethod($stmt);
111131

112132
$debug = $this->debugDataHolder->getData()['default'] ?? [];
113133
$this->assertCount(2, $debug);
114-
$this->assertSame('INSERT INTO products(name, price, stock) VALUES (?, ?, ?)', $debug[1]['sql']);
115-
$this->assertSame(['product1', 12.5, 5], $debug[1]['params']);
116-
$this->assertSame([ParameterType::STRING, ParameterType::STRING, ParameterType::INTEGER], $debug[1]['types']);
134+
$this->assertSame($sql, $debug[1]['sql']);
135+
$this->assertSame(['product1', 12.5, 5, $res, 'foo,bar', '2022-06-12 11:00:00'], $debug[1]['params']);
136+
$this->assertSame([ParameterType::STRING, ParameterType::STRING, ParameterType::INTEGER, ParameterType::BINARY, ParameterType::STRING, ParameterType::STRING], $debug[1]['types']);
117137
$this->assertGreaterThan(0, $debug[1]['executionMS']);
118138
}
119139

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