ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\FileUpload\Processor\PreProcessorManagerImplTest Class Reference

Class PreProcessorManagerImplTest. More...

+ Inheritance diagram for ILIAS\FileUpload\Processor\PreProcessorManagerImplTest:
+ Collaboration diagram for ILIAS\FileUpload\Processor\PreProcessorManagerImplTest:

Public Member Functions

 testProcessValidFileWhichShouldSucceed ()
 
 testProcessWithoutProcessorsWhichShouldSucceed ()
 
 testProcessInvalidFileWhichShouldGetRejected ()
 
 testProcessValidFileWithFailingProcessorWhichShouldGetRejected ()
 

Protected Member Functions

 setUp ()
 @inheritDoc More...
 

Private Attributes

PreProcessorManagerImpl $subject
 

Detailed Description

Member Function Documentation

◆ setUp()

ILIAS\FileUpload\Processor\PreProcessorManagerImplTest::setUp ( )
protected

@inheritDoc

Definition at line 59 of file PreProcessorManagerImplTestTBD.php.

59 : void
60 {
61 parent::setUp();
62
63 $this->subject = new PreProcessorManagerImpl();
64 }

◆ testProcessInvalidFileWhichShouldGetRejected()

ILIAS\FileUpload\Processor\PreProcessorManagerImplTest::testProcessInvalidFileWhichShouldGetRejected ( )

Definition at line 111 of file PreProcessorManagerImplTestTBD.php.

111 : void
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 }

References ILIAS\FileUpload\DTO\ProcessingStatus\OK, and ILIAS\FileUpload\DTO\ProcessingStatus\REJECTED.

◆ testProcessValidFileWhichShouldSucceed()

ILIAS\FileUpload\Processor\PreProcessorManagerImplTest::testProcessValidFileWhichShouldSucceed ( )

Definition at line 68 of file PreProcessorManagerImplTestTBD.php.

68 : void
69 {
70 $response = new ProcessingStatus(ProcessingStatus::OK, 'All green!');
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 }
$response
Definition: xapitoken.php:93

References $response, and ILIAS\FileUpload\DTO\ProcessingStatus\OK.

◆ testProcessValidFileWithFailingProcessorWhichShouldGetRejected()

ILIAS\FileUpload\Processor\PreProcessorManagerImplTest::testProcessValidFileWithFailingProcessorWhichShouldGetRejected ( )

Definition at line 141 of file PreProcessorManagerImplTestTBD.php.

141 : void
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 }

References ILIAS\FileUpload\DTO\ProcessingStatus\OK, and ILIAS\FileUpload\DTO\ProcessingStatus\REJECTED.

◆ testProcessWithoutProcessorsWhichShouldSucceed()

ILIAS\FileUpload\Processor\PreProcessorManagerImplTest::testProcessWithoutProcessorsWhichShouldSucceed ( )

Definition at line 96 of file PreProcessorManagerImplTestTBD.php.

96 : void
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 }

References ILIAS\FileUpload\DTO\ProcessingStatus\OK.

Field Documentation

◆ $subject

PreProcessorManager ILIAS\FileUpload\Processor\PreProcessorManagerImplTest::$subject
private

Definition at line 53 of file PreProcessorManagerImplTestTBD.php.


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