ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
XSendfileTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use PHPUnit\Framework\Attributes\BackupGlobals;
24use PHPUnit\Framework\Attributes\BackupStaticProperties;
25use PHPUnit\Framework\Attributes\PreserveGlobalState;
26use PHPUnit\Framework\Attributes\RunInSeparateProcess;
27use PHPUnit\Framework\Attributes\Test;
28use PHPUnit\Framework\MockObject\MockObject;
30use PHPUnit\Framework\TestCase;
31use Psr\Http\Message\ResponseInterface;
33
39#[BackupGlobals(false)]
40#[BackupStaticProperties(false)]
41#[PreserveGlobalState(false)]
42class XSendfileTest extends TestCase
43{
48
52 protected function setUp(): void
53 {
54 $this->httpServiceMock = $this->getMockBuilder(Services::class)
55 ->disableOriginalConstructor()
56 ->getMock();
57 }
58
59 #[Test]
61 {
62 $expectedHeader = 'X-Sendfile';
63 $filePath = __FILE__;
64
65 $response = $this->getMockBuilder(ResponseInterface::class)
66 ->disableOriginalConstructor()
67 ->getMock();
68
69 $response->expects($this->once())
70 ->method('withHeader')
71 ->with($expectedHeader, $filePath)
72 ->willReturnSelf();
73
74 $this->httpServiceMock->expects($this->once())
75 ->method('response')
76 ->willReturn($response);
77
78 $this->httpServiceMock->expects($this->once())
79 ->method('saveResponse')
80 ->with($response);
81
82 $this->httpServiceMock->expects($this->once())
83 ->method('sendResponse');
84
85 $fileDeliveryType = new XSendfile($this->httpServiceMock);
86 $fileDeliveryType->deliver($filePath, false);
87 }
88}
Class Services.
Definition: Services.php:38
$response
Definition: xapitoken.php:93