1. Go to this page and download the library: Download hotmeteor/spectator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hotmeteor / spectator example snippets
Spectator::withPathPrefix('v1');
Spectator::useJsonErrors(); // emit {"errors": [...]}
Spectator::useTextErrors(); // revert to coloured text
use Spectator\Spectator;
class UserApiTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
Spectator::using('Api.v1.yml');
}
#[Test]
public function test_using_different_spec(): void
{
Spectator::using('OtherApi.v1.yml');
// ...
}
}
use Spectator\Spectator;
class UserApiTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
Spectator::using('Api.v1.yml');
}
#[Test]
public function test_create_user(): void
{
$this->postJson('/users', ['name' => 'Alice', 'email' => '[email protected]'])
->assertValidRequest()
->assertValidResponse(201);
}
#[Test]
public function test_missing_
namespace Tests\Contract;
use Spectator\Spectator;
use Tests\TestCase;
class UsersContractTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
Spectator::using('Api.v1.yml');
}
public function test_get_users(): void
{
$this->markTestIncomplete('Implement: GET /users');
}
public function test_post_users(): void
{
$this->markTestIncomplete('Implement: POST /users');
}
}