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

ListTest::testList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 16
nc 1
nop 0
dl 0
loc 22
rs 9.7333
c 0
b 0
f 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\DatabaseManager;
16
use Spiral\Tests\Framework\ConsoleTest;
17
18
class ListTest extends ConsoleTest
19
{
20
    public function testList(): void
21
    {
22
        /** @var Database $db */
23
        $db = $this->app->get(Database::class);
24
25
        $tableB = $db->table('outer')->getSchema();
26
        $tableB->primary('id');
27
        $tableB->save();
28
29
        $table = $db->table('sample')->getSchema();
30
        $table->primary('primary_id');
31
        $table->string('some_string');
32
        $table->index(['some_string'])->setName('custom_index');
33
        $table->integer('b_id');
34
        $table->foreignKey(['b_id'])->references('outer', ['id']);
35
        $table->save();
36
37
        $output = $this->runCommand('db:list');
38
        $this->assertStringContainsString('SQLite', $output);
39
        $this->assertStringContainsString(':memory:', $output);
40
        $this->assertStringContainsString('sample', $output);
41
        $this->assertStringContainsString('outer', $output);
42
    }
43
44
45
    public function testBrokenList(): void
46
    {
47
        /** @var DatabaseManager $dm */
48
        $dm = $this->app->get(DatabaseManager::class);
49
50
        $dm->addDatabase(new Database(
51
            'other',
52
            '',
53
            $dm->driver('other')
54
        ));
55
56
        $output = $this->runCommand('db:list', ['db' => 'other']);
57
        $this->assertStringContainsString('Postgres', $output);
58
        $this->assertStringContainsString('database', $output);
59
        $this->assertStringContainsString('other', $output);
60
    }
61
}
62