From 8d43fbe32af83c86f783aa5333d3cda2dbea116f Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Sun, 17 Apr 2022 13:10:49 +0200 Subject: [PATCH 1/7] fix compatibility with Symfony 6.x --- composer.json | 12 ++++++------ src/CacheWarmer/SerializerCacheWarmer.php | 6 ++++-- .../Compiler/HTMLPurifierPass.php | 2 +- src/DependencyInjection/Configuration.php | 2 +- .../ExerciseHTMLPurifierExtension.php | 2 +- src/ExerciseHTMLPurifierBundle.php | 2 +- src/Form/Listener/HTMLPurifierListener.php | 2 +- .../TypeExtension/HTMLPurifierTextTypeExtension.php | 4 ++-- src/Twig/HTMLPurifierExtension.php | 2 +- tests/CacheWarmer/SerializerCacheWarmerTest.php | 4 ++-- 10 files changed, 20 insertions(+), 18 deletions(-) diff --git a/composer.json b/composer.json index dddff0ff..89b385f9 100644 --- a/composer.json +++ b/composer.json @@ -14,14 +14,14 @@ "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" + "symfony/config": "~3.4 || ~4.0 || ^5.0 || ^6.0", + "symfony/dependency-injection": "~3.4.1 || ^4.0.1 || ^5.0 || ^6.0", + "symfony/http-kernel": "~3.4.1 || ^4.0.1 || ^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.*", + "symfony/form": "~3.4.1 || ^4.0.1 || ^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..3256503b 100644 --- a/src/CacheWarmer/SerializerCacheWarmer.php +++ b/src/CacheWarmer/SerializerCacheWarmer.php @@ -41,7 +41,7 @@ public function __construct(array $paths, array $profiles, HTMLPurifiersRegistry /** * {@inheritdoc} */ - public function warmUp($cacheDir) + public function warmUp(string $cacheDir): array { foreach ($this->paths as $path) { $this->filesystem->remove($path); // clean previous cache @@ -52,12 +52,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..f3c276c0 100644 --- a/src/DependencyInjection/Compiler/HTMLPurifierPass.php +++ b/src/DependencyInjection/Compiler/HTMLPurifierPass.php @@ -17,7 +17,7 @@ class HTMLPurifierPass implements CompilerPassInterface /** * {@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..9bc5d5c9 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -11,7 +11,7 @@ class Configuration implements ConfigurationInterface /** * {@inheritdoc} */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('exercise_html_purifier'); diff --git a/src/DependencyInjection/ExerciseHTMLPurifierExtension.php b/src/DependencyInjection/ExerciseHTMLPurifierExtension.php index 76965aaf..48105196 100644 --- a/src/DependencyInjection/ExerciseHTMLPurifierExtension.php +++ b/src/DependencyInjection/ExerciseHTMLPurifierExtension.php @@ -87,7 +87,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..3a3eebd5 100644 --- a/src/Form/Listener/HTMLPurifierListener.php +++ b/src/Form/Listener/HTMLPurifierListener.php @@ -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..72090132 100644 --- a/src/Form/TypeExtension/HTMLPurifierTextTypeExtension.php +++ b/src/Form/TypeExtension/HTMLPurifierTextTypeExtension.php @@ -39,7 +39,7 @@ public static function getExtendedTypes(): iterable /** * {@inheritdoc} */ - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver ->setDefaults([ @@ -69,7 +69,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/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..34493f17 100644 --- a/tests/CacheWarmer/SerializerCacheWarmerTest.php +++ b/tests/CacheWarmer/SerializerCacheWarmerTest.php @@ -28,7 +28,7 @@ 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)); @@ -57,6 +57,6 @@ public function testWarmUpShouldCallPurifyForEachProfile() ; $cacheWarmer = new SerializerCacheWarmer([], ['first', 'second'], $registry, new Filesystem()); - $cacheWarmer->warmUp(null); + $cacheWarmer->warmUp(''); } } From c86c72dee965713b941dfc8c14b8125a5cfcf054 Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Sun, 17 Apr 2022 13:14:32 +0200 Subject: [PATCH 2/7] drop support for Symfony < 4.4 --- composer.json | 8 ++++---- src/DependencyInjection/Configuration.php | 8 +------- src/Form/TypeExtension/HTMLPurifierTextTypeExtension.php | 8 -------- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index 89b385f9..d7f87898 100644 --- a/composer.json +++ b/composer.json @@ -14,13 +14,13 @@ "require": { "php": "^7.1.3 || ^8.0.0", "ezyang/htmlpurifier": "~4.0", - "symfony/config": "~3.4 || ~4.0 || ^5.0 || ^6.0", - "symfony/dependency-injection": "~3.4.1 || ^4.0.1 || ^5.0 || ^6.0", - "symfony/http-kernel": "~3.4.1 || ^4.0.1 || ^5.0 || ^6.0" + "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 || ^6.0", + "symfony/form": "^4.4 || ^5.0 || ^6.0", "symfony/phpunit-bridge": "^6.0", "twig/twig": "^1.35.0 || ^2.4.4 || ^3.0" }, diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 9bc5d5c9..4b534279 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -14,13 +14,7 @@ class Configuration implements ConfigurationInterface 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/Form/TypeExtension/HTMLPurifierTextTypeExtension.php b/src/Form/TypeExtension/HTMLPurifierTextTypeExtension.php index 72090132..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} */ From 40f520605ad1deb3de290ae5442eb27f6d8522d7 Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Sun, 17 Apr 2022 13:16:51 +0200 Subject: [PATCH 3/7] update README --- README.md | 37 +++---------------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) 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. From a56a9eccaf6a4739a5c6d4e8a6bf8151538c0561 Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Sun, 17 Apr 2022 13:19:05 +0200 Subject: [PATCH 4/7] fix PHPUnit 10 compatibility --- tests/CacheWarmer/SerializerCacheWarmerTest.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/tests/CacheWarmer/SerializerCacheWarmerTest.php b/tests/CacheWarmer/SerializerCacheWarmerTest.php index 34493f17..3429e5fc 100644 --- a/tests/CacheWarmer/SerializerCacheWarmerTest.php +++ b/tests/CacheWarmer/SerializerCacheWarmerTest.php @@ -45,16 +45,9 @@ 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(''); From da6c9f8ead3f8e15a797d1de1f0c593c23e15d07 Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Sun, 17 Apr 2022 13:24:54 +0200 Subject: [PATCH 5/7] update CHANGELOG --- CHANGELOG | 6 ++++++ 1 file changed, 6 insertions(+) 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. From 25e25369cdc78ddbe28e78f28abb8a438a59ba76 Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Sun, 17 Apr 2022 13:31:07 +0200 Subject: [PATCH 6/7] update php-cs-fixer --- .php-cs-fixer.cache | 1 + .php_cs.dist => .php-cs-fixer.dist.php | 4 ++-- composer.json | 2 +- src/DependencyInjection/Compiler/HTMLPurifierPass.php | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 .php-cs-fixer.cache rename .php_cs.dist => .php-cs-fixer.dist.php (65%) diff --git a/.php-cs-fixer.cache b/.php-cs-fixer.cache new file mode 100644 index 00000000..8b92120c --- /dev/null +++ b/.php-cs-fixer.cache @@ -0,0 +1 @@ +{"php":"8.1.4","version":"3.8.0:v3.8.0#cbad1115aac4b5c3c5540e7210d3c9fba2f81fa3","indent":" ","lineEnding":"\n","rules":{"array_syntax":true,"backtick_to_shell_exec":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["return"]},"braces":{"allow_single_line_anonymous_class_with_empty_body":true,"allow_single_line_closure":true},"cast_spaces":true,"class_attributes_separation":{"elements":{"method":"one"}},"class_definition":{"single_line":true},"class_reference_name_casing":true,"clean_namespace":true,"concat_space":true,"echo_tag_syntax":true,"empty_loop_body":{"style":"braces"},"empty_loop_condition":true,"fully_qualified_strict_types":true,"function_typehint_space":true,"general_phpdoc_tag_rename":{"replacements":{"inheritDocs":"inheritDoc"}},"include":true,"increment_style":true,"integer_literal_case":true,"lambda_not_used_import":true,"linebreak_after_opening_tag":true,"magic_constant_casing":true,"magic_method_casing":true,"method_argument_space":{"on_multiline":"ignore"},"native_function_casing":true,"native_function_type_declaration_casing":true,"no_alias_language_construct_call":true,"no_alternative_syntax":true,"no_binary_string":true,"no_blank_lines_after_phpdoc":true,"no_empty_comment":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_extra_blank_lines":{"tokens":["case","continue","curly_brace_block","default","extra","parenthesis_brace_block","square_brace_block","switch","throw","use"]},"no_leading_namespace_whitespace":true,"no_mixed_echo_print":true,"no_multiline_whitespace_around_double_arrow":true,"no_short_bool_cast":true,"no_singleline_whitespace_before_semicolons":true,"no_spaces_around_offset":true,"no_superfluous_phpdoc_tags":{"allow_mixed":true,"allow_unused_params":true},"no_trailing_comma_in_list_call":true,"no_trailing_comma_in_singleline_array":true,"no_trailing_comma_in_singleline_function_call":true,"no_unneeded_control_parentheses":{"statements":["break","clone","continue","echo_print","return","switch_case","yield","yield_from"]},"no_unneeded_curly_braces":{"namespaces":true},"no_unneeded_import_alias":true,"no_unset_cast":true,"no_unused_imports":true,"no_whitespace_before_comma_in_array":true,"normalize_index_brace":true,"object_operator_without_whitespace":true,"ordered_imports":true,"php_unit_fqcn_annotation":true,"php_unit_method_casing":true,"phpdoc_align":true,"phpdoc_annotation_without_dot":true,"phpdoc_indent":true,"phpdoc_inline_tag_normalizer":true,"phpdoc_no_access":true,"phpdoc_no_alias_tag":true,"phpdoc_no_package":true,"phpdoc_no_useless_inheritdoc":true,"phpdoc_return_self_reference":true,"phpdoc_scalar":true,"phpdoc_separation":true,"phpdoc_single_line_var_spacing":true,"phpdoc_summary":true,"phpdoc_tag_type":{"tags":{"inheritDoc":"inline"}},"phpdoc_to_comment":true,"phpdoc_trim":true,"phpdoc_trim_consecutive_blank_line_separation":true,"phpdoc_types":true,"phpdoc_types_order":{"null_adjustment":"always_last","sort_algorithm":"none"},"phpdoc_var_without_name":true,"protected_to_private":true,"semicolon_after_instruction":true,"single_class_element_per_statement":true,"single_line_comment_spacing":true,"single_line_comment_style":{"comment_types":["hash"]},"single_line_throw":true,"single_quote":true,"single_space_after_construct":true,"space_after_semicolon":{"remove_in_empty_for_expressions":true},"standardize_increment":true,"standardize_not_equals":true,"switch_continue_to_break":true,"trailing_comma_in_multiline":true,"trim_array_spaces":true,"types_spaces":true,"unary_operator_spaces":true,"whitespace_after_comma_in_array":true,"yoda_style":true,"blank_line_after_opening_tag":true,"compact_nullable_typehint":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"return_type_declaration":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"visibility_required":true,"blank_line_after_namespace":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"no_break_comment":true,"no_closing_tag":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true},"hashes":{"src\/HTMLPurifiersRegistryInterface.php":187845934,"src\/Form\/Listener\/HTMLPurifierListener.php":4116418424,"src\/Form\/TypeExtension\/HTMLPurifierTextTypeExtension.php":608289064,"src\/HTMLPurifiersRegistry.php":795094810,"src\/CacheWarmer\/SerializerCacheWarmer.php":2733650958,"src\/HTMLPurifierConfigFactory.php":1012979259,"src\/Twig\/HTMLPurifierExtension.php":3905834270,"src\/Twig\/HTMLPurifierRuntime.php":1281382522,"src\/DependencyInjection\/Configuration.php":2513854708,"src\/DependencyInjection\/ExerciseHTMLPurifierExtension.php":1265155058,"src\/DependencyInjection\/Compiler\/HTMLPurifierPass.php":1538180982,"src\/ExerciseHTMLPurifierBundle.php":2699336334,"tests\/HTMLPurifierConfigFactoryTest.php":969987042,"tests\/Form\/Listener\/HTMLPurifierListenerTest.php":1185658046,"tests\/Form\/TypeExtension\/HTMLPurifierTextTypeExtensionTest.php":1496463765,"tests\/CacheWarmer\/SerializerCacheWarmerTest.php":3561678071,"tests\/HTMLPurifiersRegistryTest.php":2606387570,"tests\/Twig\/HTMLPurifierRuntimeTest.php":887512979,"tests\/DependencyInjection\/ExerciseHTMLPurifierExtensionTest.php":2900253984,"tests\/DependencyInjection\/Compiler\/HTMLPurifierPassTest.php":1485032584}} \ No newline at end of file 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/composer.json b/composer.json index d7f87898..6bb8e97a 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "symfony/http-kernel": "^4.4 || ^5.0 || ^6.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.0", + "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" diff --git a/src/DependencyInjection/Compiler/HTMLPurifierPass.php b/src/DependencyInjection/Compiler/HTMLPurifierPass.php index f3c276c0..16ed073a 100644 --- a/src/DependencyInjection/Compiler/HTMLPurifierPass.php +++ b/src/DependencyInjection/Compiler/HTMLPurifierPass.php @@ -12,7 +12,7 @@ class HTMLPurifierPass implements CompilerPassInterface { - const PURIFIER_TAG = 'exercise.html_purifier'; + public const PURIFIER_TAG = 'exercise.html_purifier'; /** * {@inheritdoc} From 6c3ab4384d15fc41cf733783a32852d838a64054 Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Mon, 18 Apr 2022 19:17:54 +0200 Subject: [PATCH 7/7] update QA from travis to Github actions --- .github/workflows/qa.yaml | 119 ++++++++++++++++++ .gitignore | 2 +- .php-cs-fixer.cache | 1 - .travis.yml | 68 ---------- composer.json | 2 +- src/CacheWarmer/SerializerCacheWarmer.php | 7 +- .../ExerciseHTMLPurifierExtension.php | 5 +- src/Form/Listener/HTMLPurifierListener.php | 2 +- src/HTMLPurifierConfigFactory.php | 2 +- .../CacheWarmer/SerializerCacheWarmerTest.php | 6 +- .../Compiler/HTMLPurifierPassTest.php | 10 +- .../ExerciseHTMLPurifierExtensionTest.php | 28 ++--- .../Listener/HTMLPurifierListenerTest.php | 11 +- .../HTMLPurifierTextTypeExtensionTest.php | 12 +- tests/HTMLPurifierConfigFactoryTest.php | 8 +- tests/HTMLPurifiersRegistryTest.php | 9 +- tests/Twig/HTMLPurifierRuntimeTest.php | 2 +- 17 files changed, 178 insertions(+), 116 deletions(-) create mode 100644 .github/workflows/qa.yaml delete mode 100644 .php-cs-fixer.cache delete mode 100644 .travis.yml 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-fixer.cache b/.php-cs-fixer.cache deleted file mode 100644 index 8b92120c..00000000 --- a/.php-cs-fixer.cache +++ /dev/null @@ -1 +0,0 @@ -{"php":"8.1.4","version":"3.8.0:v3.8.0#cbad1115aac4b5c3c5540e7210d3c9fba2f81fa3","indent":" ","lineEnding":"\n","rules":{"array_syntax":true,"backtick_to_shell_exec":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["return"]},"braces":{"allow_single_line_anonymous_class_with_empty_body":true,"allow_single_line_closure":true},"cast_spaces":true,"class_attributes_separation":{"elements":{"method":"one"}},"class_definition":{"single_line":true},"class_reference_name_casing":true,"clean_namespace":true,"concat_space":true,"echo_tag_syntax":true,"empty_loop_body":{"style":"braces"},"empty_loop_condition":true,"fully_qualified_strict_types":true,"function_typehint_space":true,"general_phpdoc_tag_rename":{"replacements":{"inheritDocs":"inheritDoc"}},"include":true,"increment_style":true,"integer_literal_case":true,"lambda_not_used_import":true,"linebreak_after_opening_tag":true,"magic_constant_casing":true,"magic_method_casing":true,"method_argument_space":{"on_multiline":"ignore"},"native_function_casing":true,"native_function_type_declaration_casing":true,"no_alias_language_construct_call":true,"no_alternative_syntax":true,"no_binary_string":true,"no_blank_lines_after_phpdoc":true,"no_empty_comment":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_extra_blank_lines":{"tokens":["case","continue","curly_brace_block","default","extra","parenthesis_brace_block","square_brace_block","switch","throw","use"]},"no_leading_namespace_whitespace":true,"no_mixed_echo_print":true,"no_multiline_whitespace_around_double_arrow":true,"no_short_bool_cast":true,"no_singleline_whitespace_before_semicolons":true,"no_spaces_around_offset":true,"no_superfluous_phpdoc_tags":{"allow_mixed":true,"allow_unused_params":true},"no_trailing_comma_in_list_call":true,"no_trailing_comma_in_singleline_array":true,"no_trailing_comma_in_singleline_function_call":true,"no_unneeded_control_parentheses":{"statements":["break","clone","continue","echo_print","return","switch_case","yield","yield_from"]},"no_unneeded_curly_braces":{"namespaces":true},"no_unneeded_import_alias":true,"no_unset_cast":true,"no_unused_imports":true,"no_whitespace_before_comma_in_array":true,"normalize_index_brace":true,"object_operator_without_whitespace":true,"ordered_imports":true,"php_unit_fqcn_annotation":true,"php_unit_method_casing":true,"phpdoc_align":true,"phpdoc_annotation_without_dot":true,"phpdoc_indent":true,"phpdoc_inline_tag_normalizer":true,"phpdoc_no_access":true,"phpdoc_no_alias_tag":true,"phpdoc_no_package":true,"phpdoc_no_useless_inheritdoc":true,"phpdoc_return_self_reference":true,"phpdoc_scalar":true,"phpdoc_separation":true,"phpdoc_single_line_var_spacing":true,"phpdoc_summary":true,"phpdoc_tag_type":{"tags":{"inheritDoc":"inline"}},"phpdoc_to_comment":true,"phpdoc_trim":true,"phpdoc_trim_consecutive_blank_line_separation":true,"phpdoc_types":true,"phpdoc_types_order":{"null_adjustment":"always_last","sort_algorithm":"none"},"phpdoc_var_without_name":true,"protected_to_private":true,"semicolon_after_instruction":true,"single_class_element_per_statement":true,"single_line_comment_spacing":true,"single_line_comment_style":{"comment_types":["hash"]},"single_line_throw":true,"single_quote":true,"single_space_after_construct":true,"space_after_semicolon":{"remove_in_empty_for_expressions":true},"standardize_increment":true,"standardize_not_equals":true,"switch_continue_to_break":true,"trailing_comma_in_multiline":true,"trim_array_spaces":true,"types_spaces":true,"unary_operator_spaces":true,"whitespace_after_comma_in_array":true,"yoda_style":true,"blank_line_after_opening_tag":true,"compact_nullable_typehint":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"return_type_declaration":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"visibility_required":true,"blank_line_after_namespace":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"no_break_comment":true,"no_closing_tag":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true},"hashes":{"src\/HTMLPurifiersRegistryInterface.php":187845934,"src\/Form\/Listener\/HTMLPurifierListener.php":4116418424,"src\/Form\/TypeExtension\/HTMLPurifierTextTypeExtension.php":608289064,"src\/HTMLPurifiersRegistry.php":795094810,"src\/CacheWarmer\/SerializerCacheWarmer.php":2733650958,"src\/HTMLPurifierConfigFactory.php":1012979259,"src\/Twig\/HTMLPurifierExtension.php":3905834270,"src\/Twig\/HTMLPurifierRuntime.php":1281382522,"src\/DependencyInjection\/Configuration.php":2513854708,"src\/DependencyInjection\/ExerciseHTMLPurifierExtension.php":1265155058,"src\/DependencyInjection\/Compiler\/HTMLPurifierPass.php":1538180982,"src\/ExerciseHTMLPurifierBundle.php":2699336334,"tests\/HTMLPurifierConfigFactoryTest.php":969987042,"tests\/Form\/Listener\/HTMLPurifierListenerTest.php":1185658046,"tests\/Form\/TypeExtension\/HTMLPurifierTextTypeExtensionTest.php":1496463765,"tests\/CacheWarmer\/SerializerCacheWarmerTest.php":3561678071,"tests\/HTMLPurifiersRegistryTest.php":2606387570,"tests\/Twig\/HTMLPurifierRuntimeTest.php":887512979,"tests\/DependencyInjection\/ExerciseHTMLPurifierExtensionTest.php":2900253984,"tests\/DependencyInjection\/Compiler\/HTMLPurifierPassTest.php":1485032584}} \ No newline at end of file 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/composer.json b/composer.json index 6bb8e97a..e2c50218 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ ], "require": { "php": "^7.1.3 || ^8.0.0", - "ezyang/htmlpurifier": "~4.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" diff --git a/src/CacheWarmer/SerializerCacheWarmer.php b/src/CacheWarmer/SerializerCacheWarmer.php index 3256503b..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(string $cacheDir): array + public function warmUp($cacheDir): array { foreach ($this->paths as $path) { $this->filesystem->remove($path); // clean previous cache diff --git a/src/DependencyInjection/ExerciseHTMLPurifierExtension.php b/src/DependencyInjection/ExerciseHTMLPurifierExtension.php index 48105196..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')); diff --git a/src/Form/Listener/HTMLPurifierListener.php b/src/Form/Listener/HTMLPurifierListener.php index 3a3eebd5..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); } 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/tests/CacheWarmer/SerializerCacheWarmerTest.php b/tests/CacheWarmer/SerializerCacheWarmerTest.php index 3429e5fc..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'; @@ -35,7 +35,7 @@ public function testWarmUpShouldCreatePaths() $fs->remove($path); } - public function testWarmUpShouldCallPurifyForEachProfile() + public function testWarmUpShouldCallPurifyForEachProfile(): void { $purifier = $this->createMock(\HTMLPurifier::class); $purifier->expects($this->exactly(2)) 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

';