Add the five automation models to Relation::enforceMorphMap(), document the all-models-must-be-mapped rule in CLAUDE.md, and add MorphMapTest to fail when any app/Models class is missing from the map.
21 lines
733 B
PHP
21 lines
733 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
|
|
|
test('every Eloquent model is registered in the morph map', function () {
|
|
$mapped = array_values(Relation::morphMap());
|
|
|
|
$missing = collect(glob(app_path('Models/*.php')))
|
|
->map(fn (string $file): string => 'App\\Models\\'.pathinfo($file, PATHINFO_FILENAME))
|
|
->filter(fn (string $class): bool => class_exists($class)
|
|
&& is_subclass_of($class, Model::class)
|
|
&& ! (new ReflectionClass($class))->isAbstract())
|
|
->reject(fn (string $class): bool => in_array($class, $mapped, true))
|
|
->values()
|
|
->all();
|
|
|
|
expect($missing)->toBe([]);
|
|
});
|