Passed
Pull Request — master (#277)
by Kirill
03:11
created

DescribeTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 29
c 0
b 0
f 0
dl 0
loc 50
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testDescribeWrongTable() 0 7 1
A testDescribeExisted() 0 28 1
A testDescribeWrongDB() 0 7 1
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