cerbero90 /
octane-testbench
| 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
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
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
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
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
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 |