-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathLocalFileTest.php
53 lines (41 loc) · 1.38 KB
/
LocalFileTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
declare(strict_types=1);
use FR3D\SwaggerAssertions\PhpUnit\AssertsTrait;
use FR3D\SwaggerAssertions\SchemaManager;
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Psr7\Request;
use PHPUnit\Framework\TestCase;
/**
* PHPUnit integration example.
*/
class LocalFileTest extends TestCase
{
use AssertsTrait;
/**
* @var SchemaManager
*/
protected static $schemaManager;
/**
* @var ClientInterface
*/
protected $guzzleHttpClient;
public static function setUpBeforeClass(): void
{
$filePath = __DIR__ . '/../fixtures/pet_store.json';
// Use file:// for local files
self::$schemaManager = new SchemaManager(json_decode(file_get_contents($filePath)));
}
protected function setUp(): void
{
$this->guzzleHttpClient = new Client(['headers' => ['User-Agent' => 'https://github.com/Maks3w/SwaggerAssertions']]);
}
public function testFetchPetBodyMatchDefinition(): void
{
$request = new Request('GET', 'http://petstore.swagger.io/v2/pet/findByStatus');
$request = $request->withHeader('Accept', 'application/json');
$response = $this->guzzleHttpClient->send($request);
$responseBody = json_decode((string) $response->getBody());
self::assertResponseBodyMatch($responseBody, self::$schemaManager, '/v2/pet/findByStatus', 'get', 200);
}
}