Skip to content

[DoctrineBridge] Fix value type on Query::setValue (middlewares) #46810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Doctrine/Middleware/Debug/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function setParam(string|int $param, null|string|int|float|bool &$variabl
$this->types[$idx] = $type;
}

public function setValue(string|int $param, null|string|int|float|bool $value, int $type): void
public function setValue(string|int $param, mixed $value, int $type): void
{
// Numeric indexes start at 0 in profiler
$idx = \is_int($param) ? $param - 1 : $param;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Statement;
use Doctrine\DBAL\Types\Types;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\Middleware\Debug\DebugDataHolder;
use Symfony\Bridge\Doctrine\Middleware\Debug\Middleware;
Expand Down Expand Up @@ -61,11 +62,22 @@ private function init(bool $withStopwatch = true): void
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
price REAL NOT NULL,
stock INTEGER NOT NULL
stock INTEGER NOT NULL,
picture BLOB NULL,
tags TEXT NULL,
created_at TEXT NULL
);
EOT);
}

private function getResourceFromString(string $str)
{
$res = fopen('php://temp', 'r+');
fwrite($res, $str);

return $res;
}

public function provideExecuteMethod(): array
{
return [
Expand Down Expand Up @@ -102,18 +114,26 @@ public function testWithValueBound(callable $executeMethod)
{
$this->init();

$stmt = $this->conn->prepare('INSERT INTO products(name, price, stock) VALUES (?, ?, ?)');
$sql = <<<EOT
INSERT INTO products(name, price, stock, picture, tags, created_at)
VALUES (?, ?, ?, ?, ?, ?)
EOT;

$stmt = $this->conn->prepare($sql);
$stmt->bindValue(1, 'product1');
$stmt->bindValue(2, 12.5);
$stmt->bindValue(3, 5, ParameterType::INTEGER);
$stmt->bindValue(4, $res = $this->getResourceFromString('mybinarydata'), ParameterType::BINARY);
$stmt->bindValue(5, ['foo', 'bar'], Types::SIMPLE_ARRAY);
$stmt->bindValue(6, new \DateTime('2022-06-12 11:00:00'), Types::DATETIME_MUTABLE);

$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->assertSame($sql, $debug[1]['sql']);
$this->assertSame(['product1', 12.5, 5, $res, 'foo,bar', '2022-06-12 11:00:00'], $debug[1]['params']);
$this->assertSame([ParameterType::STRING, ParameterType::STRING, ParameterType::INTEGER, ParameterType::BINARY, ParameterType::STRING, ParameterType::STRING], $debug[1]['types']);
$this->assertGreaterThan(0, $debug[1]['executionMS']);
}

Expand Down