Skip to content

Commit

Permalink
add api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Apr 23, 2016
1 parent cd94ce3 commit 9918ed3
Show file tree
Hide file tree
Showing 25 changed files with 518 additions and 137 deletions.
17 changes: 9 additions & 8 deletions tests/Api/Generator/RamlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class RamlTest extends ApiTestCase
{
public function testGet()
{
$response = $this->sendRequest('http://127.0.0.1/generator/raml/*/population/annotation', 'GET');
$response = $this->sendRequest('http://127.0.0.1/generator/raml/*/population/popo', 'GET');

$body = (string) $response->getBody();
$expect = <<<'RAML'
Expand All @@ -18,7 +18,7 @@ public function testGet()
baseUri: 'http://127.0.0.1/'
version: v0
title: Population
/population/annotation:
/population/popo:
description: 'Collection endpoint'
get:
queryParameters:
Expand All @@ -40,7 +40,7 @@ public function testGet()
"title": "collection",
"description": "Collection result",
"definitions": {
"ref11097597650a2b8da8978e836e225413": {
"ref4fe78e9f8d9266767f15f9b094d00e9d": {
"type": "object",
"properties": {
"id": {
Expand All @@ -66,7 +66,7 @@ public function testGet()
"type": "integer",
"description": "Number of internet users"
},
"world_users": {
"worldUsers": {
"type": "number",
"description": "Percentage users of the world"
},
Expand All @@ -82,8 +82,9 @@ public function testGet()
"region",
"population",
"users",
"world_users"
"worldUsers"
],
"reference": "PSX\\Project\\Tests\\Model\\Entity",
"additionalProperties": false
}
},
Expand All @@ -94,7 +95,7 @@ public function testGet()
"entry": {
"type": "array",
"items": {
"$ref": "#\/definitions\/ref11097597650a2b8da8978e836e225413"
"$ref": "#\/definitions\/ref4fe78e9f8d9266767f15f9b094d00e9d"
},
"title": "entry"
}
Expand Down Expand Up @@ -135,7 +136,7 @@ public function testGet()
"type": "integer",
"description": "Number of internet users"
},
"world_users": {
"worldUsers": {
"type": "number",
"description": "Percentage users of the world"
},
Expand All @@ -149,7 +150,7 @@ public function testGet()
"region",
"population",
"users",
"world_users"
"worldUsers"
],
"additionalProperties": false
}
Expand Down
36 changes: 21 additions & 15 deletions tests/Api/Generator/SwaggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ public function testGet()
"apiVersion": "1.0",
"apis": [
{
"path": "\/*\/population\/annotation"
"path": "\/*\/population\/popo"
},
{
"path": "\/*\/population\/annotation\/{id}"
"path": "\/*\/population\/popo\/{id}"
},
{
"path": "\/*\/population\/jsonschema"
},
{
"path": "\/*\/population\/jsonschema\/{id}"
},
{
"path": "\/*\/population\/raml"
Expand All @@ -44,18 +50,18 @@ public function testGet()

public function testGetDetail()
{
$response = $this->sendRequest('http://127.0.0.1/generator/swagger/*/population/annotation', 'GET');
$response = $this->sendRequest('http://127.0.0.1/generator/swagger/*/population/popo', 'GET');

$body = (string) $response->getBody();
$expect = <<<'JSON'
{
"swaggerVersion": "1.2",
"apiVersion": 0,
"basePath": "http:\/\/127.0.0.1\/",
"resourcePath": "\/population\/annotation",
"resourcePath": "\/population\/popo",
"apis": [
{
"path": "\/population\/annotation",
"path": "\/population\/popo",
"description": "Collection endpoint",
"operations": [
{
Expand Down Expand Up @@ -116,15 +122,15 @@ public function testGetDetail()
}
}
},
"ref11097597650a2b8da8978e836e225413": {
"id": "ref11097597650a2b8da8978e836e225413",
"ref4fe78e9f8d9266767f15f9b094d00e9d": {
"id": "ref4fe78e9f8d9266767f15f9b094d00e9d",
"description": "Represents an internet population entity",
"required": [
"place",
"region",
"population",
"users",
"world_users"
"worldUsers"
],
"properties": {
"id": {
Expand All @@ -150,7 +156,7 @@ public function testGetDetail()
"type": "integer",
"description": "Number of internet users"
},
"world_users": {
"worldUsers": {
"type": "number",
"description": "Percentage users of the world"
},
Expand All @@ -160,8 +166,8 @@ public function testGetDetail()
}
}
},
"ref86e9674085c91e87e8e04206e7c53f16": {
"id": "ref86e9674085c91e87e8e04206e7c53f16",
"ref0eaf38a348f17dc3ce8660979b1d42e6": {
"id": "ref0eaf38a348f17dc3ce8660979b1d42e6",
"description": "Collection result",
"properties": {
"totalResults": {
Expand All @@ -170,7 +176,7 @@ public function testGetDetail()
"entry": {
"type": "array",
"items": {
"$ref": "ref11097597650a2b8da8978e836e225413"
"$ref": "ref4fe78e9f8d9266767f15f9b094d00e9d"
},
"title": "entry"
}
Expand Down Expand Up @@ -209,7 +215,7 @@ public function testGetDetail()
"entry": {
"type": "array",
"items": {
"$ref": "ref11097597650a2b8da8978e836e225413"
"$ref": "ref4fe78e9f8d9266767f15f9b094d00e9d"
},
"title": "entry"
}
Expand All @@ -223,7 +229,7 @@ public function testGetDetail()
"region",
"population",
"users",
"world_users"
"worldUsers"
],
"properties": {
"id": {
Expand All @@ -249,7 +255,7 @@ public function testGetDetail()
"type": "integer",
"description": "Number of internet users"
},
"world_users": {
"worldUsers": {
"type": "number",
"description": "Percentage users of the world"
},
Expand Down
14 changes: 7 additions & 7 deletions tests/Api/Generator/WsdlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class WsdlTest extends ApiTestCase
{
public function testGet()
{
$response = $this->sendRequest('http://127.0.0.1/generator/wsdl/*/population/annotation', 'GET');
$response = $this->sendRequest('http://127.0.0.1/generator/wsdl/*/population/popo', 'GET');

$body = (string) $response->getBody();
$expect = <<<XML
Expand All @@ -24,11 +24,11 @@ public function testGet()
</xs:annotation>
<xs:sequence>
<xs:element name="totalResults" type="xs:integer" minOccurs="0" maxOccurs="1"/>
<xs:element name="entry" type="tns:type11097597650a2b8da8978e836e225413" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="entry" type="tns:type4fe78e9f8d9266767f15f9b094d00e9d" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="type11097597650a2b8da8978e836e225413">
<xs:complexType name="type4fe78e9f8d9266767f15f9b094d00e9d">
<xs:annotation>
<xs:documentation>Represents an internet population entity</xs:documentation>
</xs:annotation>
Expand All @@ -38,7 +38,7 @@ public function testGet()
<xs:element name="region" type="tns:type223a14ad48026b2ee7c4dcf2b0d4c934" minOccurs="1" maxOccurs="1"/>
<xs:element name="population" type="xs:integer" minOccurs="1" maxOccurs="1"/>
<xs:element name="users" type="xs:integer" minOccurs="1" maxOccurs="1"/>
<xs:element name="world_users" type="xs:float" minOccurs="1" maxOccurs="1"/>
<xs:element name="worldUsers" type="xs:float" minOccurs="1" maxOccurs="1"/>
<xs:element name="datetime" type="xs:dateTime" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
Expand All @@ -63,7 +63,7 @@ public function testGet()
<xs:element name="region" type="tns:type223a14ad48026b2ee7c4dcf2b0d4c934" minOccurs="1" maxOccurs="1"/>
<xs:element name="population" type="xs:integer" minOccurs="1" maxOccurs="1"/>
<xs:element name="users" type="xs:integer" minOccurs="1" maxOccurs="1"/>
<xs:element name="world_users" type="xs:float" minOccurs="1" maxOccurs="1"/>
<xs:element name="worldUsers" type="xs:float" minOccurs="1" maxOccurs="1"/>
<xs:element name="datetime" type="xs:dateTime" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
Expand Down Expand Up @@ -124,7 +124,7 @@ public function testGet()
<wsdl:binding name="PopulationBinding" type="tns:PopulationPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getCollection">
<soap:operation soapAction="/population/annotation#GET"/>
<soap:operation soapAction="/population/popo#GET"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
Expand All @@ -136,7 +136,7 @@ public function testGet()
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="postEntity">
<soap:operation soapAction="/population/annotation#POST"/>
<soap:operation soapAction="/population/popo#POST"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace PSX\Project\Tests\Api\Population;

use PSX\Framework\Controller\AnnotationApiAbstract;
use PSX\Framework\Controller\SchemaApiAbstract;
use PSX\Record\RecordInterface;

/**
* @Title("Population")
* @Description("Collection endpoint")
*/
class CollectionAnnotation extends AnnotationApiAbstract
class CollectionJsonSchema extends SchemaApiAbstract
{
/**
* @Inject
Expand All @@ -34,14 +34,14 @@ protected function doGet()
* @Incoming(schema="../../Resource/schema/population/entity.json")
* @Outgoing(code=201, schema="../../Resource/schema/population/message.json")
*/
protected function doPost(RecordInterface $record)
protected function doPost($record)
{
$this->populationService->create(
$record['place'],
$record['region'],
$record['population'],
$record['users'],
$record['world_users']
$record['worldUsers']
);

return [
Expand Down
52 changes: 52 additions & 0 deletions tests/Api/Population/CollectionPopo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace PSX\Project\Tests\Api\Population;

use PSX\Framework\Controller\SchemaApiAbstract;
use PSX\Framework\Annotation\Inject;

/**
* @Title("Population")
* @Description("Collection endpoint")
*/
class CollectionPopo extends SchemaApiAbstract
{
/**
* @Inject
* @var \PSX\Project\Tests\Service\Population
*/
protected $populationService;

/**
* @QueryParam(name="startIndex", type="integer")
* @QueryParam(name="count", type="integer")
* @Outgoing(code=200, schema="PSX\Project\Tests\Model\Collection")
*/
protected function doGet()
{
return $this->populationService->getAll(
$this->queryParameters->getProperty('startIndex'),
$this->queryParameters->getProperty('count')
);
}

/**
* @Incoming(schema="PSX\Project\Tests\Model\Entity")
* @Outgoing(code=201, schema="PSX\Project\Tests\Model\Message")
*/
protected function doPost($record)
{
$this->populationService->create(
$record->getPlace(),
$record->getRegion(),
$record->getPopulation(),
$record->getUsers(),
$record->getWorldUsers()
);

return [
'success' => true,
'message' => 'Create population successful',
];
}
}
4 changes: 2 additions & 2 deletions tests/Api/Population/CollectionRaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ protected function doGet()
);
}

protected function doPost(RecordInterface $record)
protected function doPost($record)
{
$this->populationService->create(
$record['place'],
$record['region'],
$record['population'],
$record['users'],
$record['world_users']
$record['worldUsers']
);

return [
Expand Down

0 comments on commit 9918ed3

Please sign in to comment.