From 1dc68c612fb7c2fefc8bdba59a7007de57706fc5 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 14 Sep 2025 16:27:03 +0200 Subject: [PATCH 01/13] Update to PHPStan 2 PHPStan has improved a lot since version 1.12 used by SimplePie until now. Take advantage of explicit PHPStan phpVersion range. Define explicit range of minimum and maximum PHP version supported. Useful e.g. for function signatures, which have changed over time https://phpstan.org/config-reference#phpversion Do not run PHPStan for PHP < 7.4 but the tests are covered by phpVersion min, so it is actually enough to run PHPStan once on any supported PHP version. Cannot support PHPUnit >= 10 at the same time as PHP 7.2. --- .editorconfig | 4 + .github/workflows/ci.yml | 1 + .gitignore | 1 + autoloader.php | 3 +- composer.json | 7 +- demo/index.php | 14 ++- demo/test.php | 9 +- library/SimplePie/Decode/HTML/Entities.php | 2 + phpstan.dist.neon | 65 +++---------- src/Cache/Psr16.php | 1 + src/Enclosure.php | 1 + src/File.php | 9 +- src/HTTP/FileClient.php | 1 - src/HTTP/Parser.php | 4 +- src/Locator.php | 2 +- src/Parser.php | 9 ++ src/Registry.php | 2 +- src/Sanitize.php | 1 - src/SimplePie.php | 7 +- tests/BCTest.php | 6 +- tests/CacheTest.php | 2 +- tests/EncodingTest.php | 12 +-- tests/HTTPParserTest.php | 36 +++---- tests/IRITest.php | 93 +++++++++--------- tests/Integration/CachingTest.php | 2 +- tests/Integration/HTTP/ClientsTest.php | 29 +++--- tests/Integration/SimplePieTest.php | 57 +++++------ tests/ItemTest.php | 18 ++-- tests/LocatorTest.php | 20 ++-- tests/SanitizeTest.php | 4 +- tests/SubscribeUrlTest.php | 4 +- tests/Unit/AuthorTest.php | 16 +-- tests/Unit/Cache/BaseDataCacheTest.php | 16 +-- tests/Unit/Cache/BaseTest.php | 4 +- tests/Unit/Cache/DBTest.php | 4 +- tests/Unit/Cache/FileTest.php | 4 +- tests/Unit/Cache/MemcacheTest.php | 4 +- tests/Unit/Cache/MemcachedTest.php | 4 +- tests/Unit/Cache/MySQLTest.php | 4 +- tests/Unit/Cache/Psr16Test.php | 14 +-- tests/Unit/Cache/RedisTest.php | 4 +- tests/Unit/CacheTest.php | 4 +- tests/Unit/CaptionTest.php | 4 +- tests/Unit/CategoryTest.php | 14 +-- tests/Unit/Content/Type/SnifferTest.php | 4 +- tests/Unit/CopyrightTest.php | 4 +- tests/Unit/CreditTest.php | 4 +- tests/Unit/EnclosureTest.php | 14 +-- tests/Unit/ExceptionTest.php | 4 +- tests/Unit/FileTest.php | 27 +++--- tests/Unit/GzdecodeTest.php | 4 +- tests/Unit/HTTP/ParserTest.php | 84 ++++++++-------- tests/Unit/HTTP/Psr18ClientTest.php | 9 +- tests/Unit/HTTP/Psr7ResponseTest.php | 25 ++--- tests/Unit/IRITest.php | 97 ++++++++++--------- tests/Unit/ItemTest.php | 46 ++++----- tests/Unit/LocatorTest.php | 24 ++--- tests/Unit/MiscTest.php | 28 +++--- tests/Unit/Net/IPv6Test.php | 4 +- tests/Unit/Parse/DateTest.php | 6 +- tests/Unit/ParserTest.php | 12 +-- tests/Unit/RatingTest.php | 4 +- tests/Unit/RegistryTest.php | 8 +- tests/Unit/RestrictionTest.php | 12 +-- tests/Unit/SanitizeTest.php | 8 +- tests/Unit/SimplePieTest.php | 48 ++++----- tests/Unit/SourceTest.php | 4 +- tests/Unit/XML/Declaration/ParserTest.php | 4 +- .../RegistryCallMethodReturnTypeExtension.php | 9 +- 69 files changed, 504 insertions(+), 511 deletions(-) diff --git a/.editorconfig b/.editorconfig index a760cdf84..13c02021c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -19,6 +19,10 @@ indent_style = space max_line_length = off trim_trailing_whitespace = false +[*.neon] +indent_size = 4 +indent_style = space + [*.php] indent_size = 4 indent_style = space diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 652f0ec55..07f892237 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,6 +83,7 @@ jobs: run: composer test - name: Run static analysis + if: ${{ matrix.php >= '7.4' }} run: composer phpstan -- --error-format=github test-compiled: diff --git a/.gitignore b/.gitignore index 805c1f9b9..611895a6d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ phpstan.neon phpunit.xml .php-cs-fixer.cache .phpunit.cache/ +.phpunit.result.cache diff --git a/autoloader.php b/autoloader.php index 4356b456f..1ae88be64 100644 --- a/autoloader.php +++ b/autoloader.php @@ -57,6 +57,7 @@ */ class SimplePie_Autoloader { + /** @var string */ protected $path; /** @@ -72,7 +73,7 @@ public function __construct() * * @param string $class The name of the class to attempt to load. */ - public function autoload($class) + public function autoload(string $class): void { // Only load the class if it starts with "SimplePie" if (strpos($class, 'SimplePie') !== 0) diff --git a/composer.json b/composer.json index e35a81211..365a83482 100644 --- a/composer.json +++ b/composer.json @@ -33,8 +33,9 @@ "donatj/mock-webserver": "^2.7", "friendsofphp/php-cs-fixer": "^2.19 || ^3.8", "mf2/mf2": "^0.5.0", - "phpstan/phpstan": "~1.12.2", - "phpunit/phpunit": "^8 || ^9 || ^10", + "phpstan/phpstan": "~2.1.25", + "phpstan/phpstan-phpunit": "~2.0.7", + "phpunit/phpunit": "^8 || ^9", "psr/http-client": "^1.0", "psr/http-factory": "^1.0", "psr/simple-cache": "^1 || ^2 || ^3" @@ -69,7 +70,7 @@ "coverage": "phpunit --coverage-html=.phpunit.cache/code-coverage", "cs": "php-cs-fixer fix --verbose --dry-run --diff", "fix": "php-cs-fixer fix --verbose --diff", - "phpstan": "phpstan analyze --memory-limit 512M", + "phpstan": "phpstan analyse", "test": "phpunit" } } diff --git a/demo/index.php b/demo/index.php index b07bb8a3f..5849846bc 100644 --- a/demo/index.php +++ b/demo/index.php @@ -1,7 +1,6 @@ ' . "\r\n"; // ... and display it. - echo '

' . htmlspecialchars($feed->error()) . "

\r\n"; + if (is_string($feed->error())) { + echo '

' . htmlspecialchars($feed->error()) . "

\r\n"; + } elseif (is_array($feed->error())) { + foreach ($feed->error() as $error) { + echo '

' . htmlspecialchars($error) . "

\r\n"; + } + } // Close the
element we opened. echo '
' . "\r\n"; @@ -236,7 +242,7 @@
-

Page processed in seconds.

+

Page processed in seconds.

Powered by . Run the SimplePie Compatibility Test. SimplePie is © 2004–, Ryan Parman and Sam Sneddon, and licensed under the BSD License.

diff --git a/demo/test.php b/demo/test.php index 18764106e..375207f05 100644 --- a/demo/test.php +++ b/demo/test.php @@ -4,16 +4,15 @@ // Parse it $feed = new \SimplePie\SimplePie(); if (isset($_GET['feed']) && $_GET['feed'] !== '') { + // @phpstan-ignore booleanAnd.rightAlwaysFalse if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { $_GET['feed'] = stripslashes($_GET['feed']); } $feed->set_feed_url($_GET['feed']); $feed->enable_cache(false); - $starttime = explode(' ', microtime()); - $starttime = $starttime[1] + $starttime[0]; + $starttime = microtime(true); $feed->init(); - $endtime = explode(' ', microtime()); - $endtime = $endtime[1] + $endtime[0]; + $endtime = microtime(true); $time = $endtime - $starttime; } else { $time = 'null'; @@ -39,7 +38,7 @@ } // Output buffer -function callable_htmlspecialchars($string) +function callable_htmlspecialchars(string $string): string { return htmlspecialchars($string); } diff --git a/library/SimplePie/Decode/HTML/Entities.php b/library/SimplePie/Decode/HTML/Entities.php index 3366526a5..639a8c257 100644 --- a/library/SimplePie/Decode/HTML/Entities.php +++ b/library/SimplePie/Decode/HTML/Entities.php @@ -72,6 +72,7 @@ public function parse() * * @access private * @return string|false The next byte, or false, if there is no more data + * @phpstan-impure */ public function consume() { @@ -547,6 +548,7 @@ public function entity() 'zwnj;' => "\xE2\x80\x8C" ]; + $consumed = ''; for ($i = 0, $match = null; $i < 9 && $this->consume() !== false; $i++) { // Cast for PHPStan on PHP < 8.0: We consumed as per the loop condition, // so `$this->consumed` is non-empty and the substr offset is valid. diff --git a/phpstan.dist.neon b/phpstan.dist.neon index da1d19fc6..bef3a3254 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -1,4 +1,8 @@ parameters: + phpVersion: + min: 70200 # PHP 7.2 + max: 80599 # PHP 8.5 + level: 8 paths: @@ -6,60 +10,15 @@ parameters: - src/ - tests/ - ignoreErrors: - # Ignore that only one const exists atm - - - message: "#^Strict comparison using \\!\\=\\= between 'GET' and 'GET' will always evaluate to false\\.$#" - count: 1 - path: src/HTTP/Psr18Client.php - - # SimplePie\Content\Type\Sniffer::__construct(): Parameter $file could be mixed due to BC. - - - message: '(Result of \|\| is always false\.)' - count: 1 - path: src/Content/Type/Sniffer.php - - # Not used since https://github.com/simplepie/simplepie/commit/b2eb0134d53921e75f0fa70b1cf901ed82b988b1 but cannot be removed due to BC. - - '(Constructor of class SimplePie\\Enclosure has an unused parameter \$javascript\.)' - - # Testing legacy dynamic property usage. - - '(Access to an undefined property SimplePie.IRI::\$nonexistent_prop\.)' - - - - message: '(^Strict comparison using === between string and false will always evaluate to false\.$)' - count: 1 - path: src/HTTP/Parser.php - # Only occurs on PHP ≥ 8.0 - reportUnmatched: false - - - - message: '(^Strict comparison using === between string and false will always evaluate to false\.$)' - count: 1 - path: src/IRI.php - # Only occurs on PHP ≥ 8.0 - reportUnmatched: false - - - - message: '(^Parameter #1 \$exception of method PHPUnit\\Framework\\TestCase::expectException\(\) expects class-string, string given\.$)' - - count: 3 - path: tests/Unit/Cache/Psr16Test.php - # Only occurs on PHP ≤ 7.4 - reportUnmatched: false - - - - message: '(^Parameter \$parser of method SimplePie\\Parser::(tag_open|cdata|tag_close)\(\) has invalid type XMLParser\.$)' - - count: 3 - path: src/Parser.php - # Only occurs on PHP ≤ 7.4 - reportUnmatched: false + excludePaths: + analyseAndScan: + - .git/*? + - build/*? + - vendor/* - # PHPStan stubs bug https://github.com/phpstan/phpstan/issues/8629 - - - message: '(^Access to an undefined property XMLReader::\$\w+\.$)' - # Only occurs on PHP ≥ 8.2 - reportUnmatched: false + treatPhpDocTypesAsCertain: false # TODO: Fix includes: - utils/PHPStan/extension.neon + - vendor/phpstan/phpstan-phpunit/extension.neon + - vendor/phpstan/phpstan-phpunit/rules.neon diff --git a/src/Cache/Psr16.php b/src/Cache/Psr16.php index 4dc8161d2..c353db8e5 100644 --- a/src/Cache/Psr16.php +++ b/src/Cache/Psr16.php @@ -83,6 +83,7 @@ public function get_data(string $key, $default = null) */ public function set_data(string $key, array $value, ?int $ttl = null): bool { + // @phpstan-ignore argument.type (mixed is not supported by PHP < 8.0, used by psr/simple-cache >= 2) return $this->cache->set($key, $value, $ttl); } diff --git a/src/Enclosure.php b/src/Enclosure.php index 89231c7f9..e2c72ed85 100644 --- a/src/Enclosure.php +++ b/src/Enclosure.php @@ -195,6 +195,7 @@ class Enclosure * @param Rating[]|null $ratings * @param Restriction[]|null $restrictions * @param string[]|null $thumbnails + * @phpstan-ignore constructor.unusedParameter */ public function __construct( ?string $link = null, diff --git a/src/File.php b/src/File.php index 2d6ddf2b2..3271d73e9 100644 --- a/src/File.php +++ b/src/File.php @@ -124,13 +124,16 @@ public function __construct(string $url, int $timeout = 10, int $redirects = 5, if (version_compare(\SimplePie\Misc::get_curl_version(), '7.10.5', '>=')) { curl_setopt($fp, CURLOPT_ENCODING, ''); } + /** @var non-empty-string $url */ curl_setopt($fp, CURLOPT_URL, $url); - curl_setopt($fp, CURLOPT_HEADER, 1); - curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($fp, CURLOPT_FAILONERROR, 1); + curl_setopt($fp, CURLOPT_HEADER, true); + curl_setopt($fp, CURLOPT_RETURNTRANSFER, true); + curl_setopt($fp, CURLOPT_FAILONERROR, true); curl_setopt($fp, CURLOPT_TIMEOUT, $timeout); curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, $timeout); + /** @phpstan-ignore argument.type */ curl_setopt($fp, CURLOPT_REFERER, \SimplePie\Misc::url_remove_credentials($url)); + /** @phpstan-ignore argument.type */ curl_setopt($fp, CURLOPT_USERAGENT, $useragent); curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2); foreach ($curl_options as $curl_param => $curl_value) { diff --git a/src/HTTP/FileClient.php b/src/HTTP/FileClient.php index 90fefebb0..6b35dcc8d 100644 --- a/src/HTTP/FileClient.php +++ b/src/HTTP/FileClient.php @@ -45,7 +45,6 @@ public function __construct(Registry $registry, array $options = []) */ public function request(string $method, string $url, array $headers = []): Response { - // @phpstan-ignore-next-line Enforce PHPDoc type. if ($method !== self::METHOD_GET) { throw new InvalidArgumentException(sprintf( '%s(): Argument #1 ($method) only supports method "%s".', diff --git a/src/HTTP/Parser.php b/src/HTTP/Parser.php index e9bcc4671..1363e5653 100644 --- a/src/HTTP/Parser.php +++ b/src/HTTP/Parser.php @@ -243,7 +243,7 @@ private function add_header(string $name, string $value): void $headers[$name][] = $value; } else { // For PHPStan: should be enforced by template parameter but PHPStan is not smart enough. - /** @var array) */ + /** @var array */ $headers = &$this->headers; $headers[$name] .= ', ' . $value; } @@ -258,7 +258,7 @@ private function replace_header(string $name, string $value): void $headers[$name] = [$value]; } else { // For PHPStan: should be enforced by template parameter but PHPStan is not smart enough. - /** @var array) */ + /** @var array */ $headers = &$this->headers; $headers[$name] = $value; } diff --git a/src/Locator.php b/src/Locator.php index 30a7fe525..d2c87739e 100644 --- a/src/Locator.php +++ b/src/Locator.php @@ -255,7 +255,7 @@ protected function search_elements_by_tag(string $name, array &$done, array $fee } else { $href = $this->registry->call(Misc::class, 'absolutize_url', [trim($link->getAttribute('href')), $this->http_base]); } - if ($href === false) { + if (!is_string($href)) { continue; } diff --git a/src/Parser.php b/src/Parser.php index fc93996eb..bca8787c4 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -89,28 +89,34 @@ public function parse(string &$data, string $encoding, string $url = '') // Strip BOM: // UTF-32 Big Endian BOM if (substr($data, 0, 4) === "\x00\x00\xFE\xFF") { + /** @phpstan-ignore parameterByRef.type (for PHP < 8.0) */ $data = substr($data, 4); } // UTF-32 Little Endian BOM elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00") { + /** @phpstan-ignore parameterByRef.type (for PHP < 8.0) */ $data = substr($data, 4); } // UTF-16 Big Endian BOM elseif (substr($data, 0, 2) === "\xFE\xFF") { + /** @phpstan-ignore parameterByRef.type (for PHP < 8.0) */ $data = substr($data, 2); } // UTF-16 Little Endian BOM elseif (substr($data, 0, 2) === "\xFF\xFE") { + /** @phpstan-ignore parameterByRef.type (for PHP < 8.0) */ $data = substr($data, 2); } // UTF-8 BOM elseif (substr($data, 0, 3) === "\xEF\xBB\xBF") { + /** @phpstan-ignore parameterByRef.type (for PHP < 8.0) */ $data = substr($data, 3); } if (substr($data, 0, 5) === '')) !== false) { $declaration = $this->registry->create(DeclarationParser::class, [substr($data, 5, $pos - 5)]); if ($declaration->parse()) { + /** @phpstan-ignore parameterByRef.type (for PHP < 8.0) */ $data = substr($data, $pos + 2); $data = 'version . '" encoding="' . $encoding . '" standalone="' . (($declaration->standalone) ? 'yes' : 'no') . '"?>' . "\n" . self::set_doctype($data); @@ -276,6 +282,7 @@ public function get_data() * @param XMLParser|resource|null $parser * @param array $attributes * @return void + * @phpstan-ignore class.notFound (XMLParser requires PHP >= 8.0) */ public function tag_open($parser, string $tag, array $attributes) { @@ -332,6 +339,7 @@ public function tag_open($parser, string $tag, array $attributes) /** * @param XMLParser|resource|null $parser * @return void + * @phpstan-ignore class.notFound (XMLParser requires PHP >= 8.0) */ public function cdata($parser, string $cdata) { @@ -345,6 +353,7 @@ public function cdata($parser, string $cdata) /** * @param XMLParser|resource|null $parser * @return void + * @phpstan-ignore class.notFound (XMLParser requires PHP >= 8.0) */ public function tag_close($parser, string $tag) { diff --git a/src/Registry.php b/src/Registry.php index 228f8c33c..274e4b42c 100644 --- a/src/Registry.php +++ b/src/Registry.php @@ -125,7 +125,6 @@ public function register(string $type, $class, bool $legacy = false) return false; } - /** @var string */ $base_class = $this->default[$type]; if (!is_subclass_of($class, $base_class)) { @@ -207,6 +206,7 @@ public function &create($type, array $parameters = []) $instance->set_registry($this); } elseif (method_exists($instance, 'set_registry')) { trigger_error(sprintf('Using the method "set_registry()" without implementing "%s" is deprecated since SimplePie 1.8.0, implement "%s" in "%s".', RegistryAware::class, RegistryAware::class, $class), \E_USER_DEPRECATED); + // @phpstan-ignore method.nonObject $instance->set_registry($this); } diff --git a/src/Sanitize.php b/src/Sanitize.php index c8aa2dce6..a44b70048 100644 --- a/src/Sanitize.php +++ b/src/Sanitize.php @@ -156,7 +156,6 @@ public function pass_cache_data(bool $enable_cache = true, string $cache_locatio $this->cache_location = $cache_location; } - // @phpstan-ignore-next-line Enforce PHPDoc type. if (!is_string($cache_name_function) && !$cache_name_function instanceof NameFilter) { throw new InvalidArgumentException(sprintf( '%s(): Argument #3 ($cache_name_function) must be of type %s', diff --git a/src/SimplePie.php b/src/SimplePie.php index bbc5218e6..660ede6b7 100644 --- a/src/SimplePie.php +++ b/src/SimplePie.php @@ -1810,7 +1810,7 @@ public function init() // Cache the file if caching is enabled $this->data['cache_expiration_time'] = $this->cache_duration + time(); - if ($cache && !$cache->set_data($this->get_cache_filename($this->feed_url), $this->data, $this->cache_duration)) { + if ($cache instanceof DataCache && !$cache->set_data($this->get_cache_filename($this->feed_url), $this->data, $this->cache_duration)) { trigger_error("$this->cache_location is not writable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING); } return true; @@ -1861,7 +1861,6 @@ protected function fetch_data(&$cache) $cache = new BaseDataCache($cache); } - // @phpstan-ignore-next-line Enforce PHPDoc type. if ($cache !== false && !$cache instanceof DataCache) { throw new InvalidArgumentException(sprintf( '%s(): Argument #1 ($cache) must be of type %s|false', @@ -2860,7 +2859,7 @@ public function get_links(string $rel = 'alternate') } // https://datatracker.ietf.org/doc/html/rfc8288 if (is_string($link_headers) && - preg_match_all('/<(?P[^>]+)>\s*;\s*rel\s*=\s*(?P"?)' . preg_quote($rel) . '(?P=quote)\s*(?=,|$)/i', $link_headers, $matches)) { + preg_match_all('/<(?P[^>]+)>\s*;\s*rel\s*=\s*(?P"?)' . preg_quote($rel, '/') . '(?P=quote)\s*(?=,|$)/i', $link_headers, $matches)) { return $matches['uri']; } } @@ -3370,8 +3369,6 @@ public static function merge_items(array $urls, int $start = 0, int $end = 0, in foreach ($urls as $arg) { if ($arg instanceof SimplePie) { $items = array_merge($items, $arg->get_items(0, $limit)); - - // @phpstan-ignore-next-line Enforce PHPDoc type. } else { trigger_error('Arguments must be SimplePie objects', E_USER_WARNING); } diff --git a/tests/BCTest.php b/tests/BCTest.php index 9c94ba6ee..26f2a31d8 100644 --- a/tests/BCTest.php +++ b/tests/BCTest.php @@ -17,7 +17,7 @@ class BCTest extends TestCase */ public function test_class_SimplePie_Core_exists(): void { - $this->assertTrue(class_exists('SimplePie_Core')); + self::assertTrue(class_exists('SimplePie_Core')); } /** @@ -25,7 +25,7 @@ public function test_class_SimplePie_Core_exists(): void */ public function test_class_SimplePie_Misc_exists(): void { - $this->assertTrue(class_exists('SimplePie_Misc')); + self::assertTrue(class_exists('SimplePie_Misc')); } /** @@ -33,6 +33,6 @@ public function test_class_SimplePie_Misc_exists(): void */ public function test_class_SimplePie_Decode_HTML_Entities_exists(): void { - $this->assertTrue(class_exists('SimplePie_Decode_HTML_Entities')); + self::assertTrue(class_exists('SimplePie_Decode_HTML_Entities')); } } diff --git a/tests/CacheTest.php b/tests/CacheTest.php index da5a53cda..dcf0ba07e 100644 --- a/tests/CacheTest.php +++ b/tests/CacheTest.php @@ -60,7 +60,7 @@ public function testDirectOverrideLegacy(): void // PHPUnit 10 compatible way to test trigger_error(). set_error_handler( function ($errno, $errstr): bool { - $this->assertSame( + self::assertSame( '"SimplePie\SimplePie::set_cache_class()" is deprecated since SimplePie 1.3, please use "SimplePie\SimplePie::set_cache()" instead.', $errstr ); diff --git a/tests/EncodingTest.php b/tests/EncodingTest.php index 4a637754d..da70fc5a5 100644 --- a/tests/EncodingTest.php +++ b/tests/EncodingTest.php @@ -79,7 +79,7 @@ public static function toUTF8_uconverter(): array public function test_convert_UTF8(string $input, string $expected, string $encoding): void { $encoding = SimplePie_Misc::encoding($encoding); - $this->assertSameBin2Hex($expected, (string) SimplePie_Misc::change_encoding($input, $encoding, 'UTF-8')); + self::assertSameBin2Hex($expected, (string) SimplePie_Misc::change_encoding($input, $encoding, 'UTF-8')); } /** @@ -92,7 +92,7 @@ public function test_convert_UTF8_mbstring(string $input, string $expected, stri { $encoding = SimplePie_Misc::encoding($encoding); if (extension_loaded('mbstring')) { - $this->assertSameBin2Hex($expected, (string) Mock_Misc::change_encoding_mbstring($input, $encoding, 'UTF-8')); + self::assertSameBin2Hex($expected, (string) Mock_Misc::change_encoding_mbstring($input, $encoding, 'UTF-8')); } } @@ -106,7 +106,7 @@ public function test_convert_UTF8_iconv(string $input, string $expected, string { $encoding = SimplePie_Misc::encoding($encoding); if (extension_loaded('iconv')) { - $this->assertSameBin2Hex($expected, (string) Mock_Misc::change_encoding_iconv($input, $encoding, 'UTF-8')); + self::assertSameBin2Hex($expected, (string) Mock_Misc::change_encoding_iconv($input, $encoding, 'UTF-8')); } } @@ -120,7 +120,7 @@ public function test_convert_UTF8_uconverter(string $input, string $expected, st { $encoding = SimplePie_Misc::encoding($encoding); if (extension_loaded('intl')) { - $this->assertSameBin2Hex($expected, (string) Mock_Misc::change_encoding_uconverter($input, $encoding, 'UTF-8')); + self::assertSameBin2Hex($expected, (string) Mock_Misc::change_encoding_uconverter($input, $encoding, 'UTF-8')); } } @@ -144,12 +144,12 @@ public static function toUTF16(): array public function test_convert_UTF16(string $input, string $expected, string $encoding): void { $encoding = SimplePie_Misc::encoding($encoding); - $this->assertSameBin2Hex($expected, (string) SimplePie_Misc::change_encoding($input, $encoding, 'UTF-16')); + self::assertSameBin2Hex($expected, (string) SimplePie_Misc::change_encoding($input, $encoding, 'UTF-16')); } public function test_nonexistent(): void { - $this->assertFalse(SimplePie_Misc::change_encoding('', 'TESTENC', 'UTF-8')); + self::assertFalse(SimplePie_Misc::change_encoding('', 'TESTENC', 'UTF-8')); } public static function assertSameBin2Hex(string $expected, string $actual, string $message = ''): void diff --git a/tests/HTTPParserTest.php b/tests/HTTPParserTest.php index c1ab1849a..8ac98104d 100755 --- a/tests/HTTPParserTest.php +++ b/tests/HTTPParserTest.php @@ -41,12 +41,12 @@ public function testChunkedNormal(string $data, string $expected): void $data = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n" . $data; $data = SimplePie_HTTP_Parser::prepareHeaders($data); $parser = new SimplePie_HTTP_Parser($data); - $this->assertTrue($parser->parse()); - $this->assertSame(1.1, $parser->http_version); - $this->assertSame(200, $parser->status_code); - $this->assertSame('OK', $parser->reason); - $this->assertSame(['content-type' => 'text/plain'], $parser->headers); - $this->assertSame($expected, $parser->body); + self::assertTrue($parser->parse()); + self::assertSame(1.1, $parser->http_version); + self::assertSame(200, $parser->status_code); + self::assertSame('OK', $parser->reason); + self::assertSame(['content-type' => 'text/plain'], $parser->headers); + self::assertSame($expected, $parser->body); } /** @@ -57,12 +57,12 @@ public function testChunkedProxy(string $data, string $expected): void $data = "HTTP/1.0 200 Connection established\r\n\r\nHTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n" . $data; $data = SimplePie_HTTP_Parser::prepareHeaders($data); $parser = new SimplePie_HTTP_Parser($data); - $this->assertTrue($parser->parse()); - $this->assertSame(1.1, $parser->http_version); - $this->assertSame(200, $parser->status_code); - $this->assertSame('OK', $parser->reason); - $this->assertSame(['content-type' => 'text/plain'], $parser->headers); - $this->assertSame($expected, $parser->body); + self::assertTrue($parser->parse()); + self::assertSame(1.1, $parser->http_version); + self::assertSame(200, $parser->status_code); + self::assertSame('OK', $parser->reason); + self::assertSame(['content-type' => 'text/plain'], $parser->headers); + self::assertSame($expected, $parser->body); } /** @@ -73,11 +73,11 @@ public function testChunkedProxy11(string $data, string $expected): void $data = "HTTP/1.1 200 Connection established\r\n\r\nHTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n" . $data; $data = SimplePie_HTTP_Parser::prepareHeaders($data); $parser = new SimplePie_HTTP_Parser($data); - $this->assertTrue($parser->parse()); - $this->assertSame(1.1, $parser->http_version); - $this->assertSame(200, $parser->status_code); - $this->assertSame('OK', $parser->reason); - $this->assertSame(['content-type' => 'text/plain'], $parser->headers); - $this->assertSame($expected, $parser->body); + self::assertTrue($parser->parse()); + self::assertSame(1.1, $parser->http_version); + self::assertSame(200, $parser->status_code); + self::assertSame('OK', $parser->reason); + self::assertSame(['content-type' => 'text/plain'], $parser->headers); + self::assertSame($expected, $parser->body); } } diff --git a/tests/IRITest.php b/tests/IRITest.php index 6d0fa6029..0176d9966 100644 --- a/tests/IRITest.php +++ b/tests/IRITest.php @@ -72,8 +72,8 @@ public function testStringRFC3986(string $relative, string $expected): void { $base = new SimplePie_IRI('http://a/b/c/d;p?q'); $absolutized = SimplePie_IRI::absolutize($base, $relative); - $this->assertNotFalse($absolutized); - $this->assertSame($expected, $absolutized->get_iri()); + self::assertNotFalse($absolutized); + self::assertSame($expected, $absolutized->get_iri()); } /** @@ -83,7 +83,7 @@ public function testObjectRFC3986(string $relative, string $expected): void { $base = new SimplePie_IRI('http://a/b/c/d;p?q'); $expected = new SimplePie_IRI($expected); - $this->assertEquals($expected, SimplePie_IRI::absolutize($base, $relative)); + self::assertEquals($expected, SimplePie_IRI::absolutize($base, $relative)); } /** @@ -93,9 +93,9 @@ public function testBothStringRFC3986(string $relative, string $expected): void { $base = 'http://a/b/c/d;p?q'; $absolutized = SimplePie_IRI::absolutize($base, $relative); - $this->assertNotFalse($absolutized); - $this->assertSame($expected, $absolutized->get_iri()); - $this->assertSame($expected, (string) SimplePie_IRI::absolutize($base, $relative)); + self::assertNotFalse($absolutized); + self::assertSame($expected, $absolutized->get_iri()); + self::assertSame($expected, (string) SimplePie_IRI::absolutize($base, $relative)); } /** @@ -130,8 +130,8 @@ public function testStringSP(string $base, string $relative, string $expected): { $base = new SimplePie_IRI($base); $absolutized = SimplePie_IRI::absolutize($base, $relative); - $this->assertNotFalse($absolutized); - $this->assertSame($expected, $absolutized->get_iri()); + self::assertNotFalse($absolutized); + self::assertSame($expected, $absolutized->get_iri()); } /** @@ -141,7 +141,7 @@ public function testObjectSP(string $base, string $relative, string $expected): { $base = new SimplePie_IRI($base); $expected = new SimplePie_IRI($expected); - $this->assertEquals($expected, SimplePie_IRI::absolutize($base, $relative)); + self::assertEquals($expected, SimplePie_IRI::absolutize($base, $relative)); } /** @@ -164,7 +164,7 @@ public function testStringQuery(string $query, string $expected): void { $base = new SimplePie_IRI('http://example.com/'); $base->set_query($query); - $this->assertSame($expected, $base->get_iri()); + self::assertSame($expected, $base->get_iri()); } /** @@ -175,7 +175,7 @@ public function testObjectQuery(string $query, string $expected): void $base = new SimplePie_IRI('http://example.com/'); $base->set_query($query); $expected = new SimplePie_IRI($expected); - $this->assertEquals($expected, $base); + self::assertEquals($expected, $base); } /** @@ -196,8 +196,8 @@ public function testAbsolutizeString(string $base, string $relative, string $exp { $base = new SimplePie_IRI($base); $absolutized = SimplePie_IRI::absolutize($base, $relative); - $this->assertNotFalse($absolutized); - $this->assertSame($expected, $absolutized->get_iri()); + self::assertNotFalse($absolutized); + self::assertSame($expected, $absolutized->get_iri()); } /** @@ -207,7 +207,7 @@ public function testAbsolutizeObject(string $base, string $relative, string $exp { $base = new SimplePie_IRI($base); $expected = new SimplePie_IRI($expected); - $this->assertEquals($expected, SimplePie_IRI::absolutize($base, $relative)); + self::assertEquals($expected, SimplePie_IRI::absolutize($base, $relative)); } /** @@ -302,7 +302,7 @@ public static function normalization_tests(): array public function testStringNormalization(string $input, string $output): void { $input = new SimplePie_IRI($input); - $this->assertSame($output, $input->get_iri()); + self::assertSame($output, $input->get_iri()); } /** @@ -312,7 +312,7 @@ public function testObjectNormalization(string $input, string $output): void { $input = new SimplePie_IRI($input); $output = new SimplePie_IRI($output); - $this->assertEquals($output, $input); + self::assertEquals($output, $input); } /** @@ -333,7 +333,7 @@ public static function uri_tests(): array public function testURIConversion(string $input, string $output): void { $input = new SimplePie_IRI($input); - $this->assertSame($output, $input->get_uri()); + self::assertSame($output, $input->get_uri()); } /** @@ -353,7 +353,7 @@ public function testObjectEquivalence(string $input, string $output): void { $input = new SimplePie_IRI($input); $output = new SimplePie_IRI($output); - $this->assertEquals($output, $input); + self::assertEquals($output, $input); } /** @@ -373,12 +373,12 @@ public function testObjectNotEquivalence(string $input, string $output): void { $input = new SimplePie_IRI($input); $output = new SimplePie_IRI($output); - $this->assertNotEquals($output, $input); + self::assertNotEquals($output, $input); } public function testInvalidAbsolutizeBase(): void { - $this->assertFalse(SimplePie_IRI::absolutize('://not a URL', '../')); + self::assertFalse(SimplePie_IRI::absolutize('://not a URL', '../')); } public function testInvalidPathNoHost(): void @@ -386,21 +386,21 @@ public function testInvalidPathNoHost(): void $iri = new SimplePie_IRI(); $iri->scheme = 'http'; $iri->path = '//test'; - $this->assertFalse($iri->is_valid()); + self::assertFalse($iri->is_valid()); } public function testInvalidRelativePathContainsColon(): void { $iri = new SimplePie_IRI(); $iri->path = '/test:/'; - $this->assertFalse($iri->is_valid()); + self::assertFalse($iri->is_valid()); } public function testValidRelativePathContainsColon(): void { $iri = new SimplePie_IRI(); $iri->path = '/test/:'; - $this->assertTrue($iri->is_valid()); + self::assertTrue($iri->is_valid()); } public function testFullGamut(): void @@ -412,12 +412,12 @@ public function testFullGamut(): void $iri->path = '/test/'; $iri->fragment = 'test'; - $this->assertSame('http', $iri->scheme); - $this->assertSame('user:password', $iri->userinfo); - $this->assertSame('example.com', $iri->host); - $this->assertSame(80, $iri->port); - $this->assertSame('/test/', $iri->path); - $this->assertSame('test', $iri->fragment); + self::assertSame('http', $iri->scheme); + self::assertSame('user:password', $iri->userinfo); + self::assertSame('example.com', $iri->host); + self::assertSame(80, $iri->port); + self::assertSame('/test/', $iri->path); + self::assertSame('test', $iri->fragment); } public function testReadAliased(): void @@ -429,12 +429,12 @@ public function testReadAliased(): void $iri->path = '/test/'; $iri->fragment = 'test'; - $this->assertSame('http', $iri->scheme); - $this->assertSame('user:password', $iri->userinfo); - $this->assertSame('example.com', $iri->host); - $this->assertSame(80, $iri->port); - $this->assertSame('/test/', $iri->path); - $this->assertSame('test', $iri->fragment); + self::assertSame('http', $iri->scheme); + self::assertSame('user:password', $iri->userinfo); + self::assertSame('example.com', $iri->host); + self::assertSame(80, $iri->port); + self::assertSame('/test/', $iri->path); + self::assertSame('test', $iri->fragment); } public function testWriteAliased(): void @@ -446,23 +446,23 @@ public function testWriteAliased(): void $iri->path = '/test/'; $iri->fragment = 'test'; - $this->assertSame('http', $iri->scheme); - $this->assertSame('user:password', $iri->userinfo); - $this->assertSame('example.com', $iri->host); - $this->assertSame(80, $iri->port); - $this->assertSame('/test/', $iri->path); - $this->assertSame('test', $iri->fragment); + self::assertSame('http', $iri->scheme); + self::assertSame('user:password', $iri->userinfo); + self::assertSame('example.com', $iri->host); + self::assertSame(80, $iri->port); + self::assertSame('/test/', $iri->path); + self::assertSame('test', $iri->fragment); } public function testNonexistentProperty(): void { $iri = new SimplePie_IRI(); - $this->assertFalse(isset($iri->nonexistent_prop)); + self::assertFalse(isset($iri->nonexistent_prop)); // PHPUnit 10 compatible way to test trigger_error(). set_error_handler( function ($errno, $errstr): bool { - $this->assertSame( + self::assertSame( 'Undefined property: SimplePie\IRI::nonexistent_prop', $errstr ); @@ -473,6 +473,7 @@ function ($errno, $errstr): bool { E_USER_NOTICE ); + // @phpstan-ignore property.notFound (we want to test that it fails) $should_fail = $iri->nonexistent_prop; } @@ -481,8 +482,8 @@ public function testBlankHost(): void $iri = new SimplePie_IRI('http://example.com/a/?b=c#d'); $iri->host = null; - $this->assertSame(null, $iri->host); - $this->assertSame('http:/a/?b=c#d', (string) $iri); + self::assertNull($iri->host); + self::assertSame('http:/a/?b=c#d', (string) $iri); } public function testBadPort(): void @@ -490,6 +491,6 @@ public function testBadPort(): void $iri = new SimplePie_IRI(); $iri->port = 'example'; - $this->assertSame(null, $iri->port); + self::assertNull($iri->port); } } diff --git a/tests/Integration/CachingTest.php b/tests/Integration/CachingTest.php index e01ef95a7..1051e47f5 100644 --- a/tests/Integration/CachingTest.php +++ b/tests/Integration/CachingTest.php @@ -112,7 +112,7 @@ public function testInitWithDifferentCacheStateCallsCacheCorrectly( $expectedDataWritten['cache_expiration_time'] = $writtenData['cache_expiration_time']; } - $this->assertSame($expectedDataWritten, $writtenData); + self::assertSame($expectedDataWritten, $writtenData); } /** diff --git a/tests/Integration/HTTP/ClientsTest.php b/tests/Integration/HTTP/ClientsTest.php index b9139d76a..818c0d329 100644 --- a/tests/Integration/HTTP/ClientsTest.php +++ b/tests/Integration/HTTP/ClientsTest.php @@ -47,12 +47,13 @@ private function runTestsWithClientGetContentOfLocalFile(Client $client): void $response = $client->request(Client::METHOD_GET, $filepath); - $this->assertInstanceOf(Response::class, $response); - $this->assertSame($filepath, $response->get_permanent_uri()); - $this->assertSame($filepath, $response->get_final_requested_uri()); - $this->assertSame(200, $response->get_status_code()); - $this->assertSame([], $response->get_headers()); - $this->assertStringStartsWith('', $response->get_body_content()); + // @phpstan-ignore staticMethod.alreadyNarrowedType + self::assertInstanceOf(Response::class, $response); + self::assertSame($filepath, $response->get_permanent_uri()); + self::assertSame($filepath, $response->get_final_requested_uri()); + self::assertSame(200, $response->get_status_code()); + self::assertSame([], $response->get_headers()); + self::assertStringStartsWith('', $response->get_body_content()); } public function testFileClientThrowsClientException(): void @@ -103,7 +104,7 @@ public function testFileClientReturnsResponseOn429StatusCode(): void $server->stop(); - $this->assertSame(429, $response->get_status_code()); + self::assertSame(429, $response->get_status_code()); } public function testFileClientReturnsResponseOn500StatusCode(): void @@ -122,7 +123,7 @@ public function testFileClientReturnsResponseOn500StatusCode(): void $server->stop(); - $this->assertSame(500, $response->get_status_code()); + self::assertSame(500, $response->get_status_code()); } public function testFileClientThrowsClientExceptionIfServerIsUnreachable(): void @@ -215,10 +216,10 @@ public function testRedirectsChain(Client $client): void $server->stop(); - $this->assertSame(200, $response->get_status_code()); - $this->assertSame('OK', $response->get_body_content()); - $this->assertSame($permanentLocation, $response->get_permanent_uri()); - $this->assertSame($finalLocation, $response->get_final_requested_uri()); + self::assertSame(200, $response->get_status_code()); + self::assertSame('OK', $response->get_body_content()); + self::assertSame($permanentLocation, $response->get_permanent_uri()); + self::assertSame($finalLocation, $response->get_final_requested_uri()); } /** @@ -279,12 +280,12 @@ public function testUtf16(Client $client, string $kind, string $endianness): voi $start = $endianness === 'be' ? "\x00<\x00r\x00s\x00s\x00 " : "<\x00r\x00s\x00s\x00 \x00"; $end = $endianness === 'be' ? "\x00<\x00/\x00r\x00s\x00s\x00>\x00\n" : "<\x00/\x00r\x00s\x00s\x00>\x00\n\x00"; - $this->assertSame( + self::assertSame( $start, substr($response->get_body_content(), 0, strlen($start)), 'Body does not start as expected: ' . $response->get_body_content() ); - $this->assertSame( + self::assertSame( $end, substr($response->get_body_content(), -strlen($end)), 'Body does not end as expected: ' . $response->get_body_content() diff --git a/tests/Integration/SimplePieTest.php b/tests/Integration/SimplePieTest.php index a1cb0af1b..c9af9e378 100644 --- a/tests/Integration/SimplePieTest.php +++ b/tests/Integration/SimplePieTest.php @@ -37,8 +37,8 @@ public function testRequestingALocalFileWithSetFeedUrlWorks(): void $simplepie->enable_cache(false); $simplepie->set_feed_url($filepath); - $this->assertTrue($simplepie->init()); - $this->assertSame(100, $simplepie->get_item_quantity()); + self::assertTrue($simplepie->init()); + self::assertSame(100, $simplepie->get_item_quantity()); } /** @@ -53,8 +53,8 @@ public function testRequestingALocalFileWithSetFileWorks(): void $file = new File($filepath); $simplepie->set_file($file); - $this->assertTrue($simplepie->init()); - $this->assertSame(100, $simplepie->get_item_quantity()); + self::assertTrue($simplepie->init()); + self::assertSame(100, $simplepie->get_item_quantity()); } /** @@ -73,8 +73,8 @@ public function testRequestingALocalFileWithPsr18ClientWorks(): void ); $simplepie->set_feed_url($filepath); - $this->assertTrue($simplepie->init()); - $this->assertSame(100, $simplepie->get_item_quantity()); + self::assertTrue($simplepie->init()); + self::assertSame(100, $simplepie->get_item_quantity()); } /** @@ -122,8 +122,8 @@ public function testRequestingAFeedWithPsr18ClientWorks(): void ); $simplepie->set_feed_url('https://example.org/feed.xml'); - $this->assertTrue($simplepie->init()); - $this->assertSame(100, $simplepie->get_item_quantity()); + self::assertTrue($simplepie->init()); + self::assertSame(100, $simplepie->get_item_quantity()); } public function testSimplePieReturnsCorrectStatusCodeFromServerResponse(): void @@ -145,9 +145,9 @@ public function testSimplePieReturnsCorrectStatusCodeFromServerResponse(): void $server->stop(); - $this->assertFalse($return); - $this->assertSame(429, $simplepie->status_code()); - $this->assertSame('Retrieved unsupported status code "429"', $simplepie->error()); + self::assertFalse($return); + self::assertSame(429, $simplepie->status_code()); + self::assertSame('Retrieved unsupported status code "429"', $simplepie->error()); } public function testSimplePieReturnsCorrectStatusCodeOnServerConnectionError(): void @@ -161,9 +161,9 @@ public function testSimplePieReturnsCorrectStatusCodeOnServerConnectionError(): $return = $simplepie->init(); - $this->assertFalse($return); - $this->assertSame(0, $simplepie->status_code()); - $this->assertSame('cURL error 6: Could not resolve host: example.invalid', $simplepie->error()); + self::assertFalse($return); + self::assertSame(0, $simplepie->status_code()); + self::assertSame('cURL error 6: Could not resolve host: example.invalid', $simplepie->error()); } @@ -216,8 +216,8 @@ public function testRequestingAFeedFromCacheWorks(): void $simplepie->set_feed_url('https://example.com/feed.xml'); - $this->assertTrue($simplepie->init()); - $this->assertSame(100, $simplepie->get_item_quantity()); + self::assertTrue($simplepie->init()); + self::assertSame(100, $simplepie->get_item_quantity()); BaseCacheWithCallbacksMock::resetAllCallbacks(); } @@ -258,8 +258,8 @@ public function testRequestingAFeedFromPsr16CacheWorks(): void $simplepie->set_cache($cache); $simplepie->set_feed_url('https://example.com/feed.xml'); - $this->assertTrue($simplepie->init()); - $this->assertSame(100, $simplepie->get_item_quantity()); + self::assertTrue($simplepie->init()); + self::assertSame(100, $simplepie->get_item_quantity()); } @@ -277,7 +277,7 @@ public function testWhitespaceBeforeXmlDeclaration(): void $simplepie->enable_cache(false); $simplepie->set_feed_url($filepath); - $this->assertTrue($simplepie->init()); + self::assertTrue($simplepie->init()); } /** @@ -326,14 +326,15 @@ public function testMicroformatItems(string $path, string $feedTitle, array $tit $feed->enable_cache(false); $error = implode("\n", (array) ($feed->error() ?? '')); // For PHPStan - $this->assertTrue($feed->init(), 'Failed fetching feed: ' . $error); + self::assertTrue($feed->init(), 'Failed fetching feed: ' . $error); - $this->assertSame($feedTitle, $feed->get_title()); + self::assertSame($feedTitle, $feed->get_title()); $items = $feed->get_items(); - $this->assertSame(count($titles), count($items), 'Number of items does not match'); + // @phpstan-ignore phpunit.assertCount + self::assertSame(count($titles), count($items), 'Number of items does not match'); foreach (array_map(null, $titles, $items) as $i => [$expectedTitle, $item]) { assert($item !== null); // For PHPStan - $this->assertSame($expectedTitle, $item->get_title(), "Title of item #$i does not match"); + self::assertSame($expectedTitle, $item->get_title(), "Title of item #$i does not match"); } } @@ -544,13 +545,13 @@ public function testMicroformatLinkHub(string $data, ?string $hubUrl, ?string $s $feed->enable_cache(false); $error = implode("\n", (array) ($feed->error() ?? '')); // For PHPStan - $this->assertTrue($feed->init(), 'Failed fetching feed: ' . $error); + self::assertTrue($feed->init(), 'Failed fetching feed: ' . $error); $server->stop(); - $this->assertSame($hubUrl, $feed->get_link(0, 'hub'), 'Link rel=hub does not match'); - $this->assertSame($selfUrl, $feed->get_link(0, 'self'), 'Link rel=self does not match'); - $this->assertLessThanOrEqual(1, count($feed->get_links('self') ?? []), 'Link rel=self should not be promoted from HTML when it is already present in headers'); - $this->assertSame($bogoUrl, $feed->get_link(0, 'bogo'), 'Link rel=bogo does not match'); + self::assertSame($hubUrl, $feed->get_link(0, 'hub'), 'Link rel=hub does not match'); + self::assertSame($selfUrl, $feed->get_link(0, 'self'), 'Link rel=self does not match'); + self::assertLessThanOrEqual(1, count($feed->get_links('self') ?? []), 'Link rel=self should not be promoted from HTML when it is already present in headers'); + self::assertSame($bogoUrl, $feed->get_link(0, 'bogo'), 'Link rel=bogo does not match'); } } diff --git a/tests/ItemTest.php b/tests/ItemTest.php index a909c10e8..2d79b8f0c 100644 --- a/tests/ItemTest.php +++ b/tests/ItemTest.php @@ -69,7 +69,7 @@ public function testTitleRSS20(string $title, string $expected): void '; $feed = $this->checkFromTemplate($data, $title); - $this->assertSame($expected, $feed->get_title()); + self::assertSame($expected, $feed->get_title()); } /** @@ -84,7 +84,7 @@ public function testTitleRSS20WithDC10(string $title, string $expected): void '; $feed = $this->checkFromTemplate($data, $title); - $this->assertSame($expected, $feed->get_title()); + self::assertSame($expected, $feed->get_title()); } /** @@ -99,7 +99,7 @@ public function testTitleRSS20WithDC11(string $title, string $expected): void '; $feed = $this->checkFromTemplate($data, $title); - $this->assertSame($expected, $feed->get_title()); + self::assertSame($expected, $feed->get_title()); } /** @@ -114,7 +114,7 @@ public function testTitleRSS20WithAtom03(string $title, string $expected): void '; $feed = $this->checkFromTemplate($data, $title); - $this->assertSame($expected, $feed->get_title()); + self::assertSame($expected, $feed->get_title()); } /** @@ -129,7 +129,7 @@ public function testTitleRSS20WithAtom10(string $title, string $expected): void '; $feed = $this->checkFromTemplate($data, $title); - $this->assertSame($expected, $feed->get_title()); + self::assertSame($expected, $feed->get_title()); } /** @@ -149,7 +149,7 @@ public function testTitleRSS20WithImageTitle(string $title, string $expected): v '; $feed = $this->checkFromTemplate($data, $title); - $this->assertSame($expected, $feed->get_title()); + self::assertSame($expected, $feed->get_title()); } /** @@ -169,7 +169,7 @@ public function testTitleRSS20WithImageTitleReversed(string $title, string $expe '; $feed = $this->checkFromTemplate($data, $title); - $this->assertSame($expected, $feed->get_title()); + self::assertSame($expected, $feed->get_title()); } public function testItemWithEmptyContent(): void @@ -186,7 +186,7 @@ public function testItemWithEmptyContent(): void $content = 'item description'; $feed = $this->checkFromTemplate($data, $content); $item = $feed->get_item(); - $this->assertInstanceOf(Item::class, $item); - $this->assertSame($content, $item->get_content()); + self::assertInstanceOf(Item::class, $item); + self::assertSame($content, $item->get_content()); } } diff --git a/tests/LocatorTest.php b/tests/LocatorTest.php index 3438a09e7..b8c7b25fe 100755 --- a/tests/LocatorTest.php +++ b/tests/LocatorTest.php @@ -44,7 +44,7 @@ public function testAutodiscoverOnFeed(string $mime): void $locator->set_registry($registry); $feed = $locator->find(SIMPLEPIE_LOCATOR_ALL, $all); - $this->assertSame($data, $feed); + self::assertSame($data, $feed); } public function testInvalidMIMEType(): void @@ -59,7 +59,7 @@ public function testInvalidMIMEType(): void $locator->set_registry($registry); $feed = $locator->find(SIMPLEPIE_LOCATOR_ALL, $all); - $this->assertSame(null, $feed); + self::assertNull($feed); } public function testDirectNoDOM(): void @@ -71,8 +71,8 @@ public function testDirectNoDOM(): void $locator->dom = null; $locator->set_registry($registry); - $this->assertTrue($locator->is_feed($data)); - $this->assertSame($data, $locator->find(SIMPLEPIE_LOCATOR_ALL, $found)); + self::assertTrue($locator->is_feed($data)); + self::assertSame($data, $locator->find(SIMPLEPIE_LOCATOR_ALL, $found)); } public function testFailDiscoveryNoDOM(): void @@ -88,8 +88,8 @@ public function testFailDiscoveryNoDOM(): void $locator->dom = null; $locator->set_registry($registry); - $this->assertFalse($locator->is_feed($data)); - $this->assertFalse($locator->find(SIMPLEPIE_LOCATOR_ALL, $found)); + self::assertFalse($locator->is_feed($data)); + self::assertFalse($locator->find(SIMPLEPIE_LOCATOR_ALL, $found)); } /** @@ -136,12 +136,12 @@ public function test_from_file(File $data): void //$expected = SimplePie_Misc::get_element('link', $data->body); $feed = $locator->find(SIMPLEPIE_LOCATOR_ALL, $all); - $this->assertFalse($locator->is_feed($data), 'HTML document not be a feed itself'); - $this->assertInstanceOf(FileMock::class, $feed); + self::assertFalse($locator->is_feed($data), 'HTML document not be a feed itself'); + self::assertInstanceOf(FileMock::class, $feed); $success = array_filter($expected, [get_class($this), 'filter_success']); - $found = array_map([get_class($this), 'map_url_file'], $all); - $this->assertSame($success, $found); + $found = is_array($all) ? array_map([get_class($this), 'map_url_file'], $all) : []; + self::assertSame($success, $found); } protected static function filter_success(string $url): bool diff --git a/tests/SanitizeTest.php b/tests/SanitizeTest.php index e44c6ff58..0f05c87f7 100755 --- a/tests/SanitizeTest.php +++ b/tests/SanitizeTest.php @@ -14,7 +14,7 @@ public function testSanitize(): void { $sanitize = new SimplePie_Sanitize(); - $this->assertSame( + self::assertSame( <<assertSame($expected, $sanitize->sanitize($given, SIMPLEPIE_CONSTRUCT_HTML, $base)); + self::assertSame($expected, $sanitize->sanitize($given, SIMPLEPIE_CONSTRUCT_HTML, $base)); } } diff --git a/tests/SubscribeUrlTest.php b/tests/SubscribeUrlTest.php index d8fb06333..ea339ac46 100644 --- a/tests/SubscribeUrlTest.php +++ b/tests/SubscribeUrlTest.php @@ -20,7 +20,7 @@ public function testDirectOverrideLegacy(): void $feed->init(); - $this->assertSame('https://example.com/feed/2019-10-07', $feed->subscribe_url()); - $this->assertSame('https://example.com/feed/', $feed->subscribe_url(true)); + self::assertSame('https://example.com/feed/2019-10-07', $feed->subscribe_url()); + self::assertSame('https://example.com/feed/', $feed->subscribe_url(true)); } } diff --git a/tests/Unit/AuthorTest.php b/tests/Unit/AuthorTest.php index 5355da08a..a8312116b 100644 --- a/tests/Unit/AuthorTest.php +++ b/tests/Unit/AuthorTest.php @@ -16,12 +16,12 @@ class AuthorTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Author')); + self::assertTrue(class_exists('SimplePie\Author')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Author')); + self::assertTrue(class_exists('SimplePie_Author')); } /** @@ -494,12 +494,12 @@ public function test_get_name_from_author(string $data, ?string $expected): void $feed->init(); $item = $feed->get_item(0); - $this->assertInstanceOf(Item::class, $item); + self::assertInstanceOf(Item::class, $item); $author = $item->get_author(); - $this->assertInstanceOf(Author::class, $author); + self::assertInstanceOf(Author::class, $author); - $this->assertSame($expected, $author->get_name()); + self::assertSame($expected, $author->get_name()); } /** @@ -722,11 +722,11 @@ public function test_get_name_from_contributor(string $data, string $expected): $feed->init(); $item = $feed->get_item(0); - $this->assertInstanceOf(Item::class, $item); + self::assertInstanceOf(Item::class, $item); $author = $item->get_contributor(); - $this->assertInstanceOf(Author::class, $author); + self::assertInstanceOf(Author::class, $author); - $this->assertSame($expected, $author->get_name()); + self::assertSame($expected, $author->get_name()); } } diff --git a/tests/Unit/Cache/BaseDataCacheTest.php b/tests/Unit/Cache/BaseDataCacheTest.php index e38c92f7d..fef3e6f90 100644 --- a/tests/Unit/Cache/BaseDataCacheTest.php +++ b/tests/Unit/Cache/BaseDataCacheTest.php @@ -25,7 +25,7 @@ public function testSetDataReturnsTrueIfDataCouldBeWritten(): void $cache = new BaseDataCache($baseCache); - $this->assertTrue($cache->set_data($key, $value, $ttl)); + self::assertTrue($cache->set_data($key, $value, $ttl)); } public function testSetDataReturnsFalseIfDataCouldNotBeWritten(): void @@ -39,7 +39,7 @@ public function testSetDataReturnsFalseIfDataCouldNotBeWritten(): void $cache = new BaseDataCache($baseCache); - $this->assertFalse($cache->set_data($key, $value, $ttl)); + self::assertFalse($cache->set_data($key, $value, $ttl)); } public function testGetDataReturnsCorrectData(): void @@ -53,7 +53,7 @@ public function testGetDataReturnsCorrectData(): void $cache = new BaseDataCache($baseCache); - $this->assertSame($value, $cache->get_data($key)); + self::assertSame($value, $cache->get_data($key)); } public function testGetDataWithCacheMissReturnsDefault(): void @@ -66,7 +66,7 @@ public function testGetDataWithCacheMissReturnsDefault(): void $cache = new BaseDataCache($baseCache); - $this->assertSame($default, $cache->get_data($key, $default)); + self::assertSame($default, $cache->get_data($key, $default)); } public function testGetDataWithCacheExpiredReturnsDefault(): void @@ -80,7 +80,7 @@ public function testGetDataWithCacheExpiredReturnsDefault(): void $cache = new BaseDataCache($baseCache); - $this->assertSame($default, $cache->get_data($key, $default)); + self::assertSame($default, $cache->get_data($key, $default)); } public function testGetDataWithCacheCorruptionReturnsDefault(): void @@ -93,7 +93,7 @@ public function testGetDataWithCacheCorruptionReturnsDefault(): void $cache = new BaseDataCache($baseCache); - $this->assertSame($default, $cache->get_data($key, $default)); + self::assertSame($default, $cache->get_data($key, $default)); } public function testDeleteDataReturnsTrueIfDataCouldBeDeleted(): void @@ -105,7 +105,7 @@ public function testDeleteDataReturnsTrueIfDataCouldBeDeleted(): void $cache = new BaseDataCache($baseCache); - $this->assertTrue($cache->delete_data($key)); + self::assertTrue($cache->delete_data($key)); } public function testDeleteDataReturnsFalseIfDataCouldNotBeDeleted(): void @@ -117,6 +117,6 @@ public function testDeleteDataReturnsFalseIfDataCouldNotBeDeleted(): void $cache = new BaseDataCache($baseCache); - $this->assertFalse($cache->delete_data($key)); + self::assertFalse($cache->delete_data($key)); } } diff --git a/tests/Unit/Cache/BaseTest.php b/tests/Unit/Cache/BaseTest.php index c69ac03dc..00587341a 100644 --- a/tests/Unit/Cache/BaseTest.php +++ b/tests/Unit/Cache/BaseTest.php @@ -13,11 +13,11 @@ class BaseTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(interface_exists('SimplePie\Cache\Base')); + self::assertTrue(interface_exists('SimplePie\Cache\Base')); } public function testClassExists(): void { - $this->assertTrue(interface_exists('SimplePie_Cache_Base')); + self::assertTrue(interface_exists('SimplePie_Cache_Base')); } } diff --git a/tests/Unit/Cache/DBTest.php b/tests/Unit/Cache/DBTest.php index 0f9154c99..0a02b7911 100644 --- a/tests/Unit/Cache/DBTest.php +++ b/tests/Unit/Cache/DBTest.php @@ -13,11 +13,11 @@ class DBTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Cache\DB')); + self::assertTrue(class_exists('SimplePie\Cache\DB')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Cache_DB')); + self::assertTrue(class_exists('SimplePie_Cache_DB')); } } diff --git a/tests/Unit/Cache/FileTest.php b/tests/Unit/Cache/FileTest.php index ba76d0210..cc3cbbcf6 100644 --- a/tests/Unit/Cache/FileTest.php +++ b/tests/Unit/Cache/FileTest.php @@ -13,11 +13,11 @@ class FileTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Cache\File')); + self::assertTrue(class_exists('SimplePie\Cache\File')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Cache_File')); + self::assertTrue(class_exists('SimplePie_Cache_File')); } } diff --git a/tests/Unit/Cache/MemcacheTest.php b/tests/Unit/Cache/MemcacheTest.php index 9eebc8d72..4cc1a8546 100644 --- a/tests/Unit/Cache/MemcacheTest.php +++ b/tests/Unit/Cache/MemcacheTest.php @@ -13,11 +13,11 @@ class MemcacheTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Cache\Memcache')); + self::assertTrue(class_exists('SimplePie\Cache\Memcache')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Cache_Memcache')); + self::assertTrue(class_exists('SimplePie_Cache_Memcache')); } } diff --git a/tests/Unit/Cache/MemcachedTest.php b/tests/Unit/Cache/MemcachedTest.php index ca50e4781..c8e11d1f2 100644 --- a/tests/Unit/Cache/MemcachedTest.php +++ b/tests/Unit/Cache/MemcachedTest.php @@ -13,11 +13,11 @@ class MemcachedTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Cache\Memcached')); + self::assertTrue(class_exists('SimplePie\Cache\Memcached')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Cache_Memcached')); + self::assertTrue(class_exists('SimplePie_Cache_Memcached')); } } diff --git a/tests/Unit/Cache/MySQLTest.php b/tests/Unit/Cache/MySQLTest.php index 3adb484b6..19f531964 100644 --- a/tests/Unit/Cache/MySQLTest.php +++ b/tests/Unit/Cache/MySQLTest.php @@ -13,11 +13,11 @@ class MySQLTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Cache\MySQL')); + self::assertTrue(class_exists('SimplePie\Cache\MySQL')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Cache_MySQL')); + self::assertTrue(class_exists('SimplePie_Cache_MySQL')); } } diff --git a/tests/Unit/Cache/Psr16Test.php b/tests/Unit/Cache/Psr16Test.php index 5ca3ba3db..3d8fb3b5c 100644 --- a/tests/Unit/Cache/Psr16Test.php +++ b/tests/Unit/Cache/Psr16Test.php @@ -28,7 +28,7 @@ public function testSetDataReturnsTrueIfDataCouldBeWritten(): void $cache = new Psr16($psr16); - $this->assertTrue($cache->set_data($key, $value, $ttl)); + self::assertTrue($cache->set_data($key, $value, $ttl)); } public function testSetDataReturnsFalseIfDataCouldNotBeWritten(): void @@ -42,7 +42,7 @@ public function testSetDataReturnsFalseIfDataCouldNotBeWritten(): void $cache = new Psr16($psr16); - $this->assertFalse($cache->set_data($key, $value, $ttl)); + self::assertFalse($cache->set_data($key, $value, $ttl)); } public function testSetDataWithInvalidKeyThrowsInvalidArgumentException(): void @@ -78,7 +78,7 @@ public function testGetDataReturnsCorrectData(): void $cache = new Psr16($psr16); - $this->assertSame($value, $cache->get_data($key)); + self::assertSame($value, $cache->get_data($key)); } public function testGetDataWithCacheMissReturnsDefault(): void @@ -91,7 +91,7 @@ public function testGetDataWithCacheMissReturnsDefault(): void $cache = new Psr16($psr16); - $this->assertSame($default, $cache->get_data($key, $default)); + self::assertSame($default, $cache->get_data($key, $default)); } public function testGetDataWithCacheCorruptionReturnsDefault(): void @@ -104,7 +104,7 @@ public function testGetDataWithCacheCorruptionReturnsDefault(): void $cache = new Psr16($psr16); - $this->assertSame($default, $cache->get_data($key, $default)); + self::assertSame($default, $cache->get_data($key, $default)); } public function testGetDataWithInvalidKeyThrowsInvalidArgumentException(): void @@ -137,7 +137,7 @@ public function testDeleteDataReturnsTrueIfDataCouldBeDeleted(): void $cache = new Psr16($psr16); - $this->assertTrue($cache->delete_data($key)); + self::assertTrue($cache->delete_data($key)); } public function testDeleteDataReturnsFalseIfDataCouldNotBeDeleted(): void @@ -149,7 +149,7 @@ public function testDeleteDataReturnsFalseIfDataCouldNotBeDeleted(): void $cache = new Psr16($psr16); - $this->assertFalse($cache->delete_data($key)); + self::assertFalse($cache->delete_data($key)); } public function testDeleteDataWithInvalidKeyThrowsInvalidArgumentException(): void diff --git a/tests/Unit/Cache/RedisTest.php b/tests/Unit/Cache/RedisTest.php index 3e61d6357..72c8003e7 100644 --- a/tests/Unit/Cache/RedisTest.php +++ b/tests/Unit/Cache/RedisTest.php @@ -13,11 +13,11 @@ class RedisTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Cache\Redis')); + self::assertTrue(class_exists('SimplePie\Cache\Redis')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Cache_Redis')); + self::assertTrue(class_exists('SimplePie_Cache_Redis')); } } diff --git a/tests/Unit/CacheTest.php b/tests/Unit/CacheTest.php index 0949afab4..8298e5d91 100644 --- a/tests/Unit/CacheTest.php +++ b/tests/Unit/CacheTest.php @@ -13,11 +13,11 @@ class CacheTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Cache')); + self::assertTrue(class_exists('SimplePie\Cache')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Cache')); + self::assertTrue(class_exists('SimplePie_Cache')); } } diff --git a/tests/Unit/CaptionTest.php b/tests/Unit/CaptionTest.php index e4d301bca..4ae932484 100644 --- a/tests/Unit/CaptionTest.php +++ b/tests/Unit/CaptionTest.php @@ -13,11 +13,11 @@ class CaptionTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Caption')); + self::assertTrue(class_exists('SimplePie\Caption')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Caption')); + self::assertTrue(class_exists('SimplePie_Caption')); } } diff --git a/tests/Unit/CategoryTest.php b/tests/Unit/CategoryTest.php index edcee93f6..a89f61f62 100644 --- a/tests/Unit/CategoryTest.php +++ b/tests/Unit/CategoryTest.php @@ -16,12 +16,12 @@ class CategoryTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Category')); + self::assertTrue(class_exists('SimplePie\Category')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Category')); + self::assertTrue(class_exists('SimplePie_Category')); } /** @@ -387,9 +387,9 @@ public function test_get_label_from_feed_category(string $data, string $expected $feed->init(); $category = $feed->get_category(); - $this->assertInstanceOf(Category::class, $category); + self::assertInstanceOf(Category::class, $category); - $this->assertSame($expected, $category->get_label()); + self::assertSame($expected, $category->get_label()); } /** @@ -815,11 +815,11 @@ public function test_get_label_from_item_category(string $data, string $expected $feed->init(); $item = $feed->get_item(0); - $this->assertInstanceOf(Item::class, $item); + self::assertInstanceOf(Item::class, $item); $category = $item->get_category(); - $this->assertInstanceOf(Category::class, $category); + self::assertInstanceOf(Category::class, $category); - $this->assertSame($expected, $category->get_label()); + self::assertSame($expected, $category->get_label()); } } diff --git a/tests/Unit/Content/Type/SnifferTest.php b/tests/Unit/Content/Type/SnifferTest.php index 3d5c65706..1d666ccbf 100644 --- a/tests/Unit/Content/Type/SnifferTest.php +++ b/tests/Unit/Content/Type/SnifferTest.php @@ -13,11 +13,11 @@ class SnifferTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Content\Type\Sniffer')); + self::assertTrue(class_exists('SimplePie\Content\Type\Sniffer')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Content_Type_Sniffer')); + self::assertTrue(class_exists('SimplePie_Content_Type_Sniffer')); } } diff --git a/tests/Unit/CopyrightTest.php b/tests/Unit/CopyrightTest.php index 5c1805ab9..3dca887d1 100644 --- a/tests/Unit/CopyrightTest.php +++ b/tests/Unit/CopyrightTest.php @@ -13,11 +13,11 @@ class CopyrightTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Copyright')); + self::assertTrue(class_exists('SimplePie\Copyright')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Copyright')); + self::assertTrue(class_exists('SimplePie_Copyright')); } } diff --git a/tests/Unit/CreditTest.php b/tests/Unit/CreditTest.php index 73d1b677d..ec20078ec 100644 --- a/tests/Unit/CreditTest.php +++ b/tests/Unit/CreditTest.php @@ -13,11 +13,11 @@ class CreditTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Credit')); + self::assertTrue(class_exists('SimplePie\Credit')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Credit')); + self::assertTrue(class_exists('SimplePie_Credit')); } } diff --git a/tests/Unit/EnclosureTest.php b/tests/Unit/EnclosureTest.php index 4a8eb6106..29cec789a 100644 --- a/tests/Unit/EnclosureTest.php +++ b/tests/Unit/EnclosureTest.php @@ -16,12 +16,12 @@ class EnclosureTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Enclosure')); + self::assertTrue(class_exists('SimplePie\Enclosure')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Enclosure')); + self::assertTrue(class_exists('SimplePie_Enclosure')); } /** @@ -35,11 +35,11 @@ public function test_get_link(string $data, string $expected): void $feed->init(); $item = $feed->get_item(0); - $this->assertInstanceOf(Item::class, $item); + self::assertInstanceOf(Item::class, $item); $enclosure = $item->get_enclosure(0); - $this->assertInstanceOf(Enclosure::class, $enclosure); - $this->assertSame($expected, $enclosure->get_link()); + self::assertInstanceOf(Enclosure::class, $enclosure); + self::assertSame($expected, $enclosure->get_link()); } /** @@ -135,8 +135,8 @@ public function test_get_enclosures(string $data, int $expectedEnclosureCount): $feed->init(); $item = $feed->get_item(0); - $this->assertInstanceOf(Item::class, $item); - $this->assertCount($expectedEnclosureCount, (array) $item->get_enclosures()); + self::assertInstanceOf(Item::class, $item); + self::assertCount($expectedEnclosureCount, (array) $item->get_enclosures()); } /** diff --git a/tests/Unit/ExceptionTest.php b/tests/Unit/ExceptionTest.php index 6f1c2ef36..22cd51bcd 100644 --- a/tests/Unit/ExceptionTest.php +++ b/tests/Unit/ExceptionTest.php @@ -13,11 +13,11 @@ class ExceptionTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Exception')); + self::assertTrue(class_exists('SimplePie\Exception')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Exception')); + self::assertTrue(class_exists('SimplePie_Exception')); } } diff --git a/tests/Unit/FileTest.php b/tests/Unit/FileTest.php index 85f3cc561..ea0972aea 100644 --- a/tests/Unit/FileTest.php +++ b/tests/Unit/FileTest.php @@ -16,17 +16,18 @@ class FileTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\File')); + self::assertTrue(class_exists('SimplePie\File')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_File')); + self::assertTrue(class_exists('SimplePie_File')); } public function testFileExtendsResponse(): void { - $this->assertInstanceOf(Response::class, new FileMock('')); + // @phpstan-ignore staticMethod.alreadyNarrowedType + self::assertInstanceOf(Response::class, new FileMock('')); } /** @@ -42,7 +43,7 @@ public static function getResponseData(): iterable */ public function testGetRequestedUriReturnsString(File $response): void { - $this->assertSame( + self::assertSame( 'http://example.com/feed', $response->get_final_requested_uri() ); @@ -53,7 +54,7 @@ public function testGetRequestedUriReturnsString(File $response): void */ public function testGetStatusCodeReturnsInt(File $response): void { - $this->assertSame( + self::assertSame( 200, $response->get_status_code() ); @@ -64,7 +65,7 @@ public function testGetStatusCodeReturnsInt(File $response): void */ public function testGetHeadersReturnsArray(File $response): void { - $this->assertSame( + self::assertSame( ['content-type' => ['application/atom+xml']], $response->get_headers() ); @@ -75,7 +76,7 @@ public function testGetHeadersReturnsArray(File $response): void */ public function testHasHeadersReturnsTrue(File $response): void { - $this->assertTrue($response->has_header('Content-Type')); + self::assertTrue($response->has_header('Content-Type')); } /** @@ -83,7 +84,7 @@ public function testHasHeadersReturnsTrue(File $response): void */ public function testHasHeadersReturnsFalse(File $response): void { - $this->assertFalse($response->has_header('X-Custom-Header')); + self::assertFalse($response->has_header('X-Custom-Header')); } /** @@ -91,7 +92,7 @@ public function testHasHeadersReturnsFalse(File $response): void */ public function testGetHeaderReturnsArray(File $response): void { - $this->assertSame( + self::assertSame( ['application/atom+xml'], $response->get_header('CONTENT-TYPE') ); @@ -102,7 +103,7 @@ public function testGetHeaderReturnsArray(File $response): void */ public function testGetHeaderReturnsEmptyArray(File $response): void { - $this->assertSame( + self::assertSame( [], $response->get_header('X-Custom-Header') ); @@ -113,7 +114,7 @@ public function testGetHeaderReturnsEmptyArray(File $response): void */ public function testGetHeaderLineReturnsString(File $response): void { - $this->assertSame( + self::assertSame( 'application/atom+xml', $response->get_header_line('content-Type') ); @@ -124,7 +125,7 @@ public function testGetHeaderLineReturnsString(File $response): void */ public function testGetHeaderLineReturnsEmptyString(File $response): void { - $this->assertSame( + self::assertSame( '', $response->get_header_line('X-Custom-Header') ); @@ -135,7 +136,7 @@ public function testGetHeaderLineReturnsEmptyString(File $response): void */ public function testGetBodyContentReturnsString(File $response): void { - $this->assertSame( + self::assertSame( '', $response->get_body_content() ); diff --git a/tests/Unit/GzdecodeTest.php b/tests/Unit/GzdecodeTest.php index cc3b10be3..cdaabdec4 100644 --- a/tests/Unit/GzdecodeTest.php +++ b/tests/Unit/GzdecodeTest.php @@ -13,11 +13,11 @@ class GzdecodeTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Gzdecode')); + self::assertTrue(class_exists('SimplePie\Gzdecode')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_gzdecode')); + self::assertTrue(class_exists('SimplePie_gzdecode')); } } diff --git a/tests/Unit/HTTP/ParserTest.php b/tests/Unit/HTTP/ParserTest.php index 45a149921..616b25d22 100644 --- a/tests/Unit/HTTP/ParserTest.php +++ b/tests/Unit/HTTP/ParserTest.php @@ -14,12 +14,12 @@ class ParserTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\HTTP\Parser')); + self::assertTrue(class_exists('SimplePie\HTTP\Parser')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_HTTP_Parser')); + self::assertTrue(class_exists('SimplePie_HTTP_Parser')); } /** @@ -51,12 +51,12 @@ public function testChunkedNormal(string $data, string $expected): void $data = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n" . $data; $data = Parser::prepareHeaders($data); $parser = new Parser($data); - $this->assertTrue($parser->parse()); - $this->assertSame(1.1, $parser->http_version); - $this->assertSame(200, $parser->status_code); - $this->assertSame('OK', $parser->reason); - $this->assertSame(['content-type' => 'text/plain'], $parser->headers); - $this->assertSame($expected, $parser->body); + self::assertTrue($parser->parse()); + self::assertSame(1.1, $parser->http_version); + self::assertSame(200, $parser->status_code); + self::assertSame('OK', $parser->reason); + self::assertSame(['content-type' => 'text/plain'], $parser->headers); + self::assertSame($expected, $parser->body); } /** @@ -67,12 +67,12 @@ public function testChunkedProxy(string $data, string $expected): void $data = "HTTP/1.0 200 Connection established\r\n\r\nHTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n" . $data; $data = Parser::prepareHeaders($data); $parser = new Parser($data); - $this->assertTrue($parser->parse()); - $this->assertSame(1.1, $parser->http_version); - $this->assertSame(200, $parser->status_code); - $this->assertSame('OK', $parser->reason); - $this->assertSame(['content-type' => 'text/plain'], $parser->headers); - $this->assertSame($expected, $parser->body); + self::assertTrue($parser->parse()); + self::assertSame(1.1, $parser->http_version); + self::assertSame(200, $parser->status_code); + self::assertSame('OK', $parser->reason); + self::assertSame(['content-type' => 'text/plain'], $parser->headers); + self::assertSame($expected, $parser->body); } /** @@ -83,12 +83,12 @@ public function testChunkedProxy11(string $data, string $expected): void $data = "HTTP/1.1 200 Connection established\r\n\r\nHTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n" . $data; $data = Parser::prepareHeaders($data); $parser = new Parser($data); - $this->assertTrue($parser->parse()); - $this->assertSame(1.1, $parser->http_version); - $this->assertSame(200, $parser->status_code); - $this->assertSame('OK', $parser->reason); - $this->assertSame(['content-type' => 'text/plain'], $parser->headers); - $this->assertSame($expected, $parser->body); + self::assertTrue($parser->parse()); + self::assertSame(1.1, $parser->http_version); + self::assertSame(200, $parser->status_code); + self::assertSame('OK', $parser->reason); + self::assertSame(['content-type' => 'text/plain'], $parser->headers); + self::assertSame($expected, $parser->body); } public function testDuplicateHeaders(): void @@ -96,8 +96,8 @@ public function testDuplicateHeaders(): void $data = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Security-Policy: default-src 'self' http://example.com\r\nContent-Type: text/plain\r\nContent-Security-Policy: script-src http://example.com/\r\n\r\n"; $data = Parser::prepareHeaders($data); $parser = new Parser($data); - $this->assertTrue($parser->parse()); - $this->assertSame([ + self::assertTrue($parser->parse()); + self::assertSame([ // Later Content-Type takes precedence. 'content-type' => 'text/plain', // This is invalid but we are going to remove the parser eventually. @@ -113,12 +113,12 @@ public function testChunkedNormalPsr7(string $data, string $expected): void $data = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n" . $data; $data = Parser::prepareHeaders($data); $parser = new Parser($data, true); - $this->assertTrue($parser->parse()); - $this->assertSame(1.1, $parser->http_version); - $this->assertSame(200, $parser->status_code); - $this->assertSame('OK', $parser->reason); - $this->assertSame(['content-type' => ['text/plain']], $parser->headers); - $this->assertSame($expected, $parser->body); + self::assertTrue($parser->parse()); + self::assertSame(1.1, $parser->http_version); + self::assertSame(200, $parser->status_code); + self::assertSame('OK', $parser->reason); + self::assertSame(['content-type' => ['text/plain']], $parser->headers); + self::assertSame($expected, $parser->body); } /** @@ -129,12 +129,12 @@ public function testChunkedProxyPsr7(string $data, string $expected): void $data = "HTTP/1.0 200 Connection established\r\n\r\nHTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n" . $data; $data = Parser::prepareHeaders($data); $parser = new Parser($data, true); - $this->assertTrue($parser->parse()); - $this->assertSame(1.1, $parser->http_version); - $this->assertSame(200, $parser->status_code); - $this->assertSame('OK', $parser->reason); - $this->assertSame(['content-type' => ['text/plain']], $parser->headers); - $this->assertSame($expected, $parser->body); + self::assertTrue($parser->parse()); + self::assertSame(1.1, $parser->http_version); + self::assertSame(200, $parser->status_code); + self::assertSame('OK', $parser->reason); + self::assertSame(['content-type' => ['text/plain']], $parser->headers); + self::assertSame($expected, $parser->body); } /** @@ -145,12 +145,12 @@ public function testChunkedProxy11Psr7(string $data, string $expected): void $data = "HTTP/1.1 200 Connection established\r\n\r\nHTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n" . $data; $data = Parser::prepareHeaders($data); $parser = new Parser($data, true); - $this->assertTrue($parser->parse()); - $this->assertSame(1.1, $parser->http_version); - $this->assertSame(200, $parser->status_code); - $this->assertSame('OK', $parser->reason); - $this->assertSame(['content-type' => ['text/plain']], $parser->headers); - $this->assertSame($expected, $parser->body); + self::assertTrue($parser->parse()); + self::assertSame(1.1, $parser->http_version); + self::assertSame(200, $parser->status_code); + self::assertSame('OK', $parser->reason); + self::assertSame(['content-type' => ['text/plain']], $parser->headers); + self::assertSame($expected, $parser->body); } public function testDuplicateHeadersPsr7(): void @@ -158,8 +158,8 @@ public function testDuplicateHeadersPsr7(): void $data = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Security-Policy: default-src 'self' http://example.com\r\nContent-Type: text/plain\r\nContent-Security-Policy: script-src http://example.com/\r\n\r\n"; $data = Parser::prepareHeaders($data); $parser = new Parser($data, true); - $this->assertTrue($parser->parse()); - $this->assertSame([ + self::assertTrue($parser->parse()); + self::assertSame([ // Later Content-Type takes precedence. 'content-type' => ['text/plain'], 'content-security-policy' => ["default-src 'self' http://example.com", 'script-src http://example.com/'], diff --git a/tests/Unit/HTTP/Psr18ClientTest.php b/tests/Unit/HTTP/Psr18ClientTest.php index 258590e96..c43439e13 100644 --- a/tests/Unit/HTTP/Psr18ClientTest.php +++ b/tests/Unit/HTTP/Psr18ClientTest.php @@ -27,7 +27,8 @@ public function testRequestReturnsResponse(): void $this->createMock(UriFactoryInterface::class) ); - $this->assertInstanceOf(Response::class, $client->request(Client::METHOD_GET, 'https://example.com/feed.xml')); + // @phpstan-ignore staticMethod.alreadyNarrowedType + self::assertInstanceOf(Response::class, $client->request(Client::METHOD_GET, 'https://example.com/feed.xml')); } public function testRequestReturnsResponseWithStatusCode429(): void @@ -45,7 +46,7 @@ public function testRequestReturnsResponseWithStatusCode429(): void ); // Make sure no ClientException is thrown on status code 429 - $this->assertSame( + self::assertSame( 429, $client->request(Client::METHOD_GET, 'https://example.com/429-error')->get_status_code() ); @@ -78,7 +79,7 @@ public function testRequestWithRedirectReturnsResponseWithCorrectUrls(): void $response = $client->request(Client::METHOD_GET, 'https://example.com/redirect'); - $this->assertSame('https://example.com/redirect', $response->get_permanent_uri()); - $this->assertSame('https://example.com/feed.xml', $response->get_final_requested_uri()); + self::assertSame('https://example.com/redirect', $response->get_permanent_uri()); + self::assertSame('https://example.com/feed.xml', $response->get_final_requested_uri()); } } diff --git a/tests/Unit/HTTP/Psr7ResponseTest.php b/tests/Unit/HTTP/Psr7ResponseTest.php index fc241bc06..60e895aa7 100644 --- a/tests/Unit/HTTP/Psr7ResponseTest.php +++ b/tests/Unit/HTTP/Psr7ResponseTest.php @@ -17,7 +17,8 @@ class Psr7ResponseTest extends TestCase { public function testPsr7ResponseExtendsResponse(): void { - $this->assertInstanceOf(Response::class, new Psr7Response($this->createMock(ResponseInterface::class), '', '')); + // @phpstan-ignore staticMethod.alreadyNarrowedType + self::assertInstanceOf(Response::class, new Psr7Response($this->createMock(ResponseInterface::class), '', '')); } public function createPsr7Response(): Psr7Response @@ -53,7 +54,7 @@ public function testGetPermanentUriReturnsString(): void { $response = $this->createPsr7Response(); - $this->assertSame( + self::assertSame( 'https://example.com', $response->get_permanent_uri() ); @@ -63,7 +64,7 @@ public function testGetFinalRequestedUriReturnsString(): void { $response = $this->createPsr7Response(); - $this->assertSame( + self::assertSame( 'https://example.com/feed.xml', $response->get_final_requested_uri() ); @@ -73,7 +74,7 @@ public function testGetStatusCodeReturnsInt(): void { $response = $this->createPsr7Response(); - $this->assertSame( + self::assertSame( 200, $response->get_status_code() ); @@ -83,7 +84,7 @@ public function testGetHeadersReturnsArray(): void { $response = $this->createPsr7Response(); - $this->assertSame( + self::assertSame( ['content-type' => ['application/atom+xml']], $response->get_headers() ); @@ -93,21 +94,21 @@ public function testHasHeadersReturnsTrue(): void { $response = $this->createPsr7Response(); - $this->assertTrue($response->has_header('Content-Type')); + self::assertTrue($response->has_header('Content-Type')); } public function testHasHeadersReturnsFalse(): void { $response = $this->createPsr7Response(); - $this->assertFalse($response->has_header('X-Custom-Header')); + self::assertFalse($response->has_header('X-Custom-Header')); } public function testGetHeaderReturnsArray(): void { $response = $this->createPsr7Response(); - $this->assertSame( + self::assertSame( ['application/atom+xml'], $response->get_header('CONTENT-TYPE') ); @@ -117,7 +118,7 @@ public function testGetHeaderReturnsEmptyArray(): void { $response = $this->createPsr7Response(); - $this->assertSame( + self::assertSame( [], $response->get_header('X-Custom-Header') ); @@ -127,7 +128,7 @@ public function testGetHeaderLineReturnsString(): void { $response = $this->createPsr7Response(); - $this->assertSame( + self::assertSame( 'application/atom+xml', $response->get_header_line('content-Type') ); @@ -137,7 +138,7 @@ public function testGetHeaderLineReturnsEmptyString(): void { $response = $this->createPsr7Response(); - $this->assertSame( + self::assertSame( '', $response->get_header_line('X-Custom-Header') ); @@ -147,7 +148,7 @@ public function testGetBodyContentReturnsString(): void { $response = $this->createPsr7Response(); - $this->assertSame( + self::assertSame( '', $response->get_body_content() ); diff --git a/tests/Unit/IRITest.php b/tests/Unit/IRITest.php index 02741f3fd..7a9390f80 100644 --- a/tests/Unit/IRITest.php +++ b/tests/Unit/IRITest.php @@ -14,12 +14,12 @@ class IRITest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\IRI')); + self::assertTrue(class_exists('SimplePie\IRI')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_IRI')); + self::assertTrue(class_exists('SimplePie_IRI')); } /** @@ -82,8 +82,8 @@ public function testStringRFC3986(string $relative, string $expected): void { $base = new IRI('http://a/b/c/d;p?q'); $absolutized = IRI::absolutize($base, $relative); - $this->assertNotFalse($absolutized); - $this->assertSame($expected, $absolutized->get_iri()); + self::assertNotFalse($absolutized); + self::assertSame($expected, $absolutized->get_iri()); } /** @@ -93,7 +93,7 @@ public function testObjectRFC3986(string $relative, string $expected): void { $base = new IRI('http://a/b/c/d;p?q'); $expected = new IRI($expected); - $this->assertEquals($expected, IRI::absolutize($base, $relative)); + self::assertEquals($expected, IRI::absolutize($base, $relative)); } /** @@ -103,9 +103,9 @@ public function testBothStringRFC3986(string $relative, string $expected): void { $base = 'http://a/b/c/d;p?q'; $absolutized = IRI::absolutize($base, $relative); - $this->assertNotFalse($absolutized); - $this->assertSame($expected, $absolutized->get_iri()); - $this->assertSame($expected, (string) IRI::absolutize($base, $relative)); + self::assertNotFalse($absolutized); + self::assertSame($expected, $absolutized->get_iri()); + self::assertSame($expected, (string) IRI::absolutize($base, $relative)); } /** @@ -140,8 +140,8 @@ public function testStringSP(string $base, string $relative, string $expected): { $base = new IRI($base); $absolutized = IRI::absolutize($base, $relative); - $this->assertNotFalse($absolutized); - $this->assertSame($expected, $absolutized->get_iri()); + self::assertNotFalse($absolutized); + self::assertSame($expected, $absolutized->get_iri()); } /** @@ -151,7 +151,7 @@ public function testObjectSP(string $base, string $relative, string $expected): { $base = new IRI($base); $expected = new IRI($expected); - $this->assertEquals($expected, IRI::absolutize($base, $relative)); + self::assertEquals($expected, IRI::absolutize($base, $relative)); } /** @@ -174,7 +174,7 @@ public function testStringQuery(string $query, string $expected): void { $base = new IRI('http://example.com/'); $base->set_query($query); - $this->assertSame($expected, $base->get_iri()); + self::assertSame($expected, $base->get_iri()); } /** @@ -185,7 +185,7 @@ public function testObjectQuery(string $query, string $expected): void $base = new IRI('http://example.com/'); $base->set_query($query); $expected = new IRI($expected); - $this->assertEquals($expected, $base); + self::assertEquals($expected, $base); } /** @@ -206,8 +206,8 @@ public function testAbsolutizeString(string $base, string $relative, string $exp { $base = new IRI($base); $absolutized = IRI::absolutize($base, $relative); - $this->assertNotFalse($absolutized); - $this->assertSame($expected, $absolutized->get_iri()); + self::assertNotFalse($absolutized); + self::assertSame($expected, $absolutized->get_iri()); } /** @@ -217,7 +217,7 @@ public function testAbsolutizeObject(string $base, string $relative, string $exp { $base = new IRI($base); $expected = new IRI($expected); - $this->assertEquals($expected, IRI::absolutize($base, $relative)); + self::assertEquals($expected, IRI::absolutize($base, $relative)); } /** @@ -312,7 +312,7 @@ public static function normalizationDataProvider(): array public function testStringNormalization(string $input, string $output): void { $input = new IRI($input); - $this->assertSame($output, $input->get_iri()); + self::assertSame($output, $input->get_iri()); } /** @@ -322,7 +322,7 @@ public function testObjectNormalization(string $input, string $output): void { $input = new IRI($input); $output = new IRI($output); - $this->assertEquals($output, $input); + self::assertEquals($output, $input); } /** @@ -343,7 +343,7 @@ public static function uriDataProvider(): array public function testURIConversion(string $input, string $output): void { $input = new IRI($input); - $this->assertSame($output, $input->get_uri()); + self::assertSame($output, $input->get_uri()); } /** @@ -363,7 +363,7 @@ public function testObjectEquivalence(string $input, string $output): void { $input = new IRI($input); $output = new IRI($output); - $this->assertEquals($output, $input); + self::assertEquals($output, $input); } /** @@ -383,12 +383,12 @@ public function testObjectNotEquivalence(string $input, string $output): void { $input = new IRI($input); $output = new IRI($output); - $this->assertNotEquals($output, $input); + self::assertNotEquals($output, $input); } public function testInvalidAbsolutizeBase(): void { - $this->assertFalse(IRI::absolutize('://not a URL', '../')); + self::assertFalse(IRI::absolutize('://not a URL', '../')); } public function testInvalidPathNoHost(): void @@ -396,21 +396,21 @@ public function testInvalidPathNoHost(): void $iri = new IRI(); $iri->scheme = 'http'; $iri->path = '//test'; - $this->assertFalse($iri->is_valid()); + self::assertFalse($iri->is_valid()); } public function testInvalidRelativePathContainsColon(): void { $iri = new IRI(); $iri->path = '/test:/'; - $this->assertFalse($iri->is_valid()); + self::assertFalse($iri->is_valid()); } public function testValidRelativePathContainsColon(): void { $iri = new IRI(); $iri->path = '/test/:'; - $this->assertTrue($iri->is_valid()); + self::assertTrue($iri->is_valid()); } public function testFullGamut(): void @@ -422,12 +422,12 @@ public function testFullGamut(): void $iri->path = '/test/'; $iri->fragment = 'test'; - $this->assertSame('http', $iri->scheme); - $this->assertSame('user:password', $iri->userinfo); - $this->assertSame('example.com', $iri->host); - $this->assertSame(80, $iri->port); - $this->assertSame('/test/', $iri->path); - $this->assertSame('test', $iri->fragment); + self::assertSame('http', $iri->scheme); + self::assertSame('user:password', $iri->userinfo); + self::assertSame('example.com', $iri->host); + self::assertSame(80, $iri->port); + self::assertSame('/test/', $iri->path); + self::assertSame('test', $iri->fragment); } public function testReadAliased(): void @@ -439,12 +439,12 @@ public function testReadAliased(): void $iri->path = '/test/'; $iri->fragment = 'test'; - $this->assertSame('http', $iri->scheme); - $this->assertSame('user:password', $iri->userinfo); - $this->assertSame('example.com', $iri->host); - $this->assertSame(80, $iri->port); - $this->assertSame('/test/', $iri->path); - $this->assertSame('test', $iri->fragment); + self::assertSame('http', $iri->scheme); + self::assertSame('user:password', $iri->userinfo); + self::assertSame('example.com', $iri->host); + self::assertSame(80, $iri->port); + self::assertSame('/test/', $iri->path); + self::assertSame('test', $iri->fragment); } public function testWriteAliased(): void @@ -456,23 +456,23 @@ public function testWriteAliased(): void $iri->path = '/test/'; $iri->fragment = 'test'; - $this->assertSame('http', $iri->scheme); - $this->assertSame('user:password', $iri->userinfo); - $this->assertSame('example.com', $iri->host); - $this->assertSame(80, $iri->port); - $this->assertSame('/test/', $iri->path); - $this->assertSame('test', $iri->fragment); + self::assertSame('http', $iri->scheme); + self::assertSame('user:password', $iri->userinfo); + self::assertSame('example.com', $iri->host); + self::assertSame(80, $iri->port); + self::assertSame('/test/', $iri->path); + self::assertSame('test', $iri->fragment); } public function testNonexistentProperty(): void { $iri = new IRI(); - $this->assertFalse(isset($iri->nonexistent_prop)); + self::assertFalse(isset($iri->nonexistent_prop)); // PHPUnit 10 compatible way to test trigger_error(). set_error_handler( function ($errno, $errstr): bool { - $this->assertSame( + self::assertSame( 'Undefined property: SimplePie\IRI::nonexistent_prop', $errstr ); @@ -483,6 +483,7 @@ function ($errno, $errstr): bool { E_USER_NOTICE ); + // @phpstan-ignore property.notFound (we want to test that it fails) $should_fail = $iri->nonexistent_prop; } @@ -491,8 +492,8 @@ public function testBlankHost(): void $iri = new IRI('http://example.com/a/?b=c#d'); $iri->host = null; - $this->assertSame(null, $iri->host); - $this->assertSame('http:/a/?b=c#d', (string) $iri); + self::assertNull($iri->host); + self::assertSame('http:/a/?b=c#d', (string) $iri); } public function testBadPort(): void @@ -500,6 +501,6 @@ public function testBadPort(): void $iri = new IRI(); $iri->port = 'example'; - $this->assertSame(null, $iri->port); + self::assertNull($iri->port); } } diff --git a/tests/Unit/ItemTest.php b/tests/Unit/ItemTest.php index 20c87d181..589c65698 100644 --- a/tests/Unit/ItemTest.php +++ b/tests/Unit/ItemTest.php @@ -15,12 +15,12 @@ class ItemTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Item')); + self::assertTrue(class_exists('SimplePie\Item')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Item')); + self::assertTrue(class_exists('SimplePie_Item')); } /** @@ -657,9 +657,9 @@ public function test_get_content(string $data, string $expected): void $feed->init(); $item = $feed->get_item(0); - $this->assertInstanceOf(Item::class, $item); + self::assertInstanceOf(Item::class, $item); - $this->assertSame($expected, $item->get_content()); + self::assertSame($expected, $item->get_content()); } /** @@ -1332,9 +1332,9 @@ public function test_get_date(string $data, ?int $expected): void $feed->init(); $item = $feed->get_item(0); - $this->assertInstanceOf(Item::class, $item); + self::assertInstanceOf(Item::class, $item); - $this->assertSame($expected, $item->get_date('U')); + self::assertSame($expected, $item->get_date('U')); } /** @@ -1970,9 +1970,9 @@ public function test_get_description(string $data, string $expected): void $feed->init(); $item = $feed->get_item(0); - $this->assertInstanceOf(Item::class, $item); + self::assertInstanceOf(Item::class, $item); - $this->assertSame($expected, $item->get_description()); + self::assertSame($expected, $item->get_description()); } /** @@ -2374,9 +2374,9 @@ public function test_get_id(string $data, string $expected): void $feed->init(); $item = $feed->get_item(0); - $this->assertInstanceOf(Item::class, $item); + self::assertInstanceOf(Item::class, $item); - $this->assertSame($expected, $item->get_id()); + self::assertSame($expected, $item->get_id()); } /** @@ -2601,9 +2601,9 @@ public function test_get_latitude(string $data, float $expected): void $feed->init(); $item = $feed->get_item(0); - $this->assertInstanceOf(Item::class, $item); + self::assertInstanceOf(Item::class, $item); - $this->assertSame($expected, $item->get_latitude()); + self::assertSame($expected, $item->get_latitude()); } /** @@ -2828,9 +2828,9 @@ public function test_get_longitude(string $data, float $expected): void $feed->init(); $item = $feed->get_item(0); - $this->assertInstanceOf(Item::class, $item); + self::assertInstanceOf(Item::class, $item); - $this->assertSame($expected, $item->get_longitude()); + self::assertSame($expected, $item->get_longitude()); } /** @@ -3353,9 +3353,9 @@ public function test_get_base(string $data, string $expected): void $feed->init(); $item = $feed->get_item(0); - $this->assertInstanceOf(Item::class, $item); + self::assertInstanceOf(Item::class, $item); - $this->assertSame($expected, $item->get_content()); + self::assertSame($expected, $item->get_content()); } /** @@ -3431,9 +3431,9 @@ public function test_get_permalink(string $data, ?string $expected): void $feed->init(); $item = $feed->get_item(0); - $this->assertInstanceOf(Item::class, $item); + self::assertInstanceOf(Item::class, $item); - $this->assertSame($expected, $item->get_permalink()); + self::assertSame($expected, $item->get_permalink()); } /** @@ -4944,9 +4944,9 @@ public function test_get_title(string $data, string $expected): void $feed->init(); $item = $feed->get_item(0); - $this->assertInstanceOf(Item::class, $item); + self::assertInstanceOf(Item::class, $item); - $this->assertSame($expected, $item->get_title()); + self::assertSame($expected, $item->get_title()); } /** @@ -4960,10 +4960,10 @@ public function test_get_thumbnail(string $data, string $expected): void $feed->init(); $item = $feed->get_item(0); - $this->assertInstanceOf(Item::class, $item); + self::assertInstanceOf(Item::class, $item); $thumbnail = $item->get_thumbnail(); - $this->assertNotNull($thumbnail); - $this->assertSame($expected, $thumbnail['url']); + self::assertNotNull($thumbnail); + self::assertSame($expected, $thumbnail['url']); } /** diff --git a/tests/Unit/LocatorTest.php b/tests/Unit/LocatorTest.php index f663d5899..59c1dda51 100644 --- a/tests/Unit/LocatorTest.php +++ b/tests/Unit/LocatorTest.php @@ -20,12 +20,12 @@ class LocatorTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Locator')); + self::assertTrue(class_exists('SimplePie\Locator')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Locator')); + self::assertTrue(class_exists('SimplePie_Locator')); } /** @@ -57,7 +57,7 @@ public function testAutodiscoverOnFeed(string $mime): void $locator->set_registry($registry); $feed = $locator->find(SimplePie::LOCATOR_ALL, $all); - $this->assertSame($data, $feed); + self::assertSame($data, $feed); } public function testInvalidMIMEType(): void @@ -72,7 +72,7 @@ public function testInvalidMIMEType(): void $locator->set_registry($registry); $feed = $locator->find(SimplePie::LOCATOR_ALL, $all); - $this->assertSame(null, $feed); + self::assertNull($feed); } public function testDirectNoDOM(): void @@ -84,8 +84,8 @@ public function testDirectNoDOM(): void $locator->dom = null; $locator->set_registry($registry); - $this->assertTrue($locator->is_feed($data)); - $this->assertSame($data, $locator->find(SimplePie::LOCATOR_ALL, $found)); + self::assertTrue($locator->is_feed($data)); + self::assertSame($data, $locator->find(SimplePie::LOCATOR_ALL, $found)); } public function testFailDiscoveryNoDOM(): void @@ -101,8 +101,8 @@ public function testFailDiscoveryNoDOM(): void $locator->dom = null; $locator->set_registry($registry); - $this->assertFalse($locator->is_feed($data)); - $this->assertFalse($locator->find(SimplePie::LOCATOR_ALL, $found)); + self::assertFalse($locator->is_feed($data)); + self::assertFalse($locator->find(SimplePie::LOCATOR_ALL, $found)); } /** @@ -149,12 +149,12 @@ public function test_from_file(File $data): void //$expected = SimplePie_Misc::get_element('link', $data->body); $feed = $locator->find(SimplePie::LOCATOR_ALL, $all); - $this->assertFalse($locator->is_feed($data), 'HTML document not be a feed itself'); - $this->assertInstanceOf(FileMock::class, $feed); + self::assertFalse($locator->is_feed($data), 'HTML document not be a feed itself'); + self::assertInstanceOf(FileMock::class, $feed); $success = array_filter($expected, [get_class($this), 'filter_success']); - $found = array_map([get_class($this), 'map_url_file'], $all); - $this->assertSame($success, $found); + $found = is_array($all) ? array_map([get_class($this), 'map_url_file'], $all) : []; + self::assertSame($success, $found); } protected function filter_success(string $url): bool diff --git a/tests/Unit/MiscTest.php b/tests/Unit/MiscTest.php index 32e8e3f98..769efad3e 100644 --- a/tests/Unit/MiscTest.php +++ b/tests/Unit/MiscTest.php @@ -16,24 +16,24 @@ class MiscTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists(Misc::class)); + self::assertTrue(class_exists(Misc::class)); } public function testClassExists(): void { - $this->assertTrue(class_exists(SimplePie_Misc::class)); + self::assertTrue(class_exists(SimplePie_Misc::class)); } public function test_existence_of_get_element(): void { // BC: make sure that get_element() exists - $this->assertSame([], Misc::get_element('', '')); + self::assertSame([], Misc::get_element('', '')); } public function test_existence_of_entities_decode(): void { // BC: make sure that entities_decode() exists - $this->assertSame('', Misc::entities_decode('')); + self::assertSame('', Misc::entities_decode('')); } /* ## UTF-8 methods */ @@ -67,7 +67,7 @@ public static function utf8DataProvider(): array public function test_convert_UTF8(string $input, string $expected, string $encoding): void { $encoding = Misc::encoding($encoding); - $this->assertSameBin2Hex($expected, (string) Misc::change_encoding($input, $encoding, 'UTF-8')); + self::assertSameBin2Hex($expected, (string) Misc::change_encoding($input, $encoding, 'UTF-8')); } /** @@ -95,7 +95,7 @@ public function test_convert_UTF8_mbstring(string $input, string $expected, stri } $encoding = Misc::encoding($encoding); - $this->assertSameBin2Hex($expected, (string) MiscWithPublicStaticMethodsMock::change_encoding_mbstring($input, $encoding, 'UTF-8')); + self::assertSameBin2Hex($expected, (string) MiscWithPublicStaticMethodsMock::change_encoding_mbstring($input, $encoding, 'UTF-8')); } /** @@ -123,7 +123,7 @@ public function test_convert_UTF8_iconv(string $input, string $expected, string } $encoding = Misc::encoding($encoding); - $this->assertSameBin2Hex($expected, (string) MiscWithPublicStaticMethodsMock::change_encoding_iconv($input, $encoding, 'UTF-8')); + self::assertSameBin2Hex($expected, (string) MiscWithPublicStaticMethodsMock::change_encoding_iconv($input, $encoding, 'UTF-8')); } /** @@ -151,7 +151,7 @@ public function test_convert_UTF8_uconverter(string $input, string $expected, st } $encoding = Misc::encoding($encoding); - $this->assertSameBin2Hex($expected, (string) MiscWithPublicStaticMethodsMock::change_encoding_uconverter($input, $encoding, 'UTF-8')); + self::assertSameBin2Hex($expected, (string) MiscWithPublicStaticMethodsMock::change_encoding_uconverter($input, $encoding, 'UTF-8')); } /* ## UTF-16 methods */ @@ -174,12 +174,12 @@ public static function utf16DataProvider(): array public function test_convert_UTF16(string $input, string $expected, string $encoding): void { $encoding = Misc::encoding($encoding); - $this->assertSameBin2Hex($expected, (string) Misc::change_encoding($input, $encoding, 'UTF-16')); + self::assertSameBin2Hex($expected, (string) Misc::change_encoding($input, $encoding, 'UTF-16')); } public function test_nonexistent(): void { - $this->assertFalse(Misc::change_encoding('', 'TESTENC', 'UTF-8')); + self::assertFalse(Misc::change_encoding('', 'TESTENC', 'UTF-8')); } public function assertSameBin2Hex(string $expected, string $actual, string $message = ''): void @@ -187,7 +187,7 @@ public function assertSameBin2Hex(string $expected, string $actual, string $mess $expected = bin2hex($expected); $actual = bin2hex($actual); - $this->assertSame($expected, $actual, $message); + self::assertSame($expected, $actual, $message); } /** @@ -378,7 +378,7 @@ public function test_absolutize_url_RFC3986(string $relative, string $expected): { $base = 'http://a/b/c/d;p?q'; - $this->assertSame( + self::assertSame( $expected, Misc::absolutize_url($relative, $base) ); @@ -483,7 +483,7 @@ public static function absolutizeUrlBugsDataProvider(): array */ public function test_absolutize_url_bugs(string $base, string $relative, string $expected): void { - $this->assertSame( + self::assertSame( $expected, Misc::absolutize_url($relative, $base) ); @@ -734,7 +734,7 @@ public static function parseDateDataProvider(): array */ public function test_parse_date(string $data, $expected): void { - $this->assertSame( + self::assertSame( $expected, Misc::parse_date($data) ); diff --git a/tests/Unit/Net/IPv6Test.php b/tests/Unit/Net/IPv6Test.php index fbaf65713..6623e4dbd 100644 --- a/tests/Unit/Net/IPv6Test.php +++ b/tests/Unit/Net/IPv6Test.php @@ -13,11 +13,11 @@ class IPv6Test extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Net\IPv6')); + self::assertTrue(class_exists('SimplePie\Net\IPv6')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Net_IPv6')); + self::assertTrue(class_exists('SimplePie_Net_IPv6')); } } diff --git a/tests/Unit/Parse/DateTest.php b/tests/Unit/Parse/DateTest.php index 9cbbb42bd..6a4ab581f 100644 --- a/tests/Unit/Parse/DateTest.php +++ b/tests/Unit/Parse/DateTest.php @@ -14,12 +14,12 @@ class DateTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Parse\Date')); + self::assertTrue(class_exists('SimplePie\Parse\Date')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Parse_Date')); + self::assertTrue(class_exists('SimplePie_Parse_Date')); } /** @@ -75,7 +75,7 @@ public static function w3cDtfDatesProvider(): iterable public function testW3cDtf(string $data, int $expected): void { $date = new Date(); - $this->assertSame( + self::assertSame( $expected, $date->date_w3cdtf($data) ); diff --git a/tests/Unit/ParserTest.php b/tests/Unit/ParserTest.php index 7e38696bc..cee5b4aa4 100644 --- a/tests/Unit/ParserTest.php +++ b/tests/Unit/ParserTest.php @@ -15,12 +15,12 @@ class ParserTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Parser')); + self::assertTrue(class_exists('SimplePie\Parser')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Parser')); + self::assertTrue(class_exists('SimplePie_Parser')); } /** @@ -305,9 +305,9 @@ public function test_parse(string $feed, string $base, array $parsedData): void $result = $parser->parse($feed, 'UTF-8', $base); - $this->assertTrue($result); - $this->assertSame($parser->get_error_code(), null); - $this->assertSame($parser->get_error_string(), null); - $this->assertSame($parser->get_data(), $parsedData); + self::assertTrue($result); + self::assertSame($parser->get_error_code(), null); + self::assertSame($parser->get_error_string(), null); + self::assertSame($parser->get_data(), $parsedData); } } diff --git a/tests/Unit/RatingTest.php b/tests/Unit/RatingTest.php index e2ac5c125..f449ee333 100644 --- a/tests/Unit/RatingTest.php +++ b/tests/Unit/RatingTest.php @@ -13,11 +13,11 @@ class RatingTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Rating')); + self::assertTrue(class_exists('SimplePie\Rating')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Rating')); + self::assertTrue(class_exists('SimplePie_Rating')); } } diff --git a/tests/Unit/RegistryTest.php b/tests/Unit/RegistryTest.php index fa3be6e7c..8af1f257a 100644 --- a/tests/Unit/RegistryTest.php +++ b/tests/Unit/RegistryTest.php @@ -18,12 +18,12 @@ class RegistryTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists(Registry::class)); + self::assertTrue(class_exists(Registry::class)); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Registry')); + self::assertTrue(class_exists('SimplePie_Registry')); } /** @@ -37,7 +37,7 @@ public function testGetClassReturnsCorrectClassname(string $type, string $expect { $registry = new Registry(); - $this->assertSame($expected, $registry->get_class($type)); + self::assertSame($expected, $registry->get_class($type)); } /** @@ -104,7 +104,7 @@ public function testRegisterAllowsOverridingTheDefaultClassname(string $register $registry->register($registeredType, $classname); - $this->assertSame($classname, $registry->get_class($requestedType)); + self::assertSame($classname, $registry->get_class($requestedType)); } /** diff --git a/tests/Unit/RestrictionTest.php b/tests/Unit/RestrictionTest.php index f41de484d..9dfb549c7 100644 --- a/tests/Unit/RestrictionTest.php +++ b/tests/Unit/RestrictionTest.php @@ -17,12 +17,12 @@ class RestrictionTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Restriction')); + self::assertTrue(class_exists('SimplePie\Restriction')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Restriction')); + self::assertTrue(class_exists('SimplePie_Restriction')); } /** @@ -86,14 +86,14 @@ public function test_get_relationship(string $data, string $expected): void $feed->init(); $item = $feed->get_item(0); - $this->assertInstanceOf(Item::class, $item); + self::assertInstanceOf(Item::class, $item); $enclosure = $item->get_enclosure(); - $this->assertInstanceOf(Enclosure::class, $enclosure); + self::assertInstanceOf(Enclosure::class, $enclosure); $restriction = $enclosure->get_restriction(); - $this->assertInstanceOf(Restriction::class, $restriction); + self::assertInstanceOf(Restriction::class, $restriction); - $this->assertSame($expected, $restriction->get_relationship()); + self::assertSame($expected, $restriction->get_relationship()); } } diff --git a/tests/Unit/SanitizeTest.php b/tests/Unit/SanitizeTest.php index 2731a81a9..c22c1e772 100644 --- a/tests/Unit/SanitizeTest.php +++ b/tests/Unit/SanitizeTest.php @@ -16,19 +16,19 @@ class SanitizeTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Sanitize')); + self::assertTrue(class_exists('SimplePie\Sanitize')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Sanitize')); + self::assertTrue(class_exists('SimplePie_Sanitize')); } public function testSanitize(): void { $sanitize = new Sanitize(); - $this->assertSame( + self::assertSame( <<assertSame($expected, $sanitize->sanitize($given, SIMPLEPIE_CONSTRUCT_HTML, $base)); + self::assertSame($expected, $sanitize->sanitize($given, SIMPLEPIE_CONSTRUCT_HTML, $base)); } } diff --git a/tests/Unit/SimplePieTest.php b/tests/Unit/SimplePieTest.php index 666606ebd..240423e2c 100644 --- a/tests/Unit/SimplePieTest.php +++ b/tests/Unit/SimplePieTest.php @@ -24,12 +24,12 @@ class SimplePieTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\SimplePie')); + self::assertTrue(class_exists('SimplePie\SimplePie')); } public function testClassExists(): void { - $this->assertTrue(class_exists(SimplePie::class)); + self::assertTrue(class_exists(SimplePie::class)); } /** @@ -90,7 +90,7 @@ public function testTitleRSS20(string $title, string $expected): void '; $feed = $this->createFeedWithTemplate($data, $title); - $this->assertSame($expected, $feed->get_title()); + self::assertSame($expected, $feed->get_title()); } /** @@ -105,7 +105,7 @@ public function testTitleRSS20WithDC10(string $title, string $expected): void '; $feed = $this->createFeedWithTemplate($data, $title); - $this->assertSame($expected, $feed->get_title()); + self::assertSame($expected, $feed->get_title()); } /** @@ -120,7 +120,7 @@ public function testTitleRSS20WithDC11(string $title, string $expected): void '; $feed = $this->createFeedWithTemplate($data, $title); - $this->assertSame($expected, $feed->get_title()); + self::assertSame($expected, $feed->get_title()); } /** @@ -135,7 +135,7 @@ public function testTitleRSS20WithAtom03(string $title, string $expected): void '; $feed = $this->createFeedWithTemplate($data, $title); - $this->assertSame($expected, $feed->get_title()); + self::assertSame($expected, $feed->get_title()); } /** @@ -150,7 +150,7 @@ public function testTitleRSS20WithAtom10(string $title, string $expected): void '; $feed = $this->createFeedWithTemplate($data, $title); - $this->assertSame($expected, $feed->get_title()); + self::assertSame($expected, $feed->get_title()); } /** @@ -170,7 +170,7 @@ public function testTitleRSS20WithImageTitle(string $title, string $expected): v '; $feed = $this->createFeedWithTemplate($data, $title); - $this->assertSame($expected, $feed->get_title()); + self::assertSame($expected, $feed->get_title()); } /** @@ -190,7 +190,7 @@ public function testTitleRSS20WithImageTitleReversed(string $title, string $expe '; $feed = $this->createFeedWithTemplate($data, $title); - $this->assertSame($expected, $feed->get_title()); + self::assertSame($expected, $feed->get_title()); } public function testItemWithEmptyContent(): void @@ -207,8 +207,8 @@ public function testItemWithEmptyContent(): void $content = 'item description'; $feed = $this->createFeedWithTemplate($data, $content); $item = $feed->get_item(); - $this->assertInstanceOf(Item::class, $item); - $this->assertSame($content, $item->get_content()); + self::assertInstanceOf(Item::class, $item); + self::assertSame($content, $item->get_content()); } public function testSetPsr16Cache(): void @@ -232,7 +232,7 @@ public function testLegacyCallOfSetCacheClass(): void // PHPUnit 10 compatible way to test trigger_error(). set_error_handler( function ($errno, $errstr): bool { - $this->assertSame( + self::assertSame( '"SimplePie\SimplePie::set_cache_class()" is deprecated since SimplePie 1.3, please use "SimplePie\SimplePie::set_cache()" instead.', $errstr ); @@ -281,8 +281,8 @@ public function testDirectOverrideLegacy(): void $feed->init(); - $this->assertSame('https://example.com/feed/2019-10-07', $feed->subscribe_url()); - $this->assertSame('https://example.com/feed/', $feed->subscribe_url(true)); + self::assertSame('https://example.com/feed/2019-10-07', $feed->subscribe_url()); + self::assertSame('https://example.com/feed/', $feed->subscribe_url(true)); } /** @@ -595,7 +595,7 @@ public function test_get_copyright(string $data, string $expected): void $feed->enable_cache(false); $feed->init(); - $this->assertSame($expected, $feed->get_copyright()); + self::assertSame($expected, $feed->get_copyright()); } /** @@ -1006,7 +1006,7 @@ public function test_get_description(string $data, string $expected): void $feed->enable_cache(false); $feed->init(); - $this->assertSame($expected, $feed->get_description()); + self::assertSame($expected, $feed->get_description()); } /** @@ -1303,7 +1303,7 @@ public function test_get_image_height(string $data, ?int $expected): void $feed->enable_cache(false); $feed->init(); - $this->assertSame($expected, $feed->get_image_height()); + self::assertSame($expected, $feed->get_image_height()); } /** @@ -1400,7 +1400,7 @@ public function test_get_image_link(string $data, string $expected): void $feed->enable_cache(false); $feed->init(); - $this->assertSame($expected, $feed->get_image_link()); + self::assertSame($expected, $feed->get_image_link()); } /** @@ -1647,7 +1647,7 @@ public function test_get_image_title(string $data, string $expected): void $feed->enable_cache(false); $feed->init(); - $this->assertSame($expected, $feed->get_image_title()); + self::assertSame($expected, $feed->get_image_title()); } /** @@ -1896,7 +1896,7 @@ public function test_get_image_url(string $data, string $expected): void $feed->enable_cache(false); $feed->init(); - $this->assertSame($expected, $feed->get_image_url()); + self::assertSame($expected, $feed->get_image_url()); } /** @@ -2198,7 +2198,7 @@ public function test_get_image_width(string $data, ?int $expected): void $feed->enable_cache(false); $feed->init(); - $this->assertSame($expected, $feed->get_image_width()); + self::assertSame($expected, $feed->get_image_width()); } /** @@ -2453,7 +2453,7 @@ public function test_get_language(string $data, string $expected): void $feed->enable_cache(false); $feed->init(); - $this->assertSame($expected, $feed->get_language()); + self::assertSame($expected, $feed->get_language()); } /** @@ -2721,7 +2721,7 @@ public function test_get_link(string $data, string $expected): void $feed->enable_cache(false); $feed->init(); - $this->assertSame($expected, $feed->get_link()); + self::assertSame($expected, $feed->get_link()); } /** @@ -3145,6 +3145,6 @@ public function test_get_title(string $data, string $expected): void $feed->enable_cache(false); $feed->init(); - $this->assertSame($expected, $feed->get_title()); + self::assertSame($expected, $feed->get_title()); } } diff --git a/tests/Unit/SourceTest.php b/tests/Unit/SourceTest.php index edff1e0eb..faaf199c0 100644 --- a/tests/Unit/SourceTest.php +++ b/tests/Unit/SourceTest.php @@ -13,11 +13,11 @@ class SourceTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\Source')); + self::assertTrue(class_exists('SimplePie\Source')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_Source')); + self::assertTrue(class_exists('SimplePie_Source')); } } diff --git a/tests/Unit/XML/Declaration/ParserTest.php b/tests/Unit/XML/Declaration/ParserTest.php index 5424dcb85..223104dd9 100644 --- a/tests/Unit/XML/Declaration/ParserTest.php +++ b/tests/Unit/XML/Declaration/ParserTest.php @@ -13,11 +13,11 @@ class ParserTest extends TestCase { public function testNamespacedClassExists(): void { - $this->assertTrue(class_exists('SimplePie\XML\Declaration\Parser')); + self::assertTrue(class_exists('SimplePie\XML\Declaration\Parser')); } public function testClassExists(): void { - $this->assertTrue(class_exists('SimplePie_XML_Declaration_Parser')); + self::assertTrue(class_exists('SimplePie_XML_Declaration_Parser')); } } diff --git a/utils/PHPStan/RegistryCallMethodReturnTypeExtension.php b/utils/PHPStan/RegistryCallMethodReturnTypeExtension.php index 564ba0dfa..2c3a19a66 100644 --- a/utils/PHPStan/RegistryCallMethodReturnTypeExtension.php +++ b/utils/PHPStan/RegistryCallMethodReturnTypeExtension.php @@ -59,7 +59,10 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method $classType = $scope->getType($classNameArg); $methodType = $scope->getType($methodNameArg); - if (!$classType instanceof ConstantStringType || !$methodType instanceof ConstantStringType) { + if ( + !$classType instanceof ConstantStringType || // @phpstan-ignore phpstanApi.instanceofType + !$methodType instanceof ConstantStringType // @phpstan-ignore phpstanApi.instanceofType + ) { return new MixedType(); } @@ -81,9 +84,9 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method if ($argumentsArg !== null) { $argumentsType = $scope->getType($argumentsArg); - if ($argumentsType instanceof ConstantArrayType) { + if ($argumentsType instanceof ConstantArrayType) { // @phpstan-ignore phpstanApi.instanceofType $argumentTypes = $argumentsType->getValueTypes(); - } elseif ($argumentsType instanceof ArrayType) { + } elseif ($argumentsType instanceof ArrayType) { // @phpstan-ignore phpstanApi.instanceofType $argumentTypes = [$argumentsType->getItemType()]; } else { return new MixedType(); From f6c463029100fc932232da577a26d7cdb7c0bef0 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 14 Sep 2025 16:39:22 +0200 Subject: [PATCH 02/13] Remove PHPStan for older PHP --- .github/workflows/ci.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07f892237..1fa9ce1fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,6 +68,10 @@ jobs: coverage: none tools: none + - name: Remove PHPStan for older PHP + if: ${{ matrix.php < '8.0' }} + run: composer remove --dev phpstan/phpstan phpstan/phpstan-phpunit + # Install dependencies and handle caching in one go. # @link https://github.com/marketplace/actions/install-composer-dependencies - name: "Install Composer dependencies" @@ -82,8 +86,9 @@ jobs: - name: Run unit tests run: composer test + # It is sufficient to run PHPStan with one supported PHP version - name: Run static analysis - if: ${{ matrix.php >= '7.4' }} + if: ${{ matrix.php >= '8.0' }} run: composer phpstan -- --error-format=github test-compiled: From de1d46f68aeec73ecee3a3b4a7cd5550a2be1b11 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 14 Sep 2025 16:45:10 +0200 Subject: [PATCH 03/13] It is sufficient to run PHPStan with one supported PHP version --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1fa9ce1fb..5fe1fc58d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -88,7 +88,7 @@ jobs: # It is sufficient to run PHPStan with one supported PHP version - name: Run static analysis - if: ${{ matrix.php >= '8.0' }} + if: ${{ matrix.php == '8.4' }} run: composer phpstan -- --error-format=github test-compiled: From 6d38ebc827c78b748137197d196d611b78d0b2b7 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 14 Sep 2025 16:45:59 +0200 Subject: [PATCH 04/13] It would be sufficient to run PHPStan with one supported PHP version Keep change for another PR --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5fe1fc58d..ad0d82a4e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,9 +86,9 @@ jobs: - name: Run unit tests run: composer test - # It is sufficient to run PHPStan with one supported PHP version + # It would be sufficient to run PHPStan with one supported PHP version - name: Run static analysis - if: ${{ matrix.php == '8.4' }} + if: ${{ matrix.php >= '8.0' }} run: composer phpstan -- --error-format=github test-compiled: From 37fe47102cb9e24d315042086c2b48e6bb6ab99e Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 14 Sep 2025 21:42:14 +0200 Subject: [PATCH 05/13] Remove magic_quotes_gpc --- demo/index.php | 6 ------ demo/test.php | 4 ---- 2 files changed, 10 deletions(-) diff --git a/demo/index.php b/demo/index.php index 5849846bc..22ff4d9ca 100644 --- a/demo/index.php +++ b/demo/index.php @@ -18,12 +18,6 @@ // Make sure that page is getting passed a URL if (isset($_GET['feed']) && $_GET['feed'] !== '') { - // Strip slashes if magic quotes is enabled (which automatically escapes certain characters) - // @phpstan-ignore booleanAnd.rightAlwaysFalse - if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { - $_GET['feed'] = stripslashes($_GET['feed']); - } - // Use the URL that was passed to the page in SimplePie $feed->set_feed_url($_GET['feed']); } diff --git a/demo/test.php b/demo/test.php index 375207f05..51b345638 100644 --- a/demo/test.php +++ b/demo/test.php @@ -4,10 +4,6 @@ // Parse it $feed = new \SimplePie\SimplePie(); if (isset($_GET['feed']) && $_GET['feed'] !== '') { - // @phpstan-ignore booleanAnd.rightAlwaysFalse - if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { - $_GET['feed'] = stripslashes($_GET['feed']); - } $feed->set_feed_url($_GET['feed']); $feed->enable_cache(false); $starttime = microtime(true); From f0ea60427443ce0eeafb4548da801c87f4692b8c Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 15 Sep 2025 08:40:10 +0200 Subject: [PATCH 06/13] Extracted PHPUnit fix to another PR https://github.com/simplepie/simplepie/pull/940 --- tests/BCTest.php | 6 +- tests/CacheTest.php | 2 +- tests/EncodingTest.php | 12 +-- tests/HTTPParserTest.php | 36 ++++----- tests/IRITest.php | 92 +++++++++++----------- tests/Integration/CachingTest.php | 2 +- tests/Integration/HTTP/ClientsTest.php | 28 +++---- tests/Integration/SimplePieTest.php | 56 ++++++------- tests/ItemTest.php | 18 ++--- tests/LocatorTest.php | 18 ++--- tests/SanitizeTest.php | 4 +- tests/SubscribeUrlTest.php | 4 +- tests/Unit/AuthorTest.php | 16 ++-- tests/Unit/Cache/BaseDataCacheTest.php | 16 ++-- tests/Unit/Cache/BaseTest.php | 4 +- tests/Unit/Cache/DBTest.php | 4 +- tests/Unit/Cache/FileTest.php | 4 +- tests/Unit/Cache/MemcacheTest.php | 4 +- tests/Unit/Cache/MemcachedTest.php | 4 +- tests/Unit/Cache/MySQLTest.php | 4 +- tests/Unit/Cache/Psr16Test.php | 14 ++-- tests/Unit/Cache/RedisTest.php | 4 +- tests/Unit/CacheTest.php | 4 +- tests/Unit/CaptionTest.php | 4 +- tests/Unit/CategoryTest.php | 14 ++-- tests/Unit/Content/Type/SnifferTest.php | 4 +- tests/Unit/CopyrightTest.php | 4 +- tests/Unit/CreditTest.php | 4 +- tests/Unit/EnclosureTest.php | 14 ++-- tests/Unit/ExceptionTest.php | 4 +- tests/Unit/FileTest.php | 26 +++--- tests/Unit/GzdecodeTest.php | 4 +- tests/Unit/HTTP/ParserTest.php | 84 ++++++++++---------- tests/Unit/HTTP/Psr18ClientTest.php | 8 +- tests/Unit/HTTP/Psr7ResponseTest.php | 24 +++--- tests/Unit/IRITest.php | 96 +++++++++++------------ tests/Unit/ItemTest.php | 46 +++++------ tests/Unit/LocatorTest.php | 22 +++--- tests/Unit/MiscTest.php | 28 +++---- tests/Unit/Net/IPv6Test.php | 4 +- tests/Unit/Parse/DateTest.php | 6 +- tests/Unit/ParserTest.php | 12 +-- tests/Unit/RatingTest.php | 4 +- tests/Unit/RegistryTest.php | 8 +- tests/Unit/RestrictionTest.php | 12 +-- tests/Unit/SanitizeTest.php | 8 +- tests/Unit/SimplePieTest.php | 48 ++++++------ tests/Unit/SourceTest.php | 4 +- tests/Unit/XML/Declaration/ParserTest.php | 4 +- 49 files changed, 426 insertions(+), 426 deletions(-) diff --git a/tests/BCTest.php b/tests/BCTest.php index 26f2a31d8..9c94ba6ee 100644 --- a/tests/BCTest.php +++ b/tests/BCTest.php @@ -17,7 +17,7 @@ class BCTest extends TestCase */ public function test_class_SimplePie_Core_exists(): void { - self::assertTrue(class_exists('SimplePie_Core')); + $this->assertTrue(class_exists('SimplePie_Core')); } /** @@ -25,7 +25,7 @@ public function test_class_SimplePie_Core_exists(): void */ public function test_class_SimplePie_Misc_exists(): void { - self::assertTrue(class_exists('SimplePie_Misc')); + $this->assertTrue(class_exists('SimplePie_Misc')); } /** @@ -33,6 +33,6 @@ public function test_class_SimplePie_Misc_exists(): void */ public function test_class_SimplePie_Decode_HTML_Entities_exists(): void { - self::assertTrue(class_exists('SimplePie_Decode_HTML_Entities')); + $this->assertTrue(class_exists('SimplePie_Decode_HTML_Entities')); } } diff --git a/tests/CacheTest.php b/tests/CacheTest.php index dcf0ba07e..da5a53cda 100644 --- a/tests/CacheTest.php +++ b/tests/CacheTest.php @@ -60,7 +60,7 @@ public function testDirectOverrideLegacy(): void // PHPUnit 10 compatible way to test trigger_error(). set_error_handler( function ($errno, $errstr): bool { - self::assertSame( + $this->assertSame( '"SimplePie\SimplePie::set_cache_class()" is deprecated since SimplePie 1.3, please use "SimplePie\SimplePie::set_cache()" instead.', $errstr ); diff --git a/tests/EncodingTest.php b/tests/EncodingTest.php index da70fc5a5..4a637754d 100644 --- a/tests/EncodingTest.php +++ b/tests/EncodingTest.php @@ -79,7 +79,7 @@ public static function toUTF8_uconverter(): array public function test_convert_UTF8(string $input, string $expected, string $encoding): void { $encoding = SimplePie_Misc::encoding($encoding); - self::assertSameBin2Hex($expected, (string) SimplePie_Misc::change_encoding($input, $encoding, 'UTF-8')); + $this->assertSameBin2Hex($expected, (string) SimplePie_Misc::change_encoding($input, $encoding, 'UTF-8')); } /** @@ -92,7 +92,7 @@ public function test_convert_UTF8_mbstring(string $input, string $expected, stri { $encoding = SimplePie_Misc::encoding($encoding); if (extension_loaded('mbstring')) { - self::assertSameBin2Hex($expected, (string) Mock_Misc::change_encoding_mbstring($input, $encoding, 'UTF-8')); + $this->assertSameBin2Hex($expected, (string) Mock_Misc::change_encoding_mbstring($input, $encoding, 'UTF-8')); } } @@ -106,7 +106,7 @@ public function test_convert_UTF8_iconv(string $input, string $expected, string { $encoding = SimplePie_Misc::encoding($encoding); if (extension_loaded('iconv')) { - self::assertSameBin2Hex($expected, (string) Mock_Misc::change_encoding_iconv($input, $encoding, 'UTF-8')); + $this->assertSameBin2Hex($expected, (string) Mock_Misc::change_encoding_iconv($input, $encoding, 'UTF-8')); } } @@ -120,7 +120,7 @@ public function test_convert_UTF8_uconverter(string $input, string $expected, st { $encoding = SimplePie_Misc::encoding($encoding); if (extension_loaded('intl')) { - self::assertSameBin2Hex($expected, (string) Mock_Misc::change_encoding_uconverter($input, $encoding, 'UTF-8')); + $this->assertSameBin2Hex($expected, (string) Mock_Misc::change_encoding_uconverter($input, $encoding, 'UTF-8')); } } @@ -144,12 +144,12 @@ public static function toUTF16(): array public function test_convert_UTF16(string $input, string $expected, string $encoding): void { $encoding = SimplePie_Misc::encoding($encoding); - self::assertSameBin2Hex($expected, (string) SimplePie_Misc::change_encoding($input, $encoding, 'UTF-16')); + $this->assertSameBin2Hex($expected, (string) SimplePie_Misc::change_encoding($input, $encoding, 'UTF-16')); } public function test_nonexistent(): void { - self::assertFalse(SimplePie_Misc::change_encoding('', 'TESTENC', 'UTF-8')); + $this->assertFalse(SimplePie_Misc::change_encoding('', 'TESTENC', 'UTF-8')); } public static function assertSameBin2Hex(string $expected, string $actual, string $message = ''): void diff --git a/tests/HTTPParserTest.php b/tests/HTTPParserTest.php index 8ac98104d..c1ab1849a 100755 --- a/tests/HTTPParserTest.php +++ b/tests/HTTPParserTest.php @@ -41,12 +41,12 @@ public function testChunkedNormal(string $data, string $expected): void $data = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n" . $data; $data = SimplePie_HTTP_Parser::prepareHeaders($data); $parser = new SimplePie_HTTP_Parser($data); - self::assertTrue($parser->parse()); - self::assertSame(1.1, $parser->http_version); - self::assertSame(200, $parser->status_code); - self::assertSame('OK', $parser->reason); - self::assertSame(['content-type' => 'text/plain'], $parser->headers); - self::assertSame($expected, $parser->body); + $this->assertTrue($parser->parse()); + $this->assertSame(1.1, $parser->http_version); + $this->assertSame(200, $parser->status_code); + $this->assertSame('OK', $parser->reason); + $this->assertSame(['content-type' => 'text/plain'], $parser->headers); + $this->assertSame($expected, $parser->body); } /** @@ -57,12 +57,12 @@ public function testChunkedProxy(string $data, string $expected): void $data = "HTTP/1.0 200 Connection established\r\n\r\nHTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n" . $data; $data = SimplePie_HTTP_Parser::prepareHeaders($data); $parser = new SimplePie_HTTP_Parser($data); - self::assertTrue($parser->parse()); - self::assertSame(1.1, $parser->http_version); - self::assertSame(200, $parser->status_code); - self::assertSame('OK', $parser->reason); - self::assertSame(['content-type' => 'text/plain'], $parser->headers); - self::assertSame($expected, $parser->body); + $this->assertTrue($parser->parse()); + $this->assertSame(1.1, $parser->http_version); + $this->assertSame(200, $parser->status_code); + $this->assertSame('OK', $parser->reason); + $this->assertSame(['content-type' => 'text/plain'], $parser->headers); + $this->assertSame($expected, $parser->body); } /** @@ -73,11 +73,11 @@ public function testChunkedProxy11(string $data, string $expected): void $data = "HTTP/1.1 200 Connection established\r\n\r\nHTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n" . $data; $data = SimplePie_HTTP_Parser::prepareHeaders($data); $parser = new SimplePie_HTTP_Parser($data); - self::assertTrue($parser->parse()); - self::assertSame(1.1, $parser->http_version); - self::assertSame(200, $parser->status_code); - self::assertSame('OK', $parser->reason); - self::assertSame(['content-type' => 'text/plain'], $parser->headers); - self::assertSame($expected, $parser->body); + $this->assertTrue($parser->parse()); + $this->assertSame(1.1, $parser->http_version); + $this->assertSame(200, $parser->status_code); + $this->assertSame('OK', $parser->reason); + $this->assertSame(['content-type' => 'text/plain'], $parser->headers); + $this->assertSame($expected, $parser->body); } } diff --git a/tests/IRITest.php b/tests/IRITest.php index 0176d9966..b8c0b7338 100644 --- a/tests/IRITest.php +++ b/tests/IRITest.php @@ -72,8 +72,8 @@ public function testStringRFC3986(string $relative, string $expected): void { $base = new SimplePie_IRI('http://a/b/c/d;p?q'); $absolutized = SimplePie_IRI::absolutize($base, $relative); - self::assertNotFalse($absolutized); - self::assertSame($expected, $absolutized->get_iri()); + $this->assertNotFalse($absolutized); + $this->assertSame($expected, $absolutized->get_iri()); } /** @@ -83,7 +83,7 @@ public function testObjectRFC3986(string $relative, string $expected): void { $base = new SimplePie_IRI('http://a/b/c/d;p?q'); $expected = new SimplePie_IRI($expected); - self::assertEquals($expected, SimplePie_IRI::absolutize($base, $relative)); + $this->assertEquals($expected, SimplePie_IRI::absolutize($base, $relative)); } /** @@ -93,9 +93,9 @@ public function testBothStringRFC3986(string $relative, string $expected): void { $base = 'http://a/b/c/d;p?q'; $absolutized = SimplePie_IRI::absolutize($base, $relative); - self::assertNotFalse($absolutized); - self::assertSame($expected, $absolutized->get_iri()); - self::assertSame($expected, (string) SimplePie_IRI::absolutize($base, $relative)); + $this->assertNotFalse($absolutized); + $this->assertSame($expected, $absolutized->get_iri()); + $this->assertSame($expected, (string) SimplePie_IRI::absolutize($base, $relative)); } /** @@ -130,8 +130,8 @@ public function testStringSP(string $base, string $relative, string $expected): { $base = new SimplePie_IRI($base); $absolutized = SimplePie_IRI::absolutize($base, $relative); - self::assertNotFalse($absolutized); - self::assertSame($expected, $absolutized->get_iri()); + $this->assertNotFalse($absolutized); + $this->assertSame($expected, $absolutized->get_iri()); } /** @@ -141,7 +141,7 @@ public function testObjectSP(string $base, string $relative, string $expected): { $base = new SimplePie_IRI($base); $expected = new SimplePie_IRI($expected); - self::assertEquals($expected, SimplePie_IRI::absolutize($base, $relative)); + $this->assertEquals($expected, SimplePie_IRI::absolutize($base, $relative)); } /** @@ -164,7 +164,7 @@ public function testStringQuery(string $query, string $expected): void { $base = new SimplePie_IRI('http://example.com/'); $base->set_query($query); - self::assertSame($expected, $base->get_iri()); + $this->assertSame($expected, $base->get_iri()); } /** @@ -175,7 +175,7 @@ public function testObjectQuery(string $query, string $expected): void $base = new SimplePie_IRI('http://example.com/'); $base->set_query($query); $expected = new SimplePie_IRI($expected); - self::assertEquals($expected, $base); + $this->assertEquals($expected, $base); } /** @@ -196,8 +196,8 @@ public function testAbsolutizeString(string $base, string $relative, string $exp { $base = new SimplePie_IRI($base); $absolutized = SimplePie_IRI::absolutize($base, $relative); - self::assertNotFalse($absolutized); - self::assertSame($expected, $absolutized->get_iri()); + $this->assertNotFalse($absolutized); + $this->assertSame($expected, $absolutized->get_iri()); } /** @@ -207,7 +207,7 @@ public function testAbsolutizeObject(string $base, string $relative, string $exp { $base = new SimplePie_IRI($base); $expected = new SimplePie_IRI($expected); - self::assertEquals($expected, SimplePie_IRI::absolutize($base, $relative)); + $this->assertEquals($expected, SimplePie_IRI::absolutize($base, $relative)); } /** @@ -302,7 +302,7 @@ public static function normalization_tests(): array public function testStringNormalization(string $input, string $output): void { $input = new SimplePie_IRI($input); - self::assertSame($output, $input->get_iri()); + $this->assertSame($output, $input->get_iri()); } /** @@ -312,7 +312,7 @@ public function testObjectNormalization(string $input, string $output): void { $input = new SimplePie_IRI($input); $output = new SimplePie_IRI($output); - self::assertEquals($output, $input); + $this->assertEquals($output, $input); } /** @@ -333,7 +333,7 @@ public static function uri_tests(): array public function testURIConversion(string $input, string $output): void { $input = new SimplePie_IRI($input); - self::assertSame($output, $input->get_uri()); + $this->assertSame($output, $input->get_uri()); } /** @@ -353,7 +353,7 @@ public function testObjectEquivalence(string $input, string $output): void { $input = new SimplePie_IRI($input); $output = new SimplePie_IRI($output); - self::assertEquals($output, $input); + $this->assertEquals($output, $input); } /** @@ -373,12 +373,12 @@ public function testObjectNotEquivalence(string $input, string $output): void { $input = new SimplePie_IRI($input); $output = new SimplePie_IRI($output); - self::assertNotEquals($output, $input); + $this->assertNotEquals($output, $input); } public function testInvalidAbsolutizeBase(): void { - self::assertFalse(SimplePie_IRI::absolutize('://not a URL', '../')); + $this->assertFalse(SimplePie_IRI::absolutize('://not a URL', '../')); } public function testInvalidPathNoHost(): void @@ -386,21 +386,21 @@ public function testInvalidPathNoHost(): void $iri = new SimplePie_IRI(); $iri->scheme = 'http'; $iri->path = '//test'; - self::assertFalse($iri->is_valid()); + $this->assertFalse($iri->is_valid()); } public function testInvalidRelativePathContainsColon(): void { $iri = new SimplePie_IRI(); $iri->path = '/test:/'; - self::assertFalse($iri->is_valid()); + $this->assertFalse($iri->is_valid()); } public function testValidRelativePathContainsColon(): void { $iri = new SimplePie_IRI(); $iri->path = '/test/:'; - self::assertTrue($iri->is_valid()); + $this->assertTrue($iri->is_valid()); } public function testFullGamut(): void @@ -412,12 +412,12 @@ public function testFullGamut(): void $iri->path = '/test/'; $iri->fragment = 'test'; - self::assertSame('http', $iri->scheme); - self::assertSame('user:password', $iri->userinfo); - self::assertSame('example.com', $iri->host); - self::assertSame(80, $iri->port); - self::assertSame('/test/', $iri->path); - self::assertSame('test', $iri->fragment); + $this->assertSame('http', $iri->scheme); + $this->assertSame('user:password', $iri->userinfo); + $this->assertSame('example.com', $iri->host); + $this->assertSame(80, $iri->port); + $this->assertSame('/test/', $iri->path); + $this->assertSame('test', $iri->fragment); } public function testReadAliased(): void @@ -429,12 +429,12 @@ public function testReadAliased(): void $iri->path = '/test/'; $iri->fragment = 'test'; - self::assertSame('http', $iri->scheme); - self::assertSame('user:password', $iri->userinfo); - self::assertSame('example.com', $iri->host); - self::assertSame(80, $iri->port); - self::assertSame('/test/', $iri->path); - self::assertSame('test', $iri->fragment); + $this->assertSame('http', $iri->scheme); + $this->assertSame('user:password', $iri->userinfo); + $this->assertSame('example.com', $iri->host); + $this->assertSame(80, $iri->port); + $this->assertSame('/test/', $iri->path); + $this->assertSame('test', $iri->fragment); } public function testWriteAliased(): void @@ -446,23 +446,23 @@ public function testWriteAliased(): void $iri->path = '/test/'; $iri->fragment = 'test'; - self::assertSame('http', $iri->scheme); - self::assertSame('user:password', $iri->userinfo); - self::assertSame('example.com', $iri->host); - self::assertSame(80, $iri->port); - self::assertSame('/test/', $iri->path); - self::assertSame('test', $iri->fragment); + $this->assertSame('http', $iri->scheme); + $this->assertSame('user:password', $iri->userinfo); + $this->assertSame('example.com', $iri->host); + $this->assertSame(80, $iri->port); + $this->assertSame('/test/', $iri->path); + $this->assertSame('test', $iri->fragment); } public function testNonexistentProperty(): void { $iri = new SimplePie_IRI(); - self::assertFalse(isset($iri->nonexistent_prop)); + $this->assertFalse(isset($iri->nonexistent_prop)); // PHPUnit 10 compatible way to test trigger_error(). set_error_handler( function ($errno, $errstr): bool { - self::assertSame( + $this->assertSame( 'Undefined property: SimplePie\IRI::nonexistent_prop', $errstr ); @@ -482,8 +482,8 @@ public function testBlankHost(): void $iri = new SimplePie_IRI('http://example.com/a/?b=c#d'); $iri->host = null; - self::assertNull($iri->host); - self::assertSame('http:/a/?b=c#d', (string) $iri); + $this->assertNull($iri->host); + $this->assertSame('http:/a/?b=c#d', (string) $iri); } public function testBadPort(): void @@ -491,6 +491,6 @@ public function testBadPort(): void $iri = new SimplePie_IRI(); $iri->port = 'example'; - self::assertNull($iri->port); + $this->assertNull($iri->port); } } diff --git a/tests/Integration/CachingTest.php b/tests/Integration/CachingTest.php index 1051e47f5..e01ef95a7 100644 --- a/tests/Integration/CachingTest.php +++ b/tests/Integration/CachingTest.php @@ -112,7 +112,7 @@ public function testInitWithDifferentCacheStateCallsCacheCorrectly( $expectedDataWritten['cache_expiration_time'] = $writtenData['cache_expiration_time']; } - self::assertSame($expectedDataWritten, $writtenData); + $this->assertSame($expectedDataWritten, $writtenData); } /** diff --git a/tests/Integration/HTTP/ClientsTest.php b/tests/Integration/HTTP/ClientsTest.php index 818c0d329..b088b8cf0 100644 --- a/tests/Integration/HTTP/ClientsTest.php +++ b/tests/Integration/HTTP/ClientsTest.php @@ -48,12 +48,12 @@ private function runTestsWithClientGetContentOfLocalFile(Client $client): void $response = $client->request(Client::METHOD_GET, $filepath); // @phpstan-ignore staticMethod.alreadyNarrowedType - self::assertInstanceOf(Response::class, $response); - self::assertSame($filepath, $response->get_permanent_uri()); - self::assertSame($filepath, $response->get_final_requested_uri()); - self::assertSame(200, $response->get_status_code()); - self::assertSame([], $response->get_headers()); - self::assertStringStartsWith('', $response->get_body_content()); + $this->assertInstanceOf(Response::class, $response); + $this->assertSame($filepath, $response->get_permanent_uri()); + $this->assertSame($filepath, $response->get_final_requested_uri()); + $this->assertSame(200, $response->get_status_code()); + $this->assertSame([], $response->get_headers()); + $this->assertStringStartsWith('', $response->get_body_content()); } public function testFileClientThrowsClientException(): void @@ -104,7 +104,7 @@ public function testFileClientReturnsResponseOn429StatusCode(): void $server->stop(); - self::assertSame(429, $response->get_status_code()); + $this->assertSame(429, $response->get_status_code()); } public function testFileClientReturnsResponseOn500StatusCode(): void @@ -123,7 +123,7 @@ public function testFileClientReturnsResponseOn500StatusCode(): void $server->stop(); - self::assertSame(500, $response->get_status_code()); + $this->assertSame(500, $response->get_status_code()); } public function testFileClientThrowsClientExceptionIfServerIsUnreachable(): void @@ -216,10 +216,10 @@ public function testRedirectsChain(Client $client): void $server->stop(); - self::assertSame(200, $response->get_status_code()); - self::assertSame('OK', $response->get_body_content()); - self::assertSame($permanentLocation, $response->get_permanent_uri()); - self::assertSame($finalLocation, $response->get_final_requested_uri()); + $this->assertSame(200, $response->get_status_code()); + $this->assertSame('OK', $response->get_body_content()); + $this->assertSame($permanentLocation, $response->get_permanent_uri()); + $this->assertSame($finalLocation, $response->get_final_requested_uri()); } /** @@ -280,12 +280,12 @@ public function testUtf16(Client $client, string $kind, string $endianness): voi $start = $endianness === 'be' ? "\x00<\x00r\x00s\x00s\x00 " : "<\x00r\x00s\x00s\x00 \x00"; $end = $endianness === 'be' ? "\x00<\x00/\x00r\x00s\x00s\x00>\x00\n" : "<\x00/\x00r\x00s\x00s\x00>\x00\n\x00"; - self::assertSame( + $this->assertSame( $start, substr($response->get_body_content(), 0, strlen($start)), 'Body does not start as expected: ' . $response->get_body_content() ); - self::assertSame( + $this->assertSame( $end, substr($response->get_body_content(), -strlen($end)), 'Body does not end as expected: ' . $response->get_body_content() diff --git a/tests/Integration/SimplePieTest.php b/tests/Integration/SimplePieTest.php index c9af9e378..eb381de9a 100644 --- a/tests/Integration/SimplePieTest.php +++ b/tests/Integration/SimplePieTest.php @@ -37,8 +37,8 @@ public function testRequestingALocalFileWithSetFeedUrlWorks(): void $simplepie->enable_cache(false); $simplepie->set_feed_url($filepath); - self::assertTrue($simplepie->init()); - self::assertSame(100, $simplepie->get_item_quantity()); + $this->assertTrue($simplepie->init()); + $this->assertSame(100, $simplepie->get_item_quantity()); } /** @@ -53,8 +53,8 @@ public function testRequestingALocalFileWithSetFileWorks(): void $file = new File($filepath); $simplepie->set_file($file); - self::assertTrue($simplepie->init()); - self::assertSame(100, $simplepie->get_item_quantity()); + $this->assertTrue($simplepie->init()); + $this->assertSame(100, $simplepie->get_item_quantity()); } /** @@ -73,8 +73,8 @@ public function testRequestingALocalFileWithPsr18ClientWorks(): void ); $simplepie->set_feed_url($filepath); - self::assertTrue($simplepie->init()); - self::assertSame(100, $simplepie->get_item_quantity()); + $this->assertTrue($simplepie->init()); + $this->assertSame(100, $simplepie->get_item_quantity()); } /** @@ -122,8 +122,8 @@ public function testRequestingAFeedWithPsr18ClientWorks(): void ); $simplepie->set_feed_url('https://example.org/feed.xml'); - self::assertTrue($simplepie->init()); - self::assertSame(100, $simplepie->get_item_quantity()); + $this->assertTrue($simplepie->init()); + $this->assertSame(100, $simplepie->get_item_quantity()); } public function testSimplePieReturnsCorrectStatusCodeFromServerResponse(): void @@ -145,9 +145,9 @@ public function testSimplePieReturnsCorrectStatusCodeFromServerResponse(): void $server->stop(); - self::assertFalse($return); - self::assertSame(429, $simplepie->status_code()); - self::assertSame('Retrieved unsupported status code "429"', $simplepie->error()); + $this->assertFalse($return); + $this->assertSame(429, $simplepie->status_code()); + $this->assertSame('Retrieved unsupported status code "429"', $simplepie->error()); } public function testSimplePieReturnsCorrectStatusCodeOnServerConnectionError(): void @@ -161,9 +161,9 @@ public function testSimplePieReturnsCorrectStatusCodeOnServerConnectionError(): $return = $simplepie->init(); - self::assertFalse($return); - self::assertSame(0, $simplepie->status_code()); - self::assertSame('cURL error 6: Could not resolve host: example.invalid', $simplepie->error()); + $this->assertFalse($return); + $this->assertSame(0, $simplepie->status_code()); + $this->assertSame('cURL error 6: Could not resolve host: example.invalid', $simplepie->error()); } @@ -216,8 +216,8 @@ public function testRequestingAFeedFromCacheWorks(): void $simplepie->set_feed_url('https://example.com/feed.xml'); - self::assertTrue($simplepie->init()); - self::assertSame(100, $simplepie->get_item_quantity()); + $this->assertTrue($simplepie->init()); + $this->assertSame(100, $simplepie->get_item_quantity()); BaseCacheWithCallbacksMock::resetAllCallbacks(); } @@ -258,8 +258,8 @@ public function testRequestingAFeedFromPsr16CacheWorks(): void $simplepie->set_cache($cache); $simplepie->set_feed_url('https://example.com/feed.xml'); - self::assertTrue($simplepie->init()); - self::assertSame(100, $simplepie->get_item_quantity()); + $this->assertTrue($simplepie->init()); + $this->assertSame(100, $simplepie->get_item_quantity()); } @@ -277,7 +277,7 @@ public function testWhitespaceBeforeXmlDeclaration(): void $simplepie->enable_cache(false); $simplepie->set_feed_url($filepath); - self::assertTrue($simplepie->init()); + $this->assertTrue($simplepie->init()); } /** @@ -326,15 +326,15 @@ public function testMicroformatItems(string $path, string $feedTitle, array $tit $feed->enable_cache(false); $error = implode("\n", (array) ($feed->error() ?? '')); // For PHPStan - self::assertTrue($feed->init(), 'Failed fetching feed: ' . $error); + $this->assertTrue($feed->init(), 'Failed fetching feed: ' . $error); - self::assertSame($feedTitle, $feed->get_title()); + $this->assertSame($feedTitle, $feed->get_title()); $items = $feed->get_items(); // @phpstan-ignore phpunit.assertCount - self::assertSame(count($titles), count($items), 'Number of items does not match'); + $this->assertSame(count($titles), count($items), 'Number of items does not match'); foreach (array_map(null, $titles, $items) as $i => [$expectedTitle, $item]) { assert($item !== null); // For PHPStan - self::assertSame($expectedTitle, $item->get_title(), "Title of item #$i does not match"); + $this->assertSame($expectedTitle, $item->get_title(), "Title of item #$i does not match"); } } @@ -545,13 +545,13 @@ public function testMicroformatLinkHub(string $data, ?string $hubUrl, ?string $s $feed->enable_cache(false); $error = implode("\n", (array) ($feed->error() ?? '')); // For PHPStan - self::assertTrue($feed->init(), 'Failed fetching feed: ' . $error); + $this->assertTrue($feed->init(), 'Failed fetching feed: ' . $error); $server->stop(); - self::assertSame($hubUrl, $feed->get_link(0, 'hub'), 'Link rel=hub does not match'); - self::assertSame($selfUrl, $feed->get_link(0, 'self'), 'Link rel=self does not match'); - self::assertLessThanOrEqual(1, count($feed->get_links('self') ?? []), 'Link rel=self should not be promoted from HTML when it is already present in headers'); - self::assertSame($bogoUrl, $feed->get_link(0, 'bogo'), 'Link rel=bogo does not match'); + $this->assertSame($hubUrl, $feed->get_link(0, 'hub'), 'Link rel=hub does not match'); + $this->assertSame($selfUrl, $feed->get_link(0, 'self'), 'Link rel=self does not match'); + $this->assertLessThanOrEqual(1, count($feed->get_links('self') ?? []), 'Link rel=self should not be promoted from HTML when it is already present in headers'); + $this->assertSame($bogoUrl, $feed->get_link(0, 'bogo'), 'Link rel=bogo does not match'); } } diff --git a/tests/ItemTest.php b/tests/ItemTest.php index 2d79b8f0c..a909c10e8 100644 --- a/tests/ItemTest.php +++ b/tests/ItemTest.php @@ -69,7 +69,7 @@ public function testTitleRSS20(string $title, string $expected): void '; $feed = $this->checkFromTemplate($data, $title); - self::assertSame($expected, $feed->get_title()); + $this->assertSame($expected, $feed->get_title()); } /** @@ -84,7 +84,7 @@ public function testTitleRSS20WithDC10(string $title, string $expected): void '; $feed = $this->checkFromTemplate($data, $title); - self::assertSame($expected, $feed->get_title()); + $this->assertSame($expected, $feed->get_title()); } /** @@ -99,7 +99,7 @@ public function testTitleRSS20WithDC11(string $title, string $expected): void '; $feed = $this->checkFromTemplate($data, $title); - self::assertSame($expected, $feed->get_title()); + $this->assertSame($expected, $feed->get_title()); } /** @@ -114,7 +114,7 @@ public function testTitleRSS20WithAtom03(string $title, string $expected): void '; $feed = $this->checkFromTemplate($data, $title); - self::assertSame($expected, $feed->get_title()); + $this->assertSame($expected, $feed->get_title()); } /** @@ -129,7 +129,7 @@ public function testTitleRSS20WithAtom10(string $title, string $expected): void '; $feed = $this->checkFromTemplate($data, $title); - self::assertSame($expected, $feed->get_title()); + $this->assertSame($expected, $feed->get_title()); } /** @@ -149,7 +149,7 @@ public function testTitleRSS20WithImageTitle(string $title, string $expected): v '; $feed = $this->checkFromTemplate($data, $title); - self::assertSame($expected, $feed->get_title()); + $this->assertSame($expected, $feed->get_title()); } /** @@ -169,7 +169,7 @@ public function testTitleRSS20WithImageTitleReversed(string $title, string $expe '; $feed = $this->checkFromTemplate($data, $title); - self::assertSame($expected, $feed->get_title()); + $this->assertSame($expected, $feed->get_title()); } public function testItemWithEmptyContent(): void @@ -186,7 +186,7 @@ public function testItemWithEmptyContent(): void $content = 'item description'; $feed = $this->checkFromTemplate($data, $content); $item = $feed->get_item(); - self::assertInstanceOf(Item::class, $item); - self::assertSame($content, $item->get_content()); + $this->assertInstanceOf(Item::class, $item); + $this->assertSame($content, $item->get_content()); } } diff --git a/tests/LocatorTest.php b/tests/LocatorTest.php index b8c7b25fe..f9e1270eb 100755 --- a/tests/LocatorTest.php +++ b/tests/LocatorTest.php @@ -44,7 +44,7 @@ public function testAutodiscoverOnFeed(string $mime): void $locator->set_registry($registry); $feed = $locator->find(SIMPLEPIE_LOCATOR_ALL, $all); - self::assertSame($data, $feed); + $this->assertSame($data, $feed); } public function testInvalidMIMEType(): void @@ -59,7 +59,7 @@ public function testInvalidMIMEType(): void $locator->set_registry($registry); $feed = $locator->find(SIMPLEPIE_LOCATOR_ALL, $all); - self::assertNull($feed); + $this->assertNull($feed); } public function testDirectNoDOM(): void @@ -71,8 +71,8 @@ public function testDirectNoDOM(): void $locator->dom = null; $locator->set_registry($registry); - self::assertTrue($locator->is_feed($data)); - self::assertSame($data, $locator->find(SIMPLEPIE_LOCATOR_ALL, $found)); + $this->assertTrue($locator->is_feed($data)); + $this->assertSame($data, $locator->find(SIMPLEPIE_LOCATOR_ALL, $found)); } public function testFailDiscoveryNoDOM(): void @@ -88,8 +88,8 @@ public function testFailDiscoveryNoDOM(): void $locator->dom = null; $locator->set_registry($registry); - self::assertFalse($locator->is_feed($data)); - self::assertFalse($locator->find(SIMPLEPIE_LOCATOR_ALL, $found)); + $this->assertFalse($locator->is_feed($data)); + $this->assertFalse($locator->find(SIMPLEPIE_LOCATOR_ALL, $found)); } /** @@ -136,12 +136,12 @@ public function test_from_file(File $data): void //$expected = SimplePie_Misc::get_element('link', $data->body); $feed = $locator->find(SIMPLEPIE_LOCATOR_ALL, $all); - self::assertFalse($locator->is_feed($data), 'HTML document not be a feed itself'); - self::assertInstanceOf(FileMock::class, $feed); + $this->assertFalse($locator->is_feed($data), 'HTML document not be a feed itself'); + $this->assertInstanceOf(FileMock::class, $feed); $success = array_filter($expected, [get_class($this), 'filter_success']); $found = is_array($all) ? array_map([get_class($this), 'map_url_file'], $all) : []; - self::assertSame($success, $found); + $this->assertSame($success, $found); } protected static function filter_success(string $url): bool diff --git a/tests/SanitizeTest.php b/tests/SanitizeTest.php index 0f05c87f7..e44c6ff58 100755 --- a/tests/SanitizeTest.php +++ b/tests/SanitizeTest.php @@ -14,7 +14,7 @@ public function testSanitize(): void { $sanitize = new SimplePie_Sanitize(); - self::assertSame( + $this->assertSame( <<sanitize($given, SIMPLEPIE_CONSTRUCT_HTML, $base)); + $this->assertSame($expected, $sanitize->sanitize($given, SIMPLEPIE_CONSTRUCT_HTML, $base)); } } diff --git a/tests/SubscribeUrlTest.php b/tests/SubscribeUrlTest.php index ea339ac46..d8fb06333 100644 --- a/tests/SubscribeUrlTest.php +++ b/tests/SubscribeUrlTest.php @@ -20,7 +20,7 @@ public function testDirectOverrideLegacy(): void $feed->init(); - self::assertSame('https://example.com/feed/2019-10-07', $feed->subscribe_url()); - self::assertSame('https://example.com/feed/', $feed->subscribe_url(true)); + $this->assertSame('https://example.com/feed/2019-10-07', $feed->subscribe_url()); + $this->assertSame('https://example.com/feed/', $feed->subscribe_url(true)); } } diff --git a/tests/Unit/AuthorTest.php b/tests/Unit/AuthorTest.php index a8312116b..5355da08a 100644 --- a/tests/Unit/AuthorTest.php +++ b/tests/Unit/AuthorTest.php @@ -16,12 +16,12 @@ class AuthorTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Author')); + $this->assertTrue(class_exists('SimplePie\Author')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Author')); + $this->assertTrue(class_exists('SimplePie_Author')); } /** @@ -494,12 +494,12 @@ public function test_get_name_from_author(string $data, ?string $expected): void $feed->init(); $item = $feed->get_item(0); - self::assertInstanceOf(Item::class, $item); + $this->assertInstanceOf(Item::class, $item); $author = $item->get_author(); - self::assertInstanceOf(Author::class, $author); + $this->assertInstanceOf(Author::class, $author); - self::assertSame($expected, $author->get_name()); + $this->assertSame($expected, $author->get_name()); } /** @@ -722,11 +722,11 @@ public function test_get_name_from_contributor(string $data, string $expected): $feed->init(); $item = $feed->get_item(0); - self::assertInstanceOf(Item::class, $item); + $this->assertInstanceOf(Item::class, $item); $author = $item->get_contributor(); - self::assertInstanceOf(Author::class, $author); + $this->assertInstanceOf(Author::class, $author); - self::assertSame($expected, $author->get_name()); + $this->assertSame($expected, $author->get_name()); } } diff --git a/tests/Unit/Cache/BaseDataCacheTest.php b/tests/Unit/Cache/BaseDataCacheTest.php index fef3e6f90..e38c92f7d 100644 --- a/tests/Unit/Cache/BaseDataCacheTest.php +++ b/tests/Unit/Cache/BaseDataCacheTest.php @@ -25,7 +25,7 @@ public function testSetDataReturnsTrueIfDataCouldBeWritten(): void $cache = new BaseDataCache($baseCache); - self::assertTrue($cache->set_data($key, $value, $ttl)); + $this->assertTrue($cache->set_data($key, $value, $ttl)); } public function testSetDataReturnsFalseIfDataCouldNotBeWritten(): void @@ -39,7 +39,7 @@ public function testSetDataReturnsFalseIfDataCouldNotBeWritten(): void $cache = new BaseDataCache($baseCache); - self::assertFalse($cache->set_data($key, $value, $ttl)); + $this->assertFalse($cache->set_data($key, $value, $ttl)); } public function testGetDataReturnsCorrectData(): void @@ -53,7 +53,7 @@ public function testGetDataReturnsCorrectData(): void $cache = new BaseDataCache($baseCache); - self::assertSame($value, $cache->get_data($key)); + $this->assertSame($value, $cache->get_data($key)); } public function testGetDataWithCacheMissReturnsDefault(): void @@ -66,7 +66,7 @@ public function testGetDataWithCacheMissReturnsDefault(): void $cache = new BaseDataCache($baseCache); - self::assertSame($default, $cache->get_data($key, $default)); + $this->assertSame($default, $cache->get_data($key, $default)); } public function testGetDataWithCacheExpiredReturnsDefault(): void @@ -80,7 +80,7 @@ public function testGetDataWithCacheExpiredReturnsDefault(): void $cache = new BaseDataCache($baseCache); - self::assertSame($default, $cache->get_data($key, $default)); + $this->assertSame($default, $cache->get_data($key, $default)); } public function testGetDataWithCacheCorruptionReturnsDefault(): void @@ -93,7 +93,7 @@ public function testGetDataWithCacheCorruptionReturnsDefault(): void $cache = new BaseDataCache($baseCache); - self::assertSame($default, $cache->get_data($key, $default)); + $this->assertSame($default, $cache->get_data($key, $default)); } public function testDeleteDataReturnsTrueIfDataCouldBeDeleted(): void @@ -105,7 +105,7 @@ public function testDeleteDataReturnsTrueIfDataCouldBeDeleted(): void $cache = new BaseDataCache($baseCache); - self::assertTrue($cache->delete_data($key)); + $this->assertTrue($cache->delete_data($key)); } public function testDeleteDataReturnsFalseIfDataCouldNotBeDeleted(): void @@ -117,6 +117,6 @@ public function testDeleteDataReturnsFalseIfDataCouldNotBeDeleted(): void $cache = new BaseDataCache($baseCache); - self::assertFalse($cache->delete_data($key)); + $this->assertFalse($cache->delete_data($key)); } } diff --git a/tests/Unit/Cache/BaseTest.php b/tests/Unit/Cache/BaseTest.php index 00587341a..c69ac03dc 100644 --- a/tests/Unit/Cache/BaseTest.php +++ b/tests/Unit/Cache/BaseTest.php @@ -13,11 +13,11 @@ class BaseTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(interface_exists('SimplePie\Cache\Base')); + $this->assertTrue(interface_exists('SimplePie\Cache\Base')); } public function testClassExists(): void { - self::assertTrue(interface_exists('SimplePie_Cache_Base')); + $this->assertTrue(interface_exists('SimplePie_Cache_Base')); } } diff --git a/tests/Unit/Cache/DBTest.php b/tests/Unit/Cache/DBTest.php index 0a02b7911..0f9154c99 100644 --- a/tests/Unit/Cache/DBTest.php +++ b/tests/Unit/Cache/DBTest.php @@ -13,11 +13,11 @@ class DBTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Cache\DB')); + $this->assertTrue(class_exists('SimplePie\Cache\DB')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Cache_DB')); + $this->assertTrue(class_exists('SimplePie_Cache_DB')); } } diff --git a/tests/Unit/Cache/FileTest.php b/tests/Unit/Cache/FileTest.php index cc3cbbcf6..ba76d0210 100644 --- a/tests/Unit/Cache/FileTest.php +++ b/tests/Unit/Cache/FileTest.php @@ -13,11 +13,11 @@ class FileTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Cache\File')); + $this->assertTrue(class_exists('SimplePie\Cache\File')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Cache_File')); + $this->assertTrue(class_exists('SimplePie_Cache_File')); } } diff --git a/tests/Unit/Cache/MemcacheTest.php b/tests/Unit/Cache/MemcacheTest.php index 4cc1a8546..9eebc8d72 100644 --- a/tests/Unit/Cache/MemcacheTest.php +++ b/tests/Unit/Cache/MemcacheTest.php @@ -13,11 +13,11 @@ class MemcacheTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Cache\Memcache')); + $this->assertTrue(class_exists('SimplePie\Cache\Memcache')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Cache_Memcache')); + $this->assertTrue(class_exists('SimplePie_Cache_Memcache')); } } diff --git a/tests/Unit/Cache/MemcachedTest.php b/tests/Unit/Cache/MemcachedTest.php index c8e11d1f2..ca50e4781 100644 --- a/tests/Unit/Cache/MemcachedTest.php +++ b/tests/Unit/Cache/MemcachedTest.php @@ -13,11 +13,11 @@ class MemcachedTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Cache\Memcached')); + $this->assertTrue(class_exists('SimplePie\Cache\Memcached')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Cache_Memcached')); + $this->assertTrue(class_exists('SimplePie_Cache_Memcached')); } } diff --git a/tests/Unit/Cache/MySQLTest.php b/tests/Unit/Cache/MySQLTest.php index 19f531964..3adb484b6 100644 --- a/tests/Unit/Cache/MySQLTest.php +++ b/tests/Unit/Cache/MySQLTest.php @@ -13,11 +13,11 @@ class MySQLTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Cache\MySQL')); + $this->assertTrue(class_exists('SimplePie\Cache\MySQL')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Cache_MySQL')); + $this->assertTrue(class_exists('SimplePie_Cache_MySQL')); } } diff --git a/tests/Unit/Cache/Psr16Test.php b/tests/Unit/Cache/Psr16Test.php index 3d8fb3b5c..5ca3ba3db 100644 --- a/tests/Unit/Cache/Psr16Test.php +++ b/tests/Unit/Cache/Psr16Test.php @@ -28,7 +28,7 @@ public function testSetDataReturnsTrueIfDataCouldBeWritten(): void $cache = new Psr16($psr16); - self::assertTrue($cache->set_data($key, $value, $ttl)); + $this->assertTrue($cache->set_data($key, $value, $ttl)); } public function testSetDataReturnsFalseIfDataCouldNotBeWritten(): void @@ -42,7 +42,7 @@ public function testSetDataReturnsFalseIfDataCouldNotBeWritten(): void $cache = new Psr16($psr16); - self::assertFalse($cache->set_data($key, $value, $ttl)); + $this->assertFalse($cache->set_data($key, $value, $ttl)); } public function testSetDataWithInvalidKeyThrowsInvalidArgumentException(): void @@ -78,7 +78,7 @@ public function testGetDataReturnsCorrectData(): void $cache = new Psr16($psr16); - self::assertSame($value, $cache->get_data($key)); + $this->assertSame($value, $cache->get_data($key)); } public function testGetDataWithCacheMissReturnsDefault(): void @@ -91,7 +91,7 @@ public function testGetDataWithCacheMissReturnsDefault(): void $cache = new Psr16($psr16); - self::assertSame($default, $cache->get_data($key, $default)); + $this->assertSame($default, $cache->get_data($key, $default)); } public function testGetDataWithCacheCorruptionReturnsDefault(): void @@ -104,7 +104,7 @@ public function testGetDataWithCacheCorruptionReturnsDefault(): void $cache = new Psr16($psr16); - self::assertSame($default, $cache->get_data($key, $default)); + $this->assertSame($default, $cache->get_data($key, $default)); } public function testGetDataWithInvalidKeyThrowsInvalidArgumentException(): void @@ -137,7 +137,7 @@ public function testDeleteDataReturnsTrueIfDataCouldBeDeleted(): void $cache = new Psr16($psr16); - self::assertTrue($cache->delete_data($key)); + $this->assertTrue($cache->delete_data($key)); } public function testDeleteDataReturnsFalseIfDataCouldNotBeDeleted(): void @@ -149,7 +149,7 @@ public function testDeleteDataReturnsFalseIfDataCouldNotBeDeleted(): void $cache = new Psr16($psr16); - self::assertFalse($cache->delete_data($key)); + $this->assertFalse($cache->delete_data($key)); } public function testDeleteDataWithInvalidKeyThrowsInvalidArgumentException(): void diff --git a/tests/Unit/Cache/RedisTest.php b/tests/Unit/Cache/RedisTest.php index 72c8003e7..3e61d6357 100644 --- a/tests/Unit/Cache/RedisTest.php +++ b/tests/Unit/Cache/RedisTest.php @@ -13,11 +13,11 @@ class RedisTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Cache\Redis')); + $this->assertTrue(class_exists('SimplePie\Cache\Redis')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Cache_Redis')); + $this->assertTrue(class_exists('SimplePie_Cache_Redis')); } } diff --git a/tests/Unit/CacheTest.php b/tests/Unit/CacheTest.php index 8298e5d91..0949afab4 100644 --- a/tests/Unit/CacheTest.php +++ b/tests/Unit/CacheTest.php @@ -13,11 +13,11 @@ class CacheTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Cache')); + $this->assertTrue(class_exists('SimplePie\Cache')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Cache')); + $this->assertTrue(class_exists('SimplePie_Cache')); } } diff --git a/tests/Unit/CaptionTest.php b/tests/Unit/CaptionTest.php index 4ae932484..e4d301bca 100644 --- a/tests/Unit/CaptionTest.php +++ b/tests/Unit/CaptionTest.php @@ -13,11 +13,11 @@ class CaptionTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Caption')); + $this->assertTrue(class_exists('SimplePie\Caption')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Caption')); + $this->assertTrue(class_exists('SimplePie_Caption')); } } diff --git a/tests/Unit/CategoryTest.php b/tests/Unit/CategoryTest.php index a89f61f62..edcee93f6 100644 --- a/tests/Unit/CategoryTest.php +++ b/tests/Unit/CategoryTest.php @@ -16,12 +16,12 @@ class CategoryTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Category')); + $this->assertTrue(class_exists('SimplePie\Category')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Category')); + $this->assertTrue(class_exists('SimplePie_Category')); } /** @@ -387,9 +387,9 @@ public function test_get_label_from_feed_category(string $data, string $expected $feed->init(); $category = $feed->get_category(); - self::assertInstanceOf(Category::class, $category); + $this->assertInstanceOf(Category::class, $category); - self::assertSame($expected, $category->get_label()); + $this->assertSame($expected, $category->get_label()); } /** @@ -815,11 +815,11 @@ public function test_get_label_from_item_category(string $data, string $expected $feed->init(); $item = $feed->get_item(0); - self::assertInstanceOf(Item::class, $item); + $this->assertInstanceOf(Item::class, $item); $category = $item->get_category(); - self::assertInstanceOf(Category::class, $category); + $this->assertInstanceOf(Category::class, $category); - self::assertSame($expected, $category->get_label()); + $this->assertSame($expected, $category->get_label()); } } diff --git a/tests/Unit/Content/Type/SnifferTest.php b/tests/Unit/Content/Type/SnifferTest.php index 1d666ccbf..3d5c65706 100644 --- a/tests/Unit/Content/Type/SnifferTest.php +++ b/tests/Unit/Content/Type/SnifferTest.php @@ -13,11 +13,11 @@ class SnifferTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Content\Type\Sniffer')); + $this->assertTrue(class_exists('SimplePie\Content\Type\Sniffer')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Content_Type_Sniffer')); + $this->assertTrue(class_exists('SimplePie_Content_Type_Sniffer')); } } diff --git a/tests/Unit/CopyrightTest.php b/tests/Unit/CopyrightTest.php index 3dca887d1..5c1805ab9 100644 --- a/tests/Unit/CopyrightTest.php +++ b/tests/Unit/CopyrightTest.php @@ -13,11 +13,11 @@ class CopyrightTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Copyright')); + $this->assertTrue(class_exists('SimplePie\Copyright')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Copyright')); + $this->assertTrue(class_exists('SimplePie_Copyright')); } } diff --git a/tests/Unit/CreditTest.php b/tests/Unit/CreditTest.php index ec20078ec..73d1b677d 100644 --- a/tests/Unit/CreditTest.php +++ b/tests/Unit/CreditTest.php @@ -13,11 +13,11 @@ class CreditTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Credit')); + $this->assertTrue(class_exists('SimplePie\Credit')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Credit')); + $this->assertTrue(class_exists('SimplePie_Credit')); } } diff --git a/tests/Unit/EnclosureTest.php b/tests/Unit/EnclosureTest.php index 29cec789a..4a8eb6106 100644 --- a/tests/Unit/EnclosureTest.php +++ b/tests/Unit/EnclosureTest.php @@ -16,12 +16,12 @@ class EnclosureTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Enclosure')); + $this->assertTrue(class_exists('SimplePie\Enclosure')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Enclosure')); + $this->assertTrue(class_exists('SimplePie_Enclosure')); } /** @@ -35,11 +35,11 @@ public function test_get_link(string $data, string $expected): void $feed->init(); $item = $feed->get_item(0); - self::assertInstanceOf(Item::class, $item); + $this->assertInstanceOf(Item::class, $item); $enclosure = $item->get_enclosure(0); - self::assertInstanceOf(Enclosure::class, $enclosure); - self::assertSame($expected, $enclosure->get_link()); + $this->assertInstanceOf(Enclosure::class, $enclosure); + $this->assertSame($expected, $enclosure->get_link()); } /** @@ -135,8 +135,8 @@ public function test_get_enclosures(string $data, int $expectedEnclosureCount): $feed->init(); $item = $feed->get_item(0); - self::assertInstanceOf(Item::class, $item); - self::assertCount($expectedEnclosureCount, (array) $item->get_enclosures()); + $this->assertInstanceOf(Item::class, $item); + $this->assertCount($expectedEnclosureCount, (array) $item->get_enclosures()); } /** diff --git a/tests/Unit/ExceptionTest.php b/tests/Unit/ExceptionTest.php index 22cd51bcd..6f1c2ef36 100644 --- a/tests/Unit/ExceptionTest.php +++ b/tests/Unit/ExceptionTest.php @@ -13,11 +13,11 @@ class ExceptionTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Exception')); + $this->assertTrue(class_exists('SimplePie\Exception')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Exception')); + $this->assertTrue(class_exists('SimplePie_Exception')); } } diff --git a/tests/Unit/FileTest.php b/tests/Unit/FileTest.php index ea0972aea..cbcca126c 100644 --- a/tests/Unit/FileTest.php +++ b/tests/Unit/FileTest.php @@ -16,18 +16,18 @@ class FileTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\File')); + $this->assertTrue(class_exists('SimplePie\File')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_File')); + $this->assertTrue(class_exists('SimplePie_File')); } public function testFileExtendsResponse(): void { // @phpstan-ignore staticMethod.alreadyNarrowedType - self::assertInstanceOf(Response::class, new FileMock('')); + $this->assertInstanceOf(Response::class, new FileMock('')); } /** @@ -43,7 +43,7 @@ public static function getResponseData(): iterable */ public function testGetRequestedUriReturnsString(File $response): void { - self::assertSame( + $this->assertSame( 'http://example.com/feed', $response->get_final_requested_uri() ); @@ -54,7 +54,7 @@ public function testGetRequestedUriReturnsString(File $response): void */ public function testGetStatusCodeReturnsInt(File $response): void { - self::assertSame( + $this->assertSame( 200, $response->get_status_code() ); @@ -65,7 +65,7 @@ public function testGetStatusCodeReturnsInt(File $response): void */ public function testGetHeadersReturnsArray(File $response): void { - self::assertSame( + $this->assertSame( ['content-type' => ['application/atom+xml']], $response->get_headers() ); @@ -76,7 +76,7 @@ public function testGetHeadersReturnsArray(File $response): void */ public function testHasHeadersReturnsTrue(File $response): void { - self::assertTrue($response->has_header('Content-Type')); + $this->assertTrue($response->has_header('Content-Type')); } /** @@ -84,7 +84,7 @@ public function testHasHeadersReturnsTrue(File $response): void */ public function testHasHeadersReturnsFalse(File $response): void { - self::assertFalse($response->has_header('X-Custom-Header')); + $this->assertFalse($response->has_header('X-Custom-Header')); } /** @@ -92,7 +92,7 @@ public function testHasHeadersReturnsFalse(File $response): void */ public function testGetHeaderReturnsArray(File $response): void { - self::assertSame( + $this->assertSame( ['application/atom+xml'], $response->get_header('CONTENT-TYPE') ); @@ -103,7 +103,7 @@ public function testGetHeaderReturnsArray(File $response): void */ public function testGetHeaderReturnsEmptyArray(File $response): void { - self::assertSame( + $this->assertSame( [], $response->get_header('X-Custom-Header') ); @@ -114,7 +114,7 @@ public function testGetHeaderReturnsEmptyArray(File $response): void */ public function testGetHeaderLineReturnsString(File $response): void { - self::assertSame( + $this->assertSame( 'application/atom+xml', $response->get_header_line('content-Type') ); @@ -125,7 +125,7 @@ public function testGetHeaderLineReturnsString(File $response): void */ public function testGetHeaderLineReturnsEmptyString(File $response): void { - self::assertSame( + $this->assertSame( '', $response->get_header_line('X-Custom-Header') ); @@ -136,7 +136,7 @@ public function testGetHeaderLineReturnsEmptyString(File $response): void */ public function testGetBodyContentReturnsString(File $response): void { - self::assertSame( + $this->assertSame( '', $response->get_body_content() ); diff --git a/tests/Unit/GzdecodeTest.php b/tests/Unit/GzdecodeTest.php index cdaabdec4..cc3b10be3 100644 --- a/tests/Unit/GzdecodeTest.php +++ b/tests/Unit/GzdecodeTest.php @@ -13,11 +13,11 @@ class GzdecodeTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Gzdecode')); + $this->assertTrue(class_exists('SimplePie\Gzdecode')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_gzdecode')); + $this->assertTrue(class_exists('SimplePie_gzdecode')); } } diff --git a/tests/Unit/HTTP/ParserTest.php b/tests/Unit/HTTP/ParserTest.php index 616b25d22..45a149921 100644 --- a/tests/Unit/HTTP/ParserTest.php +++ b/tests/Unit/HTTP/ParserTest.php @@ -14,12 +14,12 @@ class ParserTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\HTTP\Parser')); + $this->assertTrue(class_exists('SimplePie\HTTP\Parser')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_HTTP_Parser')); + $this->assertTrue(class_exists('SimplePie_HTTP_Parser')); } /** @@ -51,12 +51,12 @@ public function testChunkedNormal(string $data, string $expected): void $data = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n" . $data; $data = Parser::prepareHeaders($data); $parser = new Parser($data); - self::assertTrue($parser->parse()); - self::assertSame(1.1, $parser->http_version); - self::assertSame(200, $parser->status_code); - self::assertSame('OK', $parser->reason); - self::assertSame(['content-type' => 'text/plain'], $parser->headers); - self::assertSame($expected, $parser->body); + $this->assertTrue($parser->parse()); + $this->assertSame(1.1, $parser->http_version); + $this->assertSame(200, $parser->status_code); + $this->assertSame('OK', $parser->reason); + $this->assertSame(['content-type' => 'text/plain'], $parser->headers); + $this->assertSame($expected, $parser->body); } /** @@ -67,12 +67,12 @@ public function testChunkedProxy(string $data, string $expected): void $data = "HTTP/1.0 200 Connection established\r\n\r\nHTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n" . $data; $data = Parser::prepareHeaders($data); $parser = new Parser($data); - self::assertTrue($parser->parse()); - self::assertSame(1.1, $parser->http_version); - self::assertSame(200, $parser->status_code); - self::assertSame('OK', $parser->reason); - self::assertSame(['content-type' => 'text/plain'], $parser->headers); - self::assertSame($expected, $parser->body); + $this->assertTrue($parser->parse()); + $this->assertSame(1.1, $parser->http_version); + $this->assertSame(200, $parser->status_code); + $this->assertSame('OK', $parser->reason); + $this->assertSame(['content-type' => 'text/plain'], $parser->headers); + $this->assertSame($expected, $parser->body); } /** @@ -83,12 +83,12 @@ public function testChunkedProxy11(string $data, string $expected): void $data = "HTTP/1.1 200 Connection established\r\n\r\nHTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n" . $data; $data = Parser::prepareHeaders($data); $parser = new Parser($data); - self::assertTrue($parser->parse()); - self::assertSame(1.1, $parser->http_version); - self::assertSame(200, $parser->status_code); - self::assertSame('OK', $parser->reason); - self::assertSame(['content-type' => 'text/plain'], $parser->headers); - self::assertSame($expected, $parser->body); + $this->assertTrue($parser->parse()); + $this->assertSame(1.1, $parser->http_version); + $this->assertSame(200, $parser->status_code); + $this->assertSame('OK', $parser->reason); + $this->assertSame(['content-type' => 'text/plain'], $parser->headers); + $this->assertSame($expected, $parser->body); } public function testDuplicateHeaders(): void @@ -96,8 +96,8 @@ public function testDuplicateHeaders(): void $data = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Security-Policy: default-src 'self' http://example.com\r\nContent-Type: text/plain\r\nContent-Security-Policy: script-src http://example.com/\r\n\r\n"; $data = Parser::prepareHeaders($data); $parser = new Parser($data); - self::assertTrue($parser->parse()); - self::assertSame([ + $this->assertTrue($parser->parse()); + $this->assertSame([ // Later Content-Type takes precedence. 'content-type' => 'text/plain', // This is invalid but we are going to remove the parser eventually. @@ -113,12 +113,12 @@ public function testChunkedNormalPsr7(string $data, string $expected): void $data = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n" . $data; $data = Parser::prepareHeaders($data); $parser = new Parser($data, true); - self::assertTrue($parser->parse()); - self::assertSame(1.1, $parser->http_version); - self::assertSame(200, $parser->status_code); - self::assertSame('OK', $parser->reason); - self::assertSame(['content-type' => ['text/plain']], $parser->headers); - self::assertSame($expected, $parser->body); + $this->assertTrue($parser->parse()); + $this->assertSame(1.1, $parser->http_version); + $this->assertSame(200, $parser->status_code); + $this->assertSame('OK', $parser->reason); + $this->assertSame(['content-type' => ['text/plain']], $parser->headers); + $this->assertSame($expected, $parser->body); } /** @@ -129,12 +129,12 @@ public function testChunkedProxyPsr7(string $data, string $expected): void $data = "HTTP/1.0 200 Connection established\r\n\r\nHTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n" . $data; $data = Parser::prepareHeaders($data); $parser = new Parser($data, true); - self::assertTrue($parser->parse()); - self::assertSame(1.1, $parser->http_version); - self::assertSame(200, $parser->status_code); - self::assertSame('OK', $parser->reason); - self::assertSame(['content-type' => ['text/plain']], $parser->headers); - self::assertSame($expected, $parser->body); + $this->assertTrue($parser->parse()); + $this->assertSame(1.1, $parser->http_version); + $this->assertSame(200, $parser->status_code); + $this->assertSame('OK', $parser->reason); + $this->assertSame(['content-type' => ['text/plain']], $parser->headers); + $this->assertSame($expected, $parser->body); } /** @@ -145,12 +145,12 @@ public function testChunkedProxy11Psr7(string $data, string $expected): void $data = "HTTP/1.1 200 Connection established\r\n\r\nHTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n" . $data; $data = Parser::prepareHeaders($data); $parser = new Parser($data, true); - self::assertTrue($parser->parse()); - self::assertSame(1.1, $parser->http_version); - self::assertSame(200, $parser->status_code); - self::assertSame('OK', $parser->reason); - self::assertSame(['content-type' => ['text/plain']], $parser->headers); - self::assertSame($expected, $parser->body); + $this->assertTrue($parser->parse()); + $this->assertSame(1.1, $parser->http_version); + $this->assertSame(200, $parser->status_code); + $this->assertSame('OK', $parser->reason); + $this->assertSame(['content-type' => ['text/plain']], $parser->headers); + $this->assertSame($expected, $parser->body); } public function testDuplicateHeadersPsr7(): void @@ -158,8 +158,8 @@ public function testDuplicateHeadersPsr7(): void $data = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Security-Policy: default-src 'self' http://example.com\r\nContent-Type: text/plain\r\nContent-Security-Policy: script-src http://example.com/\r\n\r\n"; $data = Parser::prepareHeaders($data); $parser = new Parser($data, true); - self::assertTrue($parser->parse()); - self::assertSame([ + $this->assertTrue($parser->parse()); + $this->assertSame([ // Later Content-Type takes precedence. 'content-type' => ['text/plain'], 'content-security-policy' => ["default-src 'self' http://example.com", 'script-src http://example.com/'], diff --git a/tests/Unit/HTTP/Psr18ClientTest.php b/tests/Unit/HTTP/Psr18ClientTest.php index c43439e13..33711c564 100644 --- a/tests/Unit/HTTP/Psr18ClientTest.php +++ b/tests/Unit/HTTP/Psr18ClientTest.php @@ -28,7 +28,7 @@ public function testRequestReturnsResponse(): void ); // @phpstan-ignore staticMethod.alreadyNarrowedType - self::assertInstanceOf(Response::class, $client->request(Client::METHOD_GET, 'https://example.com/feed.xml')); + $this->assertInstanceOf(Response::class, $client->request(Client::METHOD_GET, 'https://example.com/feed.xml')); } public function testRequestReturnsResponseWithStatusCode429(): void @@ -46,7 +46,7 @@ public function testRequestReturnsResponseWithStatusCode429(): void ); // Make sure no ClientException is thrown on status code 429 - self::assertSame( + $this->assertSame( 429, $client->request(Client::METHOD_GET, 'https://example.com/429-error')->get_status_code() ); @@ -79,7 +79,7 @@ public function testRequestWithRedirectReturnsResponseWithCorrectUrls(): void $response = $client->request(Client::METHOD_GET, 'https://example.com/redirect'); - self::assertSame('https://example.com/redirect', $response->get_permanent_uri()); - self::assertSame('https://example.com/feed.xml', $response->get_final_requested_uri()); + $this->assertSame('https://example.com/redirect', $response->get_permanent_uri()); + $this->assertSame('https://example.com/feed.xml', $response->get_final_requested_uri()); } } diff --git a/tests/Unit/HTTP/Psr7ResponseTest.php b/tests/Unit/HTTP/Psr7ResponseTest.php index 60e895aa7..317882ab0 100644 --- a/tests/Unit/HTTP/Psr7ResponseTest.php +++ b/tests/Unit/HTTP/Psr7ResponseTest.php @@ -18,7 +18,7 @@ class Psr7ResponseTest extends TestCase public function testPsr7ResponseExtendsResponse(): void { // @phpstan-ignore staticMethod.alreadyNarrowedType - self::assertInstanceOf(Response::class, new Psr7Response($this->createMock(ResponseInterface::class), '', '')); + $this->assertInstanceOf(Response::class, new Psr7Response($this->createMock(ResponseInterface::class), '', '')); } public function createPsr7Response(): Psr7Response @@ -54,7 +54,7 @@ public function testGetPermanentUriReturnsString(): void { $response = $this->createPsr7Response(); - self::assertSame( + $this->assertSame( 'https://example.com', $response->get_permanent_uri() ); @@ -64,7 +64,7 @@ public function testGetFinalRequestedUriReturnsString(): void { $response = $this->createPsr7Response(); - self::assertSame( + $this->assertSame( 'https://example.com/feed.xml', $response->get_final_requested_uri() ); @@ -74,7 +74,7 @@ public function testGetStatusCodeReturnsInt(): void { $response = $this->createPsr7Response(); - self::assertSame( + $this->assertSame( 200, $response->get_status_code() ); @@ -84,7 +84,7 @@ public function testGetHeadersReturnsArray(): void { $response = $this->createPsr7Response(); - self::assertSame( + $this->assertSame( ['content-type' => ['application/atom+xml']], $response->get_headers() ); @@ -94,21 +94,21 @@ public function testHasHeadersReturnsTrue(): void { $response = $this->createPsr7Response(); - self::assertTrue($response->has_header('Content-Type')); + $this->assertTrue($response->has_header('Content-Type')); } public function testHasHeadersReturnsFalse(): void { $response = $this->createPsr7Response(); - self::assertFalse($response->has_header('X-Custom-Header')); + $this->assertFalse($response->has_header('X-Custom-Header')); } public function testGetHeaderReturnsArray(): void { $response = $this->createPsr7Response(); - self::assertSame( + $this->assertSame( ['application/atom+xml'], $response->get_header('CONTENT-TYPE') ); @@ -118,7 +118,7 @@ public function testGetHeaderReturnsEmptyArray(): void { $response = $this->createPsr7Response(); - self::assertSame( + $this->assertSame( [], $response->get_header('X-Custom-Header') ); @@ -128,7 +128,7 @@ public function testGetHeaderLineReturnsString(): void { $response = $this->createPsr7Response(); - self::assertSame( + $this->assertSame( 'application/atom+xml', $response->get_header_line('content-Type') ); @@ -138,7 +138,7 @@ public function testGetHeaderLineReturnsEmptyString(): void { $response = $this->createPsr7Response(); - self::assertSame( + $this->assertSame( '', $response->get_header_line('X-Custom-Header') ); @@ -148,7 +148,7 @@ public function testGetBodyContentReturnsString(): void { $response = $this->createPsr7Response(); - self::assertSame( + $this->assertSame( '', $response->get_body_content() ); diff --git a/tests/Unit/IRITest.php b/tests/Unit/IRITest.php index 7a9390f80..dd79f673f 100644 --- a/tests/Unit/IRITest.php +++ b/tests/Unit/IRITest.php @@ -14,12 +14,12 @@ class IRITest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\IRI')); + $this->assertTrue(class_exists('SimplePie\IRI')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_IRI')); + $this->assertTrue(class_exists('SimplePie_IRI')); } /** @@ -82,8 +82,8 @@ public function testStringRFC3986(string $relative, string $expected): void { $base = new IRI('http://a/b/c/d;p?q'); $absolutized = IRI::absolutize($base, $relative); - self::assertNotFalse($absolutized); - self::assertSame($expected, $absolutized->get_iri()); + $this->assertNotFalse($absolutized); + $this->assertSame($expected, $absolutized->get_iri()); } /** @@ -93,7 +93,7 @@ public function testObjectRFC3986(string $relative, string $expected): void { $base = new IRI('http://a/b/c/d;p?q'); $expected = new IRI($expected); - self::assertEquals($expected, IRI::absolutize($base, $relative)); + $this->assertEquals($expected, IRI::absolutize($base, $relative)); } /** @@ -103,9 +103,9 @@ public function testBothStringRFC3986(string $relative, string $expected): void { $base = 'http://a/b/c/d;p?q'; $absolutized = IRI::absolutize($base, $relative); - self::assertNotFalse($absolutized); - self::assertSame($expected, $absolutized->get_iri()); - self::assertSame($expected, (string) IRI::absolutize($base, $relative)); + $this->assertNotFalse($absolutized); + $this->assertSame($expected, $absolutized->get_iri()); + $this->assertSame($expected, (string) IRI::absolutize($base, $relative)); } /** @@ -140,8 +140,8 @@ public function testStringSP(string $base, string $relative, string $expected): { $base = new IRI($base); $absolutized = IRI::absolutize($base, $relative); - self::assertNotFalse($absolutized); - self::assertSame($expected, $absolutized->get_iri()); + $this->assertNotFalse($absolutized); + $this->assertSame($expected, $absolutized->get_iri()); } /** @@ -151,7 +151,7 @@ public function testObjectSP(string $base, string $relative, string $expected): { $base = new IRI($base); $expected = new IRI($expected); - self::assertEquals($expected, IRI::absolutize($base, $relative)); + $this->assertEquals($expected, IRI::absolutize($base, $relative)); } /** @@ -174,7 +174,7 @@ public function testStringQuery(string $query, string $expected): void { $base = new IRI('http://example.com/'); $base->set_query($query); - self::assertSame($expected, $base->get_iri()); + $this->assertSame($expected, $base->get_iri()); } /** @@ -185,7 +185,7 @@ public function testObjectQuery(string $query, string $expected): void $base = new IRI('http://example.com/'); $base->set_query($query); $expected = new IRI($expected); - self::assertEquals($expected, $base); + $this->assertEquals($expected, $base); } /** @@ -206,8 +206,8 @@ public function testAbsolutizeString(string $base, string $relative, string $exp { $base = new IRI($base); $absolutized = IRI::absolutize($base, $relative); - self::assertNotFalse($absolutized); - self::assertSame($expected, $absolutized->get_iri()); + $this->assertNotFalse($absolutized); + $this->assertSame($expected, $absolutized->get_iri()); } /** @@ -217,7 +217,7 @@ public function testAbsolutizeObject(string $base, string $relative, string $exp { $base = new IRI($base); $expected = new IRI($expected); - self::assertEquals($expected, IRI::absolutize($base, $relative)); + $this->assertEquals($expected, IRI::absolutize($base, $relative)); } /** @@ -312,7 +312,7 @@ public static function normalizationDataProvider(): array public function testStringNormalization(string $input, string $output): void { $input = new IRI($input); - self::assertSame($output, $input->get_iri()); + $this->assertSame($output, $input->get_iri()); } /** @@ -322,7 +322,7 @@ public function testObjectNormalization(string $input, string $output): void { $input = new IRI($input); $output = new IRI($output); - self::assertEquals($output, $input); + $this->assertEquals($output, $input); } /** @@ -343,7 +343,7 @@ public static function uriDataProvider(): array public function testURIConversion(string $input, string $output): void { $input = new IRI($input); - self::assertSame($output, $input->get_uri()); + $this->assertSame($output, $input->get_uri()); } /** @@ -363,7 +363,7 @@ public function testObjectEquivalence(string $input, string $output): void { $input = new IRI($input); $output = new IRI($output); - self::assertEquals($output, $input); + $this->assertEquals($output, $input); } /** @@ -383,12 +383,12 @@ public function testObjectNotEquivalence(string $input, string $output): void { $input = new IRI($input); $output = new IRI($output); - self::assertNotEquals($output, $input); + $this->assertNotEquals($output, $input); } public function testInvalidAbsolutizeBase(): void { - self::assertFalse(IRI::absolutize('://not a URL', '../')); + $this->assertFalse(IRI::absolutize('://not a URL', '../')); } public function testInvalidPathNoHost(): void @@ -396,21 +396,21 @@ public function testInvalidPathNoHost(): void $iri = new IRI(); $iri->scheme = 'http'; $iri->path = '//test'; - self::assertFalse($iri->is_valid()); + $this->assertFalse($iri->is_valid()); } public function testInvalidRelativePathContainsColon(): void { $iri = new IRI(); $iri->path = '/test:/'; - self::assertFalse($iri->is_valid()); + $this->assertFalse($iri->is_valid()); } public function testValidRelativePathContainsColon(): void { $iri = new IRI(); $iri->path = '/test/:'; - self::assertTrue($iri->is_valid()); + $this->assertTrue($iri->is_valid()); } public function testFullGamut(): void @@ -422,12 +422,12 @@ public function testFullGamut(): void $iri->path = '/test/'; $iri->fragment = 'test'; - self::assertSame('http', $iri->scheme); - self::assertSame('user:password', $iri->userinfo); - self::assertSame('example.com', $iri->host); - self::assertSame(80, $iri->port); - self::assertSame('/test/', $iri->path); - self::assertSame('test', $iri->fragment); + $this->assertSame('http', $iri->scheme); + $this->assertSame('user:password', $iri->userinfo); + $this->assertSame('example.com', $iri->host); + $this->assertSame(80, $iri->port); + $this->assertSame('/test/', $iri->path); + $this->assertSame('test', $iri->fragment); } public function testReadAliased(): void @@ -439,12 +439,12 @@ public function testReadAliased(): void $iri->path = '/test/'; $iri->fragment = 'test'; - self::assertSame('http', $iri->scheme); - self::assertSame('user:password', $iri->userinfo); - self::assertSame('example.com', $iri->host); - self::assertSame(80, $iri->port); - self::assertSame('/test/', $iri->path); - self::assertSame('test', $iri->fragment); + $this->assertSame('http', $iri->scheme); + $this->assertSame('user:password', $iri->userinfo); + $this->assertSame('example.com', $iri->host); + $this->assertSame(80, $iri->port); + $this->assertSame('/test/', $iri->path); + $this->assertSame('test', $iri->fragment); } public function testWriteAliased(): void @@ -456,23 +456,23 @@ public function testWriteAliased(): void $iri->path = '/test/'; $iri->fragment = 'test'; - self::assertSame('http', $iri->scheme); - self::assertSame('user:password', $iri->userinfo); - self::assertSame('example.com', $iri->host); - self::assertSame(80, $iri->port); - self::assertSame('/test/', $iri->path); - self::assertSame('test', $iri->fragment); + $this->assertSame('http', $iri->scheme); + $this->assertSame('user:password', $iri->userinfo); + $this->assertSame('example.com', $iri->host); + $this->assertSame(80, $iri->port); + $this->assertSame('/test/', $iri->path); + $this->assertSame('test', $iri->fragment); } public function testNonexistentProperty(): void { $iri = new IRI(); - self::assertFalse(isset($iri->nonexistent_prop)); + $this->assertFalse(isset($iri->nonexistent_prop)); // PHPUnit 10 compatible way to test trigger_error(). set_error_handler( function ($errno, $errstr): bool { - self::assertSame( + $this->assertSame( 'Undefined property: SimplePie\IRI::nonexistent_prop', $errstr ); @@ -492,8 +492,8 @@ public function testBlankHost(): void $iri = new IRI('http://example.com/a/?b=c#d'); $iri->host = null; - self::assertNull($iri->host); - self::assertSame('http:/a/?b=c#d', (string) $iri); + $this->assertNull($iri->host); + $this->assertSame('http:/a/?b=c#d', (string) $iri); } public function testBadPort(): void @@ -501,6 +501,6 @@ public function testBadPort(): void $iri = new IRI(); $iri->port = 'example'; - self::assertNull($iri->port); + $this->assertNull($iri->port); } } diff --git a/tests/Unit/ItemTest.php b/tests/Unit/ItemTest.php index 589c65698..20c87d181 100644 --- a/tests/Unit/ItemTest.php +++ b/tests/Unit/ItemTest.php @@ -15,12 +15,12 @@ class ItemTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Item')); + $this->assertTrue(class_exists('SimplePie\Item')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Item')); + $this->assertTrue(class_exists('SimplePie_Item')); } /** @@ -657,9 +657,9 @@ public function test_get_content(string $data, string $expected): void $feed->init(); $item = $feed->get_item(0); - self::assertInstanceOf(Item::class, $item); + $this->assertInstanceOf(Item::class, $item); - self::assertSame($expected, $item->get_content()); + $this->assertSame($expected, $item->get_content()); } /** @@ -1332,9 +1332,9 @@ public function test_get_date(string $data, ?int $expected): void $feed->init(); $item = $feed->get_item(0); - self::assertInstanceOf(Item::class, $item); + $this->assertInstanceOf(Item::class, $item); - self::assertSame($expected, $item->get_date('U')); + $this->assertSame($expected, $item->get_date('U')); } /** @@ -1970,9 +1970,9 @@ public function test_get_description(string $data, string $expected): void $feed->init(); $item = $feed->get_item(0); - self::assertInstanceOf(Item::class, $item); + $this->assertInstanceOf(Item::class, $item); - self::assertSame($expected, $item->get_description()); + $this->assertSame($expected, $item->get_description()); } /** @@ -2374,9 +2374,9 @@ public function test_get_id(string $data, string $expected): void $feed->init(); $item = $feed->get_item(0); - self::assertInstanceOf(Item::class, $item); + $this->assertInstanceOf(Item::class, $item); - self::assertSame($expected, $item->get_id()); + $this->assertSame($expected, $item->get_id()); } /** @@ -2601,9 +2601,9 @@ public function test_get_latitude(string $data, float $expected): void $feed->init(); $item = $feed->get_item(0); - self::assertInstanceOf(Item::class, $item); + $this->assertInstanceOf(Item::class, $item); - self::assertSame($expected, $item->get_latitude()); + $this->assertSame($expected, $item->get_latitude()); } /** @@ -2828,9 +2828,9 @@ public function test_get_longitude(string $data, float $expected): void $feed->init(); $item = $feed->get_item(0); - self::assertInstanceOf(Item::class, $item); + $this->assertInstanceOf(Item::class, $item); - self::assertSame($expected, $item->get_longitude()); + $this->assertSame($expected, $item->get_longitude()); } /** @@ -3353,9 +3353,9 @@ public function test_get_base(string $data, string $expected): void $feed->init(); $item = $feed->get_item(0); - self::assertInstanceOf(Item::class, $item); + $this->assertInstanceOf(Item::class, $item); - self::assertSame($expected, $item->get_content()); + $this->assertSame($expected, $item->get_content()); } /** @@ -3431,9 +3431,9 @@ public function test_get_permalink(string $data, ?string $expected): void $feed->init(); $item = $feed->get_item(0); - self::assertInstanceOf(Item::class, $item); + $this->assertInstanceOf(Item::class, $item); - self::assertSame($expected, $item->get_permalink()); + $this->assertSame($expected, $item->get_permalink()); } /** @@ -4944,9 +4944,9 @@ public function test_get_title(string $data, string $expected): void $feed->init(); $item = $feed->get_item(0); - self::assertInstanceOf(Item::class, $item); + $this->assertInstanceOf(Item::class, $item); - self::assertSame($expected, $item->get_title()); + $this->assertSame($expected, $item->get_title()); } /** @@ -4960,10 +4960,10 @@ public function test_get_thumbnail(string $data, string $expected): void $feed->init(); $item = $feed->get_item(0); - self::assertInstanceOf(Item::class, $item); + $this->assertInstanceOf(Item::class, $item); $thumbnail = $item->get_thumbnail(); - self::assertNotNull($thumbnail); - self::assertSame($expected, $thumbnail['url']); + $this->assertNotNull($thumbnail); + $this->assertSame($expected, $thumbnail['url']); } /** diff --git a/tests/Unit/LocatorTest.php b/tests/Unit/LocatorTest.php index 59c1dda51..d7718f68a 100644 --- a/tests/Unit/LocatorTest.php +++ b/tests/Unit/LocatorTest.php @@ -20,12 +20,12 @@ class LocatorTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Locator')); + $this->assertTrue(class_exists('SimplePie\Locator')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Locator')); + $this->assertTrue(class_exists('SimplePie_Locator')); } /** @@ -57,7 +57,7 @@ public function testAutodiscoverOnFeed(string $mime): void $locator->set_registry($registry); $feed = $locator->find(SimplePie::LOCATOR_ALL, $all); - self::assertSame($data, $feed); + $this->assertSame($data, $feed); } public function testInvalidMIMEType(): void @@ -72,7 +72,7 @@ public function testInvalidMIMEType(): void $locator->set_registry($registry); $feed = $locator->find(SimplePie::LOCATOR_ALL, $all); - self::assertNull($feed); + $this->assertNull($feed); } public function testDirectNoDOM(): void @@ -84,8 +84,8 @@ public function testDirectNoDOM(): void $locator->dom = null; $locator->set_registry($registry); - self::assertTrue($locator->is_feed($data)); - self::assertSame($data, $locator->find(SimplePie::LOCATOR_ALL, $found)); + $this->assertTrue($locator->is_feed($data)); + $this->assertSame($data, $locator->find(SimplePie::LOCATOR_ALL, $found)); } public function testFailDiscoveryNoDOM(): void @@ -101,8 +101,8 @@ public function testFailDiscoveryNoDOM(): void $locator->dom = null; $locator->set_registry($registry); - self::assertFalse($locator->is_feed($data)); - self::assertFalse($locator->find(SimplePie::LOCATOR_ALL, $found)); + $this->assertFalse($locator->is_feed($data)); + $this->assertFalse($locator->find(SimplePie::LOCATOR_ALL, $found)); } /** @@ -149,12 +149,12 @@ public function test_from_file(File $data): void //$expected = SimplePie_Misc::get_element('link', $data->body); $feed = $locator->find(SimplePie::LOCATOR_ALL, $all); - self::assertFalse($locator->is_feed($data), 'HTML document not be a feed itself'); - self::assertInstanceOf(FileMock::class, $feed); + $this->assertFalse($locator->is_feed($data), 'HTML document not be a feed itself'); + $this->assertInstanceOf(FileMock::class, $feed); $success = array_filter($expected, [get_class($this), 'filter_success']); $found = is_array($all) ? array_map([get_class($this), 'map_url_file'], $all) : []; - self::assertSame($success, $found); + $this->assertSame($success, $found); } protected function filter_success(string $url): bool diff --git a/tests/Unit/MiscTest.php b/tests/Unit/MiscTest.php index 769efad3e..32e8e3f98 100644 --- a/tests/Unit/MiscTest.php +++ b/tests/Unit/MiscTest.php @@ -16,24 +16,24 @@ class MiscTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists(Misc::class)); + $this->assertTrue(class_exists(Misc::class)); } public function testClassExists(): void { - self::assertTrue(class_exists(SimplePie_Misc::class)); + $this->assertTrue(class_exists(SimplePie_Misc::class)); } public function test_existence_of_get_element(): void { // BC: make sure that get_element() exists - self::assertSame([], Misc::get_element('', '')); + $this->assertSame([], Misc::get_element('', '')); } public function test_existence_of_entities_decode(): void { // BC: make sure that entities_decode() exists - self::assertSame('', Misc::entities_decode('')); + $this->assertSame('', Misc::entities_decode('')); } /* ## UTF-8 methods */ @@ -67,7 +67,7 @@ public static function utf8DataProvider(): array public function test_convert_UTF8(string $input, string $expected, string $encoding): void { $encoding = Misc::encoding($encoding); - self::assertSameBin2Hex($expected, (string) Misc::change_encoding($input, $encoding, 'UTF-8')); + $this->assertSameBin2Hex($expected, (string) Misc::change_encoding($input, $encoding, 'UTF-8')); } /** @@ -95,7 +95,7 @@ public function test_convert_UTF8_mbstring(string $input, string $expected, stri } $encoding = Misc::encoding($encoding); - self::assertSameBin2Hex($expected, (string) MiscWithPublicStaticMethodsMock::change_encoding_mbstring($input, $encoding, 'UTF-8')); + $this->assertSameBin2Hex($expected, (string) MiscWithPublicStaticMethodsMock::change_encoding_mbstring($input, $encoding, 'UTF-8')); } /** @@ -123,7 +123,7 @@ public function test_convert_UTF8_iconv(string $input, string $expected, string } $encoding = Misc::encoding($encoding); - self::assertSameBin2Hex($expected, (string) MiscWithPublicStaticMethodsMock::change_encoding_iconv($input, $encoding, 'UTF-8')); + $this->assertSameBin2Hex($expected, (string) MiscWithPublicStaticMethodsMock::change_encoding_iconv($input, $encoding, 'UTF-8')); } /** @@ -151,7 +151,7 @@ public function test_convert_UTF8_uconverter(string $input, string $expected, st } $encoding = Misc::encoding($encoding); - self::assertSameBin2Hex($expected, (string) MiscWithPublicStaticMethodsMock::change_encoding_uconverter($input, $encoding, 'UTF-8')); + $this->assertSameBin2Hex($expected, (string) MiscWithPublicStaticMethodsMock::change_encoding_uconverter($input, $encoding, 'UTF-8')); } /* ## UTF-16 methods */ @@ -174,12 +174,12 @@ public static function utf16DataProvider(): array public function test_convert_UTF16(string $input, string $expected, string $encoding): void { $encoding = Misc::encoding($encoding); - self::assertSameBin2Hex($expected, (string) Misc::change_encoding($input, $encoding, 'UTF-16')); + $this->assertSameBin2Hex($expected, (string) Misc::change_encoding($input, $encoding, 'UTF-16')); } public function test_nonexistent(): void { - self::assertFalse(Misc::change_encoding('', 'TESTENC', 'UTF-8')); + $this->assertFalse(Misc::change_encoding('', 'TESTENC', 'UTF-8')); } public function assertSameBin2Hex(string $expected, string $actual, string $message = ''): void @@ -187,7 +187,7 @@ public function assertSameBin2Hex(string $expected, string $actual, string $mess $expected = bin2hex($expected); $actual = bin2hex($actual); - self::assertSame($expected, $actual, $message); + $this->assertSame($expected, $actual, $message); } /** @@ -378,7 +378,7 @@ public function test_absolutize_url_RFC3986(string $relative, string $expected): { $base = 'http://a/b/c/d;p?q'; - self::assertSame( + $this->assertSame( $expected, Misc::absolutize_url($relative, $base) ); @@ -483,7 +483,7 @@ public static function absolutizeUrlBugsDataProvider(): array */ public function test_absolutize_url_bugs(string $base, string $relative, string $expected): void { - self::assertSame( + $this->assertSame( $expected, Misc::absolutize_url($relative, $base) ); @@ -734,7 +734,7 @@ public static function parseDateDataProvider(): array */ public function test_parse_date(string $data, $expected): void { - self::assertSame( + $this->assertSame( $expected, Misc::parse_date($data) ); diff --git a/tests/Unit/Net/IPv6Test.php b/tests/Unit/Net/IPv6Test.php index 6623e4dbd..fbaf65713 100644 --- a/tests/Unit/Net/IPv6Test.php +++ b/tests/Unit/Net/IPv6Test.php @@ -13,11 +13,11 @@ class IPv6Test extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Net\IPv6')); + $this->assertTrue(class_exists('SimplePie\Net\IPv6')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Net_IPv6')); + $this->assertTrue(class_exists('SimplePie_Net_IPv6')); } } diff --git a/tests/Unit/Parse/DateTest.php b/tests/Unit/Parse/DateTest.php index 6a4ab581f..9cbbb42bd 100644 --- a/tests/Unit/Parse/DateTest.php +++ b/tests/Unit/Parse/DateTest.php @@ -14,12 +14,12 @@ class DateTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Parse\Date')); + $this->assertTrue(class_exists('SimplePie\Parse\Date')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Parse_Date')); + $this->assertTrue(class_exists('SimplePie_Parse_Date')); } /** @@ -75,7 +75,7 @@ public static function w3cDtfDatesProvider(): iterable public function testW3cDtf(string $data, int $expected): void { $date = new Date(); - self::assertSame( + $this->assertSame( $expected, $date->date_w3cdtf($data) ); diff --git a/tests/Unit/ParserTest.php b/tests/Unit/ParserTest.php index cee5b4aa4..7e38696bc 100644 --- a/tests/Unit/ParserTest.php +++ b/tests/Unit/ParserTest.php @@ -15,12 +15,12 @@ class ParserTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Parser')); + $this->assertTrue(class_exists('SimplePie\Parser')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Parser')); + $this->assertTrue(class_exists('SimplePie_Parser')); } /** @@ -305,9 +305,9 @@ public function test_parse(string $feed, string $base, array $parsedData): void $result = $parser->parse($feed, 'UTF-8', $base); - self::assertTrue($result); - self::assertSame($parser->get_error_code(), null); - self::assertSame($parser->get_error_string(), null); - self::assertSame($parser->get_data(), $parsedData); + $this->assertTrue($result); + $this->assertSame($parser->get_error_code(), null); + $this->assertSame($parser->get_error_string(), null); + $this->assertSame($parser->get_data(), $parsedData); } } diff --git a/tests/Unit/RatingTest.php b/tests/Unit/RatingTest.php index f449ee333..e2ac5c125 100644 --- a/tests/Unit/RatingTest.php +++ b/tests/Unit/RatingTest.php @@ -13,11 +13,11 @@ class RatingTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Rating')); + $this->assertTrue(class_exists('SimplePie\Rating')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Rating')); + $this->assertTrue(class_exists('SimplePie_Rating')); } } diff --git a/tests/Unit/RegistryTest.php b/tests/Unit/RegistryTest.php index 8af1f257a..fa3be6e7c 100644 --- a/tests/Unit/RegistryTest.php +++ b/tests/Unit/RegistryTest.php @@ -18,12 +18,12 @@ class RegistryTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists(Registry::class)); + $this->assertTrue(class_exists(Registry::class)); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Registry')); + $this->assertTrue(class_exists('SimplePie_Registry')); } /** @@ -37,7 +37,7 @@ public function testGetClassReturnsCorrectClassname(string $type, string $expect { $registry = new Registry(); - self::assertSame($expected, $registry->get_class($type)); + $this->assertSame($expected, $registry->get_class($type)); } /** @@ -104,7 +104,7 @@ public function testRegisterAllowsOverridingTheDefaultClassname(string $register $registry->register($registeredType, $classname); - self::assertSame($classname, $registry->get_class($requestedType)); + $this->assertSame($classname, $registry->get_class($requestedType)); } /** diff --git a/tests/Unit/RestrictionTest.php b/tests/Unit/RestrictionTest.php index 9dfb549c7..f41de484d 100644 --- a/tests/Unit/RestrictionTest.php +++ b/tests/Unit/RestrictionTest.php @@ -17,12 +17,12 @@ class RestrictionTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Restriction')); + $this->assertTrue(class_exists('SimplePie\Restriction')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Restriction')); + $this->assertTrue(class_exists('SimplePie_Restriction')); } /** @@ -86,14 +86,14 @@ public function test_get_relationship(string $data, string $expected): void $feed->init(); $item = $feed->get_item(0); - self::assertInstanceOf(Item::class, $item); + $this->assertInstanceOf(Item::class, $item); $enclosure = $item->get_enclosure(); - self::assertInstanceOf(Enclosure::class, $enclosure); + $this->assertInstanceOf(Enclosure::class, $enclosure); $restriction = $enclosure->get_restriction(); - self::assertInstanceOf(Restriction::class, $restriction); + $this->assertInstanceOf(Restriction::class, $restriction); - self::assertSame($expected, $restriction->get_relationship()); + $this->assertSame($expected, $restriction->get_relationship()); } } diff --git a/tests/Unit/SanitizeTest.php b/tests/Unit/SanitizeTest.php index c22c1e772..2731a81a9 100644 --- a/tests/Unit/SanitizeTest.php +++ b/tests/Unit/SanitizeTest.php @@ -16,19 +16,19 @@ class SanitizeTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Sanitize')); + $this->assertTrue(class_exists('SimplePie\Sanitize')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Sanitize')); + $this->assertTrue(class_exists('SimplePie_Sanitize')); } public function testSanitize(): void { $sanitize = new Sanitize(); - self::assertSame( + $this->assertSame( <<sanitize($given, SIMPLEPIE_CONSTRUCT_HTML, $base)); + $this->assertSame($expected, $sanitize->sanitize($given, SIMPLEPIE_CONSTRUCT_HTML, $base)); } } diff --git a/tests/Unit/SimplePieTest.php b/tests/Unit/SimplePieTest.php index 240423e2c..666606ebd 100644 --- a/tests/Unit/SimplePieTest.php +++ b/tests/Unit/SimplePieTest.php @@ -24,12 +24,12 @@ class SimplePieTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\SimplePie')); + $this->assertTrue(class_exists('SimplePie\SimplePie')); } public function testClassExists(): void { - self::assertTrue(class_exists(SimplePie::class)); + $this->assertTrue(class_exists(SimplePie::class)); } /** @@ -90,7 +90,7 @@ public function testTitleRSS20(string $title, string $expected): void '; $feed = $this->createFeedWithTemplate($data, $title); - self::assertSame($expected, $feed->get_title()); + $this->assertSame($expected, $feed->get_title()); } /** @@ -105,7 +105,7 @@ public function testTitleRSS20WithDC10(string $title, string $expected): void '; $feed = $this->createFeedWithTemplate($data, $title); - self::assertSame($expected, $feed->get_title()); + $this->assertSame($expected, $feed->get_title()); } /** @@ -120,7 +120,7 @@ public function testTitleRSS20WithDC11(string $title, string $expected): void '; $feed = $this->createFeedWithTemplate($data, $title); - self::assertSame($expected, $feed->get_title()); + $this->assertSame($expected, $feed->get_title()); } /** @@ -135,7 +135,7 @@ public function testTitleRSS20WithAtom03(string $title, string $expected): void '; $feed = $this->createFeedWithTemplate($data, $title); - self::assertSame($expected, $feed->get_title()); + $this->assertSame($expected, $feed->get_title()); } /** @@ -150,7 +150,7 @@ public function testTitleRSS20WithAtom10(string $title, string $expected): void '; $feed = $this->createFeedWithTemplate($data, $title); - self::assertSame($expected, $feed->get_title()); + $this->assertSame($expected, $feed->get_title()); } /** @@ -170,7 +170,7 @@ public function testTitleRSS20WithImageTitle(string $title, string $expected): v '; $feed = $this->createFeedWithTemplate($data, $title); - self::assertSame($expected, $feed->get_title()); + $this->assertSame($expected, $feed->get_title()); } /** @@ -190,7 +190,7 @@ public function testTitleRSS20WithImageTitleReversed(string $title, string $expe '; $feed = $this->createFeedWithTemplate($data, $title); - self::assertSame($expected, $feed->get_title()); + $this->assertSame($expected, $feed->get_title()); } public function testItemWithEmptyContent(): void @@ -207,8 +207,8 @@ public function testItemWithEmptyContent(): void $content = 'item description'; $feed = $this->createFeedWithTemplate($data, $content); $item = $feed->get_item(); - self::assertInstanceOf(Item::class, $item); - self::assertSame($content, $item->get_content()); + $this->assertInstanceOf(Item::class, $item); + $this->assertSame($content, $item->get_content()); } public function testSetPsr16Cache(): void @@ -232,7 +232,7 @@ public function testLegacyCallOfSetCacheClass(): void // PHPUnit 10 compatible way to test trigger_error(). set_error_handler( function ($errno, $errstr): bool { - self::assertSame( + $this->assertSame( '"SimplePie\SimplePie::set_cache_class()" is deprecated since SimplePie 1.3, please use "SimplePie\SimplePie::set_cache()" instead.', $errstr ); @@ -281,8 +281,8 @@ public function testDirectOverrideLegacy(): void $feed->init(); - self::assertSame('https://example.com/feed/2019-10-07', $feed->subscribe_url()); - self::assertSame('https://example.com/feed/', $feed->subscribe_url(true)); + $this->assertSame('https://example.com/feed/2019-10-07', $feed->subscribe_url()); + $this->assertSame('https://example.com/feed/', $feed->subscribe_url(true)); } /** @@ -595,7 +595,7 @@ public function test_get_copyright(string $data, string $expected): void $feed->enable_cache(false); $feed->init(); - self::assertSame($expected, $feed->get_copyright()); + $this->assertSame($expected, $feed->get_copyright()); } /** @@ -1006,7 +1006,7 @@ public function test_get_description(string $data, string $expected): void $feed->enable_cache(false); $feed->init(); - self::assertSame($expected, $feed->get_description()); + $this->assertSame($expected, $feed->get_description()); } /** @@ -1303,7 +1303,7 @@ public function test_get_image_height(string $data, ?int $expected): void $feed->enable_cache(false); $feed->init(); - self::assertSame($expected, $feed->get_image_height()); + $this->assertSame($expected, $feed->get_image_height()); } /** @@ -1400,7 +1400,7 @@ public function test_get_image_link(string $data, string $expected): void $feed->enable_cache(false); $feed->init(); - self::assertSame($expected, $feed->get_image_link()); + $this->assertSame($expected, $feed->get_image_link()); } /** @@ -1647,7 +1647,7 @@ public function test_get_image_title(string $data, string $expected): void $feed->enable_cache(false); $feed->init(); - self::assertSame($expected, $feed->get_image_title()); + $this->assertSame($expected, $feed->get_image_title()); } /** @@ -1896,7 +1896,7 @@ public function test_get_image_url(string $data, string $expected): void $feed->enable_cache(false); $feed->init(); - self::assertSame($expected, $feed->get_image_url()); + $this->assertSame($expected, $feed->get_image_url()); } /** @@ -2198,7 +2198,7 @@ public function test_get_image_width(string $data, ?int $expected): void $feed->enable_cache(false); $feed->init(); - self::assertSame($expected, $feed->get_image_width()); + $this->assertSame($expected, $feed->get_image_width()); } /** @@ -2453,7 +2453,7 @@ public function test_get_language(string $data, string $expected): void $feed->enable_cache(false); $feed->init(); - self::assertSame($expected, $feed->get_language()); + $this->assertSame($expected, $feed->get_language()); } /** @@ -2721,7 +2721,7 @@ public function test_get_link(string $data, string $expected): void $feed->enable_cache(false); $feed->init(); - self::assertSame($expected, $feed->get_link()); + $this->assertSame($expected, $feed->get_link()); } /** @@ -3145,6 +3145,6 @@ public function test_get_title(string $data, string $expected): void $feed->enable_cache(false); $feed->init(); - self::assertSame($expected, $feed->get_title()); + $this->assertSame($expected, $feed->get_title()); } } diff --git a/tests/Unit/SourceTest.php b/tests/Unit/SourceTest.php index faaf199c0..edff1e0eb 100644 --- a/tests/Unit/SourceTest.php +++ b/tests/Unit/SourceTest.php @@ -13,11 +13,11 @@ class SourceTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\Source')); + $this->assertTrue(class_exists('SimplePie\Source')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_Source')); + $this->assertTrue(class_exists('SimplePie_Source')); } } diff --git a/tests/Unit/XML/Declaration/ParserTest.php b/tests/Unit/XML/Declaration/ParserTest.php index 223104dd9..5424dcb85 100644 --- a/tests/Unit/XML/Declaration/ParserTest.php +++ b/tests/Unit/XML/Declaration/ParserTest.php @@ -13,11 +13,11 @@ class ParserTest extends TestCase { public function testNamespacedClassExists(): void { - self::assertTrue(class_exists('SimplePie\XML\Declaration\Parser')); + $this->assertTrue(class_exists('SimplePie\XML\Declaration\Parser')); } public function testClassExists(): void { - self::assertTrue(class_exists('SimplePie_XML_Declaration_Parser')); + $this->assertTrue(class_exists('SimplePie_XML_Declaration_Parser')); } } From 41497dd4cf165a52f8d17ed48cfd06c3f6e026d2 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 15 Sep 2025 08:45:08 +0200 Subject: [PATCH 07/13] Fix PHPStan accordingly (will have to be changed back again) --- tests/Integration/HTTP/ClientsTest.php | 2 +- tests/Unit/FileTest.php | 2 +- tests/Unit/HTTP/Psr18ClientTest.php | 2 +- tests/Unit/HTTP/Psr7ResponseTest.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Integration/HTTP/ClientsTest.php b/tests/Integration/HTTP/ClientsTest.php index b088b8cf0..d46714134 100644 --- a/tests/Integration/HTTP/ClientsTest.php +++ b/tests/Integration/HTTP/ClientsTest.php @@ -47,7 +47,7 @@ private function runTestsWithClientGetContentOfLocalFile(Client $client): void $response = $client->request(Client::METHOD_GET, $filepath); - // @phpstan-ignore staticMethod.alreadyNarrowedType + // @phpstan-ignore method.alreadyNarrowedType $this->assertInstanceOf(Response::class, $response); $this->assertSame($filepath, $response->get_permanent_uri()); $this->assertSame($filepath, $response->get_final_requested_uri()); diff --git a/tests/Unit/FileTest.php b/tests/Unit/FileTest.php index cbcca126c..d892068f3 100644 --- a/tests/Unit/FileTest.php +++ b/tests/Unit/FileTest.php @@ -26,7 +26,7 @@ public function testClassExists(): void public function testFileExtendsResponse(): void { - // @phpstan-ignore staticMethod.alreadyNarrowedType + // @phpstan-ignore method.alreadyNarrowedType $this->assertInstanceOf(Response::class, new FileMock('')); } diff --git a/tests/Unit/HTTP/Psr18ClientTest.php b/tests/Unit/HTTP/Psr18ClientTest.php index 33711c564..399c1c5b8 100644 --- a/tests/Unit/HTTP/Psr18ClientTest.php +++ b/tests/Unit/HTTP/Psr18ClientTest.php @@ -27,7 +27,7 @@ public function testRequestReturnsResponse(): void $this->createMock(UriFactoryInterface::class) ); - // @phpstan-ignore staticMethod.alreadyNarrowedType + // @phpstan-ignore method.alreadyNarrowedType $this->assertInstanceOf(Response::class, $client->request(Client::METHOD_GET, 'https://example.com/feed.xml')); } diff --git a/tests/Unit/HTTP/Psr7ResponseTest.php b/tests/Unit/HTTP/Psr7ResponseTest.php index 317882ab0..8d3a16d14 100644 --- a/tests/Unit/HTTP/Psr7ResponseTest.php +++ b/tests/Unit/HTTP/Psr7ResponseTest.php @@ -17,7 +17,7 @@ class Psr7ResponseTest extends TestCase { public function testPsr7ResponseExtendsResponse(): void { - // @phpstan-ignore staticMethod.alreadyNarrowedType + // @phpstan-ignore method.alreadyNarrowedType $this->assertInstanceOf(Response::class, new Psr7Response($this->createMock(ResponseInterface::class), '', '')); } From 926dd9c99f3c57fa35e324ce442fed9e9cfd3295 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 15 Sep 2025 09:01:58 +0200 Subject: [PATCH 08/13] Add PHPStan extension to paths as recommended --- phpstan.dist.neon | 1 + 1 file changed, 1 insertion(+) diff --git a/phpstan.dist.neon b/phpstan.dist.neon index bef3a3254..16b7fb7b8 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -9,6 +9,7 @@ parameters: - library/ - src/ - tests/ + - utils/ excludePaths: analyseAndScan: From 7a24764240b7ab150cbf795029d7647e4429e417 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 22 Sep 2025 09:44:34 +0200 Subject: [PATCH 09/13] Put back memory-limit --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 365a83482..7d07d96e7 100644 --- a/composer.json +++ b/composer.json @@ -70,7 +70,7 @@ "coverage": "phpunit --coverage-html=.phpunit.cache/code-coverage", "cs": "php-cs-fixer fix --verbose --dry-run --diff", "fix": "php-cs-fixer fix --verbose --diff", - "phpstan": "phpstan analyse", + "phpstan": "phpstan analyse --memory-limit 512M", "test": "phpunit" } } From c7b53e1b56c6568ebde8e1413d13e73c1a0580f5 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 22 Sep 2025 13:08:14 +0200 Subject: [PATCH 10/13] Update .github/workflows/ci.yml Co-authored-by: Jan Tojnar --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad0d82a4e..2ea2b77c1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,7 +68,7 @@ jobs: coverage: none tools: none - - name: Remove PHPStan for older PHP + - name: Remove PHPStan for incompatible PHP versions if: ${{ matrix.php < '8.0' }} run: composer remove --dev phpstan/phpstan phpstan/phpstan-phpunit From f1b4405c8e17e1d62b5960401210464cfcc5fb05 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 22 Sep 2025 13:12:24 +0200 Subject: [PATCH 11/13] Revert type check https://github.com/simplepie/simplepie/pull/939/files#r2366447884 --- src/Locator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Locator.php b/src/Locator.php index d2c87739e..30a7fe525 100644 --- a/src/Locator.php +++ b/src/Locator.php @@ -255,7 +255,7 @@ protected function search_elements_by_tag(string $name, array &$done, array $fee } else { $href = $this->registry->call(Misc::class, 'absolutize_url', [trim($link->getAttribute('href')), $this->http_base]); } - if (!is_string($href)) { + if ($href === false) { continue; } From a55448417ecde91084665d36ee72d4ec3f50bbb0 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 25 Nov 2025 15:12:12 +0100 Subject: [PATCH 12/13] Fix PHPStan --- src/Sanitize.php | 6 ++++++ src/SimplePie.php | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Sanitize.php b/src/Sanitize.php index a44b70048..bf22477f9 100644 --- a/src/Sanitize.php +++ b/src/Sanitize.php @@ -655,6 +655,9 @@ protected function strip_tag(string $tag, DOMDocument $document, DOMXPath $xpath if ($this->encode_instead_of_strip) { foreach ($elements as $element) { + if (!($element instanceof \DOMNode)) { + continue; + } $fragment = $document->createDocumentFragment(); // For elements which aren't script or style, include the tag itself @@ -711,6 +714,9 @@ protected function strip_tag(string $tag, DOMDocument $document, DOMXPath $xpath return; } else { foreach ($elements as $element) { + if (!($element instanceof \DOMNode)) { + continue; + } $fragment = $document->createDocumentFragment(); $number = $element->childNodes->length; for ($i = $number; $i > 0; $i--) { diff --git a/src/SimplePie.php b/src/SimplePie.php index a0051d186..897cd5a28 100644 --- a/src/SimplePie.php +++ b/src/SimplePie.php @@ -1709,7 +1709,8 @@ public function init() $single_success = $this->multifeed_objects[$i]->init(); $success |= $single_success; if (!$single_success) { - $this->error[$i] = $this->multifeed_objects[$i]->error(); + $error = $this->multifeed_objects[$i]->error() ?? ''; + $this->error[$i] = is_string($error) ? $error : implode('; ', $error); } $i++; } From a6c25971153ed8feb6a9e1ed8298b655e284ae60 Mon Sep 17 00:00:00 2001 From: Jean Galea <1651502+jgalea@users.noreply.github.com> Date: Tue, 10 Nov 2026 10:29:55 +0000 Subject: [PATCH 13/13] Fix PHPStan 2 after merging master composer.json now requires PHP 7.4, so raise phpVersion.min to match. That also clears the parse_iri() return type, since PHP 7.4 fills trailing unmatched groups with PREG_UNMATCHED_AS_NULL. curlInit() is analysed against the PHP 7 cURL signatures, so type it as a resource and throw if curl_init() fails. Skip CURLOPT_REFERER and CURLOPT_USERAGENT when empty, which sends the same request as setting them to an empty string. --- phpstan.dist.neon | 2 +- src/File.php | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/phpstan.dist.neon b/phpstan.dist.neon index 16b7fb7b8..d3b949821 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -1,6 +1,6 @@ parameters: phpVersion: - min: 70200 # PHP 7.2 + min: 70400 # PHP 7.4 max: 80599 # PHP 8.5 level: 8 diff --git a/src/File.php b/src/File.php index 33b4ff349..4333f2aaa 100644 --- a/src/File.php +++ b/src/File.php @@ -411,7 +411,7 @@ final public static function fromResponse(Response $response): self /** * @param array $headers * @param array $curl_options - * @return \CurlHandle + * @return resource */ private static function curlInit( string $url, @@ -422,6 +422,9 @@ private static function curlInit( bool $setAcceptEncoding = true ) { $fp = curl_init(); + if ($fp === false) { + throw new \SimplePie\Exception('Could not initialize cURL'); + } $headers2 = []; foreach ($headers as $key => $value) { @@ -450,8 +453,13 @@ private static function curlInit( curl_setopt($fp, CURLOPT_FAILONERROR, true); curl_setopt($fp, CURLOPT_TIMEOUT, $timeout); curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, $timeout); - curl_setopt($fp, CURLOPT_REFERER, \SimplePie\Misc::url_remove_credentials($url)); - curl_setopt($fp, CURLOPT_USERAGENT, $useragent); + $referer = \SimplePie\Misc::url_remove_credentials($url); + if ($referer !== '') { + curl_setopt($fp, CURLOPT_REFERER, $referer); + } + if ($useragent !== '') { + curl_setopt($fp, CURLOPT_USERAGENT, $useragent); + } curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2); foreach ($curl_options as $curl_param => $curl_value) { curl_setopt($fp, $curl_param, $curl_value);