Testing

Webisters Testing extends PHPUnit with base classes and HTTP/CLI assertions tuned for Webisters apps. You get a real App instance per test, painless request simulation, and expressive matchers for status codes, headers, and response bodies.

Installation

composer require --dev webisters/testing

This pulls in PHPUnit as a transitive dependency.

Writing a test

Extend TestCase and use the AppTesting trait to boot a fresh app inside each test:

use Framework\Testing\TestCase;
use Framework\Testing\AppTesting;

final class HomePageTest extends TestCase
{
    use AppTesting;

    public function testHomepageReturnsWelcome(): void
    {
        $response = $this->get('/');

        $this->assertResponseStatus(200, $response);
        $this->assertResponseBodyContains('Welcome', $response);
    }
}

HTTP assertions

The library ships PHPUnit constraints for everything you typically check on a response:

$this->assertResponseStatus(201, $response);
$this->assertResponseStatusCode(204, $response);
$this->assertResponseStatusReason('OK', $response);
$this->assertResponseContainsHeader('Content-Type', $response);
$this->assertResponseHeader('Content-Type', 'application/json', $response);
$this->assertResponseBodyContains('{"id":42}', $response);
$this->assertResponseBodyNotContains('error', $response);
$this->assertMatchedRouteName('users.show', $router);

CLI assertions

Constraints for testing console commands — check what landed on stdout/stderr:

$this->assertStdoutContains('Migration applied', $command);
$this->assertStdoutNotContains('error', $command);
$this->assertStderrContains('warning', $command);
$this->assertStderrNotContains('fatal', $command);

Running tests

Use PHPUnit directly:

vendor/bin/phpunit
vendor/bin/phpunit tests/Feature
vendor/bin/phpunit --filter testHomepageReturnsWelcome

Conclusion

Treat your tests like a second client of the framework — the more you write, the more confidence you have to refactor freely.

Did you find something wrong? Be sure to let us know with an issue. Thank you!