1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\DBAL\Functional\Types; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\ParameterType; |
8
|
|
|
use Doctrine\DBAL\Schema\Table; |
9
|
|
|
use Doctrine\Tests\DbalFunctionalTestCase; |
10
|
|
|
use function microtime; |
11
|
|
|
|
12
|
|
|
class BinaryTest extends DbalFunctionalTestCase |
13
|
|
|
{ |
14
|
|
|
protected function setUp() : void |
15
|
|
|
{ |
16
|
|
|
parent::setUp(); |
17
|
|
|
|
18
|
|
|
$table = new Table('double_table'); |
19
|
|
|
$table->addColumn('id', 'integer'); |
20
|
|
|
$table->addColumn('val', 'float'); |
21
|
|
|
$table->setPrimaryKey(['id']); |
22
|
|
|
|
23
|
|
|
$sm = $this->connection->getSchemaManager(); |
24
|
|
|
$sm->dropAndCreateTable($table); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testInsertAndSelect() : void |
28
|
|
|
{ |
29
|
|
|
$value1 = 1.0; |
30
|
|
|
$value2 = 77.99999999999; |
31
|
|
|
$value3 = microtime(true); |
32
|
|
|
|
33
|
|
|
$this->insert(1, $value1); |
34
|
|
|
$this->insert(2, $value2); |
35
|
|
|
$this->insert(3, $value3); |
36
|
|
|
|
37
|
|
|
$this->assertSame($value1, $this->select(1)); |
38
|
|
|
$this->assertSame($value2, $this->select(2)); |
39
|
|
|
$this->assertSame($value3, $this->select(3)); |
40
|
|
|
$this->assertSame(1, $this->selectDouble($value1)); |
|
|
|
|
41
|
|
|
$this->assertSame(2, $this->selectDouble($value2)); |
42
|
|
|
$this->assertSame(3, $this->selectDouble($value3)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
private function insert(int $id, float $value) : void |
46
|
|
|
{ |
47
|
|
|
$result = $this->connection->insert('double_table', [ |
48
|
|
|
'id' => $id, |
49
|
|
|
'val' => $value, |
50
|
|
|
], [ |
51
|
|
|
ParameterType::INTEGER, |
52
|
|
|
ParameterType::DOUBLE, |
53
|
|
|
]); |
54
|
|
|
|
55
|
|
|
self::assertSame(1, $result); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return mixed |
60
|
|
|
*/ |
61
|
|
|
private function select(int $id) |
62
|
|
|
{ |
63
|
|
|
return $this->connection->fetchColumn( |
64
|
|
|
'SELECT val FROM double_table WHERE id = ?', |
65
|
|
|
[$id], |
66
|
|
|
0, |
67
|
|
|
[ParameterType::INTEGER] |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return mixed |
73
|
|
|
*/ |
74
|
|
|
private function selectDouble(float $value) |
75
|
|
|
{ |
76
|
|
|
return $this->connection->fetchColumn( |
77
|
|
|
'SELECT id FROM double_table WHERE val = ?', |
78
|
|
|
[$value], |
79
|
|
|
0, |
80
|
|
|
[ParameterType::DOUBLE] |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.