Laravel特性测试-插入数据

susanml 测试交流2106字数 516阅读模式
摘要我有一个元数据表,需要测试插入数据: 公共功能测试插入唯一数据() { $response=元数据::创建([ “metable\u id”=“gt;”1', metable_类型...

我有一个元数据表,需要测试插入数据:

public function test_insert_unique_data()
{
    $response = Metadata::create([
        'metable_id' => '1',
        'metable_type' => File::class,
        'type' => 'resolution',
        'key' => 'width',
        'value' => 1000,
    ]);
    $response->assertCreated();
}

这是表的迁移:文章源自玩技e族-https://www.playezu.com/180051.html

Schema::create(..., function (Blueprint $table) {
    $table->id();
    $table->bigInteger('metable_id')->unsigned()->index();
    $table->string('metable_type')->index();
    $table->string('type')->default('default');
    $table->string('key')->index();
    $table->text('value');
    $table->timestamps();

每次都会失败,所以我只能假设测试写错了。有什么指示吗?文章源自玩技e族-https://www.playezu.com/180051.html 文章源自玩技e族-https://www.playezu.com/180051.html

玩技站长微信
添加好友自动发送入群邀请
weinxin
rainbow-shownow
玩技官方公众号
官方微信公众号
weinxin
PLAYEZU
 
  • 版权提示:本站仅供存储任何法律责任由作者承担▷诈骗举报◁▷新闻不符◁▷我要投稿◁
    风险通知:非原创文章均为网络投稿真实性无法判断,侵权联系2523030730
    免责声明:内容来自用户上传发布或新闻客户端自媒体,切勿!切勿!切勿!添加联系方式以免受骗。
  • 原创转载:https://www.playezu.com/180051.html
    转载说明: 点我前往阅读>>>
评论  2  访客  2
    • Laisender
      Laisender 9

      我不知道这件事 资产已创建 但我知道类似的事情:
      public function test_insert_unique_data()
      {
      $metadata = Metadata::create([
      ‘metable_id’ => ‘1’,
      ‘metable_type’ => File::class,
      ‘type’ => ‘resolution’,
      ‘key’ => ‘width’,
      ‘value’ => 1000,
      ]);

      $this->assertModelExists($metadata);
      }

      • Matt Hatcher
        Matt Hatcher 9

        为什么不直接使用工厂?他们在数据库测试部分有各种断言。
        除非有什么原因,否则每一次使用我在现代Laravel中看到的任何模型的测试(我来自Laravel 3-5天)都是使用工厂。

      匿名

      发表评论

      匿名网友
      确定