Completed
Push — master ( 17598f...abee1f )
by Kirill
13s queued 11s
created

DescribeTest::testDescribeExisted()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 28
rs 9.6
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Framework\Database;
13
14
use Spiral\Database\Database;
15
use Spiral\Database\Exception\DBALException;
16
use Spiral\Tests\Framework\ConsoleTest;
17
18
class DescribeTest extends ConsoleTest
19
{
20
    public function testDescribeWrongDB(): void
21
    {
22
        $this->expectException(DBALException::class);
23
24
        $this->runCommand('db:table', [
25
            '--database' => 'missing',
26
            'table'      => 'missing'
27
        ]);
28
    }
29
30
    public function testDescribeWrongTable(): void
31
    {
32
        $this->expectException(DBALException::class);
33
34
        $this->runCommand('db:table', [
35
            '--database' => 'runtime',
36
            'table'      => 'missing'
37
        ]);
38
    }
39
40
    public function testDescribeExisted(): void
41
    {
42
        /** @var Database $db */
43
        $db = $this->app->get(Database::class);
44
45
        $table = $db->table('sample1')->getSchema();
46
        $table->primary('primary_id');
47
        $table->string('some_string');
48
        $table->index(['some_string'])->setName('custom_index_1');
49
        $table->save();
50
51
        $table = $db->table('sample')->getSchema();
52
        $table->primary('primary_id');
53
        $table->integer('primary1_id');
54
        $table->foreignKey(['primary1_id'])->references('sample1', ['primary_id']);
55
        $table->integer('some_int');
56
        $table->index(['some_int'])->setName('custom_index');
57
        $table->save();
58
59
        $output = $this->runCommand('db:table', [
60
            '--database' => 'default',
61
            'table'      => 'sample'
62
        ]);
63
64
        $this->assertStringContainsString('primary_id', $output);
65
        $this->assertStringContainsString('some_int', $output);
66
        $this->assertStringContainsString('custom_index', $output);
67
        $this->assertStringContainsString('sample1', $output);
68
    }
69
}
70