ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\FileUpload\Processor\PreProcessorManagerImplTest Class Reference
+ Inheritance diagram for ILIAS\FileUpload\Processor\PreProcessorManagerImplTest:
+ Collaboration diagram for ILIAS\FileUpload\Processor\PreProcessorManagerImplTest:

Public Member Functions

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

Protected Member Functions

 setUp ()
 

Private Attributes

PreProcessorManagerImpl $subject
 

Detailed Description

Definition at line 29 of file PreProcessorManagerImplTest.php.

Member Function Documentation

◆ setUp()

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

Definition at line 33 of file PreProcessorManagerImplTest.php.

33 : void
34 {
36
37 $this->subject = new PreProcessorManagerImpl(new PreProcessorCollectionImpl([]));
38 }

References setUp().

+ Here is the call graph for this function:

◆ testProcessInvalidFileWhichShouldGetRejected()

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

Definition at line 107 of file PreProcessorManagerImplTest.php.

107 : void
108 {
109 $response_good = new ProcessingStatus(ProcessingStatus::OK, 'All green!');
110 $response_bad = new ProcessingStatus(ProcessingStatus::REJECTED, 'Fail all red!');
111
112 $metadata = new Metadata('test.txt', 4500, 'text/plain');
113
114 $processor = $this->createMock(PreProcessor::class);
115 $processor->expects($this->exactly(2))
116 ->method('process')
117 ->willReturnOnConsecutiveCalls($response_good, $response_bad, $response_good);
118
119 $stream = $this->createMock(FileStream::class);
120 $stream->expects($this->exactly(2))
121 ->method('rewind');
122
123 $this->subject->with($processor);
124 $this->subject->with($processor);
125 $this->subject->with($processor);
126
127 $result = $this->subject->process($stream, $metadata);
128
129 $this->assertSame($response_bad->getCode(), $result->getCode());
130 $this->assertSame($response_bad->getMessage(), $result->getMessage());
131 }

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

◆ testProcessValidFileWhichShouldSucceed()

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

Definition at line 41 of file PreProcessorManagerImplTest.php.

41 : void
42 {
43 $response = new ProcessingStatus(ProcessingStatus::OK, 'All green!');
44 $metadata = new Metadata('test.txt', 4500, 'text/plain');
45
46 $processor = $this->createMock(PreProcessor::class);
47 $processor->expects($this->exactly(3))
48 ->method('process')
49 ->willReturn($response);
50
51 $stream = $this->createMock(FileStream::class);
52 $stream->expects($this->exactly(3))
53 ->method('rewind')
54 ->with();
55
56 $this->subject->with($processor);
57 $this->subject->with($processor);
58 $this->subject->with($processor);
59
60 $result = $this->subject->process($stream, $metadata);
61
62 $this->assertSame(ProcessingStatus::OK, $result->getCode());
63 $this->assertSame('All green!', $result->getMessage());
64 }
$response
Definition: xapitoken.php:92

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

◆ testProcessValidFileWithFailingProcessorWhichShouldGetRejected()

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

Definition at line 134 of file PreProcessorManagerImplTest.php.

134 : void
135 {
136 $response_good = new ProcessingStatus(ProcessingStatus::OK, 'All green!');
137
138 $metadata = new Metadata('test.txt', 4500, 'text/plain');
139
140 $invocations = 0;
141 $processor = $this->createMock(PreProcessor::class);
142 $processor->expects($this->exactly(3))
143 ->method('process')
144 ->willReturnCallback(
145 function () use (&$invocations, $response_good): ProcessingStatus {
146 if (++$invocations === 3) {
147 throw new \RuntimeException('Bad stuff happened!');
148 }
149 return $response_good;
150 }
151 );
152
153 $stream = $this->createMock(FileStream::class);
154 $stream->expects($this->exactly(3))
155 ->method('rewind');
156
157 $this->subject->with($processor);
158 $this->subject->with($processor);
159 $this->subject->with($processor);
160
161 $result = $this->subject->process($stream, $metadata);
162
163 $this->assertSame(ProcessingStatus::REJECTED, $result->getCode());
164 $this->assertSame('Processor failed with exception message "Bad stuff happened!"', $result->getMessage());
165 }

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

◆ testProcessWithoutProcessorsWhichShouldSucceed()

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

Definition at line 91 of file PreProcessorManagerImplTest.php.

91 : void
92 {
93 $expected_response = new ProcessingStatus(ProcessingStatus::OK, 'No processors were registered.');
94 $metadata = new Metadata('test.txt', 4500, 'text/plain');
95
96 $stream = $this->createMock(FileStream::class);
97 $stream->expects($this->never())
98 ->method('rewind');
99
100 $result = $this->subject->process($stream, $metadata);
101
102 $this->assertSame($expected_response->getCode(), $result->getCode());
103 $this->assertSame($expected_response->getMessage(), $result->getMessage());
104 }

References ILIAS\FileUpload\DTO\ProcessingStatus\OK.

◆ testProcessWithProcessorsFromCollectionWhichShouldSucceed()

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

Definition at line 67 of file PreProcessorManagerImplTest.php.

67 : void
68 {
69 $response = new ProcessingStatus(ProcessingStatus::OK, 'All green!');
70 $metadata = new Metadata('test.txt', 4500, 'text/plain');
71
72 $processor = $this->createMock(PreProcessor::class);
73 $processor->expects($this->exactly(2))
74 ->method('process')
75 ->willReturn($response);
76
77 $stream = $this->createMock(FileStream::class);
78 $stream->expects($this->exactly(2))
79 ->method('rewind');
80
81 $subject = new PreProcessorManagerImpl(new PreProcessorCollectionImpl([$processor]));
82 $subject->with($processor);
83
84 $result = $subject->process($stream, $metadata);
85
86 $this->assertSame(ProcessingStatus::OK, $result->getCode());
87 $this->assertSame('All green!', $result->getMessage());
88 }
process(FileStream $stream, Metadata $metadata)
@inheritDoc

References $response, ILIAS\FileUpload\Processor\PreProcessorManagerImplTest\$subject, ILIAS\FileUpload\DTO\ProcessingStatus\OK, ILIAS\FileUpload\Processor\PreProcessorManagerImpl\process(), and ILIAS\FileUpload\Processor\PreProcessorManagerImpl\with().

+ Here is the call graph for this function:

Field Documentation

◆ $subject

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

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