|
17 | 17 | use Doctrine\DBAL\DriverManager;
|
18 | 18 | use Doctrine\DBAL\ParameterType;
|
19 | 19 | use Doctrine\DBAL\Statement;
|
| 20 | +use Doctrine\DBAL\Types\Types; |
20 | 21 | use PHPUnit\Framework\TestCase;
|
21 | 22 | use Symfony\Bridge\Doctrine\Middleware\Debug\DebugDataHolder;
|
22 | 23 | use Symfony\Bridge\Doctrine\Middleware\Debug\Middleware;
|
@@ -61,11 +62,22 @@ private function init(bool $withStopwatch = true): void
|
61 | 62 | id INTEGER PRIMARY KEY,
|
62 | 63 | name TEXT NOT NULL,
|
63 | 64 | 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 |
65 | 69 | );
|
66 | 70 | EOT);
|
67 | 71 | }
|
68 | 72 |
|
| 73 | + private function getResourceFromString(string $str) |
| 74 | + { |
| 75 | + $res = fopen('php://temp', 'r+'); |
| 76 | + fwrite($res, $str); |
| 77 | + |
| 78 | + return $res; |
| 79 | + } |
| 80 | + |
69 | 81 | public function provideExecuteMethod(): array
|
70 | 82 | {
|
71 | 83 | return [
|
@@ -102,18 +114,26 @@ public function testWithValueBound(callable $executeMethod)
|
102 | 114 | {
|
103 | 115 | $this->init();
|
104 | 116 |
|
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); |
106 | 123 | $stmt->bindValue(1, 'product1');
|
107 | 124 | $stmt->bindValue(2, 12.5);
|
108 | 125 | $stmt->bindValue(3, 5, ParameterType::INTEGER);
|
| 126 | + $stmt->bindValue(4, $res = $this->getResourceFromString('mybinarydata'), 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); |
109 | 129 |
|
110 | 130 | $executeMethod($stmt);
|
111 | 131 |
|
112 | 132 | $debug = $this->debugDataHolder->getData()['default'] ?? [];
|
113 | 133 | $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']); |
117 | 137 | $this->assertGreaterThan(0, $debug[1]['executionMS']);
|
118 | 138 | }
|
119 | 139 |
|
|
0 commit comments