Skip to content

Commit

Permalink
Fix BigDecimal type
Browse files Browse the repository at this point in the history
  • Loading branch information
FVesely committed Jun 26, 2020
1 parent 6ed53c2 commit 517739b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Money/BigDecimalType.php
Expand Up @@ -15,6 +15,11 @@ final class BigDecimalType extends \Doctrine\DBAL\Types\Type
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
{
$fieldDeclaration['precision'] = !isset($fieldDeclaration['precision']) || empty($fieldDeclaration['precision'])
? 20 : $fieldDeclaration['precision'];
$fieldDeclaration['scale'] = !isset($fieldDeclaration['scale']) || empty($fieldDeclaration['scale'])
? 4 : $fieldDeclaration['scale'];

return $platform->getDecimalTypeDeclarationSQL($fieldDeclaration);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/DoctrineTypes/Money/BigDecimalTypeTest.phpt
Expand Up @@ -16,13 +16,13 @@ require_once __DIR__ . '/../../bootstrap.php';
final class BigDecimalTypeTest extends \Tester\TestCase
{

private const NUMBER = '123456789';
private const NUMBER = '123456789.95';

public function testGetSQLDeclaration(): void
{
$type = Type::getType(BigDecimalType::NAME);

Assert::same('NUMERIC(10, 0)', $type->getSQLDeclaration([], new Platform()));
Assert::same('NUMERIC(20, 4)', $type->getSQLDeclaration([], new Platform()));
}

public function testConvertToPhpValue(): void
Expand Down

0 comments on commit 517739b

Please sign in to comment.