|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the SF Forward Bundle. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) DAOUDI Soufian <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace SfForward\Tests\Manager; |
|
13
|
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
16
|
|
|
use Psr\Http\Message\StreamInterface; |
|
17
|
|
|
use SfForward\Manager\ResponseManager; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse; |
|
19
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
20
|
|
|
|
|
21
|
|
|
class ResponseManagerTest extends TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
protected $projectDir; |
|
24
|
|
|
protected function setUp() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->projectDir = __DIR__.'/../../var/cache'; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testGetResponseSuccess() |
|
30
|
|
|
{ |
|
31
|
|
|
$response = $this->getMockedResponse(); |
|
32
|
|
|
$responseManager = new ResponseManager($response, $this->projectDir); |
|
33
|
|
|
|
|
34
|
|
|
$this->assertInstanceOf(Response::class, $responseManager->getResponse()); |
|
35
|
|
|
$this->assertSame(Response::HTTP_OK, $responseManager->getResponse()->getStatusCode()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testGetResponseNotFound() |
|
39
|
|
|
{ |
|
40
|
|
|
$response = $this->getMockedResponse('test content', Response::HTTP_NOT_FOUND); |
|
41
|
|
|
$responseManager = new ResponseManager($response, $this->projectDir); |
|
42
|
|
|
|
|
43
|
|
|
$this->assertInstanceOf(Response::class, $responseManager->getResponse()); |
|
44
|
|
|
$this->assertSame(Response::HTTP_NOT_FOUND, $responseManager->getResponse()->getStatusCode()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testGetBinaryFileResponse() |
|
48
|
|
|
{ |
|
49
|
|
|
$response = $this->getMockedResponse('test content', Response::HTTP_OK, 'content-disposition'); |
|
50
|
|
|
$responseManager = new ResponseManager($response, $this->projectDir); |
|
51
|
|
|
|
|
52
|
|
|
$this->assertInstanceOf(BinaryFileResponse::class, $responseManager->getResponse()); |
|
53
|
|
|
$this->assertSame(Response::HTTP_OK, $responseManager->getResponse()->getStatusCode()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param string $body |
|
58
|
|
|
* @param int $statusCode |
|
59
|
|
|
* @param string $contentDisposition |
|
60
|
|
|
* |
|
61
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject |
|
62
|
|
|
*/ |
|
63
|
|
|
protected function getMockedResponse($body = '', $statusCode = Response::HTTP_OK, $contentDisposition = null) |
|
64
|
|
|
{ |
|
65
|
|
|
$stream = $this->createMock(StreamInterface::class); |
|
66
|
|
|
$stream->method('getContents') |
|
|
|
|
|
|
67
|
|
|
->willReturn($body); |
|
68
|
|
|
|
|
69
|
|
|
$response = $this->createMock(ResponseInterface::class); |
|
70
|
|
|
|
|
71
|
|
|
$response->expects($this->exactly(2)) |
|
72
|
|
|
->method('getBody') |
|
73
|
|
|
->willReturn($stream); |
|
74
|
|
|
|
|
75
|
|
|
$response->expects($this->exactly(2)) |
|
76
|
|
|
->method('getStatusCode') |
|
77
|
|
|
->willReturn($statusCode); |
|
78
|
|
|
|
|
79
|
|
|
$response->expects($this->exactly(2)) |
|
80
|
|
|
->method('hasHeader') |
|
81
|
|
|
->with('Content-Disposition') |
|
82
|
|
|
->willReturn($contentDisposition); |
|
83
|
|
|
|
|
84
|
|
|
$response->method('getHeaders') |
|
85
|
|
|
->willReturn([]); |
|
86
|
|
|
|
|
87
|
|
|
return $response; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.