|
17 | 17 | use Doctrine\DBAL\DriverManager; |
18 | 18 | use Doctrine\DBAL\ParameterType; |
19 | 19 | use Doctrine\DBAL\Result; |
| 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,12 +62,23 @@ 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 | } |
69 | 73 |
|
| 74 | + private function getResourceFromString(string $str) |
| 75 | + { |
| 76 | + $res = fopen('php://temp', 'r+'); |
| 77 | + fwrite($res, $str); |
| 78 | + |
| 79 | + return $res; |
| 80 | + } |
| 81 | + |
70 | 82 | public function provideExecuteMethod(): array |
71 | 83 | { |
72 | 84 | return [ |
@@ -107,18 +119,26 @@ public function testWithValueBound(callable $executeMethod) |
107 | 119 | { |
108 | 120 | $this->init(); |
109 | 121 |
|
110 | | - $stmt = $this->conn->prepare('INSERT INTO products(name, price, stock) VALUES (?, ?, ?)'); |
| 122 | + $sql = <<<EOT |
| 123 | +INSERT INTO products(name, price, stock, picture, tags, created_at) |
| 124 | +VALUES (?, ?, ?, ?, ?, ?) |
| 125 | +EOT; |
| 126 | + |
| 127 | + $stmt = $this->conn->prepare($sql); |
111 | 128 | $stmt->bindValue(1, 'product1'); |
112 | 129 | $stmt->bindValue(2, 12.5); |
113 | 130 | $stmt->bindValue(3, 5, ParameterType::INTEGER); |
| 131 | + $stmt->bindValue(4, $res = $this->getResourceFromString('mydata'), ParameterType::BINARY); |
| 132 | + $stmt->bindValue(5, ['foo', 'bar'], Types::SIMPLE_ARRAY); |
| 133 | + $stmt->bindValue(6, new \DateTime('2022-06-12 11:00:00'), Types::DATETIME_MUTABLE); |
114 | 134 |
|
115 | 135 | $executeMethod($stmt); |
116 | 136 |
|
117 | 137 | $debug = $this->debugDataHolder->getData()['default'] ?? []; |
118 | 138 | $this->assertCount(2, $debug); |
119 | | - $this->assertSame('INSERT INTO products(name, price, stock) VALUES (?, ?, ?)', $debug[1]['sql']); |
120 | | - $this->assertSame(['product1', 12.5, 5], $debug[1]['params']); |
121 | | - $this->assertSame([ParameterType::STRING, ParameterType::STRING, ParameterType::INTEGER], $debug[1]['types']); |
| 139 | + $this->assertSame($sql, $debug[1]['sql']); |
| 140 | + $this->assertSame(['product1', 12.5, 5, $res, 'foo,bar', '2022-06-12 11:00:00'], $debug[1]['params']); |
| 141 | + $this->assertSame([ParameterType::STRING, ParameterType::STRING, ParameterType::INTEGER, ParameterType::BINARY, ParameterType::STRING, ParameterType::STRING], $debug[1]['types']); |
122 | 142 | $this->assertGreaterThan(0, $debug[1]['executionMS']); |
123 | 143 | } |
124 | 144 |
|
|
0 commit comments