PHP code example of kent013 / artisan-command-spectator-test

1. Go to this page and download the library: Download kent013/artisan-command-spectator-test 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/ */

    

kent013 / artisan-command-spectator-test example snippets


 declare(strict_types=1);

namespace Tests\Feature\Http\Api\V1;

use Spectator\Spectator;
use Tests\TestCase;

class OrganizationProjectTest extends TestCase
{
    public function setUp(): void
    {
        parent::setUp();
        Spectator::using('api.openapi3.json');
    }

    /**
     * get /api/v1/organization/{organization_id}/projects/{project_id} Get status code 200
     */
    public function testGet200(): void
    {
        $this->getJson('/api/v1/organization/1/projects/1')
            ->assertStatus(200)
            ->assertValidRequest()
            ->assertValidResponse();
    }

    /**
     * get /api/v1/organization/{organization_id}/projects/{project_id} Get status code 401
     */
    public function testGet401(): void
    {
        $this->getJson('/api/v1/organization/1/projects/1')
            ->assertStatus(401)
            ->assertValidRequest()
            ->assertValidResponse();
    }

    /**
     * get /api/v1/organization/{organization_id}/projects/{project_id} Get status code 403
     */
    public function testGet403(): void
    {
        $this->getJson('/api/v1/organization/1/projects/1')
            ->assertStatus(403)
            ->assertValidRequest()
            ->assertValidResponse();
    }

    /**
     * put /api/v1/organization/{organization_id}/projects/{project_id} Update status code 204
     */
    public function testUpdate204(): void
    {
        $requestBody = [
          'name' => 'Fofi',
          'description' => 'An Advanced Form Filler',
        ];
        $this->putJson('/api/v1/organization/1/projects/1', $requestBody)
            ->assertStatus(204)
            ->assertValidRequest()
            ->assertValidResponse();
    }

    /**
     * put /api/v1/organization/{organization_id}/projects/{project_id} Update status code 401
     */
    public function testUpdate401(): void
    {
        $requestBody = [
          'name' => 'Fofi',
          'description' => 'An Advanced Form Filler',
        ];
        $this->putJson('/api/v1/organization/1/projects/1', $requestBody)
            ->assertStatus(401)
            ->assertValidRequest()
            ->assertValidResponse();
    }

    /**
     * put /api/v1/organization/{organization_id}/projects/{project_id} Update status code 403
     */
    public function testUpdate403(): void
    {
        $requestBody = [
          'name' => 'Fofi',
          'description' => 'An Advanced Form Filler',
        ];
        $this->putJson('/api/v1/organization/1/projects/1', $requestBody)
            ->assertStatus(403)
            ->assertValidRequest()
            ->assertValidResponse();
    }

    /**
     * put /api/v1/organization/{organization_id}/projects/{project_id} Update status code 422
     */
    public function testUpdate422(): void
    {
        $requestBody = [
          'name' => 'Fofi',
          'description' => 'An Advanced Form Filler',
        ];
        $this->putJson('/api/v1/organization/1/projects/1', $requestBody)
            ->assertStatus(422)
            ->assertValidRequest()
            ->assertValidResponse();
    }
}

php artisan vendor:publish --tag="spectator-test"