|
3 | 3 | * Copyright © Magento, Inc. All rights reserved.
|
4 | 4 | * See COPYING.txt for license details.
|
5 | 5 | */
|
| 6 | +declare(strict_types=1); |
6 | 7 |
|
7 |
| -// @codingStandardsIgnoreStart |
8 |
| -namespace Magento\PageCache\Model\App\Response { |
9 |
| - $mockPHPFunctions = false; |
| 8 | +namespace Magento\PageCache\Test\Unit\Model\App\Response; |
10 | 9 |
|
11 |
| - function headers_sent() |
12 |
| - { |
13 |
| - global $mockPHPFunctions; |
14 |
| - if ($mockPHPFunctions) { |
15 |
| - return false; |
16 |
| - } |
17 |
| - |
18 |
| - return call_user_func_array('\headers_sent', func_get_args()); |
19 |
| - } |
20 |
| -} |
21 |
| - |
22 |
| -namespace Magento\PageCache\Test\Unit\Model\App\Response { |
23 |
| - |
24 |
| - use Magento\Framework\App\Response\Http; |
25 |
| - use Magento\MediaStorage\Model\File\Storage\Response; |
26 |
| - use Magento\PageCache\Model\App\Response\HttpPlugin; |
| 10 | +use Magento\Framework\App\Response\Http as HttpResponse; |
| 11 | +use Magento\MediaStorage\Model\File\Storage\Response as FileResponse; |
| 12 | +use Magento\PageCache\Model\App\Response\HttpPlugin; |
| 13 | +use PHPUnit\Framework\MockObject\MockObject; |
| 14 | +use PHPUnit\Framework\TestCase; |
27 | 15 |
|
28 |
| - // @codingStandardsIgnoreEnd |
| 16 | +/** |
| 17 | + * Tests \Magento\PageCache\Model\App\Response\HttpPlugin. |
| 18 | + */ |
| 19 | +class HttpPluginTest extends TestCase |
| 20 | +{ |
| 21 | + /** |
| 22 | + * @var HttpPlugin |
| 23 | + */ |
| 24 | + private $httpPlugin; |
29 | 25 |
|
30 |
| - class HttpPluginTest extends \PHPUnit\Framework\TestCase |
| 26 | + /** |
| 27 | + * @inheritdoc |
| 28 | + */ |
| 29 | + protected function setUp() |
31 | 30 | {
|
32 |
| - /** |
33 |
| - * @inheritdoc |
34 |
| - */ |
35 |
| - protected function setUp() |
36 |
| - { |
37 |
| - global $mockPHPFunctions; |
38 |
| - $mockPHPFunctions = true; |
39 |
| - } |
| 31 | + parent::setUp(); |
| 32 | + $this->httpPlugin = new HttpPlugin(); |
| 33 | + } |
40 | 34 |
|
41 |
| - /** |
42 |
| - * @inheritdoc |
43 |
| - */ |
44 |
| - protected function tearDown() |
45 |
| - { |
46 |
| - global $mockPHPFunctions; |
47 |
| - $mockPHPFunctions = false; |
48 |
| - } |
| 35 | + /** |
| 36 | + * @param string $responseClass |
| 37 | + * @param bool $headersSent |
| 38 | + * @param int $sendVaryCalled |
| 39 | + * @return void |
| 40 | + * |
| 41 | + * @dataProvider beforeSendResponseDataProvider |
| 42 | + */ |
| 43 | + public function testBeforeSendResponse(string $responseClass, bool $headersSent, int $sendVaryCalled): void |
| 44 | + { |
| 45 | + /** @var HttpResponse|MockObject $responseMock */ |
| 46 | + $responseMock = $this->createMock($responseClass); |
| 47 | + $responseMock->expects($this->any())->method('headersSent')->willReturn($headersSent); |
| 48 | + $responseMock->expects($this->exactly($sendVaryCalled))->method('sendVary'); |
49 | 49 |
|
50 |
| - /** |
51 |
| - * @param string $responseInstanceClass |
52 |
| - * @param int $sendVaryCalled |
53 |
| - * @return void |
54 |
| - * |
55 |
| - * @dataProvider beforeSendResponseDataProvider |
56 |
| - */ |
57 |
| - public function testBeforeSendResponse(string $responseInstanceClass, int $sendVaryCalled): void |
58 |
| - { |
59 |
| - /** @var Http | \PHPUnit_Framework_MockObject_MockObject $responseMock */ |
60 |
| - $responseMock = $this->createMock($responseInstanceClass); |
61 |
| - $responseMock->expects($this->exactly($sendVaryCalled)) |
62 |
| - ->method('sendVary'); |
63 |
| - $plugin = new HttpPlugin(); |
64 |
| - $plugin->beforeSendResponse($responseMock); |
65 |
| - } |
| 50 | + $this->httpPlugin->beforeSendResponse($responseMock); |
| 51 | + } |
66 | 52 |
|
67 |
| - /** |
68 |
| - * @return array |
69 |
| - */ |
70 |
| - public function beforeSendResponseDataProvider(): array |
71 |
| - { |
72 |
| - return [ |
73 |
| - [Http::class, 1], |
74 |
| - [Response::class, 0] |
75 |
| - ]; |
76 |
| - } |
| 53 | + /** |
| 54 | + * @return array |
| 55 | + */ |
| 56 | + public function beforeSendResponseDataProvider(): array |
| 57 | + { |
| 58 | + return [ |
| 59 | + 'http_response_headers_not_sent' => [HttpResponse::class, false, 1], |
| 60 | + 'http_response_headers_sent' => [HttpResponse::class, true, 0], |
| 61 | + 'file_response_headers_not_sent' => [FileResponse::class, false, 0], |
| 62 | + 'file_response_headers_sent' => [FileResponse::class, true, 0], |
| 63 | + ]; |
77 | 64 | }
|
78 | 65 | }
|
0 commit comments