diff --git a/src/Builder/Syntax/AbstractSetWriter.php b/src/Builder/Syntax/AbstractSetWriter.php index 5fbe7d5..8558c32 100644 --- a/src/Builder/Syntax/AbstractSetWriter.php +++ b/src/Builder/Syntax/AbstractSetWriter.php @@ -43,7 +43,7 @@ protected function abstractWrite(QueryPartInterface $setClass, $setOperation, $g $selects = []; foreach ($setClass->$setOperation() as $select) { - $selects[] = $this->writer->write($select); + $selects[] = $this->writer->write($select, false); } return \implode("\n".$glue."\n", $selects); diff --git a/tests/Builder/Syntax/IntersectWriterTest.php b/tests/Builder/Syntax/IntersectWriterTest.php index c9ea928..cb1aef2 100644 --- a/tests/Builder/Syntax/IntersectWriterTest.php +++ b/tests/Builder/Syntax/IntersectWriterTest.php @@ -7,7 +7,6 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace NilPortugues\Tests\Sql\QueryBuilder\Builder\Syntax; use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder; @@ -48,7 +47,7 @@ public function tearDown() /** * @test */ - public function itShouldWriteIntersects() + public function itShouldWriteIntersect() { $intersect = new Intersect(); @@ -80,4 +79,40 @@ public function itShouldWriteIntersectFromGenericBuilder() SQL; $this->assertEquals($expected, $this->writer->write($intersect)); } + + /** + * @test + */ + public function itShouldNotResetPlaceholders() + { + $select1 = (new Select('table1')) + ->where() + ->between('column', 1, 2) + ->end(); + + $select2 = (new Select('table2')) + ->where() + ->between('column', 3, 4) + ->end(); + + $union = (new Intersect()) + ->add($select1) + ->add($select2); + + $expectedSql = << 1, + ':v2' => 2, + ':v3' => 3, + ':v4' => 4, + ]; + + $this->assertEquals($expectedSql, $this->writer->write($union)); + $this->assertEquals($expectedParams, $this->writer->getValues()); + } } diff --git a/tests/Builder/Syntax/UnionAllWriterTest.php b/tests/Builder/Syntax/UnionAllWriterTest.php index 15b8472..fbcd3ea 100644 --- a/tests/Builder/Syntax/UnionAllWriterTest.php +++ b/tests/Builder/Syntax/UnionAllWriterTest.php @@ -7,7 +7,6 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace NilPortugues\Tests\Sql\QueryBuilder\Builder\Syntax; use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder; @@ -48,7 +47,7 @@ public function tearDown() /** * @test */ - public function itShouldWriteIntersects() + public function itShouldWriteUnionAll() { $union = new UnionAll(); @@ -80,4 +79,40 @@ public function itShouldWriteUnionAllFromGenericBuilder() SQL; $this->assertEquals($expected, $this->writer->write($unionAll)); } + + /** + * @test + */ + public function itShouldNotResetPlaceholders() + { + $select1 = (new Select('table1')) + ->where() + ->between('column', 1, 2) + ->end(); + + $select2 = (new Select('table2')) + ->where() + ->between('column', 3, 4) + ->end(); + + $union = (new UnionAll()) + ->add($select1) + ->add($select2); + + $expectedSql = << 1, + ':v2' => 2, + ':v3' => 3, + ':v4' => 4, + ]; + + $this->assertEquals($expectedSql, $this->writer->write($union)); + $this->assertEquals($expectedParams, $this->writer->getValues()); + } } diff --git a/tests/Builder/Syntax/UnionWriterTest.php b/tests/Builder/Syntax/UnionWriterTest.php index 0f9cb7a..6d6c2d3 100644 --- a/tests/Builder/Syntax/UnionWriterTest.php +++ b/tests/Builder/Syntax/UnionWriterTest.php @@ -7,7 +7,6 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace NilPortugues\Tests\Sql\QueryBuilder\Builder\Syntax; use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder; @@ -48,7 +47,7 @@ public function tearDown() /** * @test */ - public function itShouldWriteIntersects() + public function itShouldWriteUnion() { $union = new Union(); @@ -66,7 +65,7 @@ public function itShouldWriteIntersects() /** * @test */ - public function itShouldWriteUnionAllFromGenericBuilder() + public function itShouldWriteUnionFromGenericBuilder() { $unionAll = $this->writer->union(); @@ -80,4 +79,40 @@ public function itShouldWriteUnionAllFromGenericBuilder() SQL; $this->assertEquals($expected, $this->writer->write($unionAll)); } + + /** + * @test + */ + public function itShouldNotResetPlaceholders() + { + $select1 = (new Select('table1')) + ->where() + ->between('column', 1, 2) + ->end(); + + $select2 = (new Select('table2')) + ->where() + ->between('column', 3, 4) + ->end(); + + $union = (new Union()) + ->add($select1) + ->add($select2); + + $expectedSql = << 1, + ':v2' => 2, + ':v3' => 3, + ':v4' => 4, + ]; + + $this->assertEquals($expectedSql, $this->writer->write($union)); + $this->assertEquals($expectedParams, $this->writer->getValues()); + } }