@@ -1127,6 +1127,7 @@ public static function columnsProvider()
11271127 ['column6 ' , 'float ' , []],
11281128 ['column7 ' , 'decimal ' , []],
11291129 ['decimal_precision_scale ' , 'decimal ' , ['precision ' => 10 , 'scale ' => 2 ]],
1130+ ['decimal_precision_scale_zero ' , 'decimal ' , ['precision ' => 65 , 'scale ' => 0 ]],
11301131 ['decimal_limit ' , 'decimal ' , ['limit ' => 10 ]],
11311132 ['decimal_precision ' , 'decimal ' , ['precision ' => 10 ]],
11321133 ['column8 ' , 'datetime ' , []],
@@ -2401,4 +2402,48 @@ public function testCheckConstraintWithComplexExpression()
24012402 $ this ->expectException (PDOException::class);
24022403 $ this ->
adapter ->
execute (
"INSERT INTO {$ quotedTableName } (email, status) VALUES ('[email protected] ', 'invalid') " );
24032404 }
2405+
2406+ /**
2407+ * Test that DECIMAL columns with scale=0 work correctly.
2408+ *
2409+ * This tests the fix for https://github.com/cakephp/phinx/pull/2377
2410+ * In phinx, the boolean check `$column->getPrecision() && $column->getScale()`
2411+ * would fail when scale is 0 because 0 is falsy in PHP.
2412+ *
2413+ * The 5.x branch uses CakePHP's database layer instead of phinx,
2414+ * so we need to verify it handles scale=0 correctly.
2415+ */
2416+ public function testDecimalWithScaleZero ()
2417+ {
2418+ // Create table with DECIMAL(65,0)
2419+ $ table = new Table ('decimal_scale_zero_test ' , [], $ this ->adapter );
2420+ $ table ->addColumn ('amount ' , 'decimal ' , ['precision ' => 65 , 'scale ' => 0 ])
2421+ ->create ();
2422+
2423+ // Verify the column was created with correct precision and scale
2424+ $ columns = $ this ->adapter ->getColumns ('decimal_scale_zero_test ' );
2425+ $ amountColumn = null ;
2426+ foreach ($ columns as $ column ) {
2427+ if ($ column ->getName () === 'amount ' ) {
2428+ $ amountColumn = $ column ;
2429+ break ;
2430+ }
2431+ }
2432+
2433+ $ this ->assertNotNull ($ amountColumn , 'Amount column should exist ' );
2434+ $ this ->assertEquals ('decimal ' , $ amountColumn ->getType ());
2435+ $ this ->assertEquals (65 , $ amountColumn ->getPrecision ());
2436+ $ this ->assertEquals (0 , $ amountColumn ->getScale (), 'Scale should be 0, not null ' );
2437+
2438+ // Verify the actual MySQL column definition
2439+ $ result = $ this ->adapter ->fetchRow ('SHOW CREATE TABLE `decimal_scale_zero_test` ' );
2440+ $ createTableSql = $ result ['Create Table ' ];
2441+
2442+ // The CREATE TABLE should contain DECIMAL(65,0) - case insensitive
2443+ $ this ->assertMatchesRegularExpression (
2444+ '/decimal\(65,0\)/i ' ,
2445+ $ createTableSql ,
2446+ 'CREATE TABLE should contain DECIMAL(65,0) with scale=0 properly defined ' ,
2447+ );
2448+ }
24042449}
0 commit comments