ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
PreProcessorManagerImplTestTBD.php
Go to the documentation of this file.
1 <?php
2 
20 
28 
29 require_once('./vendor/composer/vendor/autoload.php');
30 
34 use Mockery;
36 
42 #[BackupGlobals(false)]
43 #[BackupStaticProperties(false)]
44 #[PreserveGlobalState(false)]
45 #[RunTestsInSeparateProcesses]
46 class PreProcessorManagerImplTest extends TestCase
47 {
49 
54 
55 
59  protected function setUp(): void
60  {
61  parent::setUp();
62 
63  $this->subject = new PreProcessorManagerImpl();
64  }
65 
66  #[Test]
67 
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  }
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 }
$response
Definition: xapitoken.php:93
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...