Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
],
"require": {
"php" : "^7.2|^8.0",
"illuminate/database": "5.*|6.*|7.*|8.*|9.*|10.*|11.*",
"illuminate/events": "5.*|6.*|7.*|8.*|9.*|10.*|11.*"
"illuminate/database": "5.*|6.*|7.*|8.*|9.*|10.*|11.*|12.*",
"illuminate/events": "5.*|6.*|7.*|8.*|9.*|10.*|11.*|12.*"
},
"require-dev": {
"phpunit/phpunit": "^7.5.20|^8.5.28|^9.5",
Expand Down
15 changes: 8 additions & 7 deletions src/FakeConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class FakeConnection extends Connection implements ConnectionInterface
public static function resolve($connection = null, $db = '', $prefix = '', $config = ['name' => 'arrayDB'])
{
$fakeConnection = new FakeConnection(function () {
return new FakePDO;
return new FakePDO();
}, $db, $prefix, $config);

$fakeConnection->setQueryGrammar(new FakeGrammar);
$fakeConnection->setQueryGrammar(new FakeGrammar($fakeConnection));

return $fakeConnection;
}

Expand All @@ -39,26 +39,27 @@ public function getSchemaGrammar()
public function query()
{
return new FakeQueryBuilder(
$this, $this->getQueryGrammar(), $this->getPostProcessor()
$this,
$this->getQueryGrammar(),
$this->getPostProcessor()
);
}

protected function getDefaultQueryGrammar()
{
return new FakeGrammar;
return new FakeGrammar($this);
}

public function statement($query, $bindings = [])
{
if (is_object($query)) {
$query = $query->data;
} else {

}
if (FakeSchemaGrammar::$query && is_string($query)) {
$payload = array_shift(FakeSchemaGrammar::$query);
$query = [
'sql' => $query,
'sql' => $query,
'args' => $payload['args'] ?? null,
'type' => $payload['type'],
];
Expand Down
26 changes: 13 additions & 13 deletions src/FakeDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,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 @@ -79,7 +79,7 @@ public function addRow($row)
public function allRows()
{
$rows = [];
foreach((FakeDB::$fakeRows[$this->table] ?? []) as $i => $row) {
foreach ((FakeDB::$fakeRows[$this->table] ?? []) as $i => $row) {
$rows[$i] = $row[$this->table];
}

Expand Down Expand Up @@ -189,12 +189,12 @@ public static function sort($comparisons, Collection $collection)

$result = 0;

if (! is_string($prop) && is_callable($prop)) {
if (!is_string($prop) && is_callable($prop)) {
$result = $prop($a, $b);
} else {
$values = [data_get($a, $prop), data_get($b, $prop)];

if (! $ascending) {
if (!$ascending) {
$values = array_reverse($values);
}

Expand Down Expand Up @@ -241,7 +241,7 @@ public static function performSelects($collection, $columns, $selects, $_table)
return $collection->map(function ($item) use ($columns, $aliases, $_table) {
if ($columns !== ['*']) {
foreach ($columns as $i => $col) {
! Str::contains($col, '.') && $columns[$i] = $_table.'.'.$col;
!Str::contains($col, '.') && $columns[$i] = $_table.'.'.$col;
}
$newItem = [];
foreach ($columns as $col) {
Expand Down Expand Up @@ -362,7 +362,7 @@ public static function isLike($value, $pattern, $item): bool
{
$pattern = str_replace('%', '.*', preg_quote($pattern, '/'));

return (bool) (preg_match("/^{$pattern}$/i", data_get($item, $value) ?? ''));
return (bool) preg_match("/^{$pattern}$/i", data_get($item, $value) ?? '');
}

public static function whereColumn($where, $row)
Expand Down Expand Up @@ -436,7 +436,7 @@ public static function lastInsertId()

public static function prefixColumn($column, $mainTable, $joins)
{
if (! Str::contains($column, '.') && ! isset(FakeDB::$fakeRows[$mainTable][0][$mainTable][$column]) && $joins) {
if (!Str::contains($column, '.') && !isset(FakeDB::$fakeRows[$mainTable][0][$mainTable][$column]) && $joins) {
foreach ($joins as $joined) {
$table = $joined->table;
if (isset(FakeDB::$fakeRows[$table][0][$table][$column])) {
Expand All @@ -445,7 +445,7 @@ public static function prefixColumn($column, $mainTable, $joins)
}
}

if (! Str::contains($column, '.')) {
if (!Str::contains($column, '.')) {
$column = $mainTable.'.'.$column;
}

Expand Down Expand Up @@ -505,7 +505,7 @@ public static function filter($query, $columns = ['*']): Collection

$orderBy && ($collection = self::sortRows($collection, $orderBy));

if (! FakeDB::$ignoreWheres) {
if (!FakeDB::$ignoreWheres) {
$collection = FakeDB::applyWheres($query, $collection);
}

Expand All @@ -520,11 +520,11 @@ public static function filter($query, $columns = ['*']): Collection

public static function sortRows(Collection $collection, $orderBy)
{
if (! $orderBy) {
if (!$orderBy) {
return $collection;
}
if (count($orderBy) === 1 && is_object($orderBy[0]['sql'] ?? '')) {
$data = ($orderBy[0]['sql'])->data;
$data = $orderBy[0]['sql']->data;
if ($data['type'] === 'random') {
return $collection->shuffle((int) $data['seed']);
}
Expand Down Expand Up @@ -718,15 +718,15 @@ public static function delete($query)

public static function insertGetId(array $values, $table)
{
if (! Arr::isAssoc($values)) {
if (!Arr::isAssoc($values)) {
foreach ($values as $value) {
self::insertGetId($value, $table);
}

return true;
}

if (! isset($values['id'])) {
if (!isset($values['id'])) {
$values['id'] = (FakeDB::$tables[$table]['latestRowId'] ?? 0) + 1;
}

Expand Down
25 changes: 14 additions & 11 deletions src/FakeSchemaGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function compileAdd(Blueprint $blueprint, Fluent $command)
public function compileChange(Blueprint $blueprint, Fluent $command, Connection $connection)
{
self::keepData('change', [$blueprint, $command, $connection]);

return parent::compileChange($blueprint, $command, $connection);
}

Expand All @@ -41,17 +41,14 @@ public function compileIndex(Blueprint $blueprint, Fluent $command)

public function compileKey(Blueprint $blueprint, Fluent $command, $type)
{

}

public function compileRenameIndex(Blueprint $blueprint, Fluent $command)
{

}

public function compileForeign(Blueprint $blueprint, Fluent $command)
{

}

public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Connection $connection)
Expand All @@ -63,7 +60,6 @@ public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Conne

public function compileUnique(Blueprint $blueprint, Fluent $command)
{

}

public function compileRename(Blueprint $blueprint, Fluent $command)
Expand Down Expand Up @@ -91,17 +87,25 @@ public function compileColumnListing()
{
return $this->stringy([
'type' => 'columnListing',
'sql' => parent::compileColumnListing(),
'sql' => parent::compileColumnListing(),
]);

return parent::compileColumnListing();
}

public function compileTableListing($schema = null, $schemaQualified = true)
{
return $this->stringy([
'type' => 'getAllTables',
'sql' => parent::compileTableListing($schema, $schemaQualified),
]);
}

public function compileGetAllTables()
{
return $this->stringy([
'type' => 'getAllTables',
'sql' => parent::compileGetAllTables(),
'sql' => parent::compileGetAllTables(),
]);
}

Expand All @@ -110,7 +114,7 @@ public function compileColumns($database, $table)
return $this->stringy([
'type' => 'columns',
'args' => ['database' => $database, 'table' => $table],
'sql' => parent::compileColumns($database, $table),
'sql' => parent::compileColumns($database, $table),
]);
}

Expand Down Expand Up @@ -153,14 +157,13 @@ public function compileTableExists()
{
return $this->stringy([
'type' => 'tableExists',
'sql' => parent::compileTableExists(),
'sql' => parent::compileTableExists(),
]);
}

private function stringy(array $data)
{
return new class ($data){

return new class($data) {
public $data;

public function __construct($data)
Expand Down