lumen unit test GET '/' Expected status code 200, got 500.

解决方法: https://blog.csdn.net/fareast_mzh/article/details/82179781

.\vendor\bin\phpunit
PHPUnit 7.2.7 by Sebastian Bergmann and contributors.

F...                                                                4 / 4 (100%)

Time: 462 ms, Memory: 8.00MB

There was 1 failure:

1) ExampleTest::testExample
Expected status code 200, got 500.
Failed asserting that false is true.

E:\easyeye\src\admin\vendor\laravel\lumen-framework\src\Testing\Concerns\MakesHttpRequests.php:397
E:\easyeye\src\admin\tests\ExampleTest.php:20
E:\easyeye\src\admin\tests\ExampleTest.php:25
 

* call stack

.\vendor\phpunit\phpunit\src\Framework\TestCase.php

.\vendor\laravel\lumen-framework\src\Testing\TestCase.php

.\tests\TestCase.php

.\tests\ExampleTest.php

 

* test case

.\tests\ExampleTest.php

get('/');// var_dump($this->response); die;$this->assertResponseOk();$this->assertEquals($this->app->version(), $this->response->getContent());}public function run(\PHPUnit\Framework\TestResult $result = null): \PHPUnit\Framework\TestResult {return parent::run($result);}
}

var_dump($this->response);

$app->middleware([// App\Http\Middleware\CorsMiddleware::class,Illuminate\Session\Middleware\StartSession::class
]);$app->routeMiddleware(['auth' => App\Http\Middleware\Authenticate::class,// 'cors' => App\Http\Middleware\CorsMiddleware::class
]);

workaround:

header之前不能有任何输出

error_reporting(E_ERROR | E_PARSE);

Solution:

换一个cors

https://packagist.org/packages/barryvdh/laravel-cors


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部