/
githubmirror
/
framework
Обзор
Документация
Войти
/
githubmirror
/
framework
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
13.x
tests/Database/DatabaseEloquentStrictMorphsTest.php
82 строки
2 KB
Lucas Michot
Remove useless parent::setUp()/tearDown() calls in tests extending PHPUnit's TestCase directly (#60994)
03 авг 2026, 20:54
Не верифицирован
03 авг 2026, 20:54
14a6983
Код
Авторство
О чём код?
<?php namespace Illuminate\Tests\Database; use Illuminate\Database\ClassMorphViolationException; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\Pivot; use Illuminate\Database\Eloquent\Relations\Relation; use PHPUnit\Framework\TestCase; class DatabaseEloquentStrictMorphsTest extends TestCase { protected function setUp(): void { Relation::requireMorphMap(); } public function testStrictModeThrowsAnExceptionOnClassMap() { $this->expectException(ClassMorphViolationException::class); $model = new TestModel; $model->getMorphClass(); } public function testStrictModeDoesNotThrowExceptionWhenMorphMap() { $model = new TestModel; Relation::morphMap([ 'test' => TestModel::class, ]); $morphName = $model->getMorphClass(); $this->assertSame('test', $morphName); } public function testMapsCanBeEnforcedInOneMethod() { $model = new TestModel; Relation::requireMorphMap(false); Relation::enforceMorphMap([ 'test' => TestModel::class, ]); $morphName = $model->getMorphClass(); $this->assertSame('test', $morphName); } public function testMapIgnoreGenericPivotClass() { $pivotModel = new Pivot(); $pivotModel->getMorphClass(); } public function testMapCanBeEnforcedToCustomPivotClass() { $this->expectException(ClassMorphViolationException::class); $pivotModel = new TestPivotModel(); $pivotModel->getMorphClass(); } protected function tearDown(): void { Relation::morphMap([], false); Relation::requireMorphMap(false); } } class TestModel extends Model { } class TestPivotModel extends Pivot { }