TestCase (Foundation\Testing)

TestCase

class TestCase extends TestCase (View source)

Traits

InteractsWithContainer
MakesHttpRequests
InteractsWithAuthentication
InteractsWithConsole
InteractsWithDatabase
InteractsWithSession
MocksApplicationServices

Methods

$this withoutMiddleware()

Disable middleware for the test.

from MakesHttpRequests
TestResponse get(string $uri, array $headers = array())

Visit the given URI with a GET request.

from MakesHttpRequests
TestResponse getJson(string $uri, array $headers = array())

Visit the given URI with a GET request, expecting a JSON response.

from MakesHttpRequests
TestResponse post(string $uri, array $data = array(), array $headers = array())

Visit the given URI with a POST request.

from MakesHttpRequests
TestResponse postJson(string $uri, array $data = array(), array $headers = array())

Visit the given URI with a POST request, expecting a JSON response.

from MakesHttpRequests
TestResponse put(string $uri, array $data = array(), array $headers = array())

Visit the given URI with a PUT request.

from MakesHttpRequests
TestResponse putJson(string $uri, array $data = array(), array $headers = array())

Visit the given URI with a PUT request, expecting a JSON response.

from MakesHttpRequests
TestResponse patch(string $uri, array $data = array(), array $headers = array())

Visit the given URI with a PATCH request.

from MakesHttpRequests
TestResponse patchJson(string $uri, array $data = array(), array $headers = array())

Visit the given URI with a PATCH request, expecting a JSON response.

from MakesHttpRequests
TestResponse delete(string $uri, array $data = array(), array $headers = array())

Visit the given URI with a DELETE request.

from MakesHttpRequests
TestResponse deleteJson(string $uri, array $data = array(), array $headers = array())

Visit the given URI with a DELETE request, expecting a JSON response.

from MakesHttpRequests
TestResponse json(string $method, string $uri, array $data = array(), array $headers = array())

Call the given URI with a JSON request.

from MakesHttpRequests
TestResponse call(string $method, string $uri, array $parameters = array(), array $cookies = array(), array $files = array(), array $server = array(), string $content = null)

Call the given URI and return the Response.

from MakesHttpRequests
$this actingAs(Authenticatable $user, string|null $driver = null)

Set the currently logged in user for the application.

from InteractsWithAuthentication
void be(Authenticatable $user, string|null $driver = null)

Set the currently logged in user for the application.

from InteractsWithAuthentication
$this seeIsAuthenticated(string|null $guard = null)

Assert that the user is authenticated.

from InteractsWithAuthentication
$this dontSeeIsAuthenticated(string|null $guard = null)

Assert that the user is not authenticated.

from InteractsWithAuthentication
$this seeIsAuthenticatedAs($user, string|null $guard = null)

Assert that the user is authenticated as the given user.

from InteractsWithAuthentication
$this seeCredentials(array $credentials, string|null $guard = null)

Assert that the given credentials are valid.

from InteractsWithAuthentication
$this dontSeeCredentials(array $credentials, string|null $guard = null)

Assert that the given credentials are invalid.

from InteractsWithAuthentication
int artisan(string $command, array $parameters = array())

Call artisan command and return code.

from InteractsWithConsole
$this seed(string $class = 'DatabaseSeeder')

Seed a given database connection.

from InteractsWithDatabase
$this withSession(array $data)

Set the session to the given array.

from InteractsWithSession
$this session(array $data)

Set the session to the given array.

from InteractsWithSession
$this flushSession()

Flush all of the current session data.

from InteractsWithSession
$this expectsEvents(array|string $events)

Specify a list of events that should be fired for the given operation.

from MocksApplicationServices
$this doesntExpectEvents(array|string $events)

Specify a list of events that should not be fired for the given operation.

from MocksApplicationServices
HttpKernelInterface createApplication()

Creates the application.

void afterApplicationCreated(callable $callback)

Register a callback to be run after the application is created.

Details

$this withoutMiddleware()

Disable middleware for the test.

Return Value

$this

TestResponse get(string $uri, array $headers = array())

Visit the given URI with a GET request.

Parameters

string $uri
array $headers

Return Value

TestResponse

TestResponse getJson(string $uri, array $headers = array())

Visit the given URI with a GET request, expecting a JSON response.

Parameters

string $uri
array $headers

Return Value

TestResponse

TestResponse post(string $uri, array $data = array(), array $headers = array())

Visit the given URI with a POST request.

Parameters

string $uri
array $data
array $headers

Return Value

TestResponse

TestResponse postJson(string $uri, array $data = array(), array $headers = array())

Visit the given URI with a POST request, expecting a JSON response.

Parameters

string $uri
array $data
array $headers

Return Value

TestResponse

TestResponse put(string $uri, array $data = array(), array $headers = array())

Visit the given URI with a PUT request.

Parameters

string $uri
array $data
array $headers

Return Value

TestResponse

TestResponse putJson(string $uri, array $data = array(), array $headers = array())

Visit the given URI with a PUT request, expecting a JSON response.

Parameters

string $uri
array $data
array $headers

Return Value

TestResponse

TestResponse patch(string $uri, array $data = array(), array $headers = array())

Visit the given URI with a PATCH request.

Parameters

string $uri
array $data
array $headers

Return Value

TestResponse

TestResponse patchJson(string $uri, array $data = array(), array $headers = array())

Visit the given URI with a PATCH request, expecting a JSON response.

Parameters

string $uri
array $data
array $headers

Return Value

TestResponse

TestResponse delete(string $uri, array $data = array(), array $headers = array())

Visit the given URI with a DELETE request.

Parameters

string $uri
array $data
array $headers

Return Value

TestResponse

TestResponse deleteJson(string $uri, array $data = array(), array $headers = array())

Visit the given URI with a DELETE request, expecting a JSON response.

Parameters

string $uri
array $data
array $headers

Return Value

TestResponse

TestResponse json(string $method, string $uri, array $data = array(), array $headers = array())

Call the given URI with a JSON request.

Parameters

string $method
string $uri
array $data
array $headers

Return Value

TestResponse

TestResponse call(string $method, string $uri, array $parameters = array(), array $cookies = array(), array $files = array(), array $server = array(), string $content = null)

Call the given URI and return the Response.

Parameters

string $method
string $uri
array $parameters
array $cookies
array $files
array $server
string $content

Return Value

TestResponse

$this actingAs(Authenticatable $user, string|null $driver = null)

Set the currently logged in user for the application.

Parameters

Authenticatable $user
string|null $driver

Return Value

$this

void be(Authenticatable $user, string|null $driver = null)

Set the currently logged in user for the application.

Parameters

Authenticatable $user
string|null $driver

Return Value

void

$this seeIsAuthenticated(string|null $guard = null)

Assert that the user is authenticated.

Parameters

string|null $guard

Return Value

$this

$this dontSeeIsAuthenticated(string|null $guard = null)

Assert that the user is not authenticated.

Parameters

string|null $guard

Return Value

$this

$this seeIsAuthenticatedAs($user, string|null $guard = null)

Assert that the user is authenticated as the given user.

Parameters

$user
string|null $guard

Return Value

$this

$this seeCredentials(array $credentials, string|null $guard = null)

Assert that the given credentials are valid.

Parameters

array $credentials
string|null $guard

Return Value

$this

$this dontSeeCredentials(array $credentials, string|null $guard = null)

Assert that the given credentials are invalid.

Parameters

array $credentials
string|null $guard

Return Value

$this

int artisan(string $command, array $parameters = array())

Call artisan command and return code.

Parameters

string $command
array $parameters

Return Value

int

$this seed(string $class = 'DatabaseSeeder')

Seed a given database connection.

Parameters

string $class

Return Value

$this

$this withSession(array $data)

Set the session to the given array.

Parameters

array $data

Return Value

$this

$this session(array $data)

Set the session to the given array.

Parameters

array $data

Return Value

$this

$this flushSession()

Flush all of the current session data.

Return Value

$this

$this expectsEvents(array|string $events)

Specify a list of events that should be fired for the given operation.

These events will be mocked, so that handlers will not actually be executed.

Parameters

array|string $events

Return Value

$this

Exceptions

Exception

$this doesntExpectEvents(array|string $events)

Specify a list of events that should not be fired for the given operation.

These events will be mocked, so that handlers will not actually be executed.

Parameters

array|string $events

Return Value

$this

abstract HttpKernelInterface createApplication()

Creates the application.

Needs to be implemented by subclasses.

Return Value

HttpKernelInterface

void afterApplicationCreated(callable $callback)

Register a callback to be run after the application is created.

Parameters

callable $callback

Return Value

void

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.4/Illuminate/Foundation/Testing/TestCase.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部