【发布时间】:2018-01-22 07:56:56
【问题描述】:
场景:
我有以下测试用例,我想在其中测试场景,如果用户找到用户类型 superadmin 然后将用户重定向到 /home 路由,如果用户未找到重定向他到 /superadmin/setup 路线。尝试了多种方法,但无法弄清楚。怎样才能通过这个测试?
我正在使用 Laravel 5.4。
测试用例:
<?php
namespace Tests\Feature;
use App\User;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class SuperAdminRegistrationTest extends TestCase
{
use DatabaseMigrations;
public function testRegistrationForm()
{
factory(User::class)->create(['usertype' => 'superadmin']);
$user = User::getUserFromUsertype('superadmin');
//If valid user is found with usertype 'superadmin' then
// $this->get('/home');
// $this->assertStatus(200);
//Else user not found with given usertype then
// $this->get('/superadmin/setup');
// $this->assertStatus(200);
}
}
【问题讨论】:
标签: php laravel unit-testing phpunit