Skip to content

Commit

Permalink
Add spec fixtures to validate reflection analyser results
Browse files Browse the repository at this point in the history
  • Loading branch information
DerManoMann committed Aug 26, 2021
1 parent d15547d commit 65fde13
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 6 deletions.
10 changes: 6 additions & 4 deletions tests/Analysers/ReflectionAnalyserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ public function testSingleFileDocBlock()
$operations = $analysis->getAnnotationsOfType(Operation::class);
$this->assertIsArray($operations);

file_put_contents(__DIR__ . '/basic_docblocks.yml', $analysis->openapi->toYaml());

$spec = $this->fixture('Apis/DocBlocks/basic.yaml');
//file_put_contents($spec, $analysis->openapi->toYaml());
$this->assertTrue($analysis->validate());
$this->assertSpecEquals(file_get_contents($spec), $analysis->openapi);
}

/**
Expand All @@ -93,8 +94,9 @@ public function testSingleFileAttributes()
$operations = $analysis->getAnnotationsOfType(Operation::class);
$this->assertIsArray($operations);

file_put_contents(__DIR__ . '/basic_attributes.yml', $analysis->openapi->toYaml());

$spec = $this->fixture('Apis/Attributes/basic.yaml');
//file_put_contents($spec, $analysis->openapi->toYaml());
$this->assertTrue($analysis->validate());
$this->assertSpecEquals(file_get_contents($spec), $analysis->openapi);
}
}
2 changes: 1 addition & 1 deletion tests/Fixtures/Apis/Attributes/basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use OpenApi\Annotations as OA;

#[OA\Info(version: '1.0.0', title: 'Basic single file Php8 API')]
#[OA\Info(version: '1.0.0', title: 'Basic single file Attributes API')]
class OpenApiSpec
{

Expand Down
38 changes: 38 additions & 0 deletions tests/Fixtures/Apis/Attributes/basic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
openapi: 3.0.0
info:
title: 'Basic single file Attributes API'
version: 1.0.0
paths:
'/products/{product_id}':
get:
tags:
- Products
operationId: ce0e618e1b2e89d5464e39a96cc178dd
responses:
'200':
description: 'successful operation'
content:
application/json:
schema:
$ref: '#/components/schemas/Product'
'401':
description: oops
components:
schemas:
NameTrait:
properties:
name:
description: 'The name.'
type: object
Product:
title: Product
description: Product
allOf:
-
$ref: '#/components/schemas/NameTrait'
-
properties:
id:
description: 'The id.'
format: int64
example: 1
2 changes: 1 addition & 1 deletion tests/Fixtures/Apis/DocBlocks/basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* @OA\Info(
* version="1.0.0",
* title="Basic single file API"
* title="Basic single file DocBlocks API"
* )
*/
class OpenApiSpec
Expand Down
38 changes: 38 additions & 0 deletions tests/Fixtures/Apis/DocBlocks/basic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
openapi: 3.0.0
info:
title: 'Basic single file DocBlocks API'
version: 1.0.0
paths:
'/products/{product_id}':
get:
tags:
- Products
operationId: 430e769e8375f88711f6a2c5ad8b5dee
responses:
'200':
description: 'successful operation'
content:
application/json:
schema:
$ref: '#/components/schemas/Product'
'401':
description: oops
components:
schemas:
NameTrait:
properties:
name:
description: 'The name.'
type: object
Product:
title: Product
description: Product
allOf:
-
$ref: '#/components/schemas/NameTrait'
-
properties:
id:
description: 'The id.'
format: int64
example: 1

0 comments on commit 65fde13

Please sign in to comment.