ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PreProcessorManagerImplTest.php
Go to the documentation of this file.
1 <?php
2 
4 
5 require_once('./libs/composer/vendor/autoload.php');
6 
10 use Mockery;
12 
23 class PreProcessorManagerImplTest extends TestCase
24 {
26 
30  private $subject;
31 
32 
36  protected function setUp()
37  {
38  parent::setUp();
39 
40  $this->subject = new PreProcessorManagerImpl();
41  }
42 
48  {
49  $response = new ProcessingStatus(ProcessingStatus::OK, 'All green!');
50  $metadata = new Metadata('test.txt', 4500, 'text/plain');
51 
52  $processor = Mockery::mock(PreProcessor::class);
53  $processor->shouldReceive('process')
54  ->withAnyArgs()
55  ->times(3)
56  ->andReturn($response);
57 
58  $stream = Mockery::mock(FileStream::class);
59  $stream->shouldReceive('rewind')
60  ->withNoArgs()
61  ->times(3);
62 
63  $this->subject->with($processor);
64  $this->subject->with($processor);
65  $this->subject->with($processor);
66 
67  $result = $this->subject->process($stream, $metadata);
68 
69  $this->assertSame(ProcessingStatus::OK, $result->getCode());
70  $this->assertSame('All green!', $result->getMessage());
71  }
72 
78  {
79  $expectedResponse = new ProcessingStatus(ProcessingStatus::OK, 'No processors were registered.');
80  $metadata = new Metadata('test.txt', 4500, 'text/plain');
81 
82  $stream = Mockery::mock(FileStream::class);
83 
84  $result = $this->subject->process($stream, $metadata);
85 
86  $this->assertSame($expectedResponse->getCode(), $result->getCode());
87  $this->assertSame($expectedResponse->getMessage(), $result->getMessage());
88  }
89 
95  {
96  $responseGood = new ProcessingStatus(ProcessingStatus::OK, 'All green!');
97  $responseBad = new ProcessingStatus(ProcessingStatus::REJECTED, 'Fail all red!');
98 
99  $metadata = new Metadata('test.txt', 4500, 'text/plain');
100 
101  $processor = Mockery::mock(PreProcessor::class);
102  $processor->shouldReceive('process')
103  ->withAnyArgs()
104  ->times(2)
105  ->andReturnValues([$responseGood, $responseBad, $responseGood]);
106 
107  $stream = Mockery::mock(FileStream::class);
108  $stream->shouldReceive('rewind')
109  ->withNoArgs()
110  ->times(2);
111 
112  $this->subject->with($processor);
113  $this->subject->with($processor);
114  $this->subject->with($processor);
115 
116  $result = $this->subject->process($stream, $metadata);
117 
118  $this->assertSame($responseBad->getCode(), $result->getCode());
119  $this->assertSame($responseBad->getMessage(), $result->getMessage());
120  }
121 
127  {
128  $responseGood = new ProcessingStatus(ProcessingStatus::OK, 'All green!');
129 
130  $metadata = new Metadata('test.txt', 4500, 'text/plain');
131 
132  $processor = Mockery::mock(PreProcessor::class);
133  $processor->shouldReceive('process')
134  ->withAnyArgs()
135  ->times(2)
136  ->andReturn($responseGood);
137 
138  $processor->shouldReceive('process')
139  ->withAnyArgs()
140  ->once()
141  ->andThrow(\RuntimeException::class, 'Bad stuff happened!');
142 
143  $stream = Mockery::mock(FileStream::class);
144  $stream->shouldReceive('rewind')
145  ->withNoArgs()
146  ->times(3);
147 
148  $this->subject->with($processor);
149  $this->subject->with($processor);
150  $this->subject->with($processor);
151 
152  $result = $this->subject->process($stream, $metadata);
153 
154  $this->assertSame(ProcessingStatus::REJECTED, $result->getCode());
155  $this->assertSame('Processor failed with exception message "Bad stuff happened!"', $result->getMessage());
156  }
157 }
const REJECTED
Upload got rejected by a processor.
$result
$metadata['__DYNAMIC:1__']
$stream
PHP stream implementation.
$response