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

Commit

Permalink
Updated docs for latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kleijnweb committed Sep 19, 2015
1 parent 61fed20 commit 296bd2d
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Any of these will work (assuming the `in: body` parameter is named `body` in you
public function placeOrder(Request $request)
{
/** @var array $order */
$order = $request->getContent();
$order = $request->attributes->get('body');

//...
}
Expand All @@ -103,6 +103,9 @@ public function placeOrder(array $body)
}
```

__NOTE:__ SwaggerBundle applies some type conversion to input and adds the converted types to the Request `attributes`.
Using `Request::get()` will give precedence to parameters in `query`. These values will be 'raw', using `attributes` is preferred.

Your controllers do not need to implement any interfaces or extend any classes. A controller might look like this (using object deserialization, see section below):

```php
Expand Down Expand Up @@ -183,22 +186,22 @@ parameters:
$ref: '#/definitions/Pet'
```

Similar to arrays, you may use the reference the parameter in your controller signature, or use `$request->getContent()`:
Similar to arrays, you may use the reference the parameter in your controller signature, or use `attributes`:


```php
public function placeOrder(Request $request)
public function placeOrder(Order $body)
{
/** @var Order $order */
$order = $request->getContent();

//...
//...
}
```

```php
public function placeOrder(Order $body)
public function placeOrder(Request $request)
{
//...
/** @var Order $order */
$order = $request->attributes->get('body');

//...
}
```

Expand Down Expand Up @@ -351,12 +354,14 @@ See `app/console swagger:generate:resources --help` for more details.

## Functional Testing Your API

The easiest way to create functional tests for your API, is by extending `ApiTestCase`. This will provide you with some convenience methods (`get()`, `post()`, `put()`, etc) and
The easiest way to create functional tests for your API, is by using mixin `ApiTestCase`. This will provide you with some convenience methods (`get()`, `post()`, `put()`, etc) and
will validate responses using SwaggerAssertions to ensure the responses received are compliant with your Swagger spec. Example:

```php
class PetStoreApiTest extends ApiTestCase
class PetStoreApiTest extends WebTestCase
{
use ApiTestCase;

/**
* Use config_basic.yml
*
Expand All @@ -371,13 +376,12 @@ class PetStoreApiTest extends ApiTestCase
*/
protected $validateErrorResponse = false;


/**
* Init response validation, point to your spec
*/
public static function setUpBeforeClass()
{
parent::initSchemaManager(__DIR__ . '/path/to/a/spec.yml');
static::initSchemaManager(__DIR__ . '/path/to/a/spec.yml');
}

/**
Expand Down

0 comments on commit 296bd2d

Please sign in to comment.