Passed
Pull Request — master (#380)
by Wilmer
02:44
created

AbstractSchemaTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
dl 0
loc 48
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetDefaultSchema() 0 7 1
A testColumnSchemaDbTypecastWithEmptyCharType() 0 6 1
A testGetPDOType() 0 27 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Tests;
6
7
use PDO;
8
use PHPUnit\Framework\TestCase;
9
use Yiisoft\Db\Schema\ColumnSchema;
10
use Yiisoft\Db\Schema\Schema;
11
use Yiisoft\Db\Tests\Support\TestTrait;
12
13
use function fclose;
14
use function fopen;
15
use function print_r;
16
17
abstract class AbstractSchemaTest extends TestCase
18
{
19
    use TestTrait;
20
21
    public function testColumnSchemaDbTypecastWithEmptyCharType(): void
22
    {
23
        $columnSchema = new ColumnSchema();
24
        $columnSchema->setType(Schema::TYPE_CHAR);
25
26
        $this->assertSame('', $columnSchema->dbTypecast(''));
27
    }
28
29
    public function testGetDefaultSchema(): void
30
    {
31
        $db = $this->getConnection();
32
33
        $schema = $db->getSchema();
34
35
        $this->assertNull($schema->getDefaultSchema());
36
    }
37
38
    public function testGetPDOType(): void
39
    {
40
        $values = [
41
            [null, PDO::PARAM_NULL],
42
            ['', PDO::PARAM_STR],
43
            ['hello', PDO::PARAM_STR],
44
            [0, PDO::PARAM_INT],
45
            [1, PDO::PARAM_INT],
46
            [1337, PDO::PARAM_INT],
47
            [true, PDO::PARAM_BOOL],
48
            [false, PDO::PARAM_BOOL],
49
            [$fp = fopen(__FILE__, 'rb'), PDO::PARAM_LOB],
50
        ];
51
52
        $db = $this->getConnection();
53
54
        $schema = $db->getSchema();
55
56
        foreach ($values as $value) {
57
            $this->assertSame(
58
                $value[1],
59
                $schema->getPdoType($value[0]),
60
                'type for value ' . print_r($value[0], true) . ' does not match.',
0 ignored issues
show
Bug introduced by
Are you sure print_r($value[0], true) of type string|true can be used in concatenation? ( Ignorable by Annotation )

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

60
                'type for value ' . /** @scrutinizer ignore-type */ print_r($value[0], true) . ' does not match.',
Loading history...
61
            );
62
        }
63
64
        fclose($fp);
65
    }
66
}
67