Skip to content

Commit f5335c2

Browse files
authored
Merge pull request #73 from pamil/moar-tests
Test & fix assertResponseContent for incorrect response given
2 parents 5d5586c + 7a885ae commit f5335c2

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed

src/ApiTestCase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ protected function assertResponseContent($actualResponse, $filename, $mimeType)
195195
$actualResponse = trim($actualResponse);
196196
$expectedResponse = trim(file_get_contents(PathBuilder::build($responseSource, sprintf('%s.%s', $filename, $mimeType))));
197197

198-
$result = (new SimpleFactory())->createMatcher()->match($actualResponse, $expectedResponse);
198+
$matcher = (new SimpleFactory())->createMatcher();
199+
$result = $matcher->match($actualResponse, $expectedResponse);
199200

200201
if (!$result) {
201202
$diff = new \Diff(explode(PHP_EOL, $expectedResponse), explode(PHP_EOL, $actualResponse), []);

test/src/Tests/Controller/SampleControllerJsonTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Lakion\ApiTestCase\Test\Tests\Controller;
1313

1414
use Lakion\ApiTestCase\JsonApiTestCase;
15+
use PHPUnit_Framework_AssertionFailedError;
1516

1617
/**
1718
* @author Łukasz Chruściel <[email protected]>
@@ -27,6 +28,18 @@ public function testGetHelloWorldResponse()
2728
$this->assertResponse($response, 'hello_world');
2829
}
2930

31+
/**
32+
* @expectedException PHPUnit_Framework_AssertionFailedError
33+
*/
34+
public function testGetHelloWorldIncorrectResponse()
35+
{
36+
$this->client->request('GET', '/');
37+
38+
$response = $this->client->getResponse();
39+
40+
$this->assertResponse($response, 'incorrect_hello_world');
41+
}
42+
3043
public function testGetHelloWorldWithMatcherResponse()
3144
{
3245
$this->client->request('GET', '/');

test/src/Tests/Controller/SampleControllerXmlTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Lakion\ApiTestCase\Test\Tests\Controller;
1313

1414
use Lakion\ApiTestCase\XmlApiTestCase;
15+
use PHPUnit_Framework_AssertionFailedError;
1516

1617
/**
1718
* @author Arkadiusz Krakowiak <[email protected]>
@@ -27,6 +28,18 @@ public function testGetHelloWorldResponse()
2728
$this->assertResponse($response, 'hello_world');
2829
}
2930

31+
/**
32+
* @expectedException PHPUnit_Framework_AssertionFailedError
33+
*/
34+
public function testGetHelloWorldIncorrectResponse()
35+
{
36+
$this->client->request('GET', '/');
37+
38+
$response = $this->client->getResponse();
39+
40+
$this->assertResponse($response, 'incorrect_hello_world');
41+
}
42+
3043
public function testGetHelloWorldWithMatcherResponse()
3144
{
3245
$this->client->request('GET', '/');
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"message": "Iron Maiden can't be fought!"
3+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<greetings>Iron Maiden can't be sought!</greetings>

0 commit comments

Comments
 (0)