Completed
Push — develop ( 0c4aa7...b62acb )
by Sergei
55s queued 14s
created

ColumnTest::testVariableLengthBinaryNoLength()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\DBAL\Functional\Platform;
6
7
use Doctrine\DBAL\ParameterType;
8
use Doctrine\DBAL\Schema\Table;
9
use Doctrine\DBAL\Types\Type;
10
use Doctrine\DBAL\Types\Types;
11
use Doctrine\Tests\DbalFunctionalTestCase;
12
use function sprintf;
13
14
abstract class ColumnTest extends DbalFunctionalTestCase
15
{
16
    public function testVariableLengthStringNoLength() : void
17
    {
18
        $this->assertColumn(Types::STRING, [], 'Test', ParameterType::STRING);
19
    }
20
21
    public function testVariableLengthStringWithLength() : void
22
    {
23
        $this->assertColumn(Types::STRING, ['length' => 8], 'Doctrine', ParameterType::STRING);
24
    }
25
26
    public function testFixedLengthStringNoLength() : void
27
    {
28
        $this->assertColumn(Types::STRING, ['fixed' => true], 'Z', ParameterType::STRING);
29
    }
30
31
    public function testFixedLengthStringWithLength() : void
32
    {
33
        $this->assertColumn(Types::STRING, [
34
            'fixed' => true,
35
            'length' => 8,
36
        ], 'Doctrine', ParameterType::STRING);
37
    }
38
39
    public function testVariableLengthBinaryNoLength() : void
40
    {
41
        $this->assertColumn(Types::BINARY, [], "\x00\x01\x02\x03", ParameterType::BINARY);
42
    }
43
44
    public function testVariableLengthBinaryWithLength() : void
45
    {
46
        $this->assertColumn(Types::BINARY, ['length' => 8], "\xCE\xC6\x6B\xDD\x9F\xD8\x07\xB4", ParameterType::BINARY);
47
    }
48
49
    public function testFixedLengthBinaryNoLength() : void
50
    {
51
        $this->assertColumn(Types::BINARY, ['fixed' => true], "\xFF", ParameterType::BINARY);
52
    }
53
54
    public function testFixedLengthBinaryWithLength() : void
55
    {
56
        $this->assertColumn(Types::BINARY, [
57
            'fixed' => true,
58
            'length' => 8,
59
        ], "\xA0\x0A\x7B\x0E\xA4\x60\x78\xD8", ParameterType::BINARY);
60
    }
61
62
    protected function requirePlatform(string $class) : void
63
    {
64
        if ($this->connection->getDatabasePlatform() instanceof $class) {
65
            return;
66
        }
67
68
        self::markTestSkipped(sprintf('The test requires %s', $class));
69
    }
70
71
    /**
72
     * @param array<string, mixed> $column
73
     */
74
    protected function assertColumn(string $type, array $column, string $value, int $bindType) : void
75
    {
76
        $table = new Table('column_test');
77
        $table->addColumn('val', $type, $column);
78
79
        $sm = $this->connection->getSchemaManager();
80
        $sm->dropAndCreateTable($table);
81
82
        self::assertSame(1, $this->connection->insert('column_test', ['val' => $value], [$bindType]));
83
84
        self::assertSame($value, Type::getType($type)->convertToPHPValue(
85
            $this->connection->fetchColumn('SELECT val FROM column_test'),
86
            $this->connection->getDatabasePlatform()
87
        ));
88
    }
89
}
90