ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
VirusScannerPreProcessorTestTBD.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\VirusScanner\tests;
22 
28 use Mockery;
29 
30 #[\PHPUnit\Framework\Attributes\BackupGlobals(false)]
31 #[\PHPUnit\Framework\Attributes\BackupStaticProperties(false)]
32 #[\PHPUnit\Framework\Attributes\PreserveGlobalState(false)]
33 #[\PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses]
34 class VirusScannerPreProcessorTest extends TestCase
35 {
37 
38  public function testVirusDetected(): void
39  {
40  $stream = Streams::ofString('Awesome stuff');
41  $mock = $this->getMockBuilder(\ilVirusScanner::class)
42  ->disableOriginalConstructor()
43  ->getMock();
44  $mock->expects($this->once())->method('scanFile')->with($stream->getMetadata('uri'))->willReturn(
45  'Virus found!!!'
46  );
47 
48  $subject = new ilVirusScannerPreProcessor($mock);
49  $result = $subject->process(
50  $stream,
51  new Metadata('MyVirus.exe', $stream->getSize(), 'application/vnd.microsoft.portable-executable')
52  );
53  $this->assertSame(ProcessingStatus::DENIED, $result->getCode());
54  $this->assertSame('Virus detected.', $result->getMessage());
55  }
56 
57  public function testNoVirusDetected(): void
58  {
59  $stream = Streams::ofString('Awesome stuff');
60 
61  $mock = $this->getMockBuilder(\ilVirusScanner::class)
62  ->disableOriginalConstructor()
63  ->getMock();
64  $mock->expects($this->once())->method('scanFile')->with($stream->getMetadata('uri'))->willReturn('');
65 
66  $subject = new ilVirusScannerPreProcessor($mock);
67  $result = $subject->process(
68  $stream,
69  new Metadata('MyVirus.exe', $stream->getSize(), 'application/vnd.microsoft.portable-executable')
70  );
71  $this->assertSame(ProcessingStatus::OK, $result->getCode());
72  }
73 }