Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: "CI Tests"

on:
push:
pull_request:

jobs:
tests:
name: "PHP ${{ matrix.php }} - Symfony ${{ matrix.symfony }}${{ matrix.composer-flags != '' && format(' - Composer {0}', matrix.composer-flags) || '' }}"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php:
- '7.4'
- '8.0'
- '8.1'
- '8.2'
symfony:
- '3.4.*'
- '4.4.*'
- '5.4.*'
composer-flags:
- '--prefer-stable'
include:
# Lowest Deps
- php: 7.4
symfony: 3.4.*
composer-flags: '--prefer-stable --prefer-lowest'
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
with:
fetch-depth: 2

- name: "Cache Composer packages"
uses: "actions/cache@v3"
with:
path: "~/.composer/cache"
key: "php-${{ matrix.php }}-symfony-${{ matrix.symfony }}-composer-${{ hashFiles('composer.json') }}-flags-${{ matrix.composer-flags }}"
restore-keys: "php-"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php }}"
tools: "composer:v2,flex"

- name: "Set Composer stability"
run: "composer config minimum-stability dev"

- name: "Install dependencies"
run: "composer update ${{ matrix.composer-flags }} --prefer-dist"
env:
SYMFONY_REQUIRE: "${{ matrix.symfony }}"

- name: "Validate composer"
run: "composer validate --strict --no-check-lock --no-check-all"

- name: "Run PHPUnit Tests"
run: "vendor/bin/phpunit"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.phpunit.result.cache
composer.lock
phpunit.xml
vendor
12 changes: 9 additions & 3 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$tb = new TreeBuilder();

$treeBuilder = new TreeBuilder('tissue');
$self = $this;
$rootNode = $tb->root('tissue');
if (method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
$rootNode = $treeBuilder->root('tissue');
}

$rootNode
->canBeEnabled()
Expand Down Expand Up @@ -101,7 +107,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->end()
;

return $tb;
return $treeBuilder;
}

/**
Expand Down
28 changes: 18 additions & 10 deletions Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
namespace CL\Bundle\TissueBundle\Tests\DependencyInjection;

use CL\Bundle\TissueBundle\DependencyInjection\Configuration;
use Matthias\SymfonyConfigTest\PhpUnit\AbstractConfigurationTestCase;
use PHPUnit\Framework\TestCase;
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;

class ConfigurationTest extends AbstractConfigurationTestCase
class ConfigurationTest extends TestCase
{
use ConfigurationTestCaseTrait;

public function testValuesAreInvalidIfRequiredValueIsNotProvided()
{
$this->assertConfigurationIsInvalid(
Expand Down Expand Up @@ -87,7 +90,8 @@ public function getProcessedConfigurations()
'adapter' => [
'alias' => 'foobar',
'options' => [],
]
],
'enabled' => true,
]
],
[
Expand All @@ -100,25 +104,29 @@ public function getProcessedConfigurations()
'adapter' => [
'alias' => 'foobar',
'options' => [],
]
],
'enabled' => true,
]
],
[
[
'adapter' => [
'alias' => 'foobar',
'alias' => 'clamav',
'options' => [
'apple' => 'pie'
'bin' => '/usr/bin/pie',
'database' => 'foobar',
]
]
],
],
[
'adapter' => [
'alias' => 'foobar',
'alias' => 'clamav',
'options' => [
'apple' => 'pie'
'bin' => '/usr/bin/pie',
'database' => 'foobar',
],
]
],
'enabled' => true,
]
]
];
Expand Down
27 changes: 23 additions & 4 deletions Tests/Validator/Constraints/CleanFileValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@
use CL\Bundle\TissueBundle\Validator\Constraints\CleanFileValidator;
use CL\Tissue\Adapter\MockAdapter;
use CL\Tissue\Tests\Adapter\AbstractAdapterTestCase;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;
use Symfony\Component\Validator\Validation;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;

class CleanFileValidatorTest extends AbstractConstraintValidatorTest

class CleanFileValidatorTest extends ConstraintValidatorTestCase
{
/**
* @var CleanFileValidator
Expand All @@ -42,7 +46,10 @@ protected function getApiVersion()

protected function createValidator()
{
return new CleanFileValidator(new MockAdapter());
return new CleanFileValidator(
$this->createMock(EventDispatcherInterface::class),
new MockAdapter()
);
}

public function testNullIsValid()
Expand All @@ -61,15 +68,27 @@ public function testEmptyStringIsValid()

public function testCleanFileIsValid()
{
$this->validator->validate(AbstractAdapterTestCase::getPathToCleanFile(), new CleanFile());
$this->validator->validate($this->createUploadedFile(__DIR__ . '/fixtures/clean.txt', 'clean_file'), new CleanFile());

$this->assertNoViolation();
}

public function testInfectedFileIsInvalid()
{
$this->validator->validate(AbstractAdapterTestCase::getPathToInfectedFile(), new CleanFile());
$this->validator->validate($this->createUploadedFile(__DIR__ . '/fixtures/infected.txt', 'infected_file'), new CleanFile());

$this->buildViolation('This file contains a virus.')->assertRaised();
}

private function createUploadedFile(string $filepath, string $orignalName): UploadedFile
{
$class = new \ReflectionClass(UploadedFile::class);

if ($class->getConstructor()->getNumberOfParameters() === 6) {
// BC layer for symfony 3.4
return new UploadedFile($filepath, $orignalName,null, null, UPLOAD_ERR_OK, true);
}

return new UploadedFile($filepath, $orignalName,null,UPLOAD_ERR_OK, true);
}
}
1 change: 1 addition & 0 deletions Tests/Validator/Constraints/fixtures/clean.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OK
1 change: 1 addition & 0 deletions Tests/Validator/Constraints/fixtures/infected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
5 changes: 5 additions & 0 deletions Tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

require __DIR__ . '/../vendor/autoload.php';

class_alias('PHPUnit\Framework\TestCase', '\PHPUnit_Framework_TestCase');
1 change: 1 addition & 0 deletions Validator/Constraints/CleanFileValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function validate($value, Constraint $constraint): void
if ($constraint->autoRemove) {
unlink($path);
}

$this->context->buildViolation($constraint->virusDetectedMessage)->addViolation();

$event = new DetectionVirusEvent($value, $constraint);
Expand Down
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@
],
"require": {
"php": ">=7.1",
"symfony/symfony": "^3.0 || ^4.0",
"symfony/options-resolver": "^3.0 || ^4.0",
"symfony/validator": "^3.0 || ^4.0",
"symfony/event-dispatcher": "^3.0 || ^4.0",
"symfony/symfony": "^3.4 || ^4.0 || ^5.0",
"symfony/options-resolver": "^3.4 || ^4.0 || ^5.0",
"symfony/validator": "^3.4 || ^4.0 || ^5.0",
"symfony/event-dispatcher": "^3.4 || ^4.0 || ^5.0",
"evozon-php/tissue": "*",
"evozon-php/tissue-clamav-adapter": "*"
},
"require-dev": {
"phpunit/phpunit": "^6.0",
"matthiasnoback/symfony-config-test": "^3.1"
"phpunit/phpunit": "^6.5 || ^7.0 || ^8.0",
"symfony/phpunit-bridge": "^3.4 || ^4.0 || ^5.0",
"matthiasnoback/symfony-config-test": "^3.1 || ^4.0"
},
"suggests": {
"suggest": {
"cleentfaar/tissue-clamavphp-adapter": "If you want to scan your files using the PHP-extension of the ClamAV engine"
},
"minimum-stability": "dev",
Expand Down
6 changes: 5 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
bootstrap="Tests/bootstrap.php"
>
<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[direct]=0"/>
</php>

<testsuites>
<testsuite name="CL TissueBundle Test Suite">
<directory>./Tests/</directory>
Expand Down