Merge pull request #308 from shikorism/fix/force-testing-env

phpunit.xml内の環境変数を強制適用する
This commit is contained in:
shibafu 2019-12-30 16:04:03 +09:00 committed by GitHub
commit d9cf5e54e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 23 deletions

View File

@ -27,9 +27,9 @@
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="APP_ENV" value="testing" force="true"/>
<env name="CACHE_DRIVER" value="array" force="true"/>
<env name="SESSION_DRIVER" value="array" force="true"/>
<env name="QUEUE_DRIVER" value="sync" force="true"/>
</php>
</phpunit>

View File

@ -30,13 +30,9 @@ class SettingTest extends TestCase
'ejaculation_id' => $ejaculation->id,
]);
$token = $this->getCsrfToken($user, '/setting/deactivate');
$response = $this->actingAs($user)
->followingRedirects()
->post('/setting/deactivate', [
'_token' => $token,
'password' => 'secret',
]);
->post('/setting/deactivate', ['password' => 'secret']);
$response->assertStatus(200)
->assertViewIs('setting.deactivated');
@ -47,18 +43,4 @@ class SettingTest extends TestCase
$this->assertDatabaseMissing('likes', ['id' => $anotherLike->id]);
$this->assertDatabaseHas('deactivated_users', ['name' => $user->name]);
}
/**
* テスト対象を呼び出す前にGETリクエストを行い、CSRFトークンを得る
* @param Authenticatable $user 認証情報
* @param string $uri リクエスト先
* @return string CSRFトークン
*/
private function getCsrfToken(Authenticatable $user, string $uri): string
{
$response = $this->actingAs($user)->get($uri);
$crawler = new Crawler($response->getContent());
return $crawler->filter('input[name=_token]')->attr('value');
}
}