add test batches
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Foundation\Application;
|
||||
|
||||
class BaseModel extends Model
|
||||
{
|
||||
@@ -13,9 +12,8 @@ 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;
|
||||
}));
|
||||
@@ -24,10 +22,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';
|
||||
}
|
||||
}
|
||||
@@ -51,7 +49,7 @@ class BaseModel extends Model
|
||||
if (function_exists('app')) {
|
||||
try {
|
||||
$app = app();
|
||||
if ($app instanceof Application && $app->runningUnitTests()) {
|
||||
if ($app instanceof \Illuminate\Foundation\Application && $app->runningUnitTests()) {
|
||||
return true;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
@@ -84,7 +82,7 @@ class BaseModel extends Model
|
||||
}
|
||||
|
||||
if ($pattern === null) {
|
||||
$pattern = __DIR__.'/../../database/migrations/*.php';
|
||||
$pattern = __DIR__ . '/../../database/migrations/*.php';
|
||||
}
|
||||
|
||||
$files = glob($pattern) ?: [];
|
||||
@@ -100,7 +98,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;
|
||||
}
|
||||
}
|
||||
@@ -118,7 +116,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;
|
||||
}
|
||||
}
|
||||
@@ -130,7 +128,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;
|
||||
}
|
||||
|
||||
@@ -152,7 +150,7 @@ class BaseModel extends Model
|
||||
$columns[] = 'deleted_at';
|
||||
}
|
||||
|
||||
if (! empty($columns)) {
|
||||
if (!empty($columns)) {
|
||||
$map[$table] = $columns;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user