解决方法: 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
<?php
declare(strict_types=1);
use Laravel\Lumen\Testing\DatabaseMigrations;
use Laravel\Lumen\Testing\DatabaseTransactions;
class ExampleTest extends TestCase {
protected $baseUrl = 'http://127.0.0.1:8000';
/**
* A basic test example.
*
* @return void
*/
public function testExample() {
$this->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);
E:\easyeye\src\admin\tests\ExampleTest.php:18:
class Illuminate\Http\Response#338 (8) {
public $headers =>
class Symfony\Component\HttpFoundation\ResponseHeaderBag#337 (5) {
protected $computedCacheControl =>
array(2) {
'no-cache' =>
bool(true)
'private' =>
bool(true)
}
protected $cookies =>
array(0) {
}
protected $headerNames =>
array(2) {
'cache-control' =>
string(13) "Cache-Control"
'date' =>
string(4) "Date"
}
protected $headers =>
array(2) {
'cache-control' =>
array(1) {
...
}
'date' =>
array(1) {
...
}
}
protected $cacheControl =>
array(0) {
}
}
protected $content =>
string(36016) "<!DOCTYPE html>
<html>
<head>
<meta name="robots" content="noindex,nofollow" />
<style>
/* Copyright (c) 2010, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.com/yui/license.html */
html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}"...
protected $version =>
string(3) "1.0"
protected $statusCode =>
int(500)
protected $statusText =>
string(21) "Internal Server Error"
protected $charset =>
NULL
public $original =>
string(36016) "<!DOCTYPE html>
<html>
<head>
<meta name="robots" content="noindex,nofollow" />
<style>
/* Copyright (c) 2010, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.com/yui/license.html */
html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}"...
public $exception =>
class ErrorException#343 (9) {
protected $message =>
string(147) "Cannot modify header information - headers already sent by (output started at E:\easyeye\src\admin\vendor\phpunit\phpunit\src\Util\Printer.php:109)"
private $string =>
string(3425) "ErrorException: Cannot modify header information - headers already sent by (output started at E:\easyeye\src\admin\vendor\phpunit\phpunit\src\Util\Printer.php:109) in E:\easyeye\src\admin\app\Http\Middleware\CorsMiddleware.php:51
Stack trace:
#0 [internal function]: Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}(2, 'Cannot modify h...', 'E:\\easyeye\\src\\...', 51, Array)
#1 E:\easyeye\src\admin\app\Http\Middleware\CorsMiddleware.php(51): header('Access-Control-...')
#2 E:\easyeye\src\admin\ven"...
protected $code =>
int(0)
protected $file =>
string(59) "E:\easyeye\src\admin\app\Http\Middleware\CorsMiddleware.php"
protected $line =>
int(51)
private $trace =>
array(23) {
[0] =>
array(4) {
...
}
...
}
private $previous =>
NULL
protected $severity =>
int(2)
public $xdebug_message =>
string(3516) "
ErrorException: Cannot modify header information - headers already sent by (output started at E:\easyeye\src\admin\vendor\phpunit\phpunit\src\Util\Printer.php:109) in E:\easyeye\src\admin\app\Http\Middleware\CorsMiddleware.php on line 51
Call Stack:
0.0008 381120 1. {main}() E:\easyeye\src\admin\vendor\phpunit\phpunit\phpunit:0
0.0217 1356656 2. PHPUnit\TextUI\Command::main() E:\easyeye\src\admin\vendor\phpunit\phpunit\phpunit:53
0.0218 1361216 3. PHPUnit\TextUI\Command->run() "...
}
}
.\vendor\phpunit\phpunit\src\Util\Printer.php:109
CORS
* .\bootstrap\app.php 先禁用
$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