-
Notifications
You must be signed in to change notification settings - Fork 121
Adding a test for scale 0. #931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+45
−0
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1126,6 +1126,7 @@ public static function columnsProvider() | |
| ['column6', 'float', []], | ||
| ['column7', 'decimal', []], | ||
| ['decimal_precision_scale', 'decimal', ['precision' => 10, 'scale' => 2]], | ||
| ['decimal_precision_scale_zero', 'decimal', ['precision' => 65, 'scale' => 0]], | ||
| ['decimal_limit', 'decimal', ['limit' => 10]], | ||
| ['decimal_precision', 'decimal', ['precision' => 10]], | ||
| ['column8', 'datetime', []], | ||
|
|
@@ -2410,4 +2411,48 @@ public function testCheckConstraintWithComplexExpression() | |
| $this->expectException(PDOException::class); | ||
| $this->adapter->execute("INSERT INTO {$quotedTableName} (email, status) VALUES ('[email protected]', 'invalid')"); | ||
| } | ||
|
|
||
| /** | ||
| * Test that DECIMAL columns with scale=0 work correctly. | ||
| * | ||
| * This tests the fix for https://github.com/cakephp/phinx/pull/2377 | ||
| * In phinx, the boolean check `$column->getPrecision() && $column->getScale()` | ||
| * would fail when scale is 0 because 0 is falsy in PHP. | ||
| * | ||
| * The 5.x branch uses CakePHP's database layer instead of phinx, | ||
| * so we need to verify it handles scale=0 correctly. | ||
| */ | ||
| public function testDecimalWithScaleZero() | ||
| { | ||
| // Create table with DECIMAL(65,0) | ||
| $table = new Table('decimal_scale_zero_test', [], $this->adapter); | ||
| $table->addColumn('amount', 'decimal', ['precision' => 65, 'scale' => 0]) | ||
| ->create(); | ||
|
|
||
| // Verify the column was created with correct precision and scale | ||
| $columns = $this->adapter->getColumns('decimal_scale_zero_test'); | ||
| $amountColumn = null; | ||
| foreach ($columns as $column) { | ||
| if ($column->getName() === 'amount') { | ||
| $amountColumn = $column; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| $this->assertNotNull($amountColumn, 'Amount column should exist'); | ||
| $this->assertEquals('decimal', $amountColumn->getType()); | ||
| $this->assertEquals(65, $amountColumn->getPrecision()); | ||
| $this->assertEquals(0, $amountColumn->getScale(), 'Scale should be 0, not null'); | ||
|
|
||
| // Verify the actual MySQL column definition | ||
| $result = $this->adapter->fetchRow('SHOW CREATE TABLE `decimal_scale_zero_test`'); | ||
| $createTableSql = $result['Create Table']; | ||
|
|
||
| // The CREATE TABLE should contain DECIMAL(65,0) - case insensitive | ||
| $this->assertMatchesRegularExpression( | ||
| '/decimal\(65,0\)/i', | ||
| $createTableSql, | ||
| 'CREATE TABLE should contain DECIMAL(65,0) with scale=0 properly defined', | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like an assertion that may become brittle over time. We can try it and see how it goes. I think this kind of assertion is better done in cakephp/database as that is where the implementation lives.