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

Commit

Permalink
Fixes #30
Browse files Browse the repository at this point in the history
  • Loading branch information
kleijnweb committed Sep 19, 2015
1 parent 0b164f6 commit 61fed20
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 30 deletions.
25 changes: 5 additions & 20 deletions src/Dev/Test/ApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,15 @@
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
use org\bovigo\vfs\vfsStreamWrapper;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Yaml\Yaml;

/**
* @author John Kleijn <john@kleijnweb.nl>
*/
abstract class ApiTestCase extends WebTestCase
trait ApiTestCase
{
use AssertsTrait;

/**
* @var string
*/
protected $env = 'test';

/**
* @var SchemaManager
*/
Expand All @@ -44,16 +38,6 @@ abstract class ApiTestCase extends WebTestCase
*/
protected $client;

/**
* @var array
*/
protected $defaultServerVars = [];

/**
* @var bool
*/
protected $validateErrorResponse = true;

/**
* PHPUnit cannot add this to code coverage
*
Expand Down Expand Up @@ -82,7 +66,7 @@ public static function initSchemaManager($swaggerPath)
*/
protected function setUp()
{
$this->client = static::createClient(['environment' => $this->env]);
$this->client = static::createClient(['environment' => $this->env ?: 'test']);

parent::setUp();
}
Expand Down Expand Up @@ -163,7 +147,8 @@ protected function put($path, array $content, array $params = [])
protected function sendRequest($path, $method, array $params = [], array $content = null)
{
$request = new ApiRequest($this->assembleUri($path, $params), $method);
$request->setServer(array_merge($this->defaultServerVars, ['CONTENT_TYPE' => 'application/json']));
$defaults = isset($this->defaultServerVars) ? $this->defaultServerVars : [];
$request->setServer(array_merge($defaults ?: [], ['CONTENT_TYPE' => 'application/json']));
if ($content !== null) {
$request->setContent(json_encode($content));
}
Expand Down Expand Up @@ -211,7 +196,7 @@ private function getJsonForLastRequest($fullPath, $method)
$json = json_decode($responseContent);

if ($response->getStatusCode() !== 200) {
if ($this->validateErrorResponse) {
if (!isset($this->validateErrorResponse) || !$this->validateErrorResponse) {
$this->assertResponseBodyMatch(
$json,
self::$schemaManager,
Expand Down
7 changes: 5 additions & 2 deletions src/Tests/Functional/BasicPetStoreApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
namespace KleijnWeb\SwaggerBundle\Tests\Functional;

use KleijnWeb\SwaggerBundle\Dev\Test\ApiTestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

/**
* @author John Kleijn <john@kleijnweb.nl>
*/
class BasicPetStoreApiTest extends ApiTestCase
class BasicPetStoreApiTest extends WebTestCase
{
use ApiTestCase;

/**
* Use config_basic.yml
*
Expand All @@ -33,7 +36,7 @@ class BasicPetStoreApiTest extends ApiTestCase

public static function setUpBeforeClass()
{
parent::initSchemaManager(__DIR__ . '/PetStore/app/petstore.yml');
static::initSchemaManager(__DIR__ . '/PetStore/app/petstore.yml');
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/Tests/Functional/SecuredPetStoreApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@

use KleijnWeb\SwaggerBundle\Dev\Test\ApiTestCase;
use KleijnWeb\SwaggerBundle\Tests\Security\Authenticator\JwtAuthenticatorTest;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

/**
* @author John Kleijn <john@kleijnweb.nl>
*/
class SecuredPetStoreApiTest extends ApiTestCase
class SecuredPetStoreApiTest extends WebTestCase
{
use ApiTestCase;

// @codingStandardsIgnoreStart
const KEY_ONE_TOKEN = JwtAuthenticatorTest::TEST_TOKEN;
const KEY_TWO_TOKEN = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtleVR3byJ9.eyJwcm4iOiJqb2huIiwiaXNzIjoiaHR0cDovL2FwaS5zZXJ2ZXIyLmNvbS9vYXV0aDIvdG9rZW4ifQ.vdGhD5E4Ibj2Tndlh_0pPgJsOuRUpAn1QYu5miB6qwjrXhKCicuTKOuC9x2_2ErUOApv5KiblYds_gcWONdGKx1tQyQa1dsuhrkiVn_VJAsaaix8nJiHAuNv-ukm8mnSWJoVuOcTQIQG8IaupviyphEAEdjrm9QQhvzERgdFUT4bdCdfywrC37oYEAH5bHpiiUK2UzyNuUIHwOP_gWODodbEWRJOxtefwJ_vdpqHvSZzyW7Vei4mCtr2vE1k2qBvG_Qjw2ebLfEdX58k6-eYa7phle9hYjA_q-I8Y-S1ulBiVf_tpvayk8-4lWup9Wbg_BT2vDJOidQgM4l9jV9QHg';
Expand All @@ -39,7 +42,7 @@ class SecuredPetStoreApiTest extends ApiTestCase

public static function setUpBeforeClass()
{
parent::initSchemaManager(__DIR__ . '/PetStore/app/petstore.yml');
static::initSchemaManager(__DIR__ . '/PetStore/app/petstore.yml');
}

/**
Expand Down
11 changes: 5 additions & 6 deletions src/Tests/Functional/SerializationPetStoreApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@

namespace KleijnWeb\SwaggerBundle\Tests\Functional;

use JMS\Serializer\Serializer;
use KleijnWeb\SwaggerBundle\Dev\Test\ApiTestCase;
use KleijnWeb\SwaggerBundle\Request\ContentDecoder;
use KleijnWeb\SwaggerBundle\Serializer\SerializationTypeResolver;
use KleijnWeb\SwaggerBundle\Serializer\SerializerAdapter;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

/**
* @author John Kleijn <john@kleijnweb.nl>
*/
class SerializationPetStoreApiTest extends ApiTestCase
class SerializationPetStoreApiTest extends WebTestCase
{
use ApiTestCase;

/**
* Use config_jms.yml
*
Expand All @@ -39,7 +38,7 @@ class SerializationPetStoreApiTest extends ApiTestCase
*/
public static function setUpBeforeClass()
{
parent::initSchemaManager(__DIR__ . '/PetStore/app/petstore.yml');
static::initSchemaManager(__DIR__ . '/PetStore/app/petstore.yml');
}

/**
Expand Down

0 comments on commit 61fed20

Please sign in to comment.