ViewAssertions::seeView()   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 ViewAssertions
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
    abstract public static function assertFalse($condition, string $message = ''): void;
19
20
    protected function assertSameView(string $expectedDef, string $view): void
21
    {
22
        $definition = $this->getViewDefinition($view);
23
24
        $this->assertSame($expectedDef, $definition);
25
    }
26
27
    protected function seeView(string $view): void
28
    {
29
        $this->assertTrue(Schema::hasView($view));
0 ignored issues
show
Bug introduced by
The method hasView() 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

29
        $this->assertTrue(Schema::/** @scrutinizer ignore-call */ hasView($view));

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...
30
    }
31
32
    protected function notSeeView(string $view): void
33
    {
34
        $this->assertFalse(Schema::hasView($view));
35
    }
36
37
    private function getViewDefinition(string $view): string
38
    {
39
        return preg_replace(
40
            "#\s+#",
41
            ' ',
42
            strtolower(trim(str_replace("\n", ' ', Schema::getViewDefinition($view))))
0 ignored issues
show
Bug introduced by
The method getViewDefinition() 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

42
            strtolower(trim(str_replace("\n", ' ', Schema::/** @scrutinizer ignore-call */ getViewDefinition($view))))

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...
43
        );
44
    }
45
}
46