Skip to content

Commit

Permalink
refactor float type column tests
Browse files Browse the repository at this point in the history
  • Loading branch information
berkut1 committed Jul 18, 2024
1 parent cb740c3 commit ac30dbf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 29 deletions.
32 changes: 8 additions & 24 deletions tests/Functional/Schema/MySQLSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
use Doctrine\DBAL\Tests\Functional\Schema\MySQL\PointType;
use Doctrine\DBAL\Tests\TestUtil;
use Doctrine\DBAL\Types\BlobType;
use Doctrine\DBAL\Types\FloatType;
use Doctrine\DBAL\Types\JsonType;
use Doctrine\DBAL\Types\RealFloatType;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;

Expand Down Expand Up @@ -370,40 +372,22 @@ public function testListDecimalTypeColumns(): void
self::assertTrue($columns['col_unsigned']->getUnsigned());
}

public function testListFloatTypeColumns(): void
public function testListUnsignedFloatTypeColumns(): void
{
$tableName = 'test_list_float_columns';
$tableName = 'test_unsigned_float_columns';
$table = new Table($tableName);

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

$this->dropAndCreateTable($table);

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

self::assertArrayHasKey('col', $columns);
self::assertArrayHasKey('col_unsigned', $columns);
self::assertFalse($columns['col']->getUnsigned());
self::assertTrue($columns['col_unsigned']->getUnsigned());
}

public function testListRealFloatTypeColumns(): void
{
$tableName = 'test_list_real_columns';
$table = new Table($tableName);

$table->addColumn('col', Types::REAL);
$table->addColumn('col_unsigned', Types::REAL, ['unsigned' => true]);

$this->dropAndCreateTable($table);

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

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

public function testJsonColumnType(): void
Expand Down
8 changes: 6 additions & 2 deletions tests/Functional/Schema/SchemaManagerFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -863,16 +863,20 @@ public function testListTableWithBlob(): void

public function testListTableFloatTypeColumns(): void
{
$table = new Table('test_float_table');
$tableName = 'test_float_columns';
$table = new Table($tableName);

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

$this->dropAndCreateTable($table);

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

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

/** @param mixed[] $data */
Expand Down
4 changes: 1 addition & 3 deletions tests/Types/RealFloatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ protected function setUp(): void

public function testFloatConvertsToPHPValue(): void
{
$result = $this->type->convertToPHPValue('5.5', $this->platform);
self::assertIsFloat($result);
self::assertEquals(5.5, $result);
self::assertEquals(5.5, $this->type->convertToPHPValue('5.5', $this->platform));
}

public function testFloatNullConvertsToPHPValue(): void
Expand Down

0 comments on commit ac30dbf

Please sign in to comment.