ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryTest Class Reference

Temporary files are removed by a shutdown function as soon as the request exits, header based delivery (X-Sendfile, X-Accel) opens them only afterwards. More...

+ Inheritance diagram for ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryTest:
+ Collaboration diagram for ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryTest:

Public Member Functions

 testTemporaryFileIsDeliveredByTheFallback ()
 
 testRegularFileIsDeliveredByTheConfiguredBuilder ()
 
 testMemoryStreamIsDeliveredByTheFallback ()
 

Protected Member Functions

 tearDown ()
 

Private Member Functions

 assertDeliveredBy (string $expected, FileStream $stream)
 
 builder (string $name, bool $used, ResponseInterface $response)
 
 requestTo (string $uri)
 

Private Attributes

string $temp_file = null
 

Detailed Description

Temporary files are removed by a shutdown function as soon as the request exits, header based delivery (X-Sendfile, X-Accel) opens them only afterwards.

They must be streamed by PHP, see https://mantis.ilias.de/view.php?id=48367

Definition at line 41 of file StreamDeliveryTest.php.

Member Function Documentation

◆ assertDeliveredBy()

ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryTest::assertDeliveredBy ( string  $expected,
FileStream  $stream 
)
private

Definition at line 79 of file StreamDeliveryTest.php.

79 : void
80 {
81 $response = (new MessageFactoryImpl())->response();
82
83 $http = $this->createStub(\ILIAS\HTTP\Services::class);
84 $http->method('request')->willReturn($this->requestTo('https://ilias.example.org/'));
85 $http->method('response')->willReturn($response);
86 // close() is never, the test leaves deliver() by an exception instead
87 $http->method('close')->willThrowException(new \RuntimeException('closed'));
88
89 $configured = $this->builder('configured', $expected === 'configured', $response);
90 $fallback = $this->builder('fallback', $expected === 'fallback', $response);
91
92 $delivery = new StreamDelivery(
93 new DataSigner(new SecretKeyRotation(new SecretKey(str_repeat('a', 32)))),
94 $http,
95 $configured,
96 $fallback
97 );
98
99 $this->expectExceptionMessage('closed');
100 $delivery->attached($stream, 'file.zip', 'application/zip');
101 }
builder(string $name, bool $used, ResponseInterface $response)
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
$response
Definition: xapitoken.php:92

References ILIAS\BookingManager\Common\Table\$http, $response, ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryTest\builder(), ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryTest\requestTo(), and ILIAS\Scripts\PHPStan\str_repeat.

Referenced by ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryTest\testMemoryStreamIsDeliveredByTheFallback(), ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryTest\testRegularFileIsDeliveredByTheConfiguredBuilder(), and ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryTest\testTemporaryFileIsDeliveredByTheFallback().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ builder()

ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryTest::builder ( string  $name,
bool  $used,
ResponseInterface  $response 
)
private

Definition at line 103 of file StreamDeliveryTest.php.

103 : ResponseBuilder&MockObject
104 {
105 $builder = $this->createMock(ResponseBuilder::class);
106 $builder->method('getName')->willReturn($name);
107 $builder->expects($used ? $this->once() : $this->never())
108 ->method('buildForStream')
109 ->willReturn($response);
110
111 return $builder;
112 }

References $response.

Referenced by ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryTest\assertDeliveredBy().

+ Here is the caller graph for this function:

◆ requestTo()

ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryTest::requestTo ( string  $uri)
private

Definition at line 114 of file StreamDeliveryTest.php.

114 : ServerRequestInterface
115 {
116 $request = $this->createStub(ServerRequestInterface::class);
117 $request->method('getUri')->willReturn((new MessageFactoryImpl())->uri($uri));
118
119 return $request;
120 }
$request
@ilCtrl_Calls ilObjLearningSequenceContentGUI: ilObjLearningSequenceConditionsGUI
Definition: ltiauth.php:39

References $request.

Referenced by ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryTest\assertDeliveredBy().

+ Here is the caller graph for this function:

◆ tearDown()

ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryTest::tearDown ( )
protected

Definition at line 45 of file StreamDeliveryTest.php.

45 : void
46 {
47 if ($this->temp_file !== null && is_file($this->temp_file)) {
48 unlink($this->temp_file);
49 }
50 }

◆ testMemoryStreamIsDeliveredByTheFallback()

ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryTest::testMemoryStreamIsDeliveredByTheFallback ( )

Definition at line 71 of file StreamDeliveryTest.php.

71 : void
72 {
73 $this->assertDeliveredBy(
74 'fallback',
75 Streams::ofString('content')
76 );
77 }
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:41
assertDeliveredBy(string $expected, FileStream $stream)

References ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryTest\assertDeliveredBy(), and ILIAS\Filesystem\Stream\Streams\ofString().

+ Here is the call graph for this function:

◆ testRegularFileIsDeliveredByTheConfiguredBuilder()

ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryTest::testRegularFileIsDeliveredByTheConfiguredBuilder ( )

Definition at line 63 of file StreamDeliveryTest.php.

63 : void
64 {
65 $this->assertDeliveredBy(
66 'configured',
67 Streams::ofResource(fopen(__FILE__, 'rb'))
68 );
69 }
static ofResource($resource)
Wraps an already created resource with the stream abstraction.
Definition: Streams.php:64

References ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryTest\assertDeliveredBy(), and ILIAS\Filesystem\Stream\Streams\ofResource().

+ Here is the call graph for this function:

◆ testTemporaryFileIsDeliveredByTheFallback()

ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryTest::testTemporaryFileIsDeliveredByTheFallback ( )

Definition at line 52 of file StreamDeliveryTest.php.

52 : void
53 {
54 $this->temp_file = tempnam(sys_get_temp_dir(), 'zip');
55 file_put_contents($this->temp_file, 'zip');
56
57 $this->assertDeliveredBy(
58 'fallback',
59 Streams::ofResource(fopen($this->temp_file, 'rb'))
60 );
61 }

References ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryTest\assertDeliveredBy(), and ILIAS\Filesystem\Stream\Streams\ofResource().

+ Here is the call graph for this function:

Field Documentation

◆ $temp_file

string ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryTest::$temp_file = null
private

Definition at line 43 of file StreamDeliveryTest.php.


The documentation for this class was generated from the following file: