Skip to content

Commit

Permalink
Rename Real type to SmallFloat
Browse files Browse the repository at this point in the history
  • Loading branch information
berkut1 committed Jul 20, 2024
1 parent ac30dbf commit d2c45cb
Show file tree
Hide file tree
Showing 21 changed files with 40 additions and 56 deletions.
4 changes: 2 additions & 2 deletions docs/en/reference/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ or ``null`` if no data is present.
it approximates precision which can lead to false assumptions in
applications.

real
smallfloat
+++++

Maps and converts single precision floating-point values.
Expand Down Expand Up @@ -580,7 +580,7 @@ Please also notice the mapping specific footnotes for additional information.
| | +--------------------------+ | |
| | | **SQLite** | | |
+-------------------+---------------+--------------------------+---------+----------------------------------------------------------+
| **real** | ``float`` | **MySQL** | *all* | ``FLOAT`` ``UNSIGNED`` [10] |
| **smallfloat** | ``float`` | **MySQL** | *all* | ``FLOAT`` ``UNSIGNED`` [10] |
| | +--------------------------+---------+----------------------------------------------------------+
| | | **PostgreSQL** | *all* | ``REAL`` |
| | +--------------------------+ | |
Expand Down
4 changes: 2 additions & 2 deletions src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ public function getFloatDeclarationSQL(array $column): string
/**
* {@inheritDoc}
*/
public function getRealFloatDeclarationSQL(array $column): string
public function getSmallFloatDeclarationSQL(array $column): string
{
return 'FLOAT' . $this->getUnsignedDeclaration($column);
}
Expand Down Expand Up @@ -735,7 +735,7 @@ protected function initializeDoctrineTypeMappings(): void
'datetime' => Types::DATETIME_MUTABLE,
'decimal' => Types::DECIMAL,
'double' => Types::FLOAT,
'float' => Types::REAL,
'float' => Types::SMALLFLOAT,
'int' => Types::INTEGER,
'integer' => Types::INTEGER,
'json' => Types::JSON,
Expand Down
2 changes: 1 addition & 1 deletion src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1878,7 +1878,7 @@ public function getFloatDeclarationSQL(array $column): string
}

/** @param mixed[] $column */
public function getRealFloatDeclarationSQL(array $column): string
public function getSmallFloatDeclarationSQL(array $column): string
{
return 'REAL';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Platforms/DB2Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function initializeDoctrineTypeMappings(): void
'decimal' => Types::DECIMAL,
'double' => Types::FLOAT,
'integer' => Types::INTEGER,
'real' => Types::REAL,
'real' => Types::SMALLFLOAT,
'smallint' => Types::SMALLINT,
'time' => Types::TIME_MUTABLE,
'timestamp' => Types::DATETIME_MUTABLE,
Expand Down
2 changes: 1 addition & 1 deletion src/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ protected function initializeDoctrineTypeMappings(): void
'nvarchar2' => Types::STRING,
'pls_integer' => Types::BOOLEAN,
'raw' => Types::BINARY,
'real' => Types::REAL,
'real' => Types::SMALLFLOAT,
'rowid' => Types::STRING,
'timestamp' => Types::DATETIME_MUTABLE,
'timestamptz' => Types::DATETIMETZ_MUTABLE,
Expand Down
4 changes: 2 additions & 2 deletions src/Platforms/PostgreSQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ protected function initializeDoctrineTypeMappings(): void
'double' => Types::FLOAT,
'double precision' => Types::FLOAT,
'float' => Types::FLOAT,
'float4' => Types::REAL,
'float4' => Types::SMALLFLOAT,
'float8' => Types::FLOAT,
'inet' => Types::STRING,
'int' => Types::INTEGER,
Expand All @@ -717,7 +717,7 @@ protected function initializeDoctrineTypeMappings(): void
'serial' => Types::INTEGER,
'serial4' => Types::INTEGER,
'serial8' => Types::BIGINT,
'real' => Types::REAL,
'real' => Types::SMALLFLOAT,
'smallint' => Types::SMALLINT,
'text' => Types::TEXT,
'time' => Types::TIME_MUTABLE,
Expand Down
2 changes: 1 addition & 1 deletion src/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ protected function initializeDoctrineTypeMappings(): void
'ntext' => Types::TEXT,
'numeric' => Types::DECIMAL,
'nvarchar' => Types::STRING,
'real' => Types::REAL,
'real' => Types::SMALLFLOAT,
'smalldatetime' => Types::DATETIME_MUTABLE,
'smallint' => Types::SMALLINT,
'smallmoney' => Types::INTEGER,
Expand Down
2 changes: 1 addition & 1 deletion src/Platforms/SQLitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ protected function initializeDoctrineTypeMappings(): void
'ntext' => 'string',
'numeric' => 'decimal',
'nvarchar' => 'string',
'real' => 'real',
'real' => 'smallfloat',
'serial' => 'integer',
'smallint' => 'smallint',
'string' => 'string',
Expand Down
4 changes: 2 additions & 2 deletions src/Types/RealFloatType.php → src/Types/SmallFloatType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

use Doctrine\DBAL\Platforms\AbstractPlatform;

final class RealFloatType extends Type
class SmallFloatType extends Type
{
/**
* {@inheritDoc}
*/
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
return $platform->getRealFloatDeclarationSQL($column);
return $platform->getSmallFloatDeclarationSQL($column);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Types/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ abstract class Type
Types::GUID => GuidType::class,
Types::INTEGER => IntegerType::class,
Types::JSON => JsonType::class,
Types::REAL => RealFloatType::class,
Types::SIMPLE_ARRAY => SimpleArrayType::class,
Types::SMALLFLOAT => SmallFloatType::class,
Types::SMALLINT => SmallIntType::class,
Types::STRING => StringType::class,
Types::TEXT => TextType::class,
Expand Down
2 changes: 1 addition & 1 deletion src/Types/Types.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ final class Types
public const GUID = 'guid';
public const INTEGER = 'integer';
public const JSON = 'json';
public const REAL = 'real';
public const SIMPLE_ARRAY = 'simple_array';
public const SMALLFLOAT = 'smallfloat';
public const SMALLINT = 'smallint';
public const STRING = 'string';
public const TEXT = 'text';
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/Driver/PgSQL/ResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ public static function typedValueProvider(): Generator
yield 'boolean true' => ['BOOLEAN', true, Types::BOOLEAN];
yield 'boolean false' => ['BOOLEAN', false, Types::BOOLEAN];
yield 'float' => ['DOUBLE PRECISION', 47.11, Types::FLOAT];
yield 'real' => ['REAL', 47.11, Types::REAL];
yield 'real' => ['REAL', 47.11, Types::SMALLFLOAT];
yield 'negative float with exponent' => ['DOUBLE PRECISION', -8.15e10, Types::FLOAT];
yield 'negative real with exponent' => ['REAL', -8.15e5, Types::REAL];
yield 'negative real with exponent' => ['REAL', -8.15e5, Types::SMALLFLOAT];
yield 'double' => ['DOUBLE PRECISION', 47.11, Types::FLOAT];
yield 'decimal' => ['NUMERIC (6, 2)', '47.11', Types::DECIMAL];
yield 'binary' => ['BYTEA', chr(0x8b), Types::BINARY];
Expand Down
8 changes: 4 additions & 4 deletions tests/Functional/Schema/MySQLSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Doctrine\DBAL\Types\BlobType;
use Doctrine\DBAL\Types\FloatType;
use Doctrine\DBAL\Types\JsonType;
use Doctrine\DBAL\Types\RealFloatType;
use Doctrine\DBAL\Types\SmallFloatType;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;

Expand Down Expand Up @@ -378,16 +378,16 @@ public function testListUnsignedFloatTypeColumns(): void
$table = new Table($tableName);

$table->addColumn('col_unsigned', Types::FLOAT, ['unsigned' => true]);
$table->addColumn('col_real_unsigned', Types::REAL, ['unsigned' => true]);
$table->addColumn('col_smallfloat_unsigned', Types::SMALLFLOAT, ['unsigned' => true]);

$this->dropAndCreateTable($table);

$columns = $this->schemaManager->listTableColumns($tableName);

self::assertInstanceOf(FloatType::class, $columns['col_unsigned']->getType());
self::assertInstanceOf(RealFloatType::class, $columns['col_real_unsigned']->getType());
self::assertInstanceOf(SmallFloatType::class, $columns['col_smallfloat_unsigned']->getType());
self::assertTrue($columns['col_unsigned']->getUnsigned());
self::assertTrue($columns['col_real_unsigned']->getUnsigned());
self::assertTrue($columns['col_smallfloat_unsigned']->getUnsigned());
}

public function testJsonColumnType(): void
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/Schema/PostgreSQLSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public function testListNegativeColumnDefaultValue(): void
$table->addColumn('col_integer', Types::INTEGER, ['default' => -1]);
$table->addColumn('col_bigint', Types::BIGINT, ['default' => -1]);
$table->addColumn('col_float', Types::FLOAT, ['default' => -1.1]);
$table->addColumn('col_real', Types::REAL, ['default' => -1.1]);
$table->addColumn('col_smallfloat', Types::SMALLFLOAT, ['default' => -1.1]);
$table->addColumn('col_decimal', Types::DECIMAL, [
'precision' => 2,
'scale' => 1,
Expand All @@ -431,7 +431,7 @@ public function testListNegativeColumnDefaultValue(): void
self::assertEquals(-1, $columns['col_integer']->getDefault());
self::assertEquals(-1, $columns['col_bigint']->getDefault());
self::assertEquals(-1.1, $columns['col_float']->getDefault());
self::assertEquals(-1.1, $columns['col_real']->getDefault());
self::assertEquals(-1.1, $columns['col_smallfloat']->getDefault());
self::assertEquals(-1.1, $columns['col_decimal']->getDefault());
self::assertEquals('(-1)', $columns['col_string']->getDefault());
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Functional/Schema/SchemaManagerFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use Doctrine\DBAL\Types\DecimalType;
use Doctrine\DBAL\Types\FloatType;
use Doctrine\DBAL\Types\IntegerType;
use Doctrine\DBAL\Types\RealFloatType;
use Doctrine\DBAL\Types\SmallFloatType;
use Doctrine\DBAL\Types\StringType;
use Doctrine\DBAL\Types\TextType;
use Doctrine\DBAL\Types\TimeType;
Expand Down Expand Up @@ -867,16 +867,16 @@ public function testListTableFloatTypeColumns(): void
$table = new Table($tableName);

$table->addColumn('col_float', Types::FLOAT);
$table->addColumn('col_real_float', Types::REAL);
$table->addColumn('col_smallfloat', Types::SMALLFLOAT);

$this->dropAndCreateTable($table);

$columns = $this->schemaManager->listTableColumns($tableName);

self::assertInstanceOf(FloatType::class, $columns['col_float']->getType());
self::assertInstanceOf(RealFloatType::class, $columns['col_real_float']->getType());
self::assertInstanceOf(SmallFloatType::class, $columns['col_smallfloat']->getType());
self::assertFalse($columns['col_float']->getUnsigned());
self::assertFalse($columns['col_real_float']->getUnsigned());
self::assertFalse($columns['col_smallfloat']->getUnsigned());
}

/** @param mixed[] $data */
Expand Down
20 changes: 2 additions & 18 deletions tests/Functional/TypeConversionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function setUp(): void
$table->addColumn('test_text', Types::TEXT, ['notnull' => false]);
$table->addColumn('test_json', Types::JSON, ['notnull' => false]);
$table->addColumn('test_float', Types::FLOAT, ['notnull' => false]);
$table->addColumn('test_real', Types::REAL, ['notnull' => false]);
$table->addColumn('test_smallfloat', Types::SMALLFLOAT, ['notnull' => false]);
$table->addColumn('test_decimal', Types::DECIMAL, ['notnull' => false, 'scale' => 2, 'precision' => 10]);
$table->setPrimaryKey(['id']);

Expand Down Expand Up @@ -92,23 +92,7 @@ public static function floatProvider(): iterable
{
return [
'float' => [Types::FLOAT, 1.5],
];
}

#[DataProvider('realFloatProvider')]
public function testIdempotentConversionToRealFloat(string $type, mixed $originalValue): void
{
$dbValue = $this->processValue($type, $originalValue);

self::assertIsFloat($dbValue);
self::assertEquals($originalValue, $dbValue);
}

/** @return mixed[][] */
public static function realFloatProvider(): iterable
{
return [
'real' => [Types::REAL, 1.5],
'smallfloat' => [Types::SMALLFLOAT, 1.5],
];
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Platforms/AbstractMySQLPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ public static function getGeneratesFloatDeclarationSQL(): iterable
/**
* {@inheritDoc}
*/
public static function getGeneratesRealFloatDeclarationSQL(): iterable
public static function getGeneratesSmallFloatDeclarationSQL(): iterable
{
return [
[[], 'FLOAT'],
Expand Down
8 changes: 4 additions & 4 deletions tests/Platforms/AbstractPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -979,14 +979,14 @@ public static function getGeneratesFloatDeclarationSQL(): iterable
}

/** @param mixed[] $column */
#[DataProvider('getGeneratesRealFloatDeclarationSQL')]
public function testGeneratesRealFloatDeclarationSQL(array $column, string $expectedSql): void
#[DataProvider('getGeneratesSmallFloatDeclarationSQL')]
public function testGeneratesSmallFloatDeclarationSQL(array $column, string $expectedSql): void
{
self::assertSame($expectedSql, $this->platform->getRealFloatDeclarationSQL($column));
self::assertSame($expectedSql, $this->platform->getSmallFloatDeclarationSQL($column));
}

/** @return mixed[][] */
public static function getGeneratesRealFloatDeclarationSQL(): iterable
public static function getGeneratesSmallFloatDeclarationSQL(): iterable
{
return [
[[], 'REAL'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Platforms/OraclePlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public function testInitializesDoctrineTypeMappings(): void
self::assertSame(Types::DATE_MUTABLE, $this->platform->getDoctrineTypeMapping('date'));

self::assertTrue($this->platform->hasDoctrineTypeMappingFor('real'));
self::assertSame(Types::REAL, $this->platform->getDoctrineTypeMapping('real'));
self::assertSame(Types::SMALLFLOAT, $this->platform->getDoctrineTypeMapping('real'));
}

public function testGetVariableLengthStringTypeDeclarationSQLNoLength(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Platforms/SQLServerPlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ public function testInitializesDoctrineTypeMappings(): void
self::assertSame(Types::FLOAT, $this->platform->getDoctrineTypeMapping('float'));

self::assertTrue($this->platform->hasDoctrineTypeMappingFor('real'));
self::assertSame(Types::REAL, $this->platform->getDoctrineTypeMapping('real'));
self::assertSame(Types::SMALLFLOAT, $this->platform->getDoctrineTypeMapping('real'));

self::assertTrue($this->platform->hasDoctrineTypeMappingFor('double'));
self::assertSame(Types::FLOAT, $this->platform->getDoctrineTypeMapping('double'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
namespace Doctrine\DBAL\Tests\Types;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\RealFloatType;
use Doctrine\DBAL\Types\SmallFloatType;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class RealFloatTest extends TestCase
class SmallFloatTest extends TestCase
{
private AbstractPlatform&MockObject $platform;
private RealFloatType $type;
private SmallFloatType $type;

protected function setUp(): void
{
$this->platform = $this->createMock(AbstractPlatform::class);
$this->type = new RealFloatType();
$this->type = new SmallFloatType();
}

public function testFloatConvertsToPHPValue(): void
Expand Down

0 comments on commit d2c45cb

Please sign in to comment.