TableAssertions::getTableDefinition()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Umbrellio\Postgres\Helpers;
6
7
use Illuminate\Support\Facades\Schema;
8
9
/**
10
 * @codeCoverageIgnore
11
 */
12
trait TableAssertions
13
{
14
    abstract public static function assertSame($expected, $actual, string $message = ''): void;
15
16
    abstract public static function assertTrue($condition, string $message = ''): void;
17
18
    protected function assertCompareTables(string $sourceTable, string $destinationTable): void
19
    {
20
        $this->assertSame($this->getTableDefinition($sourceTable), $this->getTableDefinition($destinationTable));
21
    }
22
23
    protected function assertSameTable(array $expectedDef, string $table): void
24
    {
25
        $definition = $this->getTableDefinition($table);
26
27
        $this->assertSame($expectedDef, $definition);
28
    }
29
30
    protected function seeTable(string $table): void
31
    {
32
        $this->assertTrue(Schema::hasTable($table));
0 ignored issues
show
Bug introduced by
The method hasTable() does not exist on Illuminate\Support\Facades\Schema. ( Ignorable by Annotation )

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

32
        $this->assertTrue(Schema::/** @scrutinizer ignore-call */ hasTable($table));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
    }
34
35
    private function getTableDefinition(string $table): array
36
    {
37
        return Schema::getColumnListing($table);
0 ignored issues
show
Bug introduced by
The method getColumnListing() does not exist on Illuminate\Support\Facades\Schema. ( Ignorable by Annotation )

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

37
        return Schema::/** @scrutinizer ignore-call */ getColumnListing($table);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
    }
39
}
40