diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..107b775 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -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" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f973ee0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.phpunit.result.cache +composer.lock +phpunit.xml +vendor diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 4d50040..df36c11 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -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() @@ -101,7 +107,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->end() ; - return $tb; + return $treeBuilder; } /** diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index b1f1575..0ef8423 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -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( @@ -87,7 +90,8 @@ public function getProcessedConfigurations() 'adapter' => [ 'alias' => 'foobar', 'options' => [], - ] + ], + 'enabled' => true, ] ], [ @@ -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, ] ] ]; diff --git a/Tests/Validator/Constraints/CleanFileValidatorTest.php b/Tests/Validator/Constraints/CleanFileValidatorTest.php index 2e63128..3129272 100755 --- a/Tests/Validator/Constraints/CleanFileValidatorTest.php +++ b/Tests/Validator/Constraints/CleanFileValidatorTest.php @@ -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 @@ -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() @@ -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); + } } diff --git a/Tests/Validator/Constraints/fixtures/clean.txt b/Tests/Validator/Constraints/fixtures/clean.txt new file mode 100644 index 0000000..d86bac9 --- /dev/null +++ b/Tests/Validator/Constraints/fixtures/clean.txt @@ -0,0 +1 @@ +OK diff --git a/Tests/Validator/Constraints/fixtures/infected.txt b/Tests/Validator/Constraints/fixtures/infected.txt new file mode 100644 index 0000000..a2463df --- /dev/null +++ b/Tests/Validator/Constraints/fixtures/infected.txt @@ -0,0 +1 @@ +X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H* \ No newline at end of file diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php new file mode 100644 index 0000000..a90bdd1 --- /dev/null +++ b/Tests/bootstrap.php @@ -0,0 +1,5 @@ +autoRemove) { unlink($path); } + $this->context->buildViolation($constraint->virusDetectedMessage)->addViolation(); $event = new DetectionVirusEvent($value, $constraint); diff --git a/composer.json b/composer.json index 0bf2502..f96a3a9 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index cb32a91..02dee58 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -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" > + + + + ./Tests/