zl程序教程

您现在的位置是:首页 >  其它

当前栏目

lumen 单元测试

单元测试 Lumen
2023-09-11 14:16:35 时间

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

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

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

 

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

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 即可