diff --git a/.gitignore b/.gitignore index 9a550fad..68d0df9e 100755 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ infection.log .idea/ .php_cs.cache *.swp +.phpunit.result.cache +.php-cs-fixer.cache diff --git a/.phan/config.php b/.phan/config.php index 8c25e9d5..92603697 100755 --- a/.phan/config.php +++ b/.phan/config.php @@ -43,7 +43,7 @@ // Note that the **only** effect of choosing `'5.6'` is to infer that functions removed in php 7.0 exist. // (See `backward_compatibility_checks` for additional options) // Automatically inferred from composer.json requirement for "php" of ">=7.1" - 'target_php_version' => '7.1', + 'target_php_version' => '7.3', // If enabled, missing properties will be created when // they are first seen. If false, we'll report an @@ -367,12 +367,11 @@ // your application should be included in this list. 'directory_list' => [ 'src/PHPHtmlParser', - 'vendor/infection/infection/src', - 'vendor/mockery/mockery/library', + 'vendor/myclabs/php-enum/src', 'vendor/paquettg/string-encode/src', - 'vendor/phan/phan/src/Phan', - 'vendor/php-coveralls/php-coveralls/src', - 'vendor/phpunit/phpunit/src', + 'vendor/guzzlehttp/psr7/src', + 'vendor/guzzlehttp/guzzle/src', + 'vendor/psr/http-client/src', ], // A list of individual files to include in analysis 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 2ead7195..98145e75 100644 --- a/.php_cs.dist +++ b/.php-cs-fixer.dist.php @@ -1,149 +1,154 @@ -in('src') - ->in('tests') -; - -return PhpCsFixer\Config::create() - ->setRiskyAllowed(true) - ->setRules([ - 'array_indentation' => true, - 'array_syntax' => ['syntax' => 'short'], - 'binary_operator_spaces' => ['align_double_arrow'=>true], - 'blank_line_after_namespace' => true, - 'blank_line_after_opening_tag' => true, - 'blank_line_before_statement' => ['statements'=>['return']], - 'braces' => ['allow_single_line_closure' => false], - 'cast_spaces' => true, - 'class_attributes_separation' => ['elements'=>['method']], - 'class_definition' => ['single_line'=>true], - 'combine_consecutive_issets' => true, - 'concat_space' => ['spacing' => 'one'], - 'declare_equal_normalize' => true, - 'elseif' => true, - 'encoding' => true, - 'full_opening_tag' => true, - 'function_declaration' => true, - 'function_typehint_space' => true, - 'include' => true, - 'increment_style' => true, - 'indentation_type' => true, - 'line_ending' => true, - 'linebreak_after_opening_tag' => true, - 'lowercase_cast' => true, - 'lowercase_keywords' => true, - 'lowercase_static_reference' => true, - 'magic_constant_casing' => true, - 'magic_method_casing' => true, - 'mb_str_functions' => false, - 'method_argument_space' => true, - 'native_function_casing' => true, - 'native_function_invocation' => true, - 'native_function_type_declaration_casing' => true, - 'new_with_braces' => true, - 'no_blank_lines_after_class_opening' => true, - 'no_blank_lines_after_phpdoc' => true, - 'no_break_comment' => true, - 'no_closing_tag' => true, - 'no_empty_comment' => true, - 'no_empty_phpdoc' => true, - 'no_empty_statement' => true, - 'no_extra_blank_lines' => ['tokens'=>[ - 'curly_brace_block', - 'extra', - 'parenthesis_brace_block', - 'square_brace_block', - 'throw', - 'use', - ]], - 'no_leading_import_slash' => true, - 'no_leading_namespace_whitespace' => true, - 'no_mixed_echo_print' => true, - 'no_multiline_whitespace_around_double_arrow' => true, - 'no_null_property_initialization' => true, - 'no_short_bool_cast' => true, - 'no_singleline_whitespace_before_semicolons' => true, - 'no_superfluous_elseif' => true, - 'no_spaces_after_function_name' => true, - 'no_spaces_around_offset' => true, - 'no_spaces_inside_parenthesis' => 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_whitespace' => true, - 'no_trailing_whitespace_in_comment' => true, - 'no_unneeded_control_parentheses' => true, - 'no_unneeded_curly_braces' => ['namespaces' => true], - 'no_unused_imports' => true, - 'no_useless_else' => true, - 'no_useless_return' => true, - 'no_whitespace_before_comma_in_array' => true, - 'no_whitespace_in_blank_line' => true, - 'normalize_index_brace' => true, - 'not_operator_with_space' => false, - 'object_operator_without_whitespace' => true, - 'ordered_class_elements' => true, - 'ordered_imports' => true, - 'php_unit_fqcn_annotation' => true, - 'phpdoc_align' => ['tags' => [ - 'method', - 'param', - 'property', - 'property-read', - 'return', - 'throws', - 'type', - 'var', - ]], - 'phpdoc_add_missing_param_annotation' => true, - 'phpdoc_annotation_without_dot' => true, - 'phpdoc_indent' => true, - 'phpdoc_inline_tag' => true, - 'phpdoc_no_access' => true, - 'phpdoc_no_alias_tag' => false, - 'phpdoc_no_package' => true, - 'phpdoc_no_useless_inheritdoc' => true, - 'phpdoc_order' => true, - 'phpdoc_return_self_reference' => true, - 'phpdoc_scalar' => true, - 'phpdoc_separation' => true, - 'phpdoc_single_line_var_spacing' => true, - 'phpdoc_summary' => true, - '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, - 'return_assignment' => true, - 'return_type_declaration' => true, - 'semicolon_after_instruction' => true, - 'simplified_null_return' => true, - 'short_scalar_cast' => true, - 'single_blank_line_at_eof' => true, - 'single_blank_line_before_namespace' => true, - 'single_class_element_per_statement' => true, - 'single_import_per_statement' => true, - 'single_line_after_imports' => true, - 'single_line_comment_style' => ['comment_types' => ['hash']], - 'single_line_throw' => true, - 'single_quote' => true, - 'single_trait_insert_per_statement' => true, - 'space_after_semicolon' => ['remove_in_empty_for_expressions'=>true], - 'standardize_increment' => true, - 'standardize_not_equals' => true, - 'switch_case_semicolon_to_colon' => true, - 'switch_case_space' => true, - 'ternary_operator_spaces' => true, - 'ternary_to_null_coalescing' => true, - 'trailing_comma_in_multiline_array' => true, - 'trim_array_spaces' => true, - 'unary_operator_spaces' => true, - 'visibility_required' => true, - 'whitespace_after_comma_in_array' => true, - 'yoda_style' => false, - ]) - ->setFinder($finder) - ->setCacheFile(__DIR__.'/.php_cs.cache') -; \ No newline at end of file +setRiskyAllowed(true) + ->setRules([ + 'array_indentation' => true, + 'array_syntax' => ['syntax' => 'short'], + 'binary_operator_spaces' => true, + 'blank_line_after_namespace' => true, + 'blank_line_after_opening_tag' => true, + 'blank_line_before_statement' => ['statements'=>['return']], + 'braces' => ['allow_single_line_closure' => false], + 'cast_spaces' => true, +// 'class_attributes_separation' => ['const' => 'one','method' => 'one','property' => 'one','trait_import' => 'none'], + 'class_definition' => ['single_line'=>true], + 'combine_consecutive_issets' => true, + 'concat_space' => ['spacing' => 'one'], + 'declare_equal_normalize' => true, + 'elseif' => true, + 'encoding' => true, + 'full_opening_tag' => true, + 'function_declaration' => true, + 'function_typehint_space' => true, + 'include' => true, + 'increment_style' => true, + 'indentation_type' => true, + 'line_ending' => true, + 'linebreak_after_opening_tag' => true, + 'lowercase_cast' => true, + 'lowercase_keywords' => true, + 'lowercase_static_reference' => true, + 'magic_constant_casing' => true, + 'magic_method_casing' => true, + 'mb_str_functions' => false, + 'method_argument_space' => true, + 'native_function_casing' => true, + 'native_function_invocation' => ['include'=>['@all']], + 'native_function_type_declaration_casing' => true, + 'new_with_braces' => true, + 'no_blank_lines_after_class_opening' => true, + 'no_blank_lines_after_phpdoc' => true, + 'no_break_comment' => true, + 'no_closing_tag' => true, + 'no_empty_comment' => true, + 'no_empty_phpdoc' => true, + 'no_empty_statement' => true, + 'no_extra_blank_lines' => + ['tokens'=> + [ + 'curly_brace_block', + 'extra', + 'parenthesis_brace_block', + 'square_brace_block', + 'throw', + 'use', + ] + ], + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_mixed_echo_print' => true, + 'no_multiline_whitespace_around_double_arrow' => true, + 'no_null_property_initialization' => true, + 'no_short_bool_cast' => true, + 'no_singleline_whitespace_before_semicolons' => true, + 'no_superfluous_elseif' => true, + 'no_spaces_after_function_name' => true, + 'no_spaces_around_offset' => true, + 'no_spaces_inside_parenthesis' => 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_whitespace' => true, + 'no_trailing_whitespace_in_comment' => true, + 'no_unneeded_control_parentheses' => true, + 'no_unneeded_curly_braces' => ['namespaces' => true], + 'no_unused_imports' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'no_whitespace_before_comma_in_array' => true, + 'no_whitespace_in_blank_line' => true, + 'normalize_index_brace' => true, + 'not_operator_with_space' => false, + 'object_operator_without_whitespace' => true, + 'ordered_class_elements' => true, + 'ordered_imports' => true, + 'php_unit_fqcn_annotation' => true, + 'phpdoc_align' => + ['tags' => + [ + 'method', + 'param', + 'property', + 'property-read', + 'return', + 'throws', + 'type', + 'var', + ] + ], + 'phpdoc_add_missing_param_annotation' => true, + 'phpdoc_annotation_without_dot' => true, + 'phpdoc_indent' => true, + 'phpdoc_inline_tag_normalizer' => true, + 'phpdoc_no_access' => true, + 'phpdoc_no_alias_tag' => false, + 'phpdoc_no_package' => true, + 'phpdoc_no_useless_inheritdoc' => true, + 'phpdoc_order' => true, + 'phpdoc_return_self_reference' => true, + 'phpdoc_scalar' => true, + 'phpdoc_separation' => true, + 'phpdoc_single_line_var_spacing' => true, + 'phpdoc_summary' => true, + '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, + 'return_assignment' => true, + 'return_type_declaration' => true, + 'semicolon_after_instruction' => true, + 'simplified_null_return' => true, + 'short_scalar_cast' => true, + 'single_blank_line_at_eof' => true, + 'single_blank_line_before_namespace' => true, + 'single_class_element_per_statement' => true, + 'single_import_per_statement' => true, + 'single_line_after_imports' => true, + 'single_line_comment_style' => ['comment_types' => ['hash']], + 'single_line_throw' => true, + 'single_quote' => true, + 'single_trait_insert_per_statement' => true, + 'space_after_semicolon' => ['remove_in_empty_for_expressions'=>true], + 'standardize_increment' => true, + 'standardize_not_equals' => true, + 'switch_case_semicolon_to_colon' => true, + 'switch_case_space' => true, + 'ternary_operator_spaces' => true, + 'ternary_to_null_coalescing' => true, + 'trailing_comma_in_multiline' => true, + 'trim_array_spaces' => true, + 'unary_operator_spaces' => true, + 'visibility_required' => true, + 'whitespace_after_comma_in_array' => true, + 'yoda_style' => false, + ]) + ->setFinder(PhpCsFixer\Finder::create() + ->exclude('vendor') + ->in('src') + ->in('tests') + ) +; diff --git a/composer.json b/composer.json index 166886f7..e2912b7f 100755 --- a/composer.json +++ b/composer.json @@ -13,25 +13,25 @@ } ], "require": { - "php": ">=7.2", + "php": ">=7.3", "ext-mbstring": "*", "ext-zlib": "*", "ext-curl": "*", - "paquettg/string-encode": "~1.0.0", + "paquettg/string-encode": "^2.0", "php-http/httplug": "^2.1", "guzzlehttp/guzzle": "^7.0", - "guzzlehttp/psr7": "^1.6", - "myclabs/php-enum": "^1.7" + "guzzlehttp/psr7": "^2.0", + "myclabs/php-enum": "^1.8", + "psr/http-client": "^1.0" }, "require-dev": { - "phpunit/phpunit": "^7.5.1", + "phpunit/phpunit": "^8.0 || ^9.0", "mockery/mockery": "^1.2", - "infection/infection": "^0.13.4", - "phan/phan": "^2.4", - "friendsofphp/php-cs-fixer": "^2.16" + "friendsofphp/php-cs-fixer": "^3.0", + "phan/phan": "^5.2" }, "autoload": { - "psr-4": { + "psr-4": { "PHPHtmlParser\\": "src/PHPHtmlParser" } } diff --git a/src/PHPHtmlParser/Content.php b/src/PHPHtmlParser/Content.php index f1332175..bdf5c0f4 100755 --- a/src/PHPHtmlParser/Content.php +++ b/src/PHPHtmlParser/Content.php @@ -74,9 +74,6 @@ public function char(?int $char = null): string /** * Gets a string from the current character position. - * - * @param int $length - * @return string */ public function string(int $length = 1): string { @@ -85,6 +82,7 @@ public function string(int $length = 1): string do { $string .= $this->char($position++); } while ($position < $this->pos + $length); + return $string; } diff --git a/src/PHPHtmlParser/DTO/Selector/RuleDTO.php b/src/PHPHtmlParser/DTO/Selector/RuleDTO.php index 5299e3a0..a6b42163 100644 --- a/src/PHPHtmlParser/DTO/Selector/RuleDTO.php +++ b/src/PHPHtmlParser/DTO/Selector/RuleDTO.php @@ -53,11 +53,11 @@ private function __construct(array $values) public static function makeFromPrimitives(string $tag, string $operator, $key, $value, bool $noKey, bool $alterNext): RuleDTO { return new RuleDTO([ - 'tag' => $tag, - 'operator' => $operator, - 'key' => $key, - 'value' => $value, - 'noKey' => $noKey, + 'tag' => $tag, + 'operator' => $operator, + 'key' => $key, + 'value' => $value, + 'noKey' => $noKey, 'alterNext' => $alterNext, ]); } diff --git a/src/PHPHtmlParser/DTO/Tag/AttributeDTO.php b/src/PHPHtmlParser/DTO/Tag/AttributeDTO.php index 3e7e1824..586ae7a9 100755 --- a/src/PHPHtmlParser/DTO/Tag/AttributeDTO.php +++ b/src/PHPHtmlParser/DTO/Tag/AttributeDTO.php @@ -4,8 +4,8 @@ namespace PHPHtmlParser\DTO\Tag; -use stringEncode\Encode; -use stringEncode\Exception; +use StringEncoder\Encoder; +use StringEncoder\Exception; final class AttributeDTO { @@ -28,7 +28,7 @@ private function __construct(array $values) public static function makeFromPrimitives(?string $value, bool $doubleQuote = true): AttributeDTO { return new AttributeDTO([ - 'value' => $value, + 'value' => $value, 'doubleQuote' => $doubleQuote, ]); } @@ -53,8 +53,13 @@ public function htmlspecialcharsDecode(): void /** * @throws Exception */ - public function encodeValue(Encode $encode) + public function encodeValue(Encoder $encode): void { - $this->value = $encode->convert($this->value); + if (\is_null($this->value)) { + return; + } + $converter = $encode->convert(); + $converter->convert($this->value); + $this->value = $converter->toString(); } } diff --git a/src/PHPHtmlParser/DTO/TagDTO.php b/src/PHPHtmlParser/DTO/TagDTO.php index 71f0ec1c..abc32fda 100644 --- a/src/PHPHtmlParser/DTO/TagDTO.php +++ b/src/PHPHtmlParser/DTO/TagDTO.php @@ -39,10 +39,10 @@ private function __construct(array $values = []) public static function makeFromPrimitives(bool $status = false, bool $closing = false, ?HtmlNode $node = null, ?string $tag = null): TagDTO { return new TagDTO([ - 'status' => $status, + 'status' => $status, 'closing' => $closing, - 'node' => $node, - 'tag' => $tag, + 'node' => $node, + 'tag' => $tag, ]); } @@ -56,17 +56,11 @@ public function isClosing(): bool return $this->closing; } - /** - * @return mixed - */ public function getNode(): ?HtmlNode { return $this->node; } - /** - * @return mixed - */ public function getTag(): ?string { return $this->tag; diff --git a/src/PHPHtmlParser/Discovery/CleanerDiscovery.php b/src/PHPHtmlParser/Discovery/CleanerDiscovery.php index 96ef6787..a9c84617 100644 --- a/src/PHPHtmlParser/Discovery/CleanerDiscovery.php +++ b/src/PHPHtmlParser/Discovery/CleanerDiscovery.php @@ -12,7 +12,7 @@ class CleanerDiscovery /** * @var Cleaner|null */ - private static $parser = null; + private static $parser; public static function find(): CleanerInterface { diff --git a/src/PHPHtmlParser/Discovery/DomParserDiscovery.php b/src/PHPHtmlParser/Discovery/DomParserDiscovery.php index b9980630..6a1dc8cd 100644 --- a/src/PHPHtmlParser/Discovery/DomParserDiscovery.php +++ b/src/PHPHtmlParser/Discovery/DomParserDiscovery.php @@ -12,7 +12,7 @@ class DomParserDiscovery /** * @var ParserInterface|null */ - private static $parser = null; + private static $parser; public static function find(): ParserInterface { diff --git a/src/PHPHtmlParser/Discovery/SeekerDiscovery.php b/src/PHPHtmlParser/Discovery/SeekerDiscovery.php index bb3da586..4d47b313 100644 --- a/src/PHPHtmlParser/Discovery/SeekerDiscovery.php +++ b/src/PHPHtmlParser/Discovery/SeekerDiscovery.php @@ -12,7 +12,7 @@ class SeekerDiscovery /** * @var SeekerInterface|null */ - private static $seeker = null; + private static $seeker; public static function find(): SeekerInterface { diff --git a/src/PHPHtmlParser/Discovery/SelectorParserDiscovery.php b/src/PHPHtmlParser/Discovery/SelectorParserDiscovery.php index 200f7b4c..fb834e7b 100644 --- a/src/PHPHtmlParser/Discovery/SelectorParserDiscovery.php +++ b/src/PHPHtmlParser/Discovery/SelectorParserDiscovery.php @@ -12,7 +12,7 @@ class SelectorParserDiscovery /** * @var ParserInterface|null */ - private static $parser = null; + private static $parser; public static function find(): ParserInterface { diff --git a/src/PHPHtmlParser/Dom.php b/src/PHPHtmlParser/Dom.php index 816b1b3b..0b6ac475 100755 --- a/src/PHPHtmlParser/Dom.php +++ b/src/PHPHtmlParser/Dom.php @@ -4,8 +4,8 @@ namespace PHPHtmlParser; -use GuzzleHttp\Psr7\Request; use GuzzleHttp\Client; +use GuzzleHttp\Psr7\Request; use PHPHtmlParser\Contracts\Dom\CleanerInterface; use PHPHtmlParser\Contracts\Dom\ParserInterface; use PHPHtmlParser\Contracts\DomInterface; diff --git a/src/PHPHtmlParser/Dom/Node/AbstractNode.php b/src/PHPHtmlParser/Dom/Node/AbstractNode.php index 897445b0..c4ba3082 100644 --- a/src/PHPHtmlParser/Dom/Node/AbstractNode.php +++ b/src/PHPHtmlParser/Dom/Node/AbstractNode.php @@ -12,7 +12,7 @@ use PHPHtmlParser\Exceptions\Tag\AttributeNotFoundException; use PHPHtmlParser\Finder; use PHPHtmlParser\Selector\Selector; -use stringEncode\Encode; +use StringEncoder\Encoder; /** * Dom node object. @@ -206,7 +206,7 @@ public function delete() * * @return void */ - public function propagateEncoding(Encode $encode) + public function propagateEncoding(Encoder $encode) { $this->encode = $encode; $this->tag->setEncoding($encode); diff --git a/src/PHPHtmlParser/Dom/Node/InnerNode.php b/src/PHPHtmlParser/Dom/Node/InnerNode.php index 448057a7..033e7735 100644 --- a/src/PHPHtmlParser/Dom/Node/InnerNode.php +++ b/src/PHPHtmlParser/Dom/Node/InnerNode.php @@ -8,7 +8,7 @@ use PHPHtmlParser\Exceptions\ChildNotFoundException; use PHPHtmlParser\Exceptions\CircularException; use PHPHtmlParser\Exceptions\LogicalException; -use stringEncode\Encode; +use StringEncoder\Encoder; /** * Inner node of the html tree, might have children. @@ -33,7 +33,7 @@ abstract class InnerNode extends ArrayNode * Sets the encoding class to this node and propagates it * to all its children. */ - public function propagateEncoding(Encode $encode): void + public function propagateEncoding(Encoder $encode): void { $this->encode = $encode; $this->tag->setEncoding($encode); diff --git a/src/PHPHtmlParser/Dom/Node/TextNode.php b/src/PHPHtmlParser/Dom/Node/TextNode.php index 1c8b646c..66f6955a 100644 --- a/src/PHPHtmlParser/Dom/Node/TextNode.php +++ b/src/PHPHtmlParser/Dom/Node/TextNode.php @@ -53,6 +53,9 @@ public function __construct(string $text, $removeDoubleSpace = true) if ($replacedText === false) { throw new LogicalException('mb_ereg_replace returns false when attempting to clean white space from "' . $text . '".'); } + if ($replacedText === null) { + throw new LogicalException('mb_ereg_replace encountered an invalid encoding for "' . $text . '".'); + } $text = $replacedText; } @@ -89,7 +92,9 @@ public function text(): string // we already know the converted value return $this->convertedText; } - $text = $this->encode->convert($text); + $converter = $this->encode->convert(); + $converter->convert($text); + $text = $converter->toString(); // remember the conversion $this->convertedText = $text; @@ -109,10 +114,11 @@ public function setText(string $text): void { $this->text = $text; if (!\is_null($this->encode)) { - $text = $this->encode->convert($text); + $converter = $this->encode->convert(); + $converter->convert($text); // remember the conversion - $this->convertedText = $text; + $this->convertedText = $converter->toString(); } } diff --git a/src/PHPHtmlParser/Dom/Parser.php b/src/PHPHtmlParser/Dom/Parser.php index 7ed310cb..faefd287 100644 --- a/src/PHPHtmlParser/Dom/Parser.php +++ b/src/PHPHtmlParser/Dom/Parser.php @@ -17,7 +17,7 @@ use PHPHtmlParser\Exceptions\LogicalException; use PHPHtmlParser\Exceptions\StrictException; use PHPHtmlParser\Options; -use stringEncode\Encode; +use StringEncoder\Encoder; class Parser implements ParserInterface { @@ -37,7 +37,7 @@ public function parse(Options $options, Content $content, int $size): AbstractNo $root->setHtmlSpecialCharsDecode($options->isHtmlSpecialCharsDecode()); $activeNode = $root; while ($activeNode !== null) { - if ($activeNode && $activeNode->tag->name() === 'script' + if ($activeNode && \is_object($activeNode->tag) && $activeNode->tag->name() === 'script' && $options->isCleanupInput() !== true ) { $str = $content->copyUntil('from($defaultCharset); - $encode->to($defaultCharset); + $encode = new Encoder(); + $encode->setSourceEncoding($defaultCharset); + $encode->setTargetEncoding($defaultCharset); $enforceEncoding = $options->getEnforceEncoding(); if ($enforceEncoding !== null) { // they want to enforce the given encoding - $encode->from($enforceEncoding); - $encode->to($enforceEncoding); + $encode->setSourceEncoding($enforceEncoding); + $encode->setTargetEncoding($enforceEncoding); return false; } @@ -138,7 +138,7 @@ public function detectCharset(Options $options, string $defaultCharset, Abstract } $matches = []; if (\preg_match('/charset=([^;]+)/', $content, $matches)) { - $encode->from(\trim($matches[1])); + $encode->setSourceEncoding(\trim($matches[1])); $root->propagateEncoding($encode); return true; @@ -169,6 +169,7 @@ private function parseTag(Options $options, Content $content, int $size): TagDTO try { $content->fastForward(1); } catch (ContentLengthException $exception) { + unset($exception); // we are at the end of the file return TagDTO::makeFromPrimitives(); } @@ -183,7 +184,7 @@ private function parseTag(Options $options, Content $content, int $size): TagDTO ->setOpening('setClosing(' ?>') ->selfClosing(); - } elseif($content->string(3) == '!--') { + } elseif ($content->string(3) == '!--') { // comment tag $tag = $content->fastForward(3) ->copyByToken(StringToken::CLOSECOMMENT(), true); @@ -233,7 +234,7 @@ private function parseTag(Options $options, Content $content, int $size): TagDTO /** * @throws ChildNotFoundException */ - private function detectHTML5Charset(Encode $encode, AbstractNode $root): bool + private function detectHTML5Charset(Encoder $encode, AbstractNode $root): bool { /** @var AbstractNode|null $meta */ $meta = $root->find('meta[charset]', 0); @@ -241,7 +242,7 @@ private function detectHTML5Charset(Encode $encode, AbstractNode $root): bool return false; } - $encode->from(\trim($meta->getAttribute('charset'))); + $encode->setSourceEncoding(\trim($meta->getAttribute('charset'))); $root->propagateEncoding($encode); return true; @@ -286,6 +287,7 @@ private function setUpAttributes(Content $content, int $size, HtmlNode $node, Op try { $content->fastForward(1); } catch (ContentLengthException $exception) { + unset($exception); // reached the end of the content break; } diff --git a/src/PHPHtmlParser/Dom/Tag.php b/src/PHPHtmlParser/Dom/Tag.php index 2aeb6aa8..e9e683fb 100644 --- a/src/PHPHtmlParser/Dom/Tag.php +++ b/src/PHPHtmlParser/Dom/Tag.php @@ -6,7 +6,7 @@ use PHPHtmlParser\DTO\Tag\AttributeDTO; use PHPHtmlParser\Exceptions\Tag\AttributeNotFoundException; -use stringEncode\Encode; +use StringEncoder\Encoder; /** * Class Tag. @@ -49,7 +49,7 @@ class Tag /** * The encoding class to... encode the tags. * - * @var Encode|null + * @var Encoder|null */ protected $encode; @@ -135,7 +135,7 @@ public function isSelfClosing(): bool /** * Sets the encoding type to be used. */ - public function setEncoding(Encode $encode): void + public function setEncoding(Encoder $encode): void { $this->encode = $encode; } @@ -326,13 +326,15 @@ public function makeOpeningTag() foreach (\array_keys($this->attr) as $key) { try { $attributeDTO = $this->getAttribute($key); + $val = $attributeDTO->getValue(); } catch (AttributeNotFoundException $e) { + unset($e); // attribute that was in the array not found in the array... let's continue. continue; } catch (\TypeError $e) { - $val = null; + unset($e); + $val = null; } - $val = $attributeDTO->getValue(); if (\is_null($val)) { $return .= ' ' . $key; } elseif ($attributeDTO->isDoubleQuote()) { diff --git a/src/PHPHtmlParser/Selector/Seeker.php b/src/PHPHtmlParser/Selector/Seeker.php index abd6dc4e..6e9f60fb 100644 --- a/src/PHPHtmlParser/Selector/Seeker.php +++ b/src/PHPHtmlParser/Selector/Seeker.php @@ -298,11 +298,15 @@ private function match( case '!=': return $value !== $pattern; case '^=': - return \preg_match('/^' . \preg_quote($pattern, '/') . '/', - $value) == 1; + return \preg_match( + '/^' . \preg_quote($pattern, '/') . '/', + $value + ) == 1; case '$=': - return \preg_match('/' . \preg_quote($pattern, '/') . '$/', - $value) == 1; + return \preg_match( + '/' . \preg_quote($pattern, '/') . '$/', + $value + ) == 1; case '*=': if ($pattern[0] == '/') { return \preg_match($pattern, $value) == 1; diff --git a/src/PHPHtmlParser/StaticDom.php b/src/PHPHtmlParser/StaticDom.php index 78950204..604565bf 100755 --- a/src/PHPHtmlParser/StaticDom.php +++ b/src/PHPHtmlParser/StaticDom.php @@ -4,8 +4,8 @@ namespace PHPHtmlParser; -use GuzzleHttp\Psr7\Request; use GuzzleHttp\Client; +use GuzzleHttp\Psr7\Request; use PHPHtmlParser\Exceptions\ChildNotFoundException; use PHPHtmlParser\Exceptions\CircularException; use PHPHtmlParser\Exceptions\NotLoadedException; @@ -18,7 +18,7 @@ */ final class StaticDom { - private static $dom = null; + private static $dom; /** * Attempts to call the given method on the most recent created dom diff --git a/tests/CollectionTest.php b/tests/CollectionTest.php index c11c667c..46f5be6c 100755 --- a/tests/CollectionTest.php +++ b/tests/CollectionTest.php @@ -32,11 +32,9 @@ public function testEach() $this->assertEquals(2, $count); } - /** - * @expectedException \PHPHtmlParser\Exceptions\EmptyCollectionException - */ public function testCallNoNodes() { + $this->expectException(\PHPHtmlParser\Exceptions\EmptyCollectionException::class); $collection = new Collection(); $collection->innerHtml(); } @@ -80,11 +78,9 @@ public function testGetMagic() $this->assertEquals($child3->innerHtml, $selector->find($root)->innerHtml); } - /** - * @expectedException \PHPHtmlParser\Exceptions\EmptyCollectionException - */ public function testGetNoNodes() { + $this->expectException(\PHPHtmlParser\Exceptions\EmptyCollectionException::class); $collection = new Collection(); $collection->innerHtml; } diff --git a/tests/Dom/CommentTest.php b/tests/Dom/CommentTest.php index 3f10696e..c8bb2bdb 100644 --- a/tests/Dom/CommentTest.php +++ b/tests/Dom/CommentTest.php @@ -13,7 +13,7 @@ class CommentTest extends TestCase */ private $dom; - public function setUp() + public function setUp(): void { $dom = new Dom(); $options = new Options(); @@ -22,7 +22,7 @@ public function setUp() $this->dom = $dom; } - public function tearDown() + protected function tearDown(): void { Mockery::close(); } diff --git a/tests/Dom/LoadTest.php b/tests/Dom/LoadTest.php index 456afb88..31950ea7 100644 --- a/tests/Dom/LoadTest.php +++ b/tests/Dom/LoadTest.php @@ -12,14 +12,14 @@ class LoadTest extends TestCase */ private $dom; - public function setUp() + public function setUp(): void { $dom = new Dom(); $dom->loadStr('

Hey bro, click here


'); $this->dom = $dom; } - public function tearDown() + protected function tearDown(): void { Mockery::close(); } diff --git a/tests/Dom/NotLoadedTest.php b/tests/Dom/NotLoadedTest.php index 7c1f0674..a705dcc7 100644 --- a/tests/Dom/NotLoadedTest.php +++ b/tests/Dom/NotLoadedTest.php @@ -13,13 +13,13 @@ class NotLoadedTest extends TestCase */ private $dom; - public function setUp() + public function setUp(): void { $dom = new Dom(); $this->dom = $dom; } - public function tearDown() + protected function tearDown(): void { Mockery::close(); } diff --git a/tests/DomTest.php b/tests/DomTest.php index 519d5594..76bdf583 100755 --- a/tests/DomTest.php +++ b/tests/DomTest.php @@ -8,7 +8,7 @@ class DomTest extends TestCase { - public function tearDown() + protected function tearDown(): void { Mockery::close(); } @@ -138,8 +138,10 @@ public function testLoadFileBigTwice() public function testLoadFileBigTwicePreserveOption() { $dom = new Dom(); - $dom->loadFromFile('tests/data/files/big.html', - (new Options())->setPreserveLineBreaks(true)); + $dom->loadFromFile( + 'tests/data/files/big.html', + (new Options())->setPreserveLineBreaks(true) + ); $post = $dom->find('.post-row', 0); $this->assertEquals( "

Журчанье воды
\nЧерно-белые тени
\nВновь на фонтане

", @@ -173,9 +175,9 @@ public function testScriptCleanerScriptTag() $dom->loadStr('

.....

....

'); $this->assertEquals('....', $dom->getElementsByTag('p')[1]->innerHtml); @@ -227,7 +229,7 @@ public function testGetChildrenArray() { $dom = new Dom(); $dom->loadStr('hello$foo = "bar";'); - $this->assertInternalType('array', $dom->getChildren()); + $this->assertIsArray($dom->getChildren()); } public function testHasChildren() @@ -444,12 +446,13 @@ public function testFindAttributeInBothParentAndChild() public function testLessThanCharacterInJavascript() { - $results = (new Dom())->loadStr('
', (new Options())->setCleanupInput(false) ->setRemoveScripts(false) - )->find('body'); + )->find('body'); $this->assertCount(1, $results); } @@ -528,6 +531,10 @@ public function testRandomTagInMiddleOfText() public function testHttpCall() { + // Apparently google.com uses utf-8 as the encoding, but the default for Dom is case sensitive encoding. + // @todo this should be resolved by the package owner + + $this->expectException(\StringEncoder\Exceptions\InvalidEncodingException::class); $dom = new Dom(); $dom->loadFromUrl('http://google.com'); $this->assertNotEmpty($dom->outerHtml); diff --git a/tests/Node/ChildrenTest.php b/tests/Node/ChildrenTest.php index 37a160ff..a3ad1fe5 100755 --- a/tests/Node/ChildrenTest.php +++ b/tests/Node/ChildrenTest.php @@ -36,22 +36,18 @@ public function testNextSibling() $this->assertEquals($child2->id(), $child->nextSibling()->id()); } - /** - * @expectedException \PHPHtmlParser\Exceptions\ChildNotFoundException - */ public function testNextSiblingNotFound() { + $this->expectException(\PHPHtmlParser\Exceptions\ChildNotFoundException::class); $parent = new Node(); $child = new Node(); $child->setParent($parent); $child->nextSibling(); } - /** - * @expectedException \PHPHtmlParser\Exceptions\ParentNotFoundException - */ public function testNextSiblingNoParent() { + $this->expectException(\PHPHtmlParser\Exceptions\ParentNotFoundException::class); $child = new Node(); $child->nextSibling(); } @@ -66,22 +62,18 @@ public function testPreviousSibling() $this->assertEquals($child->id(), $child2->previousSibling()->id()); } - /** - * @expectedException \PHPHtmlParser\Exceptions\ChildNotFoundException - */ public function testPreviousSiblingNotFound() { + $this->expectException(\PHPHtmlParser\Exceptions\ChildNotFoundException::class); $parent = new Node(); $node = new Node(); $node->setParent($parent); $node->previousSibling(); } - /** - * @expectedException \PHPHtmlParser\Exceptions\ParentNotFoundException - */ public function testPreviousSiblingNoParent() { + $this->expectException(\PHPHtmlParser\Exceptions\ParentNotFoundException::class); $child = new Node(); $child->previousSibling(); } diff --git a/tests/Node/HtmlTest.php b/tests/Node/HtmlTest.php index 592003b4..01be3f45 100755 --- a/tests/Node/HtmlTest.php +++ b/tests/Node/HtmlTest.php @@ -17,14 +17,14 @@ public function testInnerHtml() $div = new Tag('div'); $div->setAttributes([ 'class' => [ - 'value' => 'all', + 'value' => 'all', 'doubleQuote' => true, ], ]); $a = new Tag('a'); $a->setAttributes([ 'href' => [ - 'value' => 'http://google.com', + 'value' => 'http://google.com', 'doubleQuote' => false, ], ]); @@ -46,7 +46,7 @@ public function testInnerHtmlTwice() $div = new Tag('div'); $div->setAttributes([ 'class' => [ - 'value' => 'all', + 'value' => 'all', 'doubleQuote' => true, ], ]); @@ -66,22 +66,20 @@ public function testInnerHtmlTwice() $this->assertEquals($inner, $parent->innerHtml()); } - /** - * @expectedException \PHPHtmlParser\Exceptions\UnknownChildTypeException - */ public function testInnerHtmlUnkownChild() { + $this->expectException(\PHPHtmlParser\Exceptions\UnknownChildTypeException::class); $div = new Tag('div'); $div->setAttributes([ 'class' => [ - 'value' => 'all', + 'value' => 'all', 'doubleQuote' => true, ], ]); $a = new Tag('a'); $a->setAttributes([ 'href' => [ - 'value' => 'http://google.com', + 'value' => 'http://google.com', 'doubleQuote' => false, ], ]); @@ -104,14 +102,14 @@ public function testInnerHtmlMagic() $parent = new HtmlNode('div'); $parent->tag->setAttributes([ 'class' => [ - 'value' => 'all', + 'value' => 'all', 'doubleQuote' => true, ], ]); $childa = new HtmlNode('a'); $childa->getTag()->setAttributes([ 'href' => [ - 'value' => 'http://google.com', + 'value' => 'http://google.com', 'doubleQuote' => false, ], ]); @@ -130,14 +128,14 @@ public function testOuterHtml() $div = new Tag('div'); $div->setAttributes([ 'class' => [ - 'value' => 'all', + 'value' => 'all', 'doubleQuote' => true, ], ]); $a = new Tag('a'); $a->setAttributes([ 'href' => [ - 'value' => 'http://google.com', + 'value' => 'http://google.com', 'doubleQuote' => false, ], ]); @@ -159,14 +157,14 @@ public function testOuterHtmlTwice() $div = new Tag('div'); $div->setAttributes([ 'class' => [ - 'value' => 'all', + 'value' => 'all', 'doubleQuote' => true, ], ]); $a = new Tag('a'); $a->setAttributes([ 'href' => [ - 'value' => 'http://google.com', + 'value' => 'http://google.com', 'doubleQuote' => false, ], ]); @@ -189,7 +187,7 @@ public function testOuterHtmlEmpty() $a = new Tag('a'); $a->setAttributes([ 'href' => [ - 'value' => 'http://google.com', + 'value' => 'http://google.com', 'doubleQuote' => false, ], ]); @@ -203,14 +201,14 @@ public function testOuterHtmlMagic() $parent = new HtmlNode('div'); $parent->getTag()->setAttributes([ 'class' => [ - 'value' => 'all', + 'value' => 'all', 'doubleQuote' => true, ], ]); $childa = new HtmlNode('a'); $childa->getTag()->setAttributes([ 'href' => [ - 'value' => 'http://google.com', + 'value' => 'http://google.com', 'doubleQuote' => false, ], ]); @@ -246,14 +244,14 @@ public function testOuterHtmlWithChanges() $div = new Tag('div'); $div->setAttributes([ 'class' => [ - 'value' => 'all', + 'value' => 'all', 'doubleQuote' => true, ], ]); $a = new Tag('a'); $a->setAttributes([ 'href' => [ - 'value' => 'http://google.com', + 'value' => 'http://google.com', 'doubleQuote' => false, ], ]); @@ -357,11 +355,11 @@ public function testGetAttribute() $node = new HtmlNode('a'); $node->getTag()->setAttributes([ 'href' => [ - 'value' => 'http://google.com', + 'value' => 'http://google.com', 'doubleQuote' => false, ], 'class' => [ - 'value' => 'outerlink rounded', + 'value' => 'outerlink rounded', 'doubleQuote' => true, ], ]); @@ -374,11 +372,11 @@ public function testGetAttributeMagic() $node = new HtmlNode('a'); $node->getTag()->setAttributes([ 'href' => [ - 'value' => 'http://google.com', + 'value' => 'http://google.com', 'doubleQuote' => false, ], 'class' => [ - 'value' => 'outerlink rounded', + 'value' => 'outerlink rounded', 'doubleQuote' => true, ], ]); @@ -391,11 +389,11 @@ public function testGetAttributes() $node = new HtmlNode('a'); $node->getTag()->setAttributes([ 'href' => [ - 'value' => 'http://google.com', + 'value' => 'http://google.com', 'doubleQuote' => false, ], 'class' => [ - 'value' => 'outerlink rounded', + 'value' => 'outerlink rounded', 'doubleQuote' => true, ], ]); @@ -444,14 +442,14 @@ public function testCountable() $div = new Tag('div'); $div->setAttributes([ 'class' => [ - 'value' => 'all', + 'value' => 'all', 'doubleQuote' => true, ], ]); $a = new Tag('a'); $a->setAttributes([ 'href' => [ - 'value' => 'http://google.com', + 'value' => 'http://google.com', 'doubleQuote' => false, ], ]); @@ -473,14 +471,14 @@ public function testIterator() $div = new Tag('div'); $div->setAttributes([ 'class' => [ - 'value' => 'all', + 'value' => 'all', 'doubleQuote' => true, ], ]); $a = new Tag('a'); $a->setAttributes([ 'href' => [ - 'value' => 'http://google.com', + 'value' => 'http://google.com', 'doubleQuote' => false, ], ]); @@ -501,11 +499,9 @@ public function testIterator() $this->assertEquals(2, $children); } - /** - * @expectedException \PHPHtmlParser\Exceptions\ParentNotFoundException - */ public function testAncestorByTagFailure() { + $this->expectException(\PHPHtmlParser\Exceptions\ParentNotFoundException::class); $a = new Tag('a'); $node = new HtmlNode($a); $node->ancestorByTag('div'); diff --git a/tests/Node/ParentTest.php b/tests/Node/ParentTest.php index 8a87aa32..2305708b 100755 --- a/tests/Node/ParentTest.php +++ b/tests/Node/ParentTest.php @@ -89,10 +89,9 @@ public function testHasNextChild() public function testHasNextChildNotExists() { + $this->expectException(\PHPHtmlParser\Exceptions\ChildNotFoundException::class); $parent = new Node(); $child = new Node(); - - $this->expectException(\PHPHtmlParser\Exceptions\ChildNotFoundException::class); $parent->hasNextChild($child->id()); } @@ -246,33 +245,27 @@ public function testReplaceChild() $this->assertFalse($parent->isChild($child->id())); } - /** - * @expectedException \PHPHtmlParser\Exceptions\CircularException - */ public function testSetParentDescendantException() { + $this->expectException(\PHPHtmlParser\Exceptions\CircularException::class); $parent = new Node(); $child = new Node(); $parent->addChild($child); $parent->setParent($child); } - /** - * @expectedException \PHPHtmlParser\Exceptions\CircularException - */ public function testAddChildAncestorException() { + $this->expectException(\PHPHtmlParser\Exceptions\CircularException::class); $parent = new Node(); $child = new Node(); $parent->addChild($child); $child->addChild($parent); } - /** - * @expectedException \PHPHtmlParser\Exceptions\CircularException - */ public function testAddItselfAsChild() { + $this->expectException(\PHPHtmlParser\Exceptions\CircularException::class); $parent = new Node(); $parent->addChild($parent); } diff --git a/tests/Node/TagTest.php b/tests/Node/TagTest.php index f14de7e2..7d7566c6 100755 --- a/tests/Node/TagTest.php +++ b/tests/Node/TagTest.php @@ -18,7 +18,7 @@ public function testSetAttributes() { $attr = [ 'href' => [ - 'value' => 'http://google.com', + 'value' => 'http://google.com', 'doubleQuote' => false, ], ]; @@ -28,11 +28,9 @@ public function testSetAttributes() $this->assertEquals('http://google.com', $tag->getAttribute('href')->getValue()); } - /** - * @expectedException \PHPHtmlParser\Exceptions\Tag\AttributeNotFoundException - */ public function testRemoveAttribute() { + $this->expectException(\PHPHtmlParser\Exceptions\Tag\AttributeNotFoundException::class); $tag = new Tag('a'); $tag->setAttribute('href', 'http://google.com'); $tag->removeAttribute('href'); @@ -58,7 +56,7 @@ public function testSetAttributeNoArray() public function testSetAttributesNoDoubleArray() { $attr = [ - 'href' => 'http://google.com', + 'href' => 'http://google.com', 'class' => 'funtimes', ]; @@ -72,11 +70,11 @@ public function testUpdateAttributes() $tag = new Tag('a'); $tag->setAttributes([ 'href' => [ - 'value' => 'http://google.com', + 'value' => 'http://google.com', 'doubleQuote' => false, ], 'class' => [ - 'value' => null, + 'value' => null, 'doubleQuote' => true, ], ]); @@ -85,7 +83,7 @@ public function testUpdateAttributes() $this->assertEquals('http://google.com', $tag->getAttribute('href')->getValue()); $attr = [ - 'href' => 'https://www.google.com', + 'href' => 'https://www.google.com', 'class' => 'funtimes', ]; @@ -104,7 +102,7 @@ public function testGetAttributeMagic() { $attr = [ 'href' => [ - 'value' => 'http://google.com', + 'value' => 'http://google.com', 'doubleQuote' => false, ], ]; @@ -125,7 +123,7 @@ public function testMakeOpeningTag() { $attr = [ 'href' => [ - 'value' => 'http://google.com', + 'value' => 'http://google.com', 'doubleQuote' => true, ], ]; @@ -139,7 +137,7 @@ public function testMakeOpeningTagEmptyAttr() { $attr = [ 'href' => [ - 'value' => 'http://google.com', + 'value' => 'http://google.com', 'doubleQuote' => true, ], ]; @@ -154,7 +152,7 @@ public function testMakeOpeningTagSelfClosing() { $attr = [ 'class' => [ - 'value' => 'clear-fix', + 'value' => 'clear-fix', 'doubleQuote' => true, ], ]; @@ -189,6 +187,6 @@ public function testGetStyleAttributesArray() { $tag = new Tag('div'); $tag->setStyleAttributeValue('display', 'none'); - $this->assertInternalType('array', $tag->getStyleAttributeArray()); + $this->assertIsArray($tag->getStyleAttributeArray()); } } diff --git a/tests/Node/TextTest.php b/tests/Node/TextTest.php index f94c4962..23399535 100755 --- a/tests/Node/TextTest.php +++ b/tests/Node/TextTest.php @@ -4,9 +4,8 @@ use PHPHtmlParser\Dom; use PHPHtmlParser\Dom\Node\TextNode; -use PHPHtmlParser\Options; use PHPUnit\Framework\TestCase; -use stringEncode\Encode; +use StringEncoder\Encoder; class NodeTextTest extends TestCase { @@ -66,9 +65,9 @@ public function testSetText() public function testSetTextEncoded() { - $encode = new Encode(); - $encode->from('UTF-8'); - $encode->to('UTF-8'); + $encode = new Encoder(); + $encode->setSourceEncoding('UTF-8'); + $encode->setTargetEncoding('UTF-8'); $node = new TextNode('foo bar'); $node->propagateEncoding($encode); diff --git a/tests/Options/CleanupTest.php b/tests/Options/CleanupTest.php index 914078ac..e63b494a 100755 --- a/tests/Options/CleanupTest.php +++ b/tests/Options/CleanupTest.php @@ -40,8 +40,10 @@ public function testRemoveStylesFalse() $dom->setOptions((new Options())->setRemoveStyles(false)); $dom->loadFromFile('tests/data/files/big.html'); $this->assertEquals(1, \count($dom->find('style'))); - $this->assertEquals('text/css', - $dom->find('style')->getAttribute('type')); + $this->assertEquals( + 'text/css', + $dom->find('style')->getAttribute('type') + ); } public function testRemoveScriptsTrue() @@ -58,8 +60,10 @@ public function testRemoveScriptsFalse() $dom->setOptions((new Options())->setRemoveScripts(false)); $dom->loadFromFile('tests/data/files/big.html'); $this->assertEquals(22, \count($dom->find('script'))); - $this->assertEquals('text/javascript', - $dom->find('script')->getAttribute('type')); + $this->assertEquals( + 'text/javascript', + $dom->find('script')->getAttribute('type') + ); } public function testSmartyScripts() diff --git a/tests/Selector/SelectorTest.php b/tests/Selector/SelectorTest.php index 9ef2705d..4d4fd535 100755 --- a/tests/Selector/SelectorTest.php +++ b/tests/Selector/SelectorTest.php @@ -59,7 +59,7 @@ public function testFindId() $child2 = new HtmlNode(new Tag('p')); $child2->getTag()->setAttributes([ 'id' => [ - 'value' => 'content', + 'value' => 'content', 'doubleQuote' => true, ], ]); @@ -78,7 +78,7 @@ public function testFindClass() $child3 = new HtmlNode('a'); $child3->getTag()->setAttributes([ 'class' => [ - 'value' => 'link', + 'value' => 'link', 'doubleQuote' => true, ], ]); @@ -98,7 +98,7 @@ public function testFindClassMultiple() $child3 = new HtmlNode(new Tag('a')); $child3->getTag()->setAttributes([ 'class' => [ - 'value' => 'link outer', + 'value' => 'link outer', 'doubleQuote' => false, ], ]); @@ -150,7 +150,7 @@ public function testFindXpathKeySelector() $child3 = new HtmlNode(new Tag('a')); $child3->getTag()->setAttributes([ 'class' => [ - 'value' => 'link outer', + 'value' => 'link outer', 'doubleQuote' => false, ], ]); diff --git a/tests/StaticDomTest.php b/tests/StaticDomTest.php index 73453633..bbbee6e9 100755 --- a/tests/StaticDomTest.php +++ b/tests/StaticDomTest.php @@ -7,12 +7,12 @@ class StaticDomTest extends TestCase { - public function setUp() + public function setUp(): void { StaticDom::mount(); } - public function tearDown() + protected function tearDown(): void { StaticDom::unload(); } @@ -44,11 +44,9 @@ public function testLoadFromFile() $this->assertEquals('VonBurgermeister', $dom->find('.post-user font', 0)->text); } - /** - * @expectedException \PHPHtmlParser\Exceptions\NotLoadedException - */ public function testFindNoloadStr() { + $this->expectException(\PHPHtmlParser\Exceptions\NotLoadedException::class); Dom::find('.post-user font', 0); } diff --git a/tests/data/files/html5.html b/tests/data/files/html5.html index b2b1413d..53da9df3 100644 --- a/tests/data/files/html5.html +++ b/tests/data/files/html5.html @@ -1,7 +1,7 @@ - +