fix tests
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Foundation\Application;
|
||||
|
||||
class BaseModel extends Model
|
||||
{
|
||||
@@ -12,8 +13,9 @@ class BaseModel extends Model
|
||||
{
|
||||
if ($this->isTestingEnv()) {
|
||||
$columns = $this->tableColumns();
|
||||
if (!empty($columns)) {
|
||||
if (! empty($columns)) {
|
||||
$key = $this->getKeyName();
|
||||
|
||||
return array_values(array_filter($columns, static function ($col) use ($key) {
|
||||
return $col !== $key;
|
||||
}));
|
||||
@@ -22,10 +24,10 @@ class BaseModel extends Model
|
||||
|
||||
$fillable = parent::getFillable();
|
||||
if ($this->timestamps) {
|
||||
if (!in_array('created_at', $fillable, true)) {
|
||||
if (! in_array('created_at', $fillable, true)) {
|
||||
$fillable[] = 'created_at';
|
||||
}
|
||||
if (!in_array('updated_at', $fillable, true)) {
|
||||
if (! in_array('updated_at', $fillable, true)) {
|
||||
$fillable[] = 'updated_at';
|
||||
}
|
||||
}
|
||||
@@ -49,7 +51,7 @@ class BaseModel extends Model
|
||||
if (function_exists('app')) {
|
||||
try {
|
||||
$app = app();
|
||||
if ($app instanceof \Illuminate\Foundation\Application && $app->runningUnitTests()) {
|
||||
if ($app instanceof Application && $app->runningUnitTests()) {
|
||||
return true;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
@@ -82,7 +84,7 @@ class BaseModel extends Model
|
||||
}
|
||||
|
||||
if ($pattern === null) {
|
||||
$pattern = __DIR__ . '/../../database/migrations/*.php';
|
||||
$pattern = __DIR__.'/../../database/migrations/*.php';
|
||||
}
|
||||
|
||||
$files = glob($pattern) ?: [];
|
||||
@@ -98,7 +100,7 @@ class BaseModel extends Model
|
||||
}
|
||||
|
||||
foreach ($this->parseSchemaCreateTables($contents) as $table => $columns) {
|
||||
if (!isset($map[$table]) || empty($map[$table])) {
|
||||
if (! isset($map[$table]) || empty($map[$table])) {
|
||||
$map[$table] = $columns;
|
||||
}
|
||||
}
|
||||
@@ -116,7 +118,7 @@ class BaseModel extends Model
|
||||
$colsBlock = $match[2];
|
||||
preg_match_all('/`([^`]+)`\\s+[^,]+/m', $colsBlock, $colsMatch);
|
||||
$columns = $colsMatch[1] ?? [];
|
||||
if (!empty($columns)) {
|
||||
if (! empty($columns)) {
|
||||
$map[$table] = $columns;
|
||||
}
|
||||
}
|
||||
@@ -128,7 +130,7 @@ class BaseModel extends Model
|
||||
private function parseSchemaCreateTables(string $contents): array
|
||||
{
|
||||
$map = [];
|
||||
if (!preg_match_all('/Schema::create\\(\\s*[\'"]([^\'"]+)[\'"]\\s*,\\s*function\\s*\\([^)]*\\)\\s*\\{(.*?)\\n\\s*\\}\\);/is', $contents, $matches, PREG_SET_ORDER)) {
|
||||
if (! preg_match_all('/Schema::create\\(\\s*[\'"]([^\'"]+)[\'"]\\s*,\\s*function\\s*\\([^)]*\\)\\s*\\{(.*?)\\n\\s*\\}\\);/is', $contents, $matches, PREG_SET_ORDER)) {
|
||||
return $map;
|
||||
}
|
||||
|
||||
@@ -150,7 +152,7 @@ class BaseModel extends Model
|
||||
$columns[] = 'deleted_at';
|
||||
}
|
||||
|
||||
if (!empty($columns)) {
|
||||
if (! empty($columns)) {
|
||||
$map[$table] = $columns;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user