概要
外部ライブラリをcomposerなどでインストールして使っていると、
$_SERVERなどの値が必要とのエラーが出たりした。
そういった場合の対応として調べたことをメモしておく。
$_SERVERの値を追加する
$_SERVERの値をsetUpメソッドで定義する
namespace Tests\Feature;
use Tests\TestCase;
class hogeTest extends TestCase
{
/**
* テスト前の準備作業
*
* @access public
* @return void
*/
public function setUp()
{
$_SERVER['HTTP_HOST'] = 'www.example.com';
$_SERVER['REQUEST_URI'] = 'http://www.exsample.com/mypage';
parent::setUp();
}
/**
* テスト実行
*
* @access public
* @return void
*/
public function testGetRequest()
{
$response = $this
->withServerVariables([
'HTTP_HOST' => 'www.example.com',
'REQUEST_URI' => 'http://www.exsample.com/mypage'
])
->get('/hoge');
$response->assertStatus(200);
}
}