Skip to content

Commit

Permalink
Enhance the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
imanghafoori1 committed Sep 4, 2023
1 parent c178cda commit f68bb38
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 161 deletions.
3 changes: 2 additions & 1 deletion src/FakeConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Closure;
use Illuminate\Database\Connection;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Database\Schema\MySqlBuilder;
use Illuminate\Support\Arr;

class FakeConnection extends Connection implements ConnectionInterface
Expand All @@ -27,7 +28,7 @@ public function transaction(Closure $callback, $attempts = 1)

public function getSchemaBuilder()
{
return new FakeSchemaBuilder($this);
return new MySqlBuilder($this);
}

public function getSchemaGrammar()
Expand Down
25 changes: 15 additions & 10 deletions src/FakeDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function createTable($args)

public static function table($table)
{
return new class ($table){
return new class ($table) {
private $table;

public function __construct($table)
Expand All @@ -74,17 +74,22 @@ public function addRow($row)
{
FakeDB::addRow($this->table, $row);
}
};
}

public static function getChangedModel(string $action, $index, $model)
{
return FakeDB::$changedModels[$model][$action][$index] ?? null;
}
public function allRows()
{
$rows = [];
foreach((FakeDB::$fakeRows[$this->table] ?? []) as $i => $row) {
$rows[$i] = $row[$this->table];
}

public static function setChangedModel(string $action, $model)
{
FakeDB::$changedModels[get_class($model)][$action][] = $model;
return $rows;
}

public function count()
{
return count(FakeDB::$fakeRows[$this->table] ?? []);
}
};
}

public static function truncate($query = null)
Expand Down
44 changes: 0 additions & 44 deletions src/FakeEloquentBuilder.php

This file was deleted.

12 changes: 5 additions & 7 deletions src/FakeGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,11 @@ public function compileRandom($seed)

public function compileTruncate(Builder $query)
{
return
$this->stringy([
'type' => 'truncate',
'builder' => $query,
'sql' => parent::compileTruncate($query),
])
;
return $this->stringy([
'type' => 'truncate',
'builder' => $query,
'sql' => parent::compileTruncate($query),
]);
}

private function stringy($query)
Expand Down
10 changes: 0 additions & 10 deletions src/FakeSchemaBuilder.php

This file was deleted.

89 changes: 0 additions & 89 deletions src/MockableModel.php

This file was deleted.

0 comments on commit f68bb38

Please sign in to comment.