Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Merge 6dc4cee into 34732e5
Browse files Browse the repository at this point in the history
  • Loading branch information
foaly-nr1 committed Nov 14, 2017
2 parents 34732e5 + 6dc4cee commit 8ea1a78
Show file tree
Hide file tree
Showing 26 changed files with 310 additions and 572 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"symfony/yaml": ">=2.8.7"
},
"require-dev": {
"phpunit/phpunit": "^5.2",
"phpunit/phpunit-mock-objects": "^3.1",
"phpunit/phpunit": "^6.4",
"mikey179/vfsStream": "^1.6",
"doctrine/cache": "^1.6",
"satooshi/php-coveralls": "^1.0"
Expand Down
7 changes: 2 additions & 5 deletions tests/Description/Builder/OpenApi/ArrayReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ protected function setUp()
$this->setUpDescription('tests/definitions/openapi/data.yml');
}

/**
* @test
*/
public function arrayReferenceSchemaIsArraySchema()
public function testArrayReferenceSchemaIsArraySchema()
{
$this->assertInstanceOf(
self::assertInstanceOf(
ArraySchema::class,
$this->description
->getPath('/entity/{type}/findByCriteria')
Expand Down
28 changes: 8 additions & 20 deletions tests/Description/Builder/OpenApi/ExtensionsApiBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,24 @@ protected function setUp()
$this->setUpDescription('tests/definitions/openapi/extensions.yml');
}

/**
* @test
*/
public function getGetRootExtension()
public function testGetGetRootExtension()
{
$this->assertSame('foo.bar', $this->description->getExtension('root'));
self::assertSame('foo.bar', $this->description->getExtension('root'));
}

/**
* @test
*/
public function getGetPathsExtension()
public function testGetGetPathsExtension()
{
$this->assertSame('bar.foo', $this->description->getExtension('router'));
self::assertSame('bar.foo', $this->description->getExtension('router'));
}

/**
* @test
*/
public function getGetPathItemExtension()
public function testGetGetPathItemExtension()
{
$this->assertSame('doh.foo', $this->description->getPath('/entity/{type}')->getExtension('router-controller'));
self::assertSame('doh.foo', $this->description->getPath('/entity/{type}')->getExtension('router-controller'));
}

/**
* @test
*/
public function canGetOperationExtension()
public function testCanGetOperationExtension()
{
$this->assertSame(
self::assertSame(
'bar.doh',
$this->description->getPath('/entity/{type}')->getOperation('get')->getExtension('router-controller')
);
Expand Down
14 changes: 4 additions & 10 deletions tests/Description/Builder/OpenApi/PathParamApiBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,19 @@ protected function setUp()
$this->setUpDescription('tests/definitions/openapi/data.yml');
}

/**
* @test
*/
public function canGetPathParameters()
public function testCanGetPathParameters()
{
$this->assertCount(
self::assertCount(
1,
$this->description
->getPath('/entity/{type}')
->getPathParameters()
);
}

/**
* @test
*/
public function canGetPathParametersFromOperationObject()
public function testCanGetPathParametersFromOperationObject()
{
$this->assertInstanceOf(
self::assertInstanceOf(
Parameter::class,
$this->description
->getPath('/entity/{type}')
Expand Down
75 changes: 22 additions & 53 deletions tests/Description/Builder/OpenApi/PetStoreBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,12 @@ protected function setUp()
$this->setUpDescription('tests/definitions/openapi/petstore.yml');
}


/**
* @test
*/
public function hasComplexTypes()
public function testHasComplexTypes()
{
/** @var ComplexType[] $types */
$types = [];
foreach ($this->description->getComplexTypes() as $type) {
$this->assertInstanceOf(ComplexType::class, $type);
self::assertInstanceOf(ComplexType::class, $type);
$types[$type->getName()] = $type;
}
$expected = [
Expand All @@ -43,29 +39,23 @@ public function hasComplexTypes()
'Order',
'User',
];
$this->assertSame($expected, array_keys($types));
self::assertSame($expected, array_keys($types));
/** @var ObjectSchema $propertySchema */
$propertySchema = $types['Pet']->getSchema()->getPropertySchema('category');
$this->assertSame($propertySchema->getComplexType(), $types['Category']);
$this->assertTrue($types['Pet']->getSchema()->getPropertySchema('category')->isType($types['Category']));
self::assertSame($propertySchema->getComplexType(), $types['Category']);
self::assertTrue($types['Pet']->getSchema()->getPropertySchema('category')->isType($types['Category']));
}

/**
* @test
*/
public function unknownPathThrowsException()
public function testUnknownPathThrowsException()
{
$this->setExpectedException(\InvalidArgumentException::class);
self::expectException(\InvalidArgumentException::class);

$this->description->getPath('foo');
}

/**
* @test
*/
public function canGetCollectionFormatFromParameter()
public function testCanGetCollectionFormatFromParameter()
{
$this->assertSame(
self::assertSame(
'multi',
$this->description
->getPath('/pets/findByStatus')
Expand All @@ -75,41 +65,29 @@ public function canGetCollectionFormatFromParameter()
);
}

/**
* @test
*/
public function unknownMethodThrowsException()
public function testUnknownMethodThrowsException()
{
$this->setExpectedException(\InvalidArgumentException::class);
self::expectException(\InvalidArgumentException::class);

$this->description->getPath('/pets')->getOperation('get');
}

/**
* @test
*/
public function unknownStatusCodeThrowsException()
public function testUnknownStatusCodeThrowsException()
{
$this->setExpectedException(\InvalidArgumentException::class);
self::expectException(\InvalidArgumentException::class);

$this->description->getPath('/pets')->getOperation('post')->getResponse(123);
}

/**
* @test
*/
public function canGetDefaultResponse()
public function testCanGetDefaultResponse()
{
$this->assertInstanceOf(
self::assertInstanceOf(
Response::class,
$this->description->getPath('/users')->getOperation('post')->getResponse(123)
);
}

/**
* @test
*/
public function canGetSupportedStatusCodes()
public function testCanGetSupportedStatusCodes()
{
$map = [
'/pets' => ['post' => [405, 200], 'put' => [405, 404, 400, 200]],
Expand All @@ -134,7 +112,7 @@ public function canGetSupportedStatusCodes()

foreach ($this->description->getPaths() as $path) {
foreach ($path->getOperations() as $operation) {
$this->assertSame(
self::assertSame(
$map[$operation->getPath()][$operation->getMethod()],
$operation->getStatusCodes(),
"Mismatch for operation {$operation->getId()}"
Expand All @@ -143,25 +121,16 @@ public function canGetSupportedStatusCodes()
}
}

/**
* @test
*/
public function canGetRequestBodyParameter()
public function testCanGetRequestBodyParameter()
{
$this->assertInstanceOf(Parameter::class, $this->description->getRequestBodyParameter('/pets', 'post'));
self::assertInstanceOf(Parameter::class, $this->description->getRequestBodyParameter('/pets', 'post'));
}

/**
* @test
*/
public function getRequestBodyParameterWillReturnNullIfNonExistent()
public function testGetRequestBodyParameterWillReturnNullIfNonExistent()
{
$this->assertNull($this->description->getRequestBodyParameter('/pets/findByStatus', 'get'));
self::assertNull($this->description->getRequestBodyParameter('/pets/findByStatus', 'get'));
}

/**
* @test
*/
public function testGetters()
{
$map = [
Expand All @@ -171,7 +140,7 @@ public function testGetters()

];
foreach ($map as $methodName => $value) {
$this->assertSame($value, $this->description->$methodName());
self::assertSame($value, $this->description->$methodName());
}
}
}
21 changes: 6 additions & 15 deletions tests/Description/Builder/OpenApi/SecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,29 @@ protected function setUp()
$this->setUpDescription('tests/definitions/openapi/mixed-security.yml');
}

/**
* @test
*/
public function noSecurityMarksOperationUnsecured()
public function testNoSecurityMarksOperationUnsecured()
{
$this->assertFalse(
self::assertFalse(
$this->description
->getPath('/none')
->getOperation('get')
->isSecured()
);
}

/**
* @test
*/
public function apiKeySecurityMarksOperationSecured()
public function testApiKeySecurityMarksOperationSecured()
{
$this->assertTrue(
self::assertTrue(
$this->description
->getPath('/apiKey')
->getOperation('get')
->isSecured()
);
}

/**
* @test
*/
public function oauth2SecurityMarksOperationSecured()
public function testOauth2SecurityMarksOperationSecured()
{
$this->assertTrue(
self::assertTrue(
$this->description
->getPath('/oauth2')
->getOperation('get')
Expand Down
26 changes: 9 additions & 17 deletions tests/Description/Builder/OpenApiBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
use KleijnWeb\PhpApi\Descriptions\Description\Document\Definition\RefResolver\RefResolver;
use KleijnWeb\PhpApi\Descriptions\Description\Document\Document;
use KleijnWeb\PhpApi\Descriptions\Description\Schema\Schema;
use PHPUnit\Framework\TestCase;

/**
* @author John Kleijn <john@kleijnweb.nl>
*/
abstract class OpenApiBuilderTest extends \PHPUnit_Framework_TestCase
abstract class OpenApiBuilderTest extends TestCase
{
/**
* @var Description
Expand All @@ -45,35 +46,26 @@ protected function setUpDescription(string $uri)
$this->description = $builder->build();
}

/**
* @test
*/
public function isSerializable()
public function testIsSerializable()
{
$this->assertEquals(unserialize(serialize($this->description)), $this->description);
self::assertEquals(unserialize(serialize($this->description)), $this->description);
}

/**
* @test
*/
public function canGetRequestSchema()
public function testCanGetRequestSchema()
{
foreach ($this->description->getPaths() as $path) {
foreach ($path->getOperations() as $operation) {
$actual = $this->description->getRequestSchema($operation->getPath(), $operation->getMethod());
$this->assertInstanceOf(Schema::class, $actual);
self::assertInstanceOf(Schema::class, $actual);
$definition = $actual->getDefinition();
foreach ($operation->getParameters() as $parameter) {
$this->assertObjectHasAttribute($parameter->getName(), $definition->properties);
self::assertObjectHasAttribute($parameter->getName(), $definition->properties);
}
}
}
}

/**
* @test
*/
public function canGetResponseSchema()
public function testCanGetResponseSchema()
{
foreach ($this->description->getPaths() as $path) {
foreach ($path->getOperations() as $operation) {
Expand All @@ -83,7 +75,7 @@ public function canGetResponseSchema()
$operation->getMethod(),
$response->getCode()
);
$this->assertInstanceOf(Schema::class, $actual);
self::assertInstanceOf(Schema::class, $actual);
}
}
}
Expand Down
Loading

0 comments on commit 8ea1a78

Please sign in to comment.