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

refactored WebTestCase into a trait #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Test/JsonTestTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* This file is part of the RestExtraBundle package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

namespace Bazinga\Bundle\RestExtraBundle\Test;

/**
* @author William Durand <[email protected]>
*/
trait JsonTestTrait
{
protected function assertJsonResponse($response, $statusCode = 200)
{
$this->assertEquals(
$statusCode, $response->getStatusCode(),
$response->getContent()
);
$this->assertTrue(
$response->headers->contains('Content-Type', 'application/json'),
$response->headers
);
}

protected function jsonRequest($verb, $endpoint, array $data = array())
{
$data = empty($data) ? null : json_encode($data);

return $this->client->request($verb, $endpoint,
array(),
array(),
array(
'HTTP_ACCEPT' => 'application/json',
'CONTENT_TYPE' => 'application/json'
),
$data
);
}
}
27 changes: 1 addition & 26 deletions Test/WebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,5 @@
*/
abstract class WebTestCase extends BaseWebTestCase
{
protected function assertJsonResponse($response, $statusCode = 200)
{
$this->assertEquals(
$statusCode, $response->getStatusCode(),
$response->getContent()
);
$this->assertTrue(
$response->headers->contains('Content-Type', 'application/json'),
$response->headers
);
}

protected function jsonRequest($verb, $endpoint, array $data = array())
{
$data = empty($data) ? null : json_encode($data);

return $this->client->request($verb, $endpoint,
array(),
array(),
array(
'HTTP_ACCEPT' => 'application/json',
'CONTENT_TYPE' => 'application/json'
),
$data
);
}
use JsonTestTrait;
}