Skip to content

[DoctrineBridge] Fix comment for type on Query::setValue (middlewares) #46811

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

Merged
merged 1 commit into from
Jul 2, 2022
Merged
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
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Doctrine/Middleware/Debug/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public function setParam($param, &$variable, int $type): void
}

/**
* @param string|int $param
* @param string|int|float|bool|null $value
* @param string|int $param
* @param mixed $value
*/
public function setValue($param, $value, int $type): void
{
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\Result;
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,12 +62,23 @@ 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 @@ -107,18 +119,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('mydata'), 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