From debb3192fb05fe1311f3531c0305a205a0e9bf2a Mon Sep 17 00:00:00 2001 From: ldaspt Date: Wed, 8 Mar 2023 10:50:15 +0100 Subject: [PATCH 1/3] Fix deprecations sf4.3 + tests The "Symfony\Component\Config\Definition\Builder\TreeBuilder::root()" method called for the "tissue" configuration is deprecated since Symfony 4.3, pass the root name to the constructor instead. --- .../DependencyInjection/ConfigurationTest.php | 28 ++++++++++++------- .../Constraints/CleanFileValidatorTest.php | 15 +++++++--- .../Validator/Constraints/fixtures/clean.txt | 1 + .../Constraints/fixtures/infected.txt | 1 + Tests/bootstrap.php | 5 ++++ Validator/Constraints/CleanFileValidator.php | 1 + composer.json | 10 +++---- phpunit.xml.dist | 2 +- 8 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 Tests/Validator/Constraints/fixtures/clean.txt create mode 100644 Tests/Validator/Constraints/fixtures/infected.txt create mode 100644 Tests/bootstrap.php 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..b6098f9 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,14 +68,14 @@ public function testEmptyStringIsValid() public function testCleanFileIsValid() { - $this->validator->validate(AbstractAdapterTestCase::getPathToCleanFile(), new CleanFile()); + $this->validator->validate(new UploadedFile(__DIR__ . '/fixtures/clean.txt', 'clean_file',null, null,null, true), new CleanFile()); $this->assertNoViolation(); } public function testInfectedFileIsInvalid() { - $this->validator->validate(AbstractAdapterTestCase::getPathToInfectedFile(), new CleanFile()); + $this->validator->validate(new UploadedFile(__DIR__ . '/fixtures/infected.txt', 'infected_file', null, null,null, true), new CleanFile()); $this->buildViolation('This file contains a virus.')->assertRaised(); } 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..2788292 100644 --- a/composer.json +++ b/composer.json @@ -19,15 +19,15 @@ ], "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", + "phpunit/phpunit": "^6.5", "matthiasnoback/symfony-config-test": "^3.1" }, "suggests": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index cb32a91..d95a0d8 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -4,7 +4,7 @@ xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd" backupGlobals="false" colors="true" - bootstrap="vendor/autoload.php" + bootstrap="Tests/bootstrap.php" > From b77196df3a5999a0b46ca737d21f6a6005fd5994 Mon Sep 17 00:00:00 2001 From: ldaspt Date: Wed, 8 Mar 2023 11:45:16 +0100 Subject: [PATCH 2/3] Fix deprecations sf4.3 + phpunitbrige to see deprecations --- DependencyInjection/Configuration.php | 12 +++++++++--- .../Constraints/CleanFileValidatorTest.php | 16 ++++++++++++++-- composer.json | 5 +++-- 3 files changed, 26 insertions(+), 7 deletions(-) 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/Validator/Constraints/CleanFileValidatorTest.php b/Tests/Validator/Constraints/CleanFileValidatorTest.php index b6098f9..3129272 100755 --- a/Tests/Validator/Constraints/CleanFileValidatorTest.php +++ b/Tests/Validator/Constraints/CleanFileValidatorTest.php @@ -68,15 +68,27 @@ public function testEmptyStringIsValid() public function testCleanFileIsValid() { - $this->validator->validate(new UploadedFile(__DIR__ . '/fixtures/clean.txt', 'clean_file',null, null,null, true), new CleanFile()); + $this->validator->validate($this->createUploadedFile(__DIR__ . '/fixtures/clean.txt', 'clean_file'), new CleanFile()); $this->assertNoViolation(); } public function testInfectedFileIsInvalid() { - $this->validator->validate(new UploadedFile(__DIR__ . '/fixtures/infected.txt', 'infected_file', null, null,null, true), 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/composer.json b/composer.json index 2788292..cec6f9d 100644 --- a/composer.json +++ b/composer.json @@ -27,8 +27,9 @@ "evozon-php/tissue-clamav-adapter": "*" }, "require-dev": { - "phpunit/phpunit": "^6.5", - "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": { "cleentfaar/tissue-clamavphp-adapter": "If you want to scan your files using the PHP-extension of the ClamAV engine" From da5b05b1ad22920754dd903fc4e28f9d4e29c4ae Mon Sep 17 00:00:00 2001 From: ldaspt Date: Thu, 9 Mar 2023 20:38:08 +0100 Subject: [PATCH 3/3] Add github actions --- .github/workflows/ci.yaml | 61 +++++++++++++++++++++++++++++++++++++++ .gitignore | 4 +++ composer.json | 2 +- phpunit.xml.dist | 4 +++ 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yaml create mode 100644 .gitignore 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/composer.json b/composer.json index cec6f9d..f96a3a9 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "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 d95a0d8..02dee58 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -6,6 +6,10 @@ colors="true" bootstrap="Tests/bootstrap.php" > + + + + ./Tests/