Skip to content

Commit 878f955

Browse files
committed
adjust test for sqlite issue
1 parent dbb41c5 commit 878f955

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

tests/TypecastingTest.php

+10-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Atk4\Data\Model;
99
use Atk4\Data\Schema\TestCase;
1010
use Doctrine\DBAL\Platforms\OraclePlatform;
11+
use Doctrine\DBAL\Platforms\SqlitePlatform;
1112

1213
class TypecastingTest extends TestCase
1314
{
@@ -110,10 +111,16 @@ public function testType(): void
110111

111112
$this->assertEquals($first, $duplicate);
112113

113-
$m->load(2)->set('float', 8.202343767574731)->save();
114+
$m->load(2)->set('float', 8.20234376757474)->save();
114115
// pack is needed to compare float numbers exactly, see https://github.com/sebastianbergmann/phpunit/issues/4966
115-
// remove bin2hex/pack once fixed in phpunit officially
116-
$this->assertSame(bin2hex(pack('e', 8.202343767574731)), bin2hex(pack('e', $m->load(2)->get('float'))));
116+
// remove bin2hex/pack once phpunit is fixed officially
117+
$this->assertSame(bin2hex(pack('e', 8.20234376757474)), bin2hex(pack('e', $m->load(2)->get('float'))));
118+
$m->load(2)->set('float', 8.202343767574732)->save();
119+
// pdo_sqlite in truncating float when converted to string, see https://github.com/php/php-src/issues/8510
120+
// fixed since PHP 8.1, but if converted in SQL to string explicitly, the result is still wrong
121+
if (!$this->getDatabasePlatform() instanceof SqlitePlatform || \PHP_VERSION_ID >= 81000) {
122+
$this->assertSame(bin2hex(pack('e', 8.202343767574732)), bin2hex(pack('e', $m->load(2)->get('float'))));
123+
}
117124
}
118125

119126
public function testEmptyValues(): void

0 commit comments

Comments
 (0)