1. Go to this page and download the library: Download n4m-ward/laravel-perry 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/ */
n4m-ward / laravel-perry example snippets
namespace Tests\Perry;
use Perry\Attributes\Info;
use Perry\Attributes\Server;
use Perry\Attributes\Servers;
use Perry\PerryHttp\PerryHttpRequest;
use Illuminate\Foundation\Testing\TestCase as LaravelTestCase;
#[Servers(
new Server(description: 'Example server local', url: 'http://localhost:8000')
)]
#[Info(
version: '1.0.0',
title: 'Example server title',
description: 'Example server description',
contactEmail: '[email protected]',
termsOfService: 'https://example.com/terms-of-service', // optional parameter
externalDocs: new ExternalDocs( // optional parameter
url: 'https://example.com/external-docs',
description: 'Find more info here',
),
)]
abstract class BaseTestCase extends LaravelTestCase
{
use PerryHttpRequest;
}
public function test_exampleWithHeaders(): void
{
$this
->perryHttp()
->withHeaders([
'Authorization' => 'Bearer token',
])
->get('/api/example');
}
public function test_exampleWithHeaders(): void
{
$this
->perryHttp()
->withBody([
'foo' => 'bar',
])
->post('/api/example');
}
public function test_exampleWithHeadersAndBody(): void
{
$this
->perryHttp()
->withHeaders([
'Authorization' => 'Bearer token',
])
->withBody([
'foo' => 'bar',
])
->post('/api/example');
}
public function test_get(): void
{
$this->perryHttp()->get('/api/example/123');
}
public function test_post(): void
{
$this
->perryHttp()
->withBody(['foo' => 'bar'])
->post('/api/example');
}
public function test_put(): void
{
$this
->perryHttp()
->withBody(['foo' => 'bar'])
->put('/api/example/123');
}
public function test_patch(): void
{
$this
->perryHttp()
->withBody(['foo' => 'bar'])
->patch('/api/example/123');
}
public function test_delete(): void
{
$this->perryHttp()->delete('/api/example/123');
}
#[UseSecurityScheme('BearerToken')]
public function test_shouldCreateUser(): void
{
}
#[\Perry\Attributes\Tag\Tag(name: 'User', description: "User related endpoints")]
class SomeTest extends BaseTestCase {}
#[\Perry\Attributes\Tag\Tag(
name: 'User',
description: "User related endpoints"
externalDocs: new \Perry\Attributes\ExternalDocs(
url: 'https://example.com/external-docs',
description: 'Find more info here',
)]
class SomeTest extends BaseTestCase {}
#[\Perry\Attributes\Tag\UsingTag('User')]
public function test_shouldCreateUser(): void
{
}