forked from doctrine/dbal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address issue doctrine#3631 by adding support for a float datatype
Also try to add a new functional test per request.
- Loading branch information
Showing
5 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\DBAL\Functional\Types; | ||
|
||
use Doctrine\DBAL\ParameterType; | ||
use Doctrine\DBAL\Schema\Table; | ||
use Doctrine\Tests\DbalFunctionalTestCase; | ||
use function microtime; | ||
|
||
class DoubleTest extends DbalFunctionalTestCase | ||
{ | ||
protected function setUp() : void | ||
{ | ||
parent::setUp(); | ||
|
||
$table = new Table('double_table'); | ||
$table->addColumn('id', 'integer'); | ||
$table->addColumn('val', 'float'); | ||
$table->setPrimaryKey(['id']); | ||
|
||
$sm = $this->connection->getSchemaManager(); | ||
$sm->dropAndCreateTable($table); | ||
} | ||
|
||
public function testInsertAndSelect() : void | ||
{ | ||
$value1 = 1.0; | ||
$value2 = 77.99999999999; | ||
$value3 = microtime(true); | ||
|
||
$this->insert(1, $value1); | ||
$this->insert(2, $value2); | ||
$this->insert(3, $value3); | ||
|
||
$this->assertSame($value1, $this->select(1)); | ||
$this->assertSame($value2, $this->select(2)); | ||
$this->assertSame($value3, $this->select(3)); | ||
$this->assertSame(1, $this->selectDouble($value1)); | ||
$this->assertSame(2, $this->selectDouble($value2)); | ||
$this->assertSame(3, $this->selectDouble($value3)); | ||
} | ||
|
||
private function insert(int $id, float $value) : void | ||
{ | ||
$result = $this->connection->insert('double_table', [ | ||
'id' => $id, | ||
'val' => $value, | ||
], [ | ||
ParameterType::INTEGER, | ||
ParameterType::DOUBLE, | ||
]); | ||
|
||
self::assertSame(1, $result); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
private function select(int $id) | ||
{ | ||
return $this->connection->fetchColumn( | ||
'SELECT val FROM double_table WHERE id = ?', | ||
[$id], | ||
0, | ||
[ParameterType::INTEGER] | ||
); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
private function selectDouble(float $value) | ||
{ | ||
return $this->connection->fetchColumn( | ||
'SELECT id FROM double_table WHERE val = ?', | ||
[$value], | ||
0, | ||
[ParameterType::DOUBLE] | ||
); | ||
} | ||
} |