【发布时间】:2021-05-31 11:03:29
【问题描述】:
我有这段代码,我想在用户表上执行批量更新和检查属性更改。但是,当我运行 php artisan 测试时,测试文件中有一个错误说“此测试没有执行任何断言”。我检查了用户表,但没有任何变化。有人能帮我吗?谢谢
<?php
namespace Tests\Feature;
use App\Models\Post;
//use http\Client\Curl\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use App\Models\User;
class PostExampleTest extends TestCase
{
/**
* A basic feature test example.
*
* @return void
*/
public function test_example()
{
$post = Post::factory()->create();
//Create 20 more posts
$post1 = Post::factory()->count(20)->create();
$post->title = 'Post Test';
$post->save();
//Create 10 more users
$makeTenUsers = User::factory()->count(10)->create();
$user = User::find(1);
$user->name = 'Kaeith';
$user->save();
//Mass Updates
User::where('email_verified_at', '2021-02-28 23:50:21')
->update(['email'=>'kaeith']);
//Examining Attribute Changes
$post->isDirty();
$post->isDirty('title');
$user->isClean();
$user->isClean('name');
}
}
user表的结构是'id', 'name', 'email', 'email_verified_at', 'password', 'created_at'
【问题讨论】: