/
githubmirror
/
framework
Обзор
Документация
Войти
/
githubmirror
/
framework
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
13.x
tests/Integration/Database/EloquentMorphToTouchesTest.php
64 строки
1 KB
Mior Muhammad Zaki
[10.x] Streamline `DatabaseMigrations` and `RefreshDatabase` events (#49153)
28 ноя 2023, 18:22
Не верифицирован
28 ноя 2023, 18:22
1e03a4a
Код
Авторство
О чём код?
<?php namespace Illuminate\Tests\Integration\Database\EloquentMorphToTouchesTest; use DB; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; use Illuminate\Tests\Integration\Database\DatabaseTestCase; class EloquentMorphToTouchesTest extends DatabaseTestCase { protected function afterRefreshingDatabase() { Schema::create('posts', function (Blueprint $table) { $table->increments('id'); $table->timestamps(); }); Schema::create('comments', function (Blueprint $table) { $table->increments('id'); $table->nullableMorphs('commentable'); }); Post::create(); } public function testNotNull() { $comment = (new Comment)->commentable()->associate(Post::first()); DB::enableQueryLog(); $comment->save(); $this->assertCount(2, DB::getQueryLog()); } public function testNull() { DB::enableQueryLog(); Comment::create(); $this->assertCount(1, DB::getQueryLog()); } } class Comment extends Model { public $timestamps = false; protected $touches = ['commentable']; public function commentable() { return $this->morphTo(null, null, null, 'id'); } } class Post extends Model { // }