Skip to content

ch08_testing

Daniel Samson edited this page Mar 7, 2025 · 3 revisions

Actions

Here is an example of how to test an action:

<?php

use PHPUnit\Framework\TestCase;


class RouterTest extends TestCase
{
    public function test_action()
    {
        $_GET['url'] = 'baz';
        router(function () {
           route(method(GET), '/baz', function() {
               json_out(['data' => 'foo']);
           })
        });
        $this->expectOutputString('{"data":"foo"}');
        $this->assertEquals(500, http_response_code());
    }

}

Clone this wiki locally