-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address issue #3631 by adding support for a float datatype
Also try to add a new functional test per request. In addition: - Fix IBM DB2 test issue due to untrusted update - Try to fix flakey Mysql tests
- Loading branch information
Showing
14 changed files
with
182 additions
and
2 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
10 changes: 10 additions & 0 deletions
10
lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnectionException.php
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,10 @@ | ||
<?php | ||
|
||
namespace Doctrine\DBAL\Driver\Mysqli; | ||
|
||
/** | ||
* Exception thrown in case the mysqli driver errors while connecting. | ||
*/ | ||
class MysqliConnectionException extends MysqliException | ||
{ | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace Doctrine\DBAL\Driver; | ||
|
||
/** | ||
* PDOConnectionException is used to distinguish connection failures from regular PDOExceptions. | ||
*/ | ||
class PDOConnectionException extends PDOException | ||
{ | ||
} |
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
112 changes: 112 additions & 0 deletions
112
tests/Doctrine/Tests/DBAL/Functional/Types/DoubleTest.php
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,112 @@ | ||
<?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 abs; | ||
use function floatval; | ||
use function is_int; | ||
use function is_string; | ||
use function localeconv; | ||
use function microtime; | ||
use function str_replace; | ||
|
||
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.1; | ||
$value2 = 77.99999999999; | ||
$value3 = microtime(true); | ||
$localeInfo = localeconv(); | ||
|
||
$this->insert(1, $value1); | ||
$this->insert(2, $value2); | ||
$this->insert(3, $value3); | ||
|
||
$result1 = $this->select(1); | ||
$result2 = $this->select(2); | ||
$result3 = $this->select(3); | ||
|
||
if (is_string($result1)) { | ||
$result1 = str_replace('.', $localeInfo['decimal_point'] ?? '.', $result1); | ||
$result2 = str_replace('.', $localeInfo['decimal_point'] ?? '.', $result2); | ||
$result3 = str_replace('.', $localeInfo['decimal_point'] ?? '.', $result3); | ||
$result1 = floatval($result1); | ||
$result2 = floatval($result2); | ||
$result3 = floatval($result3); | ||
} | ||
|
||
$diff1 = abs($result1 - $value1); | ||
$diff2 = abs($result2 - $value2); | ||
$diff3 = abs($result3 - $value3); | ||
|
||
$this->assertLessThanOrEqual(0.0001, $diff1); | ||
$this->assertLessThanOrEqual(0.0001, $diff2); | ||
$this->assertLessThanOrEqual(0.0001, $diff3); | ||
|
||
$result1 = $this->selectDouble($value1); | ||
$result2 = $this->selectDouble($value2); | ||
$result3 = $this->selectDouble($value3); | ||
|
||
$this->assertSame(is_int($result1) ? 1 : '1', $result1); | ||
$this->assertSame(is_int($result2) ? 2 : '2', $result2); | ||
$this->assertSame(is_int($result3) ? 3 : '3', $result3); | ||
} | ||
|
||
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] | ||
); | ||
} | ||
} |
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,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ex | ||
|
||
echo "Installing language pack..." | ||
|
||
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 6B05F25D762E3157 | ||
sudo apt -y -q update | ||
sudo apt install language-pack-de |
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,3 @@ | ||
<?php | ||
|
||
setlocale(LC_ALL, 'de_DE.UTF-8', 'de_DE', 'de', 'ge'); |