Skip to content

ch08_testing

Daniel Samson edited this page Jul 6, 2022 · 2 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()
    {
        router(function () {
           route(method(GET), '/', function() {
               json_out(['data' => 'foo']);
           })
        });
        $this->expectOutputString('{"data":"foo"}');
        $this->assertEquals(500, http_response_code());
    }

}
Clone this wiki locally