create(); $this->assertNotEmpty($userMark->id); return $userMark; } public function testRole(){ $role=Role::create([ 'name'=>'测试admin' ]); $this->assertNotEmpty($role->id); $authorities= Authority::get(); foreach ($authorities as $authority){ DB::table('authority_role')->insert(['id_authority'=>$authority->id,'id_role'=>$role->id]); } return $role; } /** * @depends testRole */ public function testUser(Role $role){ $user=factory(User::class)->create(); DB::table('user_role')->insert(['id_user'=>$user->id,'id_role'=>$role->id]); $this->assertNotEmpty($user->id); return $user; } public function testAdd(){ $waybillFinancialSnapshot=new WaybillFinancialSnapshot([ 'waybill_id'=>1, 'json_content'=>"{'waybill_number':'BSZX5416854985'}" ]); $result=$waybillFinancialSnapshot->save(); $this->assertTrue($result); return $waybillFinancialSnapshot; } /** * @depends testAdd * @depends testUser * @depends testUserMark */ public function testIndex(WaybillFinancialSnapshot $waybillFinancialSnapshot, User $user,User $userMark){ $response=$this->actingAs($user)->get('waybill/waybillFinancialSnapshot'); $response->assertOk()->assertSee('1'); $responseMark=$this->actingAs($userMark)->get('waybill/waybillFinancialSnapshot'); $responseMark->assertStatus(302)->assertRedirect('/'); $waybillFinancialSnapshot=WaybillFinancialSnapshot::paginate(10); $this->assertNotEmpty($waybillFinancialSnapshot); } /** * @depends testAdd * @depends testUser * @depends testUserMark * @depends testRole */ public function testDestroy(WaybillFinancialSnapshot $waybillFinancialSnapshot,User $user,User $userMark,Role $role){ $waybillFinancialSnapshot->delete(); $result=WaybillFinancialSnapshot::find($waybillFinancialSnapshot->id); $this->assertEmpty($result); $result=$user->delete(); $this->assertTrue($result); $this->assertNotEmpty($userMark->id); $resultUserMark=$userMark->delete(); $this->assertTrue($resultUserMark); $resultRole=$role->delete(); $this->assertTrue($resultRole); DB::table('authority_role')->where('id_role','=',$role->id)->delete(); DB::table('user_role')->where('id_role','=',$role->id)->delete(); } }