Failed Conditions
Pull Request — master (#3645)
by Matthew
03:37
created

BinaryTest::selectDouble()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 9
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
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 is_resource;
11
use function random_bytes;
12
use function str_replace;
13
use function stream_get_contents;
14
use function microtime;
15
16
class BinaryTest extends DbalFunctionalTestCase
17
{
18
    protected function setUp() : void
19
    {
20
        parent::setUp();
21
22
        $table = new Table('double_table');
23
        $table->addColumn('id', 'integer');
24
        $table->addColumn('val', 'float');
25
        $table->setPrimaryKey(['id']);
26
27
        $sm = $this->connection->getSchemaManager();
28
        $sm->dropAndCreateTable($table);
29
    }
30
31
    public function testInsertAndSelect() : void
32
    {
33
        $value1 = 1.0;
34
        $value2 = 77.99999999999;
35
        $value3 = microtime(true);
36
37
        $this->insert(1, $value1);
38
        $this->insert(2, $value2);
39
        $this->insert(3, $value3);
40
41
        $this->assertSame($value1, $this->select(1));
42
        $this->assertSame($value2, $this->select(2));
43
        $this->assertSame($value3, $this->select(3));
44
        $this->assertSame(1, $this->selectDouble($value1));
0 ignored issues
show
Bug introduced by
The method selectDouble() does not exist on Doctrine\Tests\DBAL\Functional\Types\BinaryTest. Did you maybe mean select()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
        $this->assertSame(1, $this->/** @scrutinizer ignore-call */ selectDouble($value1));

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.

Loading history...
45
        $this->assertSame(2, $this->selectDouble($value2));
46
        $this->assertSame(3, $this->selectDouble($value3));
47
    }
48
49
    private function insert(int $id, float $value) : void
50
    {
51
        $result = $this->connection->insert('double_table', [
52
            'id'  => $id,
53
            'val' => $value,
54
        ], [
55
            ParameterType::INTEGER,
56
            ParameterType::DOUBLE,
57
        ]);
58
59
        self::assertSame(1, $result);
60
    }
61
62
    /**
63
     * @return mixed
64
     */
65
    private function select(int $id)
66
    {
67
        $value = $this->connection->fetchColumn(
68
            'SELECT val FROM double_table WHERE id = ?',
69
            [$id],
70
            0,
71
            [ParameterType::INTEGER]
72
        );
73
        return $value;
74
    }
75
76
    /**
77
     * @return mixed
78
     */
79
    private function selectDouble(float $value)
80
    {
81
        $value = $this->connection->fetchColumn(
82
            'SELECT id FROM double_table WHERE val = ?',
83
            [$value],
84
            0,
85
            [ParameterType::DOUBLE]
86
        );
87
        return $value;
88
    }
89
}
90