diff --git a/.github/workflows/qa.yaml b/.github/workflows/qa.yaml new file mode 100644 index 00000000..55d48e32 --- /dev/null +++ b/.github/workflows/qa.yaml @@ -0,0 +1,119 @@ +name: Quality and Assurance + +on: + push: + pull_request: + +jobs: + build: + name: Build + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + php-versions: ['7.1', '8.1'] + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup PHP, extensions and composer with shivammathur/setup-php + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, xml, ctype, iconv, intl, pdo, pdo_mysql, dom, filter, gd, iconv, json, mbstring, pdo + env: + update: true + + - name: Validate composer.json + run: composer validate --strict + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Install Composer dependencies + run: composer install --no-progress --prefer-dist --optimize-autoloader + + - name: Install Lowest Composer dependencies + if: "matrix.php-versions < '8.1'" + run: composer update --prefer-lowest --no-progress --prefer-dist --optimize-autoloader + + - name: Install PHPUnit + run: vendor/bin/simple-phpunit install + + - name: Cache composer dependencies + uses: actions/cache@v1 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + php-version: ${{ matrix.php-versions }} + + qa: + name: Quality + needs: build + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + php-versions: ['8.1'] + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup PHP, extensions and composer with shivammathur/setup-php + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, xml, ctype, intl, dom, filter + tools: symfony + env: + update: true + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Install Composer dependencies + run: composer install --no-progress --prefer-dist --optimize-autoloader + + - name: PHP-CS-Fixer + run: symfony php ./vendor/bin/php-cs-fixer fix --dry-run --using-cache=no --verbose --diff + + test: + name: Tests + needs: build + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + php-versions: ['7.1', '8.1'] + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup PHP, extensions and composer with shivammathur/setup-php + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, xml, ctype, intl, dom, filter + tools: symfony + env: + update: true + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Install Composer dependencies + run: composer install --no-progress --prefer-dist --optimize-autoloader + + - name: Install Lowest Composer dependencies + if: "matrix.php-versions < '8.1'" + run: composer install --no-progress --prefer-dist --optimize-autoloader + + - name: Execute unit tests + run: symfony php ./vendor/bin/simple-phpunit diff --git a/.gitignore b/.gitignore index 3714b9b6..55240f9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -.php_cs.cache +.php-cs-fixer.cache .phpunit.result.cache phpunit.xml composer.lock diff --git a/.php_cs.dist b/.php-cs-fixer.dist.php similarity index 65% rename from .php_cs.dist rename to .php-cs-fixer.dist.php index ac731140..7de6fa49 100644 --- a/.php_cs.dist +++ b/.php-cs-fixer.dist.php @@ -1,11 +1,11 @@ exclude('Resources') ->in(__DIR__) ; -return PhpCsFixer\Config::create() +return (new PhpCsFixer\Config()) ->setRules([ '@Symfony' => true, ]) diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e0dc3bd7..00000000 --- a/.travis.yml +++ /dev/null @@ -1,68 +0,0 @@ -language: php - -sudo: false - -dist: xenial - -env: - global: - - COMPOSER_MEMORY_LIMIT=-1 - - SYMFONY_PHPUNIT_DIR=$HOME/.phpunit-bridge - -cache: - directories: - - $HOME/.composer/cache - - $HOME/.phpunit-bridge - -jobs: - include: - # Lowest - - php: 7.1 - env: COMPOSER_FLAGS="--prefer-lowest" SYMFONY_DEPRECATIONS_HELPER=weak - - php: 7.1 - env: SYMFONY_REQUIRE="4.3.*" COMPOSER_FLAGS="--prefer-lowest" SYMFONY_DEPRECATIONS_HELPER=weak - - # Stable - - php: 7.2 - env: SYMFONY_REQUIRE="3.4.*" COMPOSER_FLAGS="--prefer-stable" - - php: 7.3 - env: SYMFONY_REQUIRE="4.4.*" COMPOSER_FLAGS="--prefer-stable" - - php: 7.4 - env: SYMFONY_REQUIRE="5.0.*" COMPOSER_FLAGS="--prefer-stable" - - php: 8.0 - env: SYMFONY_REQUIRE="5.0.*" COMPOSER_FLAGS="--prefer-stable" SYMFONY_DEPRECATIONS_HELPER=weak - - # Dev - - php: 7.4 - env: STABILITY=dev - - # QA - - stage: QA - name: PHP CS Fixer - php: 7.4 - script: vendor/bin/php-cs-fixer fix --dry-run --diff - - name: Coverage - php: 7.4 - before_script: - - mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{.disabled,} - - echo "xdebug.mode = coverage" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini - - if [[ ! $(php -m | grep -si xdebug) ]]; then echo "xdebug required for coverage"; exit 1; fi - script: - - ./vendor/bin/simple-phpunit -v --coverage-text - - allow_failures: - - env: STABILITY=dev - -before_install: - - mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{,.disabled} || echo "xdebug not available" - - composer self-update - - composer global require --no-progress --no-scripts --no-plugins symfony/flex - -install: - - composer update --prefer-dist --no-interaction $COMPOSER_FLAGS - - vendor/bin/simple-phpunit install - -script: - - if [[ -v $STABILITY ]]; then composer config minimum-stability $STABILITY; fi; - - composer validate --strict --no-check-lock - - vendor/bin/simple-phpunit -v diff --git a/CHANGELOG b/CHANGELOG index 62e68f86..308e9413 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +## Version 4.0 (04/2022) + + * [BC Break] Drop support for Symfony < 4.4 + * add support for Symfony 6.x + * add support for PHPUnit 10.x + ## Version 3.0 (12/2019) * [BC break] Dropped support for PHP 5.x. PHP 7.1 minimum required. diff --git a/README.md b/README.md index 25af43e4..ae39ef4f 100644 --- a/README.md +++ b/README.md @@ -11,44 +11,13 @@ This bundle integrates [HTMLPurifier][] into Symfony. ## Installation -## Symfony 3.4 and above (using Composer) - -Require the bundle in your composer.json file: - -```json -{ - "require": { - "exercise/htmlpurifier-bundle": "*" - } -} -``` - Install the bundle: ```bash $ composer require exercise/htmlpurifier-bundle ``` -Register the bundle in Symfony 3: - -```php -// app/AppKernel.php - -public function registerBundles() -{ - return [ - // ... - new Exercise\HTMLPurifierBundle\ExerciseHTMLPurifierBundle(), - ]; -} -``` - -## Configuration in Symfony 3 - -The configuration is the same as the following section, but the path should be -`app/config.yml` instead. - -## Configuration in Symfony 4 and up +## Configuration If you do not explicitly configure this bundle, an HTMLPurifier service will be defined as `exercise_html_purifier.default`. This behavior is the same as if you @@ -117,7 +86,7 @@ services: exercise_html_purifier.default: '@App\Html\CustomHtmlPurifier' ``` -### Argument binding (Symfony >= 4.4) +### Argument binding The bundle also leverages the alias argument binding for each profile. So the following config: @@ -353,5 +322,5 @@ previous, and "all" could define its own rules too. ## Contributing -PRs are welcomed :). Please target the `2.0` branch for bug fixes and `master` +PRs are welcomed :). Please target the `3.x` branch for bug fixes and `master` for new features. diff --git a/composer.json b/composer.json index dddff0ff..e2c50218 100644 --- a/composer.json +++ b/composer.json @@ -13,15 +13,15 @@ ], "require": { "php": "^7.1.3 || ^8.0.0", - "ezyang/htmlpurifier": "~4.0", - "symfony/config": "~3.4 || ~4.0 || ^5.0", - "symfony/dependency-injection": "~3.4.1 || ^4.0.1 || ^5.0", - "symfony/http-kernel": "~3.4.1 || ^4.0.1 || ^5.0" + "ezyang/htmlpurifier": "~4.14", + "symfony/config": "~4.4 || ^5.0 || ^6.0", + "symfony/dependency-injection": "^4.4 || ^5.0 || ^6.0", + "symfony/http-kernel": "^4.4 || ^5.0 || ^6.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.0", - "symfony/form": "~3.4.1 || ^4.0.1 || ^5.0", - "symfony/phpunit-bridge": "4.4.*", + "friendsofphp/php-cs-fixer": "^3.0", + "symfony/form": "^4.4 || ^5.0 || ^6.0", + "symfony/phpunit-bridge": "^6.0", "twig/twig": "^1.35.0 || ^2.4.4 || ^3.0" }, "autoload": { @@ -35,7 +35,7 @@ }, "extra": { "branch-alias": { - "dev-master": "3.0.x-dev" + "dev-master": "4.x-dev" } } } diff --git a/src/CacheWarmer/SerializerCacheWarmer.php b/src/CacheWarmer/SerializerCacheWarmer.php index a0f9c762..bfa42f13 100644 --- a/src/CacheWarmer/SerializerCacheWarmer.php +++ b/src/CacheWarmer/SerializerCacheWarmer.php @@ -26,9 +26,8 @@ class SerializerCacheWarmer implements CacheWarmerInterface private $filesystem; /** - * @param string[] $paths - * @param string[] $profiles - * @param HTMLPurifiersRegistryInterface $registry Used to build cache within bundle runtime + * @param string[] $paths + * @param string[] $profiles */ public function __construct(array $paths, array $profiles, HTMLPurifiersRegistryInterface $registry, Filesystem $filesystem) { @@ -41,7 +40,7 @@ public function __construct(array $paths, array $profiles, HTMLPurifiersRegistry /** * {@inheritdoc} */ - public function warmUp($cacheDir) + public function warmUp($cacheDir): array { foreach ($this->paths as $path) { $this->filesystem->remove($path); // clean previous cache @@ -52,12 +51,14 @@ public function warmUp($cacheDir) // Will build the configuration $this->registry->get($profile)->purify("
"); } + + return []; } /** * {@inheritdoc} */ - public function isOptional() + public function isOptional(): bool { return false; } diff --git a/src/DependencyInjection/Compiler/HTMLPurifierPass.php b/src/DependencyInjection/Compiler/HTMLPurifierPass.php index ce744e84..16ed073a 100644 --- a/src/DependencyInjection/Compiler/HTMLPurifierPass.php +++ b/src/DependencyInjection/Compiler/HTMLPurifierPass.php @@ -12,12 +12,12 @@ class HTMLPurifierPass implements CompilerPassInterface { - const PURIFIER_TAG = 'exercise.html_purifier'; + public const PURIFIER_TAG = 'exercise.html_purifier'; /** * {@inheritdoc} */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { if (!$container->hasAlias(HTMLPurifiersRegistryInterface::class)) { return; diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 8ecee7ad..4b534279 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -11,16 +11,10 @@ class Configuration implements ConfigurationInterface /** * {@inheritdoc} */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('exercise_html_purifier'); - - if (method_exists($treeBuilder, 'getRootNode')) { - $rootNode = $treeBuilder->getRootNode(); - } else { - // BC layer for symfony/config 4.1 and older - $rootNode = $treeBuilder->root('exercise_html_purifier'); - } + $rootNode = $treeBuilder->getRootNode(); $rootNode ->children() diff --git a/src/DependencyInjection/ExerciseHTMLPurifierExtension.php b/src/DependencyInjection/ExerciseHTMLPurifierExtension.php index 76965aaf..74b067e4 100644 --- a/src/DependencyInjection/ExerciseHTMLPurifierExtension.php +++ b/src/DependencyInjection/ExerciseHTMLPurifierExtension.php @@ -14,7 +14,10 @@ class ExerciseHTMLPurifierExtension extends Extension { - public function load(array $configs, ContainerBuilder $container) + /** + * {@inheritdoc} + */ + public function load(array $configs, ContainerBuilder $container): void { $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); @@ -87,7 +90,7 @@ public function load(array $configs, ContainerBuilder $container) ; } - public function getAlias() + public function getAlias(): string { return 'exercise_html_purifier'; } diff --git a/src/ExerciseHTMLPurifierBundle.php b/src/ExerciseHTMLPurifierBundle.php index 31966ee9..f22d1b0b 100644 --- a/src/ExerciseHTMLPurifierBundle.php +++ b/src/ExerciseHTMLPurifierBundle.php @@ -11,7 +11,7 @@ class ExerciseHTMLPurifierBundle extends Bundle /** * {@inheritdoc} */ - public function build(ContainerBuilder $container) + public function build(ContainerBuilder $container): void { $container->addCompilerPass(new HTMLPurifierPass()); } diff --git a/src/Form/Listener/HTMLPurifierListener.php b/src/Form/Listener/HTMLPurifierListener.php index 98d86dd1..dfbf7420 100644 --- a/src/Form/Listener/HTMLPurifierListener.php +++ b/src/Form/Listener/HTMLPurifierListener.php @@ -25,7 +25,7 @@ public function purifySubmittedData(FormEvent $event): void return; // because we don't want to handle it here } - if (0 === strlen($submittedData = trim($data))) { + if (0 === strlen($submittedData = trim((string) $data))) { if ($submittedData !== $data) { $event->setData($submittedData); } @@ -39,7 +39,7 @@ public function purifySubmittedData(FormEvent $event): void /** * {@inheritdoc} */ - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ FormEvents::PRE_SUBMIT => ['purifySubmittedData', /* as soon as possible */ 1000000], diff --git a/src/Form/TypeExtension/HTMLPurifierTextTypeExtension.php b/src/Form/TypeExtension/HTMLPurifierTextTypeExtension.php index 0b88e03e..90815dd7 100644 --- a/src/Form/TypeExtension/HTMLPurifierTextTypeExtension.php +++ b/src/Form/TypeExtension/HTMLPurifierTextTypeExtension.php @@ -20,14 +20,6 @@ public function __construct(HTMLPurifiersRegistryInterface $registry) $this->purifiersRegistry = $registry; } - /** - * {@inheritdoc} - */ - public function getExtendedType() - { - return TextType::class; - } - /** * {@inheritdoc} */ @@ -39,7 +31,7 @@ public static function getExtendedTypes(): iterable /** * {@inheritdoc} */ - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver ->setDefaults([ @@ -69,7 +61,7 @@ public function configureOptions(OptionsResolver $resolver) /** * {@inheritdoc} */ - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { if ($options['purify_html']) { $builder->addEventSubscriber( diff --git a/src/HTMLPurifierConfigFactory.php b/src/HTMLPurifierConfigFactory.php index ce0657b2..9ba5d1aa 100644 --- a/src/HTMLPurifierConfigFactory.php +++ b/src/HTMLPurifierConfigFactory.php @@ -62,7 +62,7 @@ public static function create( * This build should never happen on runtime, since purifiers cache should * be generated during warm up. */ - public static function buildHTMLDefinition(\HTMLPurifier_Definition $def, array $attributes, array $elements, array $blankElements): void + public static function buildHTMLDefinition(\HTMLPurifier_HTMLDefinition $def, array $attributes, array $elements, array $blankElements): void { foreach ($attributes as $elementName => $rule) { foreach ($rule as $attributeName => $definition) { diff --git a/src/Twig/HTMLPurifierExtension.php b/src/Twig/HTMLPurifierExtension.php index 713596d8..aceafb77 100644 --- a/src/Twig/HTMLPurifierExtension.php +++ b/src/Twig/HTMLPurifierExtension.php @@ -10,7 +10,7 @@ class HTMLPurifierExtension extends AbstractExtension /** * {@inheritdoc} */ - public function getFilters() + public function getFilters(): array { return [ new TwigFilter('purify', [HTMLPurifierRuntime::class, 'purify'], ['is_safe' => ['html']]), diff --git a/tests/CacheWarmer/SerializerCacheWarmerTest.php b/tests/CacheWarmer/SerializerCacheWarmerTest.php index 42856753..b21ec241 100644 --- a/tests/CacheWarmer/SerializerCacheWarmerTest.php +++ b/tests/CacheWarmer/SerializerCacheWarmerTest.php @@ -9,14 +9,14 @@ class SerializerCacheWarmerTest extends TestCase { - public function testShouldBeRequired() + public function testShouldBeRequired(): void { $cacheWarmer = new SerializerCacheWarmer([], [], $this->createMock(HTMLPurifiersRegistryInterface::class), new Filesystem()); $this->assertFalse($cacheWarmer->isOptional()); } - public function testWarmUpShouldCreatePaths() + public function testWarmUpShouldCreatePaths(): void { $fs = new Filesystem(); $path = sys_get_temp_dir().DIRECTORY_SEPARATOR.'html_purifier'; @@ -28,14 +28,14 @@ public function testWarmUpShouldCreatePaths() $this->assertFalse($fs->exists($path)); $cacheWarmer = new SerializerCacheWarmer([$path], [], $this->createMock(HTMLPurifiersRegistryInterface::class), $fs); - $cacheWarmer->warmUp(null); + $cacheWarmer->warmUp(''); $this->assertTrue($fs->exists($path)); $fs->remove($path); } - public function testWarmUpShouldCallPurifyForEachProfile() + public function testWarmUpShouldCallPurifyForEachProfile(): void { $purifier = $this->createMock(\HTMLPurifier::class); $purifier->expects($this->exactly(2)) @@ -45,18 +45,11 @@ public function testWarmUpShouldCallPurifyForEachProfile() $registry = $this->createMock(HTMLPurifiersRegistryInterface::class); $registry->expects($this->exactly(2)) ->method('get') + ->withConsecutive(['first'], ['second']) ->willReturn($purifier) ; - $registry->expects($this->at(0)) - ->method('get') - ->with('first') - ; - $registry->expects($this->at(1)) - ->method('get') - ->with('second') - ; $cacheWarmer = new SerializerCacheWarmer([], ['first', 'second'], $registry, new Filesystem()); - $cacheWarmer->warmUp(null); + $cacheWarmer->warmUp(''); } } diff --git a/tests/DependencyInjection/Compiler/HTMLPurifierPassTest.php b/tests/DependencyInjection/Compiler/HTMLPurifierPassTest.php index 7c484f2f..f5ef7090 100644 --- a/tests/DependencyInjection/Compiler/HTMLPurifierPassTest.php +++ b/tests/DependencyInjection/Compiler/HTMLPurifierPassTest.php @@ -16,7 +16,7 @@ class HTMLPurifierPassTest extends TestCase { - /** @var ContainerBuilder|MockObject */ + /** @var ContainerBuilder|MockObject|null */ private $container; protected function setUp(): void @@ -34,7 +34,7 @@ protected function tearDown(): void $this->container = null; } - public function testProcessOnlyIfRegistryInterfaceIsDefined() + public function testProcessOnlyIfRegistryInterfaceIsDefined(): void { $this->container->expects($this->once()) ->method('hasAlias') @@ -50,7 +50,7 @@ public function testProcessOnlyIfRegistryInterfaceIsDefined() $pass->process($this->container); } - public function testProcess() + public function testProcess(): void { $container = new ContainerBuilder(); $purifier = $container->register(DummyPurifier::class) @@ -71,7 +71,7 @@ public function testProcess() $this->assertSame(DummyPurifier::class, (string) $map['test']->getValues()[0]); } - public function testProcessDoNothingIfRegistryIsNotDefined() + public function testProcessDoNothingIfRegistryIsNotDefined(): void { $this->container ->expects($this->once()) @@ -94,7 +94,7 @@ public function testProcessDoNothingIfRegistryIsNotDefined() $pass->process($this->container); } - public function testProcessFailsIfTaggedServiceMissesProfileName() + public function testProcessFailsIfTaggedServiceMissesProfileName(): void { $container = new ContainerBuilder(); $container->register(DummyPurifier::class) diff --git a/tests/DependencyInjection/ExerciseHTMLPurifierExtensionTest.php b/tests/DependencyInjection/ExerciseHTMLPurifierExtensionTest.php index 274e5431..ffaa3e2e 100644 --- a/tests/DependencyInjection/ExerciseHTMLPurifierExtensionTest.php +++ b/tests/DependencyInjection/ExerciseHTMLPurifierExtensionTest.php @@ -17,17 +17,17 @@ class ExerciseHTMLPurifierExtensionTest extends TestCase private const DEFAULT_CACHE_PATH = '%kernel.cache_dir%/htmlpurifier'; /** - * @var ContainerBuilder + * @var ContainerBuilder|null */ private $container; /** - * @var ExerciseHTMLPurifierExtension + * @var ExerciseHTMLPurifierExtension|null */ private $extension; /** - * @var array + * @var array|null */ private $defaultConfig; @@ -48,7 +48,7 @@ public function tearDown(): void $this->container = null; } - public function testShouldLoadDefaultConfiguration() + public function testShouldLoadDefaultConfiguration(): void { $this->extension->load([], $this->container); @@ -57,7 +57,7 @@ public function testShouldLoadDefaultConfiguration() $this->assertRegistryHasProfiles(['default']); } - public function testInvalidParent() + public function testInvalidParent(): void { $config = [ 'html_profiles' => [ @@ -80,12 +80,12 @@ public function testInvalidParent() /** * @dataProvider provideInvalidElementDefinitions */ - public function testInvalidElements(array $elementDefinition) + public function testInvalidElements(array $elementDefinition): void { $config = [ 'html_profiles' => [ 'default' => [ - 'elements' => ['a' => []], + 'elements' => ['a' => $elementDefinition], ], ], ]; @@ -104,7 +104,7 @@ public function provideInvalidElementDefinitions(): iterable yield 'too many arguments' => [['', '', '', [], [], 'extra argument']]; } - public function testShouldAllowOverridingDefaultConfigurationCacheSerializerPath() + public function testShouldAllowOverridingDefaultConfigurationCacheSerializerPath(): void { $config = [ 'default_cache_serializer_path' => null, @@ -126,7 +126,7 @@ public function testShouldAllowOverridingDefaultConfigurationCacheSerializerPath $this->assertRegistryHasProfiles(['default']); } - public function testShouldNotDeepMergeOptions() + public function testShouldNotDeepMergeOptions(): void { $configs = [ ['html_profiles' => [ @@ -154,7 +154,7 @@ public function testShouldNotDeepMergeOptions() $this->assertRegistryHasProfiles(['default']); } - public function testShouldLoadCustomConfiguration() + public function testShouldLoadCustomConfiguration(): void { $config = [ 'html_profiles' => [ @@ -195,7 +195,7 @@ public function testShouldLoadCustomConfiguration() $this->assertRegistryHasProfiles($profiles); } - public function testShouldLoadComplexCustomConfiguration() + public function testShouldLoadComplexCustomConfiguration(): void { $defaultConfig = [ 'AutoFormat.AutoParagraph' => true, @@ -288,7 +288,7 @@ public function testShouldLoadComplexCustomConfiguration() $this->assertRegistryHasProfiles($profiles); } - public function testShouldRegisterAliases() + public function testShouldRegisterAliases(): void { if (!method_exists($this->container, 'registerAliasForArgument')) { $this->markTestSkipped('Alias arguments binding is not available.'); @@ -373,10 +373,8 @@ public function testShouldRegisterAliases() /** * Asserts that the named config definition extends the default profile and * loads the given options. - * - * @param string $name */ - private function assertConfigDefinition($name, array $config, array $parents = [], array $attributes = [], array $elements = [], array $blankElements = []) + private function assertConfigDefinition(string $name, array $config, array $parents = [], array $attributes = [], array $elements = [], array $blankElements = []): void { $this->assertTrue($this->container->hasDefinition('exercise_html_purifier.config.'.$name)); diff --git a/tests/Form/Listener/HTMLPurifierListenerTest.php b/tests/Form/Listener/HTMLPurifierListenerTest.php index 14447a60..04dc8240 100644 --- a/tests/Form/Listener/HTMLPurifierListenerTest.php +++ b/tests/Form/Listener/HTMLPurifierListenerTest.php @@ -10,7 +10,7 @@ class HTMLPurifierListenerTest extends TestCase { - public function testPurify() + public function testPurify(): void { $input = 'text'; $purifiedInput = '

text

'; @@ -41,7 +41,7 @@ public function testPurify() $this->assertSame($purifiedInput, $event->getData()); } - public function testPurifyTrimEmptyValues() + public function testPurifyTrimEmptyValues(): void { $input = ' '; $trimmedInput = ''; @@ -69,8 +69,10 @@ public function testPurifyTrimEmptyValues() /** * @dataProvider provideInvalidInput + * + * @param mixed $input */ - public function testPurifyDoNothingForEmptyOrNonScalarData($input) + public function testPurifyDoNothingForEmptyOrNonScalarData($input): void { $registry = $this->createMock(HTMLPurifiersRegistryInterface::class); $registry @@ -101,6 +103,9 @@ public function provideInvalidInput(): iterable yield [new \stdClass()]; } + /** + * @param mixed $data + */ private function getFormEvent($data): FormEvent { return new FormEvent($this->createMock(FormInterface::class), $data); diff --git a/tests/Form/TypeExtension/HTMLPurifierTextTypeExtensionTest.php b/tests/Form/TypeExtension/HTMLPurifierTextTypeExtensionTest.php index 1bddef62..84682181 100644 --- a/tests/Form/TypeExtension/HTMLPurifierTextTypeExtensionTest.php +++ b/tests/Form/TypeExtension/HTMLPurifierTextTypeExtensionTest.php @@ -5,6 +5,7 @@ use Exercise\HTMLPurifierBundle\Form\Listener\HTMLPurifierListener; use Exercise\HTMLPurifierBundle\Form\TypeExtension\HTMLPurifierTextTypeExtension; use Exercise\HTMLPurifierBundle\HTMLPurifiersRegistryInterface; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormInterface; @@ -13,6 +14,7 @@ class HTMLPurifierTextTypeExtensionTest extends FormIntegrationTestCase { + /** @var HTMLPurifiersRegistryInterface|MockObject|null */ private $registry; protected function setUp(): void @@ -29,14 +31,14 @@ protected function tearDown(): void $this->registry = null; } - protected function getTypeExtensions() + protected function getTypeExtensions(): array { return [ new HTMLPurifierTextTypeExtension($this->registry), ]; } - public function testDefaultOptions() + public function testDefaultOptions(): void { $this->registry ->expects($this->never()) @@ -56,7 +58,7 @@ public function testDefaultOptions() $this->assertFalse($this->hasPurifierListener($form)); } - public function testPurifyOptionsNeedDefaultProfile() + public function testPurifyOptionsNeedDefaultProfile(): void { $this->registry ->expects($this->once()) @@ -75,7 +77,7 @@ public function testPurifyOptionsNeedDefaultProfile() $this->factory->create(TextType::class, null, ['purify_html' => true]); } - public function testDefaultOptionsWhenPurifyIsTrue() + public function testDefaultOptionsWhenPurifyIsTrue(): void { $this->registry ->expects($this->once()) @@ -93,7 +95,7 @@ public function testDefaultOptionsWhenPurifyIsTrue() $this->assertTrue($this->hasPurifierListener($form)); } - public function testInvalidProfile() + public function testInvalidProfile(): void { $this->registry ->expects($this->once()) diff --git a/tests/HTMLPurifierConfigFactoryTest.php b/tests/HTMLPurifierConfigFactoryTest.php index e0a129d6..70dfec9c 100644 --- a/tests/HTMLPurifierConfigFactoryTest.php +++ b/tests/HTMLPurifierConfigFactoryTest.php @@ -8,6 +8,7 @@ class HTMLPurifierConfigFactoryTest extends TestCase { + /** @var string */ private static $cacheDir; public static function setUpBeforeClass(): void @@ -21,14 +22,14 @@ public static function tearDownAfterClass(): void (new Filesystem())->remove(self::$cacheDir); } - public function testCreateUseDoesNotBuildDefinitionByDefault() + public function testCreateUseDoesNotBuildDefinitionByDefault(): void { TestHTMLPurifierConfigFactory::create('default', []); $this->assertSame(0, TestHTMLPurifierConfigFactory::$calledBuild); } - public function testCreateUseSerializedCache() + public function testCreateUseSerializedCache(): void { $configArgs = [ 'test', /* profile */ @@ -53,10 +54,11 @@ public function testCreateUseSerializedCache() class TestHTMLPurifierConfigFactory extends HTMLPurifierConfigFactory { + /** @var int */ public static $calledBuild = 0; public static function buildHTMLDefinition( - \HTMLPurifier_Definition $def, + \HTMLPurifier_HTMLDefinition $def, array $attributes, array $elements, array $blankElements diff --git a/tests/HTMLPurifiersRegistryTest.php b/tests/HTMLPurifiersRegistryTest.php index d58d6df0..5dcfacea 100644 --- a/tests/HTMLPurifiersRegistryTest.php +++ b/tests/HTMLPurifiersRegistryTest.php @@ -3,12 +3,15 @@ namespace Exercise\HTMLPurifierBundle\Tests; use Exercise\HTMLPurifierBundle\HTMLPurifiersRegistry; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; class HTMLPurifiersRegistryTest extends TestCase { + /** @var MockObject|ContainerInterface|null */ private $locator; + /** @var HTMLPurifiersRegistry|null */ private $registry; protected function setUp(): void @@ -32,7 +35,7 @@ public function provideProfiles(): iterable /** * @dataProvider provideProfiles */ - public function testHas($profile) + public function testHas(string $profile): void { $this->locator->expects($this->once()) ->method('has') @@ -46,7 +49,7 @@ public function testHas($profile) /** * @dataProvider provideProfiles */ - public function testHasNot($profile) + public function testHasNot(string $profile): void { $this->locator->expects($this->once()) ->method('has') @@ -60,7 +63,7 @@ public function testHasNot($profile) /** * @dataProvider provideProfiles */ - public function testGet($profile) + public function testGet(string $profile): void { $purifier = $this->createMock(\HTMLPurifier::class); diff --git a/tests/Twig/HTMLPurifierRuntimeTest.php b/tests/Twig/HTMLPurifierRuntimeTest.php index e6b03349..21594ddb 100644 --- a/tests/Twig/HTMLPurifierRuntimeTest.php +++ b/tests/Twig/HTMLPurifierRuntimeTest.php @@ -11,7 +11,7 @@ class HTMLPurifierRuntimeTest extends TestCase /** * @dataProvider providePurifierProfiles */ - public function testPurifyFilter($profile) + public function testPurifyFilter(string $profile): void { $input = 'text'; $purifiedInput = '

text

';