ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
VirusScannerPreProcessorTestTBD.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use PHPUnit\Framework\TestCase;
28use 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]
34class VirusScannerPreProcessorTest extends TestCase
35{
36 use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
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}
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Definition: Streams.php:32
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:41