abstract class ApplicationTestCase extends TestCase

Abstract class for test cases.

Properties

static array $controllerOutput

The controller output.

Methods

void
assertDatabaseHas(string $table, array $data, string $message = '')

Assert that a record exists in the specified database table with the given conditions.

void
assertDatabaseMissing(string $table, array $data, string $message = '')

Assert that no record exists in the specified database table with the given conditions.

void
assertViewContains(string $property, mixed $expectedValue = null)

Asserts that a property exists on the View object captured via controllerOutput().

string
controllerOutput(string $controllerSlug, string $actionSlug, array $urlSegments = [])

Simulates a controller action based on URL-style input and captures its output.

get(string $uri)

Simulates an HTTP GET request to a given URI by resolving and executing the corresponding controller and action, capturing the output.

void
mockFile(string $files)

Create a mock file for actions that require file input in form submissions.

post(string $uri, array $data = [])

Simulates a POST request by setting $_POST data and executing the specified controller and action. Returns a TestResponse with the output and status.

put(string $uri, array $data = [])

Simulates a DELETE request to a specified URI. This sets the request method to DELETE and runs the matching controller action.

void
setUp()

Implements setUp function from TestCase class.

Details

at line 36
void assertDatabaseHas(string $table, array $data, string $message = '')

Assert that a record exists in the specified database table with the given conditions.

This method builds a SQL WHERE clause from the provided key-value array and checks whether a matching row exists. It fails the test if no such row is found.

Parameters

string $table

The name of the database table to search.

array $data

An associative array of column => value pairs to match against.

string $message

Optional custom failure message.

Return Value

void

Exceptions

AssertionFailedError

at line 74
void assertDatabaseMissing(string $table, array $data, string $message = '')

Assert that no record exists in the specified database table with the given conditions.

This method builds a SQL WHERE clause from the provided key-value array and verifies that no matching row exists. It fails the test if such a row is found.

Parameters

string $table

The name of the database table to search.

array $data

An associative array of column => value pairs to match against.

string $message

Optional custom failure message.

Return Value

void

Exceptions

AssertionFailedError

at line 106
void assertViewContains(string $property, mixed $expectedValue = null)

Asserts that a property exists on the View object captured via controllerOutput().

Optionally asserts that the value matches.

Parameters

string $property

The view property to check.

mixed $expectedValue

Optional value to compare against.

Return Value

void

at line 132
protected string controllerOutput(string $controllerSlug, string $actionSlug, array $urlSegments = [])

Simulates a controller action based on URL-style input and captures its output.

Parameters

string $controllerSlug

e.g., 'home'

string $actionSlug

e.g., 'index'

array $urlSegments

Parameters to pass to the action

Return Value

string

Rendered HTML output

Exceptions

Exception

at line 175
protected TestResponse get(string $uri)

Simulates an HTTP GET request to a given URI by resolving and executing the corresponding controller and action, capturing the output.

Supports URI segments in the form of /controller/action/param1/param2, and maps them to a controller class and action method with optional parameters passed positionally.

Example:

  • get('/') → HomeController::indexAction()
  • get('/products/show/3') → ProductsController::showAction(3)

Parameters

string $uri

The URI string, e.g., '/home/index' or '/products/show/3'

Return Value

TestResponse

The response object containing status and content

at line 201
protected void mockFile(string $files)

Create a mock file for actions that require file input in form submissions.

Parameters

string $files

The name of the $_FILES field.

Return Value

void

at line 219
protected TestResponse post(string $uri, array $data = [])

Simulates a POST request by setting $_POST data and executing the specified controller and action. Returns a TestResponse with the output and status.

Parameters

string $uri

The URI to simulate, e.g., '/login'

array $data

The POST data to inject (e.g., ['email' => 'foo@bar.com'])

Return Value

TestResponse

The test response object

at line 255
protected TestResponse put(string $uri, array $data = [])

Simulates a DELETE request to a specified URI. This sets the request method to DELETE and runs the matching controller action.

Parameters

string $uri

The URI to simulate, e.g., '/posts/10'

array $data

The DELETE data.

Return Value

TestResponse

The test response object

at line 288
protected void setUp()

Implements setUp function from TestCase class.

Return Value

void