ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
PreProcessorManagerImplTestTBD.php
Go to the documentation of this file.
1<?php
2
20
21use PHPUnit\Framework\Attributes\BackupGlobals;
22use PHPUnit\Framework\Attributes\BackupStaticProperties;
23use PHPUnit\Framework\Attributes\PreserveGlobalState;
24use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
25use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
26use PHPUnit\Framework\Attributes\Test;
27use PHPUnit\Framework\Attributes\Small;
28
29require_once('./vendor/composer/vendor/autoload.php');
30
34use Mockery;
35use PHPUnit\Framework\TestCase;
36
42#[BackupGlobals(false)]
43#[BackupStaticProperties(false)]
44#[PreserveGlobalState(false)]
45#[RunTestsInSeparateProcesses]
46class PreProcessorManagerImplTest extends TestCase
47{
48 use MockeryPHPUnitIntegration;
49
54
55
59 protected function setUp(): void
60 {
61 parent::setUp();
62
63 $this->subject = new PreProcessorManagerImpl();
64 }
65
66 #[Test]
67
69 {
71 $metadata = new Metadata('test.txt', 4500, 'text/plain');
72
73 $processor = Mockery::mock(PreProcessor::class);
74 $processor->shouldReceive('process')
75 ->withAnyArgs()
76 ->times(3)
77 ->andReturn($response);
78
79 $stream = Mockery::mock(FileStream::class);
80 $stream->shouldReceive('rewind')
81 ->withNoArgs()
82 ->times(3);
83
84 $this->subject->with($processor);
85 $this->subject->with($processor);
86 $this->subject->with($processor);
87
88 $result = $this->subject->process($stream, $metadata);
89
90 $this->assertSame(ProcessingStatus::OK, $result->getCode());
91 $this->assertSame('All green!', $result->getMessage());
92 }
93
94 #[Test]
95
97 {
98 $expectedResponse = new ProcessingStatus(ProcessingStatus::OK, 'No processors were registered.');
99 $metadata = new Metadata('test.txt', 4500, 'text/plain');
100
101 $stream = Mockery::mock(FileStream::class);
102
103 $result = $this->subject->process($stream, $metadata);
104
105 $this->assertSame($expectedResponse->getCode(), $result->getCode());
106 $this->assertSame($expectedResponse->getMessage(), $result->getMessage());
107 }
108
109 #[Test]
110
112 {
113 $responseGood = new ProcessingStatus(ProcessingStatus::OK, 'All green!');
114 $responseBad = new ProcessingStatus(ProcessingStatus::REJECTED, 'Fail all red!');
115
116 $metadata = new Metadata('test.txt', 4500, 'text/plain');
117
118 $processor = Mockery::mock(PreProcessor::class);
119 $processor->shouldReceive('process')
120 ->withAnyArgs()
121 ->times(2)
122 ->andReturnValues([$responseGood, $responseBad, $responseGood]);
123
124 $stream = Mockery::mock(FileStream::class);
125 $stream->shouldReceive('rewind')
126 ->withNoArgs()
127 ->times(2);
128
129 $this->subject->with($processor);
130 $this->subject->with($processor);
131 $this->subject->with($processor);
132
133 $result = $this->subject->process($stream, $metadata);
134
135 $this->assertSame($responseBad->getCode(), $result->getCode());
136 $this->assertSame($responseBad->getMessage(), $result->getMessage());
137 }
138
139 #[Test]
140
142 {
143 $responseGood = new ProcessingStatus(ProcessingStatus::OK, 'All green!');
144
145 $metadata = new Metadata('test.txt', 4500, 'text/plain');
146
147 $processor = Mockery::mock(PreProcessor::class);
148 $processor->shouldReceive('process')
149 ->withAnyArgs()
150 ->times(2)
151 ->andReturn($responseGood);
152
153 $processor->shouldReceive('process')
154 ->withAnyArgs()
155 ->once()
156 ->andThrow(\RuntimeException::class, 'Bad stuff happened!');
157
158 $stream = Mockery::mock(FileStream::class);
159 $stream->shouldReceive('rewind')
160 ->withNoArgs()
161 ->times(3);
162
163 $this->subject->with($processor);
164 $this->subject->with($processor);
165 $this->subject->with($processor);
166
167 $result = $this->subject->process($stream, $metadata);
168
169 $this->assertSame(ProcessingStatus::REJECTED, $result->getCode());
170 $this->assertSame('Processor failed with exception message "Bad stuff happened!"', $result->getMessage());
171 }
172}
The base interface for all filesystem streams.
Definition: FileStream.php:32
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$response
Definition: xapitoken.php:93