Skip to content

HTTP Test

hywkd3 edited this page Dec 4, 2019 · 1 revision

HTTP TESTING

  • HTTP request-요청을 하고, 결과를 검사

  • API 검사 시 사용.

    • 요청 header, contents 등을 설정할 수 있음.
    • 응답 status, 리턴값 등을 설정할 수 있음.
  • dump, dumpHeaders

    • 응답내용을 검사할 수 있음.
  • Basic Feature Test Example

<?php
namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithoutMiddleware;

class ExampleTest extends TestCase
{
	public function testBasicTest()
	{
		$response = $this->get('/');
		$response->assertStatus(200);
	}
}

Json Http request Example

<?php
class ExampleTest extends TestCase
{

public function testBasicExample()
{
	$response = $this->withHeaders([
		'X-Header' => 'Value',
	])->json('POST', '/user', ['name' => 'Sally']);

	$response->assertStatus(201)
			->assertJson([
			'created' => true,
		]);
	}
}
code 기능
$this->assertAuthenticated($guard = null); 사용자가 인증되었는지 확인.
$this->assertGuest($guard = null); 사용자가 인증되지 않은 것을 확인.
$this->assertAuthenticatedAs($user, $guard = null); 주어진 사용자가 인증되었는지 확인.
$this->assertCredentials(array $credentials, $guard = null); 주어진 인증정보가 유효한지 확인.
$this->assertInvalidCredentials(array $credentials, $guard = null); 주어진 인증정보가 유효하지 않은 것을 확인.
Clone this wiki locally