1111class ScannerTest extends TestCase
1212{
1313 private static $ originalFilePermissionsOfInaccessibleFile ;
14+ private static $ socket ;
15+ private static $ host ;
16+ private static $ port ;
1417
1518 public static function setUpBeforeClass (): void
1619 {
20+ self ::$ socket = getenv ('CLAMAV_SOCKET ' ) ?: ScanStrategyClamdUnix::DEFAULT_SOCKET ;
21+ self ::$ host = getenv ('CLAMAV_HOST ' ) ?: ScanStrategyClamdNetwork::DEFAULT_HOST ;
22+ self ::$ port = getenv ('CLAMAV_PORT ' ) ?: ScanStrategyClamdNetwork::DEFAULT_PORT ;
23+
1724 self ::$ originalFilePermissionsOfInaccessibleFile = fileperms (__DIR__ .'/../Files/inaccessible.txt ' );
1825 chmod (__DIR__ .'/../Files/inaccessible.txt ' , 0000 );
1926 }
@@ -25,25 +32,25 @@ public static function tearDownAfterClass(): void
2532
2633 public function testPingWithClamdUnix ()
2734 {
28- $ scanner = new Scanner (new ScanStrategyClamdUnix ());
35+ $ scanner = new Scanner (new ScanStrategyClamdUnix (self :: $ socket ));
2936 $ this ->assertTrue ($ scanner ->ping ());
3037 }
3138
3239 public function testPingWithClamdNetwork ()
3340 {
34- $ scanner = new Scanner (new ScanStrategyClamdNetwork ());
41+ $ scanner = new Scanner (new ScanStrategyClamdNetwork (self :: $ host , self :: $ port ));
3542 $ this ->assertTrue ($ scanner ->ping ());
3643 }
3744
3845 public function testVersionWithClamdUnix ()
3946 {
40- $ scanner = new Scanner (new ScanStrategyClamdUnix ());
47+ $ scanner = new Scanner (new ScanStrategyClamdUnix (self :: $ socket ));
4148 $ this ->assertIsString ($ scanner ->version ());
4249 }
4350
4451 public function testVersionWithClamdNetwork ()
4552 {
46- $ scanner = new Scanner (new ScanStrategyClamdNetwork ());
53+ $ scanner = new Scanner (new ScanStrategyClamdNetwork (self :: $ host , self :: $ port ));
4754 $ this ->assertIsString ($ scanner ->version ());
4855 }
4956
@@ -53,7 +60,7 @@ public function testVersionWithClamdNetwork()
5360 */
5461 public function testScanValidFilesWithClamdUnix (string $ filePath , bool $ expectedVirus , string $ expectedVirusName )
5562 {
56- $ scanner = new Scanner (new ScanStrategyClamdUnix ());
63+ $ scanner = new Scanner (new ScanStrategyClamdUnix (self :: $ socket ));
5764
5865 $ scanResult = $ scanner ->scan ($ filePath );
5966 $ this ->assertSame ($ expectedVirus , !$ scanResult ->isClean ());
@@ -66,7 +73,7 @@ public function testScanValidFilesWithClamdUnix(string $filePath, bool $expected
6673 */
6774 public function testScanInvalidFilesWithClamdUnix (string $ filePath , string $ expectedErrorMessage )
6875 {
69- $ scanner = new Scanner (new ScanStrategyClamdUnix ());
76+ $ scanner = new Scanner (new ScanStrategyClamdUnix (self :: $ socket ));
7077
7178 $ this ->expectException (FileScanException::class);
7279 $ this ->expectExceptionMessage ($ expectedErrorMessage );
@@ -78,7 +85,7 @@ public function testScanInvalidFilesWithClamdUnix(string $filePath, string $expe
7885 */
7986 public function testScanValidFilesWithClamdNetwork (string $ filePath , bool $ expectedVirus , string $ expectedVirusName )
8087 {
81- $ scanner = new Scanner (new ScanStrategyClamdNetwork ());
88+ $ scanner = new Scanner (new ScanStrategyClamdNetwork (self :: $ host , self :: $ port ));
8289
8390 $ scanResult = $ scanner ->scan ($ filePath );
8491 $ this ->assertSame ($ expectedVirus , !$ scanResult ->isClean ());
@@ -91,7 +98,7 @@ public function testScanValidFilesWithClamdNetwork(string $filePath, bool $expec
9198 */
9299 public function testScanInvalidFilesWithClamdNetwork (string $ filePath , string $ expectedErrorMessage )
93100 {
94- $ scanner = new Scanner (new ScanStrategyClamdNetwork ());
101+ $ scanner = new Scanner (new ScanStrategyClamdNetwork (self :: $ host , self :: $ port ));
95102
96103 $ this ->expectException (FileScanException::class);
97104 $ this ->expectExceptionMessage ($ expectedErrorMessage );
@@ -101,19 +108,19 @@ public function testScanInvalidFilesWithClamdNetwork(string $filePath, string $e
101108 public function validFilesToCheckProvider ()
102109 {
103110 return [
104- [__DIR__ .'/../Files/clean.txt ' , false , '' ],
105- [__DIR__ .'/../Files/eicar.txt ' , true , 'Win.Test.EICAR_HDB-1 ' ],
106- [__DIR__ .'/../Files/eicar-dropper.pdf ' , true , 'Doc.Dropper.Agent-1540415 ' ],
107- [__DIR__ .'/../Files/infected-archive.zip ' , true , 'Win.Test.EICAR_HDB-1 ' ],
111+ [realpath ( __DIR__ .'/../Files/clean.txt ' ) , false , '' ],
112+ [realpath ( __DIR__ .'/../Files/eicar.txt ' ) , true , 'Win.Test.EICAR_HDB-1 ' ],
113+ [realpath ( __DIR__ .'/../Files/eicar-dropper.pdf ' ) , true , 'Doc.Dropper.Agent-1540415 ' ],
114+ [realpath ( __DIR__ .'/../Files/infected-archive.zip ' ) , true , 'Win.Test.EICAR_HDB-1 ' ],
108115 ];
109116 }
110117
111118 public function invalidFilesToCheckProvider ()
112119 {
113120 return [
114- [__DIR__ .'/../Files/ ' , 'Error scanning " ' .__DIR__ .'/../Files/ ' .'": Not a file. ' ],
121+ [realpath ( __DIR__ .'/../Files/ ' ) , 'Error scanning " ' .realpath ( __DIR__ .'/../Files/ ' ) .'": Not a file. ' ],
115122 ['file_does_not_exist ' , 'Error scanning "file_does_not_exist": Not a file. ' ],
116- [__DIR__ .'/../Files/inaccessible.txt ' , 'Error scanning " ' .__DIR__ .'/../Files/inaccessible.txt ' .'": Access denied. ' ],
123+ [realpath ( __DIR__ .'/../Files/inaccessible.txt ' ) , 'Error scanning " ' .realpath ( __DIR__ .'/../Files/inaccessible.txt ' ) .'": Access denied. ' ],
117124 ];
118125 }
119126}
0 commit comments