88use Cake \Console \TestSuite \StubConsoleOutput ;
99use Cake \Core \Configure ;
1010use Cake \Database \Connection ;
11+ use Cake \Database \Driver \Mysql ;
1112use Cake \Datasource \ConnectionManager ;
1213use InvalidArgumentException ;
1314use Migrations \Db \Adapter \MysqlAdapter ;
@@ -2327,10 +2328,7 @@ public function testAddCheckConstraint()
23272328 $ table ->addColumn ('price ' , 'decimal ' , ['precision ' => 10 , 'scale ' => 2 ])
23282329 ->create ();
23292330
2330- $ checkConstraint = new CheckConstraint ();
2331- $ checkConstraint ->setName ('price_positive ' )
2332- ->setExpression ('price > 0 ' );
2333-
2331+ $ checkConstraint = new CheckConstraint ('price_positive ' , 'price > 0 ' );
23342332 $ this ->adapter ->addCheckConstraint ($ table ->getTable (), $ checkConstraint );
23352333
23362334 $ this ->assertTrue ($ this ->adapter ->hasCheckConstraint ('check_table ' , 'price_positive ' ));
@@ -2342,19 +2340,18 @@ public function testAddCheckConstraintWithAutoGeneratedName()
23422340 $ table ->addColumn ('age ' , 'integer ' )
23432341 ->create ();
23442342
2345- $ checkConstraint = new CheckConstraint ();
2346- $ checkConstraint ->setExpression ('age >= 18 ' );
2343+ $ checkConstraint = new CheckConstraint ('' , 'age >= 18 ' );
23472344
23482345 $ this ->adapter ->addCheckConstraint ($ table ->getTable (), $ checkConstraint );
23492346
2350- // The constraint should exist with an auto-generated name
2351- $ constraints = $ this ->adapter ->fetchAll (sprintf (
2352- "SELECT cc.CONSTRAINT_NAME FROM INFORMATION_SCHEMA.CHECK_CONSTRAINTS cc INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON cc.CONSTRAINT_SCHEMA = tc.CONSTRAINT_SCHEMA AND cc.CONSTRAINT_NAME = tc.CONSTRAINT_NAME WHERE tc.CONSTRAINT_SCHEMA = '%s' AND tc.TABLE_NAME = 'check_table2' " ,
2353- $ this ->config ['database ' ],
2354- ));
2347+ $ driver = $ this ->adapter ->getConnection ()->getDriver ();
2348+ assert ($ driver instanceof Mysql);
23552349
2350+ $ dialect = $ driver ->schemaDialect ();
2351+ $ constraints = $ dialect ->describeCheckConstraints ('check_table2 ' );
23562352 $ this ->assertCount (1 , $ constraints );
2357- $ this ->assertStringContainsString ('check_table2_chk_ ' , $ constraints [0 ]['CONSTRAINT_NAME ' ]);
2353+ $ expected = $ driver ->isMariaDb () ? 'CONSTRAINT_1 ' : 'check_table2_chk_ ' ;
2354+ $ this ->assertStringContainsString ($ expected , $ constraints [0 ]['name ' ]);
23582355 }
23592356
23602357 public function testHasCheckConstraint ()
@@ -2363,10 +2360,7 @@ public function testHasCheckConstraint()
23632360 $ table ->addColumn ('quantity ' , 'integer ' )
23642361 ->create ();
23652362
2366- $ checkConstraint = new CheckConstraint ();
2367- $ checkConstraint ->setName ('quantity_positive ' )
2368- ->setExpression ('quantity > 0 ' );
2369-
2363+ $ checkConstraint = new CheckConstraint ('quantity_positive ' , 'quantity > 0 ' );
23702364 $ this ->assertFalse ($ this ->adapter ->hasCheckConstraint ('check_table3 ' , 'quantity_positive ' ));
23712365
23722366 $ this ->adapter ->addCheckConstraint ($ table ->getTable (), $ checkConstraint );
@@ -2380,10 +2374,7 @@ public function testDropCheckConstraint()
23802374 $ table ->addColumn ('price ' , 'decimal ' , ['precision ' => 10 , 'scale ' => 2 ])
23812375 ->create ();
23822376
2383- $ checkConstraint = new CheckConstraint ();
2384- $ checkConstraint ->setName ('price_check ' )
2385- ->setExpression ('price BETWEEN 0 AND 1000 ' );
2386-
2377+ $ checkConstraint = new CheckConstraint ('price_check ' , 'price BETWEEN 0 AND 1000 ' );
23872378 $ this ->adapter ->addCheckConstraint ($ table ->getTable (), $ checkConstraint );
23882379 $ this ->assertTrue ($ this ->adapter ->hasCheckConstraint ('check_table4 ' , 'price_check ' ));
23892380
@@ -2398,10 +2389,10 @@ public function testCheckConstraintWithComplexExpression()
23982389 ->addColumn ('status ' , 'string ' , ['limit ' => 20 ])
23992390 ->create ();
24002391
2401- $ checkConstraint = new CheckConstraint ();
2402- $ checkConstraint -> setName ( 'status_valid ' )
2403- -> setExpression ( "status IN ('active', 'inactive', 'pending') " );
2404-
2392+ $ checkConstraint = new CheckConstraint (
2393+ 'status_valid ' ,
2394+ "status IN ('active', 'inactive', 'pending') " ,
2395+ );
24052396 $ this ->adapter ->addCheckConstraint ($ table ->getTable (), $ checkConstraint );
24062397 $ this ->assertTrue ($ this ->adapter ->hasCheckConstraint ('check_table5 ' , 'status_valid ' ));
24072398
0 commit comments