Skip to content

Commit 88c8c9f

Browse files
committed
Support Laravel 12
1 parent 6255bed commit 88c8c9f

File tree

4 files changed

+37
-33
lines changed

4 files changed

+37
-33
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
],
1717
"require": {
1818
"php" : "^7.2|^8.0",
19-
"illuminate/database": "5.*|6.*|7.*|8.*|9.*|10.*|11.*",
20-
"illuminate/events": "5.*|6.*|7.*|8.*|9.*|10.*|11.*"
19+
"illuminate/database": "5.*|6.*|7.*|8.*|9.*|10.*|11.*|12.*",
20+
"illuminate/events": "5.*|6.*|7.*|8.*|9.*|10.*|11.*|12.*"
2121
},
2222
"require-dev": {
2323
"phpunit/phpunit": "^7.5.20|^8.5.28|^9.5",

src/FakeConnection.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ class FakeConnection extends Connection implements ConnectionInterface
1313
public static function resolve($connection = null, $db = '', $prefix = '', $config = ['name' => 'arrayDB'])
1414
{
1515
$fakeConnection = new FakeConnection(function () {
16-
return new FakePDO;
16+
return new FakePDO();
1717
}, $db, $prefix, $config);
1818

19-
$fakeConnection->setQueryGrammar(new FakeGrammar);
20-
19+
$fakeConnection->setQueryGrammar(new FakeGrammar($fakeConnection));
20+
2121
return $fakeConnection;
2222
}
2323

@@ -39,26 +39,27 @@ public function getSchemaGrammar()
3939
public function query()
4040
{
4141
return new FakeQueryBuilder(
42-
$this, $this->getQueryGrammar(), $this->getPostProcessor()
42+
$this,
43+
$this->getQueryGrammar(),
44+
$this->getPostProcessor()
4345
);
4446
}
4547

4648
protected function getDefaultQueryGrammar()
4749
{
48-
return new FakeGrammar;
50+
return new FakeGrammar($this);
4951
}
5052

5153
public function statement($query, $bindings = [])
5254
{
5355
if (is_object($query)) {
5456
$query = $query->data;
5557
} else {
56-
5758
}
5859
if (FakeSchemaGrammar::$query && is_string($query)) {
5960
$payload = array_shift(FakeSchemaGrammar::$query);
6061
$query = [
61-
'sql' => $query,
62+
'sql' => $query,
6263
'args' => $payload['args'] ?? null,
6364
'type' => $payload['type'],
6465
];

src/FakeDB.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static function createTable($args)
6363

6464
public static function table($table)
6565
{
66-
return new class ($table) {
66+
return new class($table) {
6767
private $table;
6868

6969
public function __construct($table)
@@ -79,7 +79,7 @@ public function addRow($row)
7979
public function allRows()
8080
{
8181
$rows = [];
82-
foreach((FakeDB::$fakeRows[$this->table] ?? []) as $i => $row) {
82+
foreach ((FakeDB::$fakeRows[$this->table] ?? []) as $i => $row) {
8383
$rows[$i] = $row[$this->table];
8484
}
8585

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

190190
$result = 0;
191191

192-
if (! is_string($prop) && is_callable($prop)) {
192+
if (!is_string($prop) && is_callable($prop)) {
193193
$result = $prop($a, $b);
194194
} else {
195195
$values = [data_get($a, $prop), data_get($b, $prop)];
196196

197-
if (! $ascending) {
197+
if (!$ascending) {
198198
$values = array_reverse($values);
199199
}
200200

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

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

368368
public static function whereColumn($where, $row)
@@ -436,7 +436,7 @@ public static function lastInsertId()
436436

437437
public static function prefixColumn($column, $mainTable, $joins)
438438
{
439-
if (! Str::contains($column, '.') && ! isset(FakeDB::$fakeRows[$mainTable][0][$mainTable][$column]) && $joins) {
439+
if (!Str::contains($column, '.') && !isset(FakeDB::$fakeRows[$mainTable][0][$mainTable][$column]) && $joins) {
440440
foreach ($joins as $joined) {
441441
$table = $joined->table;
442442
if (isset(FakeDB::$fakeRows[$table][0][$table][$column])) {
@@ -445,7 +445,7 @@ public static function prefixColumn($column, $mainTable, $joins)
445445
}
446446
}
447447

448-
if (! Str::contains($column, '.')) {
448+
if (!Str::contains($column, '.')) {
449449
$column = $mainTable.'.'.$column;
450450
}
451451

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

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

508-
if (! FakeDB::$ignoreWheres) {
508+
if (!FakeDB::$ignoreWheres) {
509509
$collection = FakeDB::applyWheres($query, $collection);
510510
}
511511

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

521521
public static function sortRows(Collection $collection, $orderBy)
522522
{
523-
if (! $orderBy) {
523+
if (!$orderBy) {
524524
return $collection;
525525
}
526526
if (count($orderBy) === 1 && is_object($orderBy[0]['sql'] ?? '')) {
527-
$data = ($orderBy[0]['sql'])->data;
527+
$data = $orderBy[0]['sql']->data;
528528
if ($data['type'] === 'random') {
529529
return $collection->shuffle((int) $data['seed']);
530530
}
@@ -718,15 +718,15 @@ public static function delete($query)
718718

719719
public static function insertGetId(array $values, $table)
720720
{
721-
if (! Arr::isAssoc($values)) {
721+
if (!Arr::isAssoc($values)) {
722722
foreach ($values as $value) {
723723
self::insertGetId($value, $table);
724724
}
725725

726726
return true;
727727
}
728728

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

src/FakeSchemaGrammar.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function compileAdd(Blueprint $blueprint, Fluent $command)
2828
public function compileChange(Blueprint $blueprint, Fluent $command, Connection $connection)
2929
{
3030
self::keepData('change', [$blueprint, $command, $connection]);
31-
31+
3232
return parent::compileChange($blueprint, $command, $connection);
3333
}
3434

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

4242
public function compileKey(Blueprint $blueprint, Fluent $command, $type)
4343
{
44-
4544
}
4645

4746
public function compileRenameIndex(Blueprint $blueprint, Fluent $command)
4847
{
49-
5048
}
5149

5250
public function compileForeign(Blueprint $blueprint, Fluent $command)
5351
{
54-
5552
}
5653

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

6461
public function compileUnique(Blueprint $blueprint, Fluent $command)
6562
{
66-
6763
}
6864

6965
public function compileRename(Blueprint $blueprint, Fluent $command)
@@ -91,17 +87,25 @@ public function compileColumnListing()
9187
{
9288
return $this->stringy([
9389
'type' => 'columnListing',
94-
'sql' => parent::compileColumnListing(),
90+
'sql' => parent::compileColumnListing(),
9591
]);
9692

9793
return parent::compileColumnListing();
9894
}
9995

96+
public function compileTableListing($schema = null, $schemaQualified = true)
97+
{
98+
return $this->stringy([
99+
'type' => 'getAllTables',
100+
'sql' => parent::compileTableListing($schema, $schemaQualified),
101+
]);
102+
}
103+
100104
public function compileGetAllTables()
101105
{
102106
return $this->stringy([
103107
'type' => 'getAllTables',
104-
'sql' => parent::compileGetAllTables(),
108+
'sql' => parent::compileGetAllTables(),
105109
]);
106110
}
107111

@@ -110,7 +114,7 @@ public function compileColumns($database, $table)
110114
return $this->stringy([
111115
'type' => 'columns',
112116
'args' => ['database' => $database, 'table' => $table],
113-
'sql' => parent::compileColumns($database, $table),
117+
'sql' => parent::compileColumns($database, $table),
114118
]);
115119
}
116120

@@ -153,14 +157,13 @@ public function compileTableExists()
153157
{
154158
return $this->stringy([
155159
'type' => 'tableExists',
156-
'sql' => parent::compileTableExists(),
160+
'sql' => parent::compileTableExists(),
157161
]);
158162
}
159163

160164
private function stringy(array $data)
161165
{
162-
return new class ($data){
163-
166+
return new class($data) {
164167
public $data;
165168

166169
public function __construct($data)

0 commit comments

Comments
 (0)