@@ -108,13 +108,12 @@ public function testGetDropTableCommand(): void
108108 * @dataProvider createTableTestSqlProvider
109109 */
110110 public function testGetCreateCommand (
111- array $ columns ,
112- array $ primaryKeys ,
113- array $ expectedColumnNames ,
114- array $ expectedPKs ,
111+ array $ columns ,
112+ array $ primaryKeys ,
113+ array $ expectedColumnNames ,
114+ array $ expectedPKs ,
115115 string $ expectedSql
116- ): void
117- {
116+ ): void {
118117 $ sql = $ this ->qb ->getCreateTableCommand (
119118 $ this ->getDatabaseName (),
120119 self ::TABLE_GENERIC ,
@@ -346,10 +345,9 @@ public function createTableTestFromDefinitionSqlProvider(): Generator
346345 */
347346 public function testGetCreateTableCommandFromDefinition (
348347 TeradataTableDefinition $ definition ,
349- string $ expectedSql ,
350- bool $ createPrimaryKeys
351- ): void
352- {
348+ string $ expectedSql ,
349+ bool $ createPrimaryKeys
350+ ): void {
353351 $ this ->cleanDatabase ($ this ->getDatabaseName ());
354352 $ this ->createDatabase ($ this ->getDatabaseName ());
355353 $ sql = $ this ->qb ->getCreateTableCommandFromDefinition ($ definition , $ createPrimaryKeys );
@@ -370,7 +368,7 @@ public function testGetCreateTableCommandFromDefinition(
370368 }
371369 }
372370
373- public function testAddAndDropPK ()
371+ public function testAddAndDropPK (): void
374372 {
375373 $ testDb = $ this ->getDatabaseName ();
376374 $ tableName = self ::TABLE_GENERIC ;
@@ -411,4 +409,51 @@ public function testAddAndDropPK()
411409 $ ref1 = new TeradataTableReflection ($ this ->connection , $ testDb , $ tableName );
412410 $ this ->assertEmpty ($ ref1 ->getPrimaryKeysNames ());
413411 }
412+
413+
414+ public function testDeduplication (): void
415+ {
416+ $ testDb = $ this ->getDatabaseName ();
417+ $ tableName = self ::TABLE_GENERIC ;
418+
419+ // definition for table
420+ $ definition = new TeradataTableDefinition (
421+ $ testDb ,
422+ $ tableName ,
423+ false ,
424+ new ColumnCollection (
425+ [
426+ TeradataColumn::createGenericColumn ('col1 ' ),
427+ TeradataColumn::createGenericColumn ('col2 ' ),
428+ TeradataColumn::createGenericColumn ('col3 ' ),
429+ ]
430+ ),
431+ []
432+ );
433+
434+ $ sql = $ this ->qb ->getCreateTableCommandFromDefinition ($ definition , true );
435+ $ this ->connection ->executeQuery ($ sql );
436+
437+ foreach ([['1 ' , '1 ' , '1 ' ], ['2 ' , '2 ' , '2 ' ], ['3 ' , '3 ' , '3 ' ]] as $ i ) {
438+ $ this ->connection ->executeStatement (sprintf (
439+ 'INSERT INTO %s.%s VALUES (%s) ' ,
440+ TeradataQuote::quoteSingleIdentifier ($ testDb ),
441+ TeradataQuote::quoteSingleIdentifier ($ tableName ),
442+ implode (', ' , $ i )
443+ ));
444+ }
445+ $ duplicatedSql = $ this ->qb ->getCommandForDuplicates ($ testDb , $ tableName , ['col2 ' , 'col3 ' ]);
446+ $ data = $ this ->connection ->fetchOne ($ duplicatedSql );
447+ $ this ->assertEquals ('1 ' , $ data );
448+
449+ $ this ->connection ->executeStatement (sprintf (
450+ 'INSERT INTO %s.%s VALUES (5,3,3) ' ,
451+ TeradataQuote::quoteSingleIdentifier ($ testDb ),
452+ TeradataQuote::quoteSingleIdentifier ($ tableName )
453+ ));
454+
455+ $ duplicatedSql = $ this ->qb ->getCommandForDuplicates ($ testDb , $ tableName , ['col2 ' , 'col3 ' ]);
456+ $ data = $ this ->connection ->fetchOne ($ duplicatedSql );
457+ $ this ->assertEquals ('2 ' , $ data );
458+ }
414459}
0 commit comments