2 declare(strict_types = 1);
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
43 protected function setUp()
47 $this->connection = $this->createMock(Connection::class);
49 $this->connection->expects($this->any())
50 ->method(
'quoteIdentifier')
51 ->will($this->returnArgument(0));
52 $this->connection->expects($this->any())
53 ->method(
'getDatabasePlatform')
62 $this->expectException(\LogicException::class);
63 $this->expectExceptionMessage(
'You need to add at least one set of values before generating the SQL.');
77 $query->addValues([]);
79 $this->assertSame(
"INSERT INTO {$this->testTable} VALUES ()", (
string)$query);
80 $this->assertSame([], $query->getParameters());
81 $this->assertSame([], $query->getParameterTypes());
90 $this->assertSame(
"INSERT INTO {$this->testTable} VALUES ()", (
string)$query);
91 $this->assertSame([], $query->getParameters());
92 $this->assertSame([], $query->getParameterTypes());
100 $query =
new BulkInsertQuery($this->connection, $this->testTable);
102 $query->addValues([
'bar',
'baz',
'named' =>
'bloo']);
104 $this->assertSame(
"INSERT INTO {$this->testTable} VALUES (?, ?, ?)", (
string)$query);
105 $this->assertSame([
'bar',
'baz',
'bloo'], $query->getParameters());
106 $this->assertSame([
null,
null,
null], $query->getParameterTypes());
108 $query =
new BulkInsertQuery($this->connection, $this->testTable);
111 [
'bar',
'baz',
'named' =>
'bloo'],
115 $this->assertSame(
"INSERT INTO {$this->testTable} VALUES (?, ?, ?)", (
string)$query);
116 $this->assertSame([
'bar',
'baz',
'bloo'], $query->getParameters());
125 $query =
new BulkInsertQuery($this->connection, $this->testTable);
127 $query->addValues([]);
128 $query->addValues([
'bar',
'baz']);
129 $query->addValues([
'bar',
'baz',
'bloo']);
130 $query->addValues([
'bar',
'baz',
'named' =>
'bloo']);
132 $this->assertSame(
"INSERT INTO {$this->testTable} VALUES (), (?, ?), (?, ?, ?), (?, ?, ?)", (
string)$query);
133 $this->assertSame([
'bar',
'baz',
'bar',
'baz',
'bloo',
'bar',
'baz',
'bloo'], $query->getParameters());
134 $this->assertSame([
null,
null,
null,
null,
null,
null,
null,
null], $query->getParameterTypes());
136 $query =
new BulkInsertQuery($this->connection, $this->testTable);
142 [
'bar',
'baz',
'named' =>
'bloo'],
146 $this->assertSame(
"INSERT INTO {$this->testTable} VALUES (), (?, ?), (?, ?, ?), (?, ?, ?)", (
string)$query);
147 $this->assertSame([
'bar',
'baz',
'bar',
'baz',
'bloo',
'bar',
'baz',
'bloo'], $query->getParameters());
159 $query->getParameterTypes()
168 $query =
new BulkInsertQuery($this->connection, $this->testTable, [
'bar',
'baz']);
170 $query->addValues([
'bar',
'baz']);
172 $this->assertSame(
"INSERT INTO {$this->testTable} (bar, baz) VALUES (?, ?)", (
string)$query);
173 $this->assertSame([
'bar',
'baz'], $query->getParameters());
174 $this->assertSame([
null,
null], $query->getParameterTypes());
176 $query =
new BulkInsertQuery($this->connection, $this->testTable, [
'bar',
'baz']);
180 $this->assertSame(
"INSERT INTO {$this->testTable} (bar, baz) VALUES (?, ?)", (
string)$query);
181 $this->assertSame([
'bar',
'baz'], $query->getParameters());
190 $query =
new BulkInsertQuery($this->connection, $this->testTable, [
'bar',
'baz']);
192 $query->addValues([
'baz' =>
'baz',
'bar' =>
'bar']);
194 $this->assertSame(
"INSERT INTO {$this->testTable} (bar, baz) VALUES (?, ?)", (
string)$query);
195 $this->assertSame([
'bar',
'baz'], $query->getParameters());
196 $this->assertSame([
null,
null], $query->getParameterTypes());
198 $query =
new BulkInsertQuery($this->connection, $this->testTable, [
'bar',
'baz']);
202 $this->assertSame(
"INSERT INTO {$this->testTable} (bar, baz) VALUES (?, ?)", (
string)$query);
203 $this->assertSame([
'bar',
'baz'], $query->getParameters());
212 $query =
new BulkInsertQuery($this->connection, $this->testTable, [
'bar',
'baz']);
214 $query->addValues([1 =>
'baz',
'bar' =>
'bar']);
216 $this->assertSame(
"INSERT INTO {$this->testTable} (bar, baz) VALUES (?, ?)", (
string)$query);
217 $this->assertSame([
'bar',
'baz'], $query->getParameters());
218 $this->assertSame([
null,
null], $query->getParameterTypes());
220 $query =
new BulkInsertQuery($this->connection, $this->testTable, [
'bar',
'baz']);
224 $this->assertSame(
"INSERT INTO {$this->testTable} (bar, baz) VALUES (?, ?)", (
string)$query);
225 $this->assertSame([
'bar',
'baz'], $query->getParameters());
234 $query =
new BulkInsertQuery($this->connection, $this->testTable, [
'bar',
'baz']);
236 $query->addValues([
'bar',
'baz']);
237 $query->addValues([1 =>
'baz',
'bar' =>
'bar']);
238 $query->addValues([
'bar',
'baz' =>
'baz']);
239 $query->addValues([
'bar' =>
'bar',
'baz' =>
'baz']);
242 "INSERT INTO {$this->testTable} (bar, baz) VALUES (?, ?), (?, ?), (?, ?), (?, ?)",
245 $this->assertSame([
'bar',
'baz',
'bar',
'baz',
'bar',
'baz',
'bar',
'baz'], $query->getParameters());
246 $this->assertSame([
null,
null,
null,
null,
null,
null,
null,
null], $query->getParameterTypes());
248 $query =
new BulkInsertQuery($this->connection, $this->testTable, [
'bar',
'baz']);
252 $query->addValues([
'bar',
'baz' =>
'baz'], [
null,
null]);
254 [
'bar' =>
'bar',
'baz' =>
'baz'],
259 "INSERT INTO {$this->testTable} (bar, baz) VALUES (?, ?), (?, ?), (?, ?), (?, ?)",
262 $this->assertSame([
'bar',
'baz',
'bar',
'baz',
'bar',
'baz',
'bar',
'baz'], $query->getParameters());
274 $query->getParameterTypes()
283 $this->expectException(\InvalidArgumentException::class);
284 $this->expectExceptionMessage(
'No value specified for column bar (index 0).');
286 $query =
new BulkInsertQuery($this->connection, $this->testTable, [
'bar',
'baz']);
287 $query->addValues([]);
295 $this->expectException(\InvalidArgumentException::class);
296 $this->expectExceptionMessage(
'Multiple values specified for column baz (index 1).');
298 $query =
new BulkInsertQuery($this->connection, $this->testTable, [
'bar',
'baz']);
299 $query->addValues([
'bar',
'baz',
'baz' => 666]);
307 $this->expectException(\InvalidArgumentException::class);
308 $this->expectExceptionMessage(
'Multiple types specified for column baz (index 1).');
310 $query =
new BulkInsertQuery($this->connection, $this->testTable, [
'bar',
'baz']);
322 $this->expectException(\LogicException::class);
323 $this->expectExceptionMessage(
'You can only insert 10 rows in a single INSERT statement with platform "mock".');
326 $subject = $this->getAccessibleMock(
327 BulkInsertQuery::class,
328 [
'getInsertMaxRows'],
329 [$this->connection, $this->testTable],
333 $subject->expects($this->any())
334 ->method(
'getInsertMaxRows')
335 ->will($this->returnValue(10));
337 for ($i = 0; $i <= 10; $i++) {
338 $subject->addValues([]);