Skip to content

Commit bb01956

Browse files
chore: don't use a mock in testIsSuccessfulException
1 parent 88fb291 commit bb01956

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

tests/App/Controller/DefaultController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,9 @@ public function embeddedAction(): Response
107107
{
108108
return new Response('Embedded Content', Response::HTTP_OK);
109109
}
110+
111+
public function exceptionAction(): Response
112+
{
113+
throw new \Exception('foo');
114+
}
110115
}

tests/App/routing.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ liipfunctionaltestbundle_json:
2525
defaults: { _controller: 'Liip\Acme\Tests\App\Controller\DefaultController::jsonAction' }
2626
requirements:
2727
userId: \d+
28+
29+
liipfunctionaltestbundle_exception:
30+
path: /exception
31+
defaults: { _controller: 'Liip\Acme\Tests\App\Controller\DefaultController::exceptionAction' }

tests/Test/WebTestCaseTest.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation;
1717
use Liip\Acme\Tests\App\AppKernel;
1818
use Liip\FunctionalTestBundle\Test\WebTestCase;
19-
use function method_exists;
2019
use PHPUnit\Framework\AssertionFailedError;
2120

2221
/**
@@ -243,25 +242,16 @@ public function test404Error(): void
243242
*/
244243
public function testIsSuccessfulException(): void
245244
{
246-
$mockBuilder = $this->getMockBuilder('Symfony\Component\HttpFoundation\Response')
247-
->disableOriginalConstructor();
248-
if (method_exists($mockBuilder, 'setMethods')) {
249-
$mockBuilder->setMethods(['getContent']);
250-
} else { // phpunit 10
251-
$mockBuilder->onlyMethods(['getContent']);
252-
}
253-
$response = $mockBuilder
254-
->getMock();
245+
$path = '/exception';
255246

256-
$response->expects($this->any())
257-
->method('getContent')
258-
->will($this->throwException(new \Exception('foo')));
247+
$client = static::makeClient();
248+
$client->request('GET', $path);
259249

260250
try {
261-
$this->isSuccessful($response);
251+
$this->isSuccessful($client->getResponse());
262252
} catch (AssertionFailedError $e) {
263253
$string = <<<'EOF'
264-
The Response was not successful: foo
254+
The Response was not successful: foo (500 Internal Server Error)
265255
Failed asserting that false is true.
266256
EOF;
267257
$this->assertSame($string, $e->getMessage());

0 commit comments

Comments
 (0)