Writing and Running Tests

In this example, we will create a simple test case to validate a method from the “Quick Start” tutorial. To create a new test case, use the make:test Artisan command:

php artisan make:test PingPongTest

To make things easier, the Sajya delivery package includes a trait called ProceduralRequests which we can add to our test class:

namespace Tests\Feature;

use Sajya\Server\Testing\ProceduralRequests;
use Tests\TestCase;

class PingPongTest extends TestCase
{
    use ProceduralRequests;
    
    //...
}

Next, we will modify the generated example to refer to our procedure server:

namespace Tests\Feature;

use Sajya\Server\Testing\ProceduralRequests;
use Tests\TestCase;

class PingPongTest extends TestCase
{
    use ProceduralRequests;

    /**
     * A basic RPC test example.
     *
     * @return void
     */
    public function testPingPong()
    {
        $this
            ->setRpcRoute('rpc.endpoint')
            ->callProcedure('tennis@ping')
            ->assertJsonFragment([
                'result' => 'pong',
            ]);
    }
}

To run the test, use the following command:

php artisan test

For more information on testing in Laravel, you can refer to the Laravel documentation.