InteractsWithTables::assertOctaneTableCount()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Cerbero\OctaneTestbench\Concerns;
4
5
use Laravel\Octane\Facades\Octane;
6
7
/**
8
 * The trait to interact with Octane tables.
9
 *
10
 */
11
trait InteractsWithTables
12
{
13
    /**
14
     * Assert that the given Laravel Octane table has the provided row
15
     *
16
     * @param string $table
17
     * @param string $row
18
     * @param mixed|null $value
19
     * @return static
20
     */
21 1
    public function assertOctaneTableHas(string $table, string $row, mixed $value = null): static
22
    {
23 1
        if ($value === null) {
24 1
            $actual = Octane::table($table)->exist($row);
25 1
            $this->assertTrue($actual, "The row [$row] is not present in the Octane table [$table]");
0 ignored issues
show
Bug introduced by
It seems like assertTrue() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

25
            $this->/** @scrutinizer ignore-call */ 
26
                   assertTrue($actual, "The row [$row] is not present in the Octane table [$table]");
Loading history...
26
        } else {
27 1
            [$row, $column] = explode('.', $row);
28 1
            $actual = Octane::table($table)->get($row, $column);
29 1
            $this->assertSame($value, $actual, "Expected value [$value] in column [$column], got [$actual] instead");
0 ignored issues
show
Bug introduced by
It seems like assertSame() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( 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->/** @scrutinizer ignore-call */ 
30
                   assertSame($value, $actual, "Expected value [$value] in column [$column], got [$actual] instead");
Loading history...
30
        }
31
32 1
        return $this;
33
    }
34
35
    /**
36
     * Assert that the given Laravel Octane table doesn't have the provided row
37
     *
38
     * @param string $table
39
     * @param string $row
40
     * @return static
41
     */
42 1
    public function assertOctaneTableMissing(string $table, string $row): static
43
    {
44 1
        $actual = Octane::table($table)->exist($row);
45
46 1
        $this->assertFalse($actual, "The row [$row] is present in the Octane table [$table]");
0 ignored issues
show
Bug introduced by
It seems like assertFalse() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

46
        $this->/** @scrutinizer ignore-call */ 
47
               assertFalse($actual, "The row [$row] is present in the Octane table [$table]");
Loading history...
47
48 1
        return $this;
49
    }
50
51
    /**
52
     * Assert that the given Laravel Octane table contains the provided number of rows
53
     *
54
     * @param string $table
55
     * @param int $count
56
     * @return static
57
     */
58 1
    public function assertOctaneTableCount(string $table, int $count): static
59
    {
60 1
        $actual = Octane::table($table)->count();
61
62 1
        $this->assertSame($count, $actual, "The rows in the Octane table [$table] are $actual");
63
64 1
        return $this;
65
    }
66
}
67