Completed
Pull Request — master (#3599)
by Sergei
60:59
created

ColumnTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 19
dl 0
loc 57
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A requirePlatform() 0 7 2
A testFixedLengthStringWithLength() 0 6 1
A stringProvider() 0 5 1
A testVariableLengthStringWithLength() 0 3 1
A assertColumn() 0 13 1
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
    /**
17
     * @dataProvider stringProvider
18
     */
19
    public function testVariableLengthStringWithLength(string $value) : void
20
    {
21
        $this->assertColumn(Types::STRING, ['length' => 8], $value, ParameterType::STRING);
22
    }
23
24
    /**
25
     * @dataProvider stringProvider
26
     */
27
    public function testFixedLengthStringWithLength(string $value) : void
28
    {
29
        $this->assertColumn(Types::STRING, [
30
            'fixed' => true,
31
            'length' => 8,
32
        ], $value, ParameterType::STRING);
33
    }
34
35
    /**
36
     * @return iterable<string, array<int, mixed>>
37
     */
38
    public static function stringProvider() : iterable
39
    {
40
        return [
41
            'ansi' => ['Doctrine'],
42
            'unicode' => ['Доктрина'],
43
        ];
44
    }
45
46
    protected function requirePlatform(string $class) : void
47
    {
48
        if ($this->connection->getDatabasePlatform() instanceof $class) {
49
            return;
50
        }
51
52
        self::markTestSkipped(sprintf('The test requires %s', $class));
53
    }
54
55
    /**
56
     * @param array<string, mixed> $column
57
     */
58
    protected function assertColumn(string $type, array $column, string $value, int $bindType) : void
59
    {
60
        $table = new Table('column_test');
61
        $table->addColumn('val', $type, $column);
62
63
        $sm = $this->connection->getSchemaManager();
64
        $sm->dropAndCreateTable($table);
65
66
        self::assertSame(1, $this->connection->insert('column_test', ['val' => $value], [$bindType]));
67
68
        self::assertSame($value, Type::getType($type)->convertToPHPValue(
69
            $this->connection->fetchColumn('SELECT val FROM column_test'),
70
            $this->connection->getDatabasePlatform()
71
        ));
72
    }
73
}
74