Skip to content

Commit 8a14e7d

Browse files
committed
Added Sf6 support
1 parent 5601b75 commit 8a14e7d

File tree

6 files changed

+82
-20
lines changed

6 files changed

+82
-20
lines changed

.coveralls.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage_clover: tests/build/clover.xml
2+
service_name: travis-ci
3+
json_path: tests/build/coveralls.json

.travis.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
language: php
2+
php:
3+
- '7.3'
4+
- '8.1'
5+
6+
env:
7+
global:
8+
- CLAMAV_SOCKET="/var/run/clamav/clamd.ctl"
9+
- CLAMAV_HOST="127.0.0.1"
10+
- CLAMAV_PORT="3310"
11+
jobs:
12+
- SYMFONY_VERSION="~6.0"
13+
- SYMFONY_VERSION="~5.0"
14+
- SYMFONY_VERSION="~4.0"
15+
16+
jobs:
17+
exclude:
18+
- env: SYMFONY_VERSION="~6.0"
19+
php: '7.3'
20+
21+
before_install:
22+
- sudo apt-get update -qq
23+
- sudo apt-get install -y libclamav-dev clamav clamav-daemon clamav-freshclam
24+
25+
install:
26+
- composer require --no-update symfony/framework-bundle:${SYMFONY_VERSION}
27+
- composer install --dev --no-interaction
28+
29+
before_script:
30+
- sudo freshclam
31+
- echo 'TCPAddr 127.0.0.1' | sudo tee -a /etc/clamav/clamd.conf
32+
- echo 'TCPSocket 3310' | sudo tee -a /etc/clamav/clamd.conf
33+
- sudo adduser clamav travis
34+
- sudo /etc/init.d/clamav-daemon start
35+
- wget -q --waitretry=1 --retry-connrefused -T 120 -O - http://${CLAMAV_HOST}:${CLAMAV_PORT}
36+
- export XDEBUG_MODE=coverage
37+
38+
script:
39+
- vendor/bin/phpunit --coverage-clover=tests/build/clover.xml 2>/dev/null
40+
- vendor/bin/phpcs -np --standard=PSR2 --ignore=vendor/,tests/,var/ ./
41+
42+
after_script:
43+
- travis_retry php vendor/bin/php-coveralls -v
44+
45+
cache:
46+
directories:
47+
- "/var/lib/clamav"
48+
apt: true

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
This library is a PHP client for working with a ClamAV daemon. It also provides optional Symfony integration.
22

3+
[![Build Status](https://app.travis-ci.com/sineflow/clamav.svg?branch=master)](https://app.travis-ci.com/github/sineflow/clamav)
4+
35
# Installation
46
```
57
$ composer require sineflow/clamav

composer.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@
1313
],
1414
"require": {
1515
"php": "^7.3 || ^8.0",
16-
"symfony/http-kernel": "~4.0 || ~5.0",
17-
"symfony/config": "~4.0 || ~5.0",
18-
"symfony/dependency-injection": "~4.0 || ~5.0",
19-
"symfony/yaml": "~4.0 || ~5.0",
16+
"symfony/http-kernel": "~4.0 || ~5.0 || ~6.0",
17+
"symfony/config": "~4.0 || ~5.0 || ~6.0",
18+
"symfony/dependency-injection": "~4.0 || ~5.0 || ~6.0",
19+
"symfony/yaml": "~4.0 || ~5.0 || ~6.0",
2020
"ext-sockets": "*"
2121
},
2222
"require-dev": {
23-
"phpunit/phpunit": "^9.0"
23+
"phpunit/phpunit": "^9.0",
24+
"squizlabs/php_codesniffer": "^3.0",
25+
"php-coveralls/php-coveralls": "^2.5"
2426
},
2527
"autoload": {
2628
"psr-4": {"Sineflow\\ClamAV\\": "src/"}

tests/Functional/BundleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class SineflowClamavTestingKernel extends Kernel
1313
{
14-
public function registerBundles()
14+
public function registerBundles(): iterable
1515
{
1616
return [
1717
new SineflowClamAVBundle(),

tests/Functional/ScannerTest.php

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@
1111
class 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

Comments
 (0)