【问题标题】:Is there any example on how to write test for CRUD based app in "Laravel 5.1"?有没有关于如何在“Laravel 5.1”中为基于 CRUD 的应用程序编写测试的示例?
【发布时间】:2015-07-18 13:28:01
【问题描述】:

我对 php 的 Laravel 框架有些经验。

在新版本 (5.1) 中,他们大幅改进了测试功能。

是否有任何示例说明如何在 laravel 5.1 中为基本的 CRUD 应用程序编写测试。

我能够测试任务的创建。但我仍然不确定这是否是最佳做法。请帮我。

<?php

use App\Task;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class TasksTest extends TestCase
{    
    use DatabaseTransactions;    
    public function testCreateTask()
    {
        $this->visit('/tasks/create')
             ->type('This is task title', 'title')
             ->type('This is task description', 'description')
             ->press('Create Task')
             ->seePageIs('/tasks')
             ->see('This is task title');
    }    
}

【问题讨论】:

标签: php laravel testing tdd laravel-5.1


【解决方案1】:

首先,只需在您的项目中添加 crud 库,然后, 只需运行此命令,

php artisan crud:generate crud-name --fields="name:string, email:string, phone:integer, message:text"

【讨论】:

  • 问题是关于测试而不是实际的 CRUD
猜你喜欢
  • 2011-05-28
  • 1970-01-01
  • 1970-01-01
  • 2016-01-06
  • 1970-01-01
  • 2011-01-08
  • 2012-02-19
  • 1970-01-01
  • 2020-03-03
相关资源
最近更新 更多