lumen 单元测试

时间:2021-11-24 10:34:31

laravel学院:http://laravelacademy.org/post/238.html

简书:https://www.jianshu.com/p/d8b3ac2c4623

问题解决:https://*.com/questions/21726963/laravel-fatal-error-for-testcase-not-found

之前添加了这篇文章,一直没有写,今天做下补充

lumen 单元测试

lumen项目根目录下有一个tests文件夹,TestCase.php

<?php

class TestCase extends Laravel\Lumen\Testing\TestCase
{
/**
* Creates the application.
*
* @return \Laravel\Lumen\Application
*/
public function createApplication()
{
return require __DIR__.'/../bootstrap/app.php';
}
}

  

新建一个类,实现以下方法

namespace Tests\Admin\User;

class UserTest extends \TestCase
{
public function testUserName()
{
$params = [
'user_id' => 1,
'nickname' => '测试',
];
$this->json('POST', '/admin/user/nickname/', $params)->seeJson();
$responseData = json_decode($this->response->content(), true);
print_r($responseData);
return $responseData;
}
}

  

右键类或者方法 RUN 即可