|
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.', |
|
|
|
|
|
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
fclose($fp); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|