77 * For the full copyright and license information, please view the LICENSE
88 * file that was distributed with this source code.
99 */
10-
1110namespace NilPortugues \Tests \Sql \QueryBuilder \Builder \Syntax ;
1211
1312use NilPortugues \Sql \QueryBuilder \Builder \GenericBuilder ;
@@ -48,7 +47,7 @@ public function tearDown()
4847 /**
4948 * @test
5049 */
51- public function itShouldWriteIntersects ()
50+ public function itShouldWriteUnion ()
5251 {
5352 $ union = new Union ();
5453
@@ -66,7 +65,7 @@ public function itShouldWriteIntersects()
6665 /**
6766 * @test
6867 */
69- public function itShouldWriteUnionAllFromGenericBuilder ()
68+ public function itShouldWriteUnionFromGenericBuilder ()
7069 {
7170 $ unionAll = $ this ->writer ->union ();
7271
@@ -80,4 +79,40 @@ public function itShouldWriteUnionAllFromGenericBuilder()
8079SQL ;
8180 $ this ->assertEquals ($ expected , $ this ->writer ->write ($ unionAll ));
8281 }
82+
83+ /**
84+ * @test
85+ */
86+ public function itShouldNotResetPlaceholders ()
87+ {
88+ $ select1 = (new Select ('table1 ' ))
89+ ->where ()
90+ ->between ('column ' , 1 , 2 )
91+ ->end ();
92+
93+ $ select2 = (new Select ('table2 ' ))
94+ ->where ()
95+ ->between ('column ' , 3 , 4 )
96+ ->end ();
97+
98+ $ union = (new Union ())
99+ ->add ($ select1 )
100+ ->add ($ select2 );
101+
102+ $ expectedSql = <<<SQL
103+ SELECT table1.* FROM table1 WHERE (table1.column BETWEEN :v1 AND :v2)
104+ UNION
105+ SELECT table2.* FROM table2 WHERE (table2.column BETWEEN :v3 AND :v4)
106+ SQL ;
107+
108+ $ expectedParams = [
109+ ':v1 ' => 1 ,
110+ ':v2 ' => 2 ,
111+ ':v3 ' => 3 ,
112+ ':v4 ' => 4 ,
113+ ];
114+
115+ $ this ->assertEquals ($ expectedSql , $ this ->writer ->write ($ union ));
116+ $ this ->assertEquals ($ expectedParams , $ this ->writer ->getValues ());
117+ }
83118}
0 commit comments