|
4 | 4 | * See COPYING.txt for license details.
|
5 | 5 | */
|
6 | 6 |
|
7 |
| -namespace Magento\PageCache\Test\Unit\Model\App\Response; |
8 |
| - |
9 |
| -use Magento\PageCache\Model\App\Response\HttpPlugin; |
10 |
| - |
11 |
| -class HttpPluginTest extends \PHPUnit\Framework\TestCase |
12 |
| -{ |
13 |
| - /** |
14 |
| - * @param \Magento\Framework\App\Response\FileInterface $responseInstanceClass |
15 |
| - * @param int $sendVaryCalled |
16 |
| - * |
17 |
| - * @dataProvider beforeSendResponseDataProvider |
18 |
| - */ |
19 |
| - public function testBeforeSendResponse($responseInstanceClass, $sendVaryCalled) |
| 7 | +// @codingStandardsIgnoreStart |
| 8 | +namespace Magento\PageCache\Model\App\Response { |
| 9 | + $mockPHPFunctions = false; |
| 10 | + |
| 11 | + function headers_sent() |
20 | 12 | {
|
21 |
| - /** @var \Magento\Framework\App\Response\Http | \PHPUnit_Framework_MockObject_MockObject $responseMock */ |
22 |
| - $responseMock = $this->createMock($responseInstanceClass); |
23 |
| - $responseMock->expects($this->exactly($sendVaryCalled)) |
24 |
| - ->method('sendVary'); |
25 |
| - $plugin = new HttpPlugin(); |
26 |
| - $plugin->beforeSendResponse($responseMock); |
| 13 | + global $mockPHPFunctions; |
| 14 | + if ($mockPHPFunctions) { |
| 15 | + return false; |
| 16 | + } |
| 17 | + |
| 18 | + return call_user_func_array('\headers_sent', func_get_args()); |
27 | 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; |
28 | 27 |
|
29 |
| - /** |
30 |
| - * @return array |
31 |
| - */ |
32 |
| - public function beforeSendResponseDataProvider() |
| 28 | + // @codingStandardsIgnoreEnd |
| 29 | + |
| 30 | + class HttpPluginTest extends \PHPUnit\Framework\TestCase |
33 | 31 | {
|
34 |
| - return [ |
35 |
| - [\Magento\Framework\App\Response\Http::class, 1], |
36 |
| - [\Magento\MediaStorage\Model\File\Storage\Response::class, 0] |
37 |
| - ]; |
| 32 | + /** |
| 33 | + * @inheritdoc |
| 34 | + */ |
| 35 | + protected function setUp() |
| 36 | + { |
| 37 | + global $mockPHPFunctions; |
| 38 | + $mockPHPFunctions = true; |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * @inheritdoc |
| 43 | + */ |
| 44 | + protected function tearDown() |
| 45 | + { |
| 46 | + global $mockPHPFunctions; |
| 47 | + $mockPHPFunctions = false; |
| 48 | + } |
| 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 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @return array |
| 69 | + */ |
| 70 | + public function beforeSendResponseDataProvider(): array |
| 71 | + { |
| 72 | + return [ |
| 73 | + [Http::class, 1], |
| 74 | + [Response::class, 0] |
| 75 | + ]; |
| 76 | + } |
38 | 77 | }
|
39 | 78 | }
|
0 commit comments