From 9ebba8b766a0691ab29eec7020cb1d337cb8cb41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Thu, 29 Dec 2022 11:54:37 +0000 Subject: [PATCH 01/30] Add assertNotContainsSelector return type --- src/MarkupAssertionsTrait.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/MarkupAssertionsTrait.php b/src/MarkupAssertionsTrait.php index 3e5cf1f..257706d 100644 --- a/src/MarkupAssertionsTrait.php +++ b/src/MarkupAssertionsTrait.php @@ -41,6 +41,8 @@ public function assertContainsSelector($selector, $markup = '', $message = '') * @param string $selector A query selector for the element to find. * @param string $markup The output that should not contain the $selector. * @param string $message A message to display if the assertion fails. + * + * @return void */ public function assertNotContainsSelector($selector, $markup = '', $message = '') { From 078d47e871f60f02597f4eb29054fd74c9ad5448 Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Mon, 13 Nov 2023 18:11:12 -0500 Subject: [PATCH 02/30] Add PHP 8.3 to the GitHub Actions test matrix Additionally, update actions/checkout from v2 to v4. --- .github/workflows/unit-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 84df900..ee96b6c 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -8,10 +8,10 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] + php-version: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 From ce31aef1ad28a48182450863d33ebeb6f57bd1aa Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Mon, 13 Nov 2023 19:05:50 -0500 Subject: [PATCH 03/30] Move CONTRIBUTING.md into .github, exclude dev files from the package archive --- CONTRIBUTING.md => .github/CONTRIBUTING.md | 0 .gitignore | 1 + composer.json | 8 ++++++++ 3 files changed, 9 insertions(+) rename CONTRIBUTING.md => .github/CONTRIBUTING.md (100%) diff --git a/CONTRIBUTING.md b/.github/CONTRIBUTING.md similarity index 100% rename from CONTRIBUTING.md rename to .github/CONTRIBUTING.md diff --git a/.gitignore b/.gitignore index bb4f4cb..235ce45 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*.DS_Store tests/coverage vendor .phpunit.result.cache diff --git a/composer.json b/composer.json index a757aca..6122761 100644 --- a/composer.json +++ b/composer.json @@ -46,5 +46,13 @@ "config": { "preferred-install": "dist", "sort-packages": true + }, + "archive": { + "exclude": [ + "_config.yml", + ".*", + "phpunit.*", + "tests" + ] } } From 24f212bb91843284f13de7a7298ca485ce277d83 Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Wed, 15 Nov 2023 20:48:13 -0500 Subject: [PATCH 04/30] Replace laminas/dom with symfony/dom-crawler --- composer.json | 3 ++- src/MarkupAssertionsTrait.php | 16 ++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 6122761..a280d4a 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ }, "require": { "php": "^5.6 || ^7.0 || ^8.0", - "laminas/laminas-dom": "~2.7.2 || ^2.8" + "symfony/css-selector": "^3.4|^4.4|^5.4|^6.0", + "symfony/dom-crawler": "^3.4|^4.4|^5.4|^6.0" }, "require-dev": { "symfony/phpunit-bridge": "^5.2 || ^6.2" diff --git a/src/MarkupAssertionsTrait.php b/src/MarkupAssertionsTrait.php index 257706d..3a80d3a 100644 --- a/src/MarkupAssertionsTrait.php +++ b/src/MarkupAssertionsTrait.php @@ -8,10 +8,8 @@ namespace SteveGrunwell\PHPUnit_Markup_Assertions; -use DOMDocument; -use Laminas\Dom\Document; -use Laminas\Dom\Document\Query; use PHPUnit\Framework\RiskyTestError; +use Symfony\Component\DomCrawler\Crawler; trait MarkupAssertionsTrait { @@ -220,15 +218,13 @@ public function assertElementNotRegExp($regexp, $selector = '', $markup = '', $m * @param string $markup The HTML for the DOMDocument. * @param string $query The DOM selector query. * - * @return \Laminas\Dom\Document\NodeList + * @return Crawler */ protected function executeDomQuery($markup, $query) { - return Query::execute( - $query, - new Document('' . $markup, Document::DOC_HTML, 'UTF-8'), - Query::TYPE_CSS - ); + $dom = new Crawler($markup); + + return $dom->filter($query); } /** @@ -277,7 +273,7 @@ protected function getInnerHtmlOfMatchedElements($markup, $query) // Loop through results and collect their innerHTML values. foreach ($results as $result) { - $document = new DOMDocument(); + $document = new \DOMDocument(); $document->appendChild($document->importNode($result->firstChild, true)); $contents[] = trim(html_entity_decode($document->saveHTML())); From 70103e41b53f6798b47845529999d1c8f1c97b7a Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Wed, 15 Nov 2023 20:48:14 -0500 Subject: [PATCH 05/30] Expand the @param tags for array arguments --- src/MarkupAssertionsTrait.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/MarkupAssertionsTrait.php b/src/MarkupAssertionsTrait.php index 3a80d3a..cde4ecc 100644 --- a/src/MarkupAssertionsTrait.php +++ b/src/MarkupAssertionsTrait.php @@ -73,10 +73,11 @@ public function assertSelectorCount($count, $selector, $markup = '', $message = * * @since 1.0.0 * - * @param array $attributes An array of HTML attributes that should be found on the element. - * @param string $markup The output that should contain an element with the - * provided $attributes. - * @param string $message A message to display if the assertion fails. + * @param array $attributes An array of HTML attributes that should be found + * on the element. + * @param string $markup The output that should contain an element with the + * provided $attributes. + * @param string $message A message to display if the assertion fails. * * @return void */ @@ -94,10 +95,11 @@ public function assertHasElementWithAttributes($attributes = [], $markup = '', $ * * @since 1.0.0 * - * @param array $attributes An array of HTML attributes that should be found on the element. - * @param string $markup The output that should not contain an element with the - * provided $attributes. - * @param string $message A message to display if the assertion fails. + * @param array $attributes An array of HTML attributes that should be found + * on the element. + * @param string $markup The output that should not contain an element with + * the provided $attributes. + * @param string $message A message to display if the assertion fails. * * @return void */ @@ -234,7 +236,7 @@ protected function executeDomQuery($markup, $query) * * @throws RiskyTestError When the $attributes array is empty. * - * @param array $attributes HTML attributes and their values. + * @param array $attributes HTML attributes and their values. * * @return string A XPath attribute query selector. */ From 154d7512e0e1817c960713188efa5fd3efaf9a04 Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Wed, 15 Nov 2023 20:48:14 -0500 Subject: [PATCH 06/30] Change the visibility of the internal methods from protected to private --- src/MarkupAssertionsTrait.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MarkupAssertionsTrait.php b/src/MarkupAssertionsTrait.php index cde4ecc..052cfe0 100644 --- a/src/MarkupAssertionsTrait.php +++ b/src/MarkupAssertionsTrait.php @@ -222,7 +222,7 @@ public function assertElementNotRegExp($regexp, $selector = '', $markup = '', $m * * @return Crawler */ - protected function executeDomQuery($markup, $query) + private function executeDomQuery($markup, $query) { $dom = new Crawler($markup); @@ -240,7 +240,7 @@ protected function executeDomQuery($markup, $query) * * @return string A XPath attribute query selector. */ - protected function flattenAttributeArray(array $attributes) + private function flattenAttributeArray(array $attributes) { if (empty($attributes)) { throw new RiskyTestError('Attributes array is empty.'); @@ -268,7 +268,7 @@ protected function flattenAttributeArray(array $attributes) * * @return string The concatenated innerHTML of any matched selectors. */ - protected function getInnerHtmlOfMatchedElements($markup, $query) + private function getInnerHtmlOfMatchedElements($markup, $query) { $results = $this->executeDomQuery($markup, $query); $contents = []; From 63c1d4dd89c4a8ea64fb751945de50b0a0a3c1cd Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Sat, 2 Dec 2023 14:31:35 -0500 Subject: [PATCH 07/30] Re-enable code coverage reporting to Coveralls --- .github/workflows/code-coverage.yml | 30 +++++++++++++++++++++++++++++ composer.json | 6 +----- 2 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/code-coverage.yml diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml new file mode 100644 index 0000000..0f2b1a5 --- /dev/null +++ b/.github/workflows/code-coverage.yml @@ -0,0 +1,30 @@ +name: Code Coverage + +on: [pull_request] + +jobs: + coverage: + name: Report code coverage + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + coverage: xdebug + + - name: Install Composer dependencies + uses: ramsey/composer-install@v2 + + - name: Run test suite + run: vendor/bin/simple-phpunit --coverage-text --coverage-clover=tests/coverage + + - name: Publish to Coveralls + uses: coverallsapp/github-action@v2 + with: + files: tests/coverage + format: clover + fail-on-error: false diff --git a/composer.json b/composer.json index a280d4a..ce47c79 100644 --- a/composer.json +++ b/composer.json @@ -35,14 +35,10 @@ "scripts": { "test": [ "simple-phpunit --testdox" - ], - "test-coverage": [ - "phpdbg -qrr -d memory_limit=-1 ./vendor/bin/simple-phpunit --coverage-html=tests/coverage --colors=always" ] }, "scripts-descriptions": { - "test": "Run all test suites.", - "test-coverage": "Generate code coverage reports in tests/coverage." + "test": "Run all test suites." }, "config": { "preferred-install": "dist", From 195b8bbffb649b5e83bd19a5cb93636cb98df070 Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Sat, 2 Dec 2023 15:00:19 -0500 Subject: [PATCH 08/30] Restore `composer test-coverage` using Xdebug --- composer.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ce47c79..c704177 100644 --- a/composer.json +++ b/composer.json @@ -35,10 +35,14 @@ "scripts": { "test": [ "simple-phpunit --testdox" + ], + "test-coverage": [ + "XDEBUG_MODE=coverage ./vendor/bin/simple-phpunit --coverage-html=tests/coverage --colors=always" ] }, "scripts-descriptions": { - "test": "Run all test suites." + "test": "Run all test suites.", + "test-coverage": "Generate code coverage reports in tests/coverage." }, "config": { "preferred-install": "dist", From 8a3bfa068262f324ee7a6cbf976898d88c6638ec Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Sat, 2 Dec 2023 15:02:21 -0500 Subject: [PATCH 09/30] Ignore the fallbacks for legacy PHPUnit methods when calculating code coverage --- .gitignore | 4 ++-- src/MarkupAssertionsTrait.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 235ce45..29813da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ *.DS_Store -tests/coverage -vendor .phpunit.result.cache .vscode +tests/coverage +vendor # The composer.lock file is not needed, as this is a library whose dependencies # will depend on the version of PHP being used. diff --git a/src/MarkupAssertionsTrait.php b/src/MarkupAssertionsTrait.php index 052cfe0..14b4906 100644 --- a/src/MarkupAssertionsTrait.php +++ b/src/MarkupAssertionsTrait.php @@ -128,7 +128,7 @@ public function assertElementContains($contents, $selector = '', $markup = '', $ { $method = method_exists($this, 'assertStringContainsString') ? 'assertStringContainsString' - : 'assertContains'; + : 'assertContains'; // @codeCoverageIgnore $this->$method( $contents, @@ -153,7 +153,7 @@ public function assertElementNotContains($contents, $selector = '', $markup = '' { $method = method_exists($this, 'assertStringNotContainsString') ? 'assertStringNotContainsString' - : 'assertNotContains'; + : 'assertNotContains'; // @codeCoverageIgnore $this->$method( $contents, @@ -178,7 +178,7 @@ public function assertElementRegExp($regexp, $selector = '', $markup = '', $mess { $method = method_exists($this, 'assertMatchesRegularExpression') ? 'assertMatchesRegularExpression' - : 'assertRegExp'; + : 'assertRegExp'; // @codeCoverageIgnore $this->$method( $regexp, @@ -203,7 +203,7 @@ public function assertElementNotRegExp($regexp, $selector = '', $markup = '', $m { $method = method_exists($this, 'assertDoesNotMatchRegularExpression') ? 'assertDoesNotMatchRegularExpression' - : 'assertNotRegExp'; + : 'assertNotRegExp'; // @codeCoverageIgnore $this->$method( $regexp, From 30ee8550b57cae561a9863007d3327ef0e8d2a74 Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Sat, 2 Dec 2023 15:03:25 -0500 Subject: [PATCH 10/30] Fix inaccuracy in CONTRIBUTING docs re: running tests --- .github/CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 1c0658b..c581be8 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -44,7 +44,7 @@ This project uses [the PSR-2 coding standards](http://www.php-fig.org/psr/psr-2/ [PHPUnit](https://phpunit.de/) is included as a development dependency, and should be run regularly. When submitting changes, please be sure to add or update unit tests accordingly. You may run unit tests at any time by running: ```bash -$ ./vendor/bin/phpunit +$ composer test ``` #### Code coverage From b2839ff15503f6faf94825167d6ea5f21eac35c5 Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Sat, 2 Dec 2023 15:17:41 -0500 Subject: [PATCH 11/30] Run code coverage when merging into develop and/or main --- .github/workflows/code-coverage.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml index 0f2b1a5..6eee129 100644 --- a/.github/workflows/code-coverage.yml +++ b/.github/workflows/code-coverage.yml @@ -1,6 +1,11 @@ name: Code Coverage -on: [pull_request] +on: + pull_request: + push: + branches: + - develop + - main jobs: coverage: From 452576e519d3e0f1b4c7b98dc4f5fbe642904e0c Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Sat, 2 Dec 2023 15:18:04 -0500 Subject: [PATCH 12/30] Add a code coverage badge to the README file --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 861f893..8915add 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # PHPUnit Markup Assertions ![Build Status](https://github.com/stevegrunwell/phpunit-markup-assertions/workflows/Unit%20Tests/badge.svg) -[![GitHub release](https://img.shields.io/github/release/stevegrunwell/phpunit-markup-assertions.svg)](https://github.com/stevegrunwell/phpunit-markup-assertions/releases) +[![Code Coverage](https://coveralls.io/repos/github/stevegrunwell/phpunit-markup-assertions/badge.svg?branch=develop)](https://coveralls.io/github/stevegrunwell/phpunit-markup-assertions?branch=develop) +[![GitHub Release](https://img.shields.io/github/release/stevegrunwell/phpunit-markup-assertions.svg)](https://github.com/stevegrunwell/phpunit-markup-assertions/releases) This library introduces the `MarkupAssertionsTrait` trait for use in [PHPUnit](https://phpunit.de) tests. From e7559b62651cfe08baa08149ebc1be6267b4ec3b Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Sun, 3 Dec 2023 17:02:26 -0500 Subject: [PATCH 13/30] Add PHP_CodeSniffer for checking coding standards --- .github/workflows/coding-standards.yml | 23 +++++++++++++++++++++++ .phpcs.xml.dist | 24 ++++++++++++++++++++++++ composer.json | 12 +++++++++++- src/MarkupAssertionsTrait.php | 1 + tests/MarkupAssertionsTraitTest.php | 3 ++- 5 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/coding-standards.yml create mode 100644 .phpcs.xml.dist diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml new file mode 100644 index 0000000..68d77bc --- /dev/null +++ b/.github/workflows/coding-standards.yml @@ -0,0 +1,23 @@ +name: Coding Standards + +on: [pull_request] + +jobs: + phpcs: + name: PHP_CodeSniffer + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + coverage: none + + - name: Install Composer dependencies + uses: ramsey/composer-install@v2 + + - name: Run test suite + run: composer coding-standards diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist new file mode 100644 index 0000000..57b3de6 --- /dev/null +++ b/.phpcs.xml.dist @@ -0,0 +1,24 @@ + + + Coding standards for PHPUnit Markup Assertions + + + + + + + . + */vendor/* + + + + + + + tests/* + + + + + + diff --git a/composer.json b/composer.json index c704177..5ce1209 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,9 @@ "symfony/dom-crawler": "^3.4|^4.4|^5.4|^6.0" }, "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "phpcompatibility/php-compatibility": "^9.3", + "phpcsstandards/php_codesniffer": "^3.7", "symfony/phpunit-bridge": "^5.2 || ^6.2" }, "autoload": { @@ -33,6 +36,9 @@ } }, "scripts": { + "coding-standards": [ + "phpcs" + ], "test": [ "simple-phpunit --testdox" ], @@ -41,12 +47,16 @@ ] }, "scripts-descriptions": { + "coding-standards": "Check coding standards.", "test": "Run all test suites.", "test-coverage": "Generate code coverage reports in tests/coverage." }, "config": { "preferred-install": "dist", - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } }, "archive": { "exclude": [ diff --git a/src/MarkupAssertionsTrait.php b/src/MarkupAssertionsTrait.php index 14b4906..59bb6fa 100644 --- a/src/MarkupAssertionsTrait.php +++ b/src/MarkupAssertionsTrait.php @@ -1,4 +1,5 @@ setAccessible(true); From 2d3a4143aaa22e860317a54133bf886c1f25a3a2 Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Mon, 11 Dec 2023 18:42:46 -0500 Subject: [PATCH 14/30] Use squizlabs, not phpcsstandards/php_codesniffer --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5ce1209..59b6172 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "^1.0", "phpcompatibility/php-compatibility": "^9.3", - "phpcsstandards/php_codesniffer": "^3.7", + "squizlabs/php_codesniffer": "^3.7", "symfony/phpunit-bridge": "^5.2 || ^6.2" }, "autoload": { From d45c3308f2577cc44c0b9c763d49424383e2541b Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Mon, 11 Dec 2023 19:47:16 -0500 Subject: [PATCH 15/30] Install Phan for static code analysis --- .github/workflows/static-code-analysis.yml | 23 ++++++++++++++++++++++ .gitignore | 3 +++ composer.json | 5 +++++ phpstan.neon.dist | 7 +++++++ 4 files changed, 38 insertions(+) create mode 100644 .github/workflows/static-code-analysis.yml create mode 100644 phpstan.neon.dist diff --git a/.github/workflows/static-code-analysis.yml b/.github/workflows/static-code-analysis.yml new file mode 100644 index 0000000..38397a9 --- /dev/null +++ b/.github/workflows/static-code-analysis.yml @@ -0,0 +1,23 @@ +name: Static Code Analysis + +on: [pull_request] + +jobs: + phpcs: + name: PHPStan + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + coverage: none + + - name: Install Composer dependencies + uses: ramsey/composer-install@v2 + + - name: Run PHPStan + run: composer static-analysis diff --git a/.gitignore b/.gitignore index 29813da..415274e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ *.DS_Store .phpunit.result.cache .vscode +phpcs.xml +phpstan.neon +phpunit.xml tests/coverage vendor diff --git a/composer.json b/composer.json index 59b6172..0e10181 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,7 @@ "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "^1.0", "phpcompatibility/php-compatibility": "^9.3", + "phpstan/phpstan": "^1.10", "squizlabs/php_codesniffer": "^3.7", "symfony/phpunit-bridge": "^5.2 || ^6.2" }, @@ -39,6 +40,9 @@ "coding-standards": [ "phpcs" ], + "static-analysis": [ + "phpstan analyse" + ], "test": [ "simple-phpunit --testdox" ], @@ -48,6 +52,7 @@ }, "scripts-descriptions": { "coding-standards": "Check coding standards.", + "static-analysis": "Run static code analysis", "test": "Run all test suites.", "test-coverage": "Generate code coverage reports in tests/coverage." }, diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..b980ecc --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,7 @@ +parameters: + level: 6 + paths: + - src + - tests + excludePaths: + - tests/coverage From b8181b5f7d9d2497366cb888b71ca245cd5ea829 Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Mon, 11 Dec 2023 19:55:26 -0500 Subject: [PATCH 16/30] Remove PHPStan as a dev dependency when running PHPUnit --- .github/workflows/unit-tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index ee96b6c..e6f3aea 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -19,6 +19,9 @@ jobs: php-version: ${{ matrix.php-version }} coverage: none + - name: Remove PHPStan as a dependency + run: composer remove --dev phpstan/phpstan + - name: Install Composer dependencies uses: ramsey/composer-install@v2 From 9e2247e12e28155e0a37dd2567e0a13cef451e8e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Dec 2023 10:28:49 +0000 Subject: [PATCH 17/30] Update symfony/phpunit-bridge requirement from ^5.2 || ^6.2 to ^5.2 || ^6.2 || ^7.0 Updates the requirements on [symfony/phpunit-bridge](https://github.com/symfony/phpunit-bridge) to permit the latest version. - [Release notes](https://github.com/symfony/phpunit-bridge/releases) - [Changelog](https://github.com/symfony/phpunit-bridge/blob/6.3/CHANGELOG.md) - [Commits](https://github.com/symfony/phpunit-bridge/commits/v7.0.1) --- updated-dependencies: - dependency-name: symfony/phpunit-bridge dependency-type: direct:development ... Signed-off-by: dependabot[bot] --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0e10181..27be0dc 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "phpcompatibility/php-compatibility": "^9.3", "phpstan/phpstan": "^1.10", "squizlabs/php_codesniffer": "^3.7", - "symfony/phpunit-bridge": "^5.2 || ^6.2" + "symfony/phpunit-bridge": "^5.2 || ^6.2 || ^7.0" }, "autoload": { "psr-4": { From 13318e54387b2be35deb04312c21eb1bfce82824 Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Thu, 10 Jul 2025 17:48:48 -0400 Subject: [PATCH 18/30] Remove PHP 5.x from composer.json, GitHub Actions --- .github/workflows/unit-tests.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index e6f3aea..3435a7c 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] + php-version: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] steps: - name: Checkout uses: actions/checkout@v4 diff --git a/composer.json b/composer.json index 27be0dc..2a98380 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "source": "https://github.com/stevegrunwell/phpunit-markup-assertions/" }, "require": { - "php": "^5.6 || ^7.0 || ^8.0", + "php": "^7.0 || ^8.0", "symfony/css-selector": "^3.4|^4.4|^5.4|^6.0", "symfony/dom-crawler": "^3.4|^4.4|^5.4|^6.0" }, From fead4597be845cb0d113f4bff87d3c69a1af0f2e Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Thu, 10 Jul 2025 17:52:16 -0400 Subject: [PATCH 19/30] Add return typehints, missing docblocks to the test class --- tests/MarkupAssertionsTraitTest.php | 50 ++++++++++++++++------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/tests/MarkupAssertionsTraitTest.php b/tests/MarkupAssertionsTraitTest.php index 0cacc7f..bee0a6c 100644 --- a/tests/MarkupAssertionsTraitTest.php +++ b/tests/MarkupAssertionsTraitTest.php @@ -19,7 +19,7 @@ class MarkupAssertionsTraitTest extends TestCase * @testdox assertContainsSelector() should find matching selectors * @dataProvider provideSelectorVariants */ - public function assertContainsSelector_should_find_matching_selectors($selector) + public function assertContainsSelector_should_find_matching_selectors(string $selector): void { $this->assertContainsSelector( $selector, @@ -31,7 +31,7 @@ public function assertContainsSelector_should_find_matching_selectors($selector) * @test * @testdox assertContainsSelector() should pick up multiple instances of a selector */ - public function assertContainsSelector_should_pick_up_multiple_instances() + public function assertContainsSelector_should_pick_up_multiple_instances(): void { $this->assertContainsSelector( 'a', @@ -44,7 +44,7 @@ public function assertContainsSelector_should_pick_up_multiple_instances() * @testdox assertNotContainsSelector() should verify that the given selector does not exist * @dataProvider provideSelectorVariants */ - public function assertNotContainsSelector_should_verify_that_the_given_selector_does_not_exist($selector) + public function assertNotContainsSelector_should_verify_that_the_given_selector_does_not_exist(string $selector): void { $this->assertNotContainsSelector( $selector, @@ -56,7 +56,7 @@ public function assertNotContainsSelector_should_verify_that_the_given_selector_ * @test * @testdox assertSelectorCount() should count the instances of a selector */ - public function assertSelectorCount_should_count_the_number_of_instances() + public function assertSelectorCount_should_count_the_number_of_instances(): void { $this->assertSelectorCount( 3, @@ -69,7 +69,7 @@ public function assertSelectorCount_should_count_the_number_of_instances() * @test * @testdox assertHasElementWithAttributes() should find an element with the given attributes */ - public function assertHasElementWithAttributes_should_find_elements_with_matching_attributes() + public function assertHasElementWithAttributes_should_find_elements_with_matching_attributes(): void { $this->assertHasElementWithAttributes( [ @@ -85,7 +85,7 @@ public function assertHasElementWithAttributes_should_find_elements_with_matchin * @testdox assertHasElementWithAttributes() should be able to parse spaces in attribute values * @ticket https://github.com/stevegrunwell/phpunit-markup-assertions/issues/13 */ - public function assertHasElementWithAttributes_should_be_able_to_handle_spaces() + public function assertHasElementWithAttributes_should_be_able_to_handle_spaces(): void { $this->assertHasElementWithAttributes( [ @@ -99,7 +99,7 @@ public function assertHasElementWithAttributes_should_be_able_to_handle_spaces() * @test * @testdox assertNotHasElementWithAttributes() should ensure no element has the provided attributes */ - public function assertNotHasElementWithAttributes_should_find_no_elements_with_matching_attributes() + public function assertNotHasElementWithAttributes_should_find_no_elements_with_matching_attributes(): void { $this->assertNotHasElementWithAttributes( [ @@ -114,7 +114,7 @@ public function assertNotHasElementWithAttributes_should_find_no_elements_with_m * @test * @testdox assertElementContains() should be able to search for a selector */ - public function assertElementContains_can_match_a_selector() + public function assertElementContains_can_match_a_selector(): void { $this->assertElementContains( 'ipsum', @@ -127,7 +127,7 @@ public function assertElementContains_can_match_a_selector() * @test * @testdox assertElementContains() should be able to chain multiple selectors */ - public function assertElementContains_can_chain_multiple_selectors() + public function assertElementContains_can_chain_multiple_selectors(): void { $this->assertElementContains( 'ipsum', @@ -140,7 +140,7 @@ public function assertElementContains_can_chain_multiple_selectors() * @test * @testdox assertElementContains() should scope text to the selected element */ - public function assertElementContains_should_scope_matches_to_selector() + public function assertElementContains_should_scope_matches_to_selector(): void { $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('The #main div does not contain the string "ipsum".'); @@ -159,7 +159,7 @@ public function assertElementContains_should_scope_matches_to_selector() * @dataProvider provideGreetingsInDifferentLanguages * @ticket https://github.com/stevegrunwell/phpunit-markup-assertions/issues/31 */ - public function assertElementContains_should_handle_various_character_sets($greeting) + public function assertElementContains_should_handle_various_character_sets(string $greeting): void { $this->assertElementContains( $greeting, @@ -172,7 +172,7 @@ public function assertElementContains_should_handle_various_character_sets($gree * @test * @testdox assertElementNotContains() should be able to search for a selector */ - public function assertElementNotContains_can_match_a_selector() + public function assertElementNotContains_can_match_a_selector(): void { $this->assertElementNotContains( 'ipsum', @@ -187,7 +187,7 @@ public function assertElementNotContains_can_match_a_selector() * @dataProvider provideGreetingsInDifferentLanguages * @ticket https://github.com/stevegrunwell/phpunit-markup-assertions/issues/31 */ - public function assertElementNotContains_should_handle_various_character_sets($greeting) + public function assertElementNotContains_should_handle_various_character_sets(string $greeting): void { $this->assertElementNotContains( $greeting, @@ -200,7 +200,7 @@ public function assertElementNotContains_should_handle_various_character_sets($g * @test * @testdox assertElementRegExp() should use regular expression matching */ - public function assertElementRegExp_should_use_regular_expression_matching() + public function assertElementRegExp_should_use_regular_expression_matching(): void { $this->assertElementRegExp( '/[A-Z0-9-]+/', @@ -213,7 +213,7 @@ public function assertElementRegExp_should_use_regular_expression_matching() * @test * @testdox assertElementRegExp() should be able to search for nested contents */ - public function assertElementRegExp_should_be_able_to_match_nested_contents() + public function assertElementRegExp_should_be_able_to_match_nested_contents(): void { $this->assertElementRegExp( '/[A-Z]+/', @@ -226,7 +226,7 @@ public function assertElementRegExp_should_be_able_to_match_nested_contents() * @test * @testdox assertElementNotRegExp() should use regular expression matching */ - public function testAssertElementNotRegExp() + public function testAssertElementNotRegExp(): void { $this->assertElementNotRegExp( '/[0-9-]+/', @@ -240,8 +240,10 @@ public function testAssertElementNotRegExp() * @test * @testdox flattenAttributeArray() should flatten an array of attributes * @dataProvider provideAttributes + * + * @param array $attributes */ - public function flattenArrayAttribute_should_flatten_arrays_of_attributes($attributes, $expected) + public function flattenArrayAttribute_should_flatten_arrays_of_attributes(array $attributes, string $expected): void { $method = new \ReflectionMethod($this, 'flattenAttributeArray'); $method->setAccessible(true); @@ -254,7 +256,7 @@ public function flattenArrayAttribute_should_flatten_arrays_of_attributes($attri * @testdox flattenAttributeArray() should throw a RiskyTestError if the array is empty * @dataProvider provideAttributes */ - public function flattenAttributeArray_should_throw_a_RiskyTestError_if_given_an_empty_array() + public function flattenAttributeArray_should_throw_a_RiskyTestError_if_given_an_empty_array(): void { $this->expectException(RiskyTestError::class); @@ -268,7 +270,7 @@ public function flattenAttributeArray_should_throw_a_RiskyTestError_if_given_an_ * @testdox getInnerHtmlOfMatchedElements() should retrieve the inner HTML * @dataProvider provideInnerHtml */ - public function getInnerHtmlOfMatchedElements_should_retrieve_the_inner_HTML($markup, $selector, $expected) + public function getInnerHtmlOfMatchedElements_should_retrieve_the_inner_HTML(string $markup, string $selector, string $expected): void { $method = new \ReflectionMethod($this, 'getInnerHtmlOfMatchedElements'); $method->setAccessible(true); @@ -278,8 +280,10 @@ public function getInnerHtmlOfMatchedElements_should_retrieve_the_inner_HTML($ma /** * Data provider for testFlattenAttributeArray(). + * + * @return array,string}> */ - public function provideAttributes() + public function provideAttributes(): array { return [ 'Single attribute' => [ @@ -321,7 +325,7 @@ public function provideAttributes() * * @return array> */ - public function provideInnerHtml() + public function provideInnerHtml(): array { return [ 'A single match' => [ @@ -347,7 +351,7 @@ public function provideInnerHtml() * * @return array> */ - public function provideSelectorVariants() + public function provideSelectorVariants(): array { return [ 'Simple tag name' => ['a'], @@ -365,7 +369,7 @@ public function provideSelectorVariants() * * @return array> */ - public function provideGreetingsInDifferentLanguages() + public function provideGreetingsInDifferentLanguages(): array { return [ 'Arabic' => ['مرحبا!'], From 72daef6dfbf92bdad505c57adb72e7d3a15988e2 Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Thu, 10 Jul 2025 18:01:06 -0400 Subject: [PATCH 20/30] Add PHP 8.4 to the unit test matrix --- .github/workflows/unit-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 3435a7c..f64fddf 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] + php-version: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] steps: - name: Checkout uses: actions/checkout@v4 From e04ac94a3bad253d6265d651c5f6fa5aecfcc916 Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Thu, 10 Jul 2025 18:12:32 -0400 Subject: [PATCH 21/30] Drop PHP 7.0 as well, since it doesn't support the void typehint --- .github/workflows/unit-tests.yml | 2 +- .phpcs.xml.dist | 2 +- composer.json | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index f64fddf..0ec9256 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] + php-version: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 57b3de6..4b4510d 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -20,5 +20,5 @@ - + diff --git a/composer.json b/composer.json index 2a98380..2979148 100644 --- a/composer.json +++ b/composer.json @@ -15,9 +15,9 @@ "source": "https://github.com/stevegrunwell/phpunit-markup-assertions/" }, "require": { - "php": "^7.0 || ^8.0", - "symfony/css-selector": "^3.4|^4.4|^5.4|^6.0", - "symfony/dom-crawler": "^3.4|^4.4|^5.4|^6.0" + "php": "^7.1 || ^8.0", + "symfony/css-selector": "^4.4|^5.4|^6.0", + "symfony/dom-crawler": "^4.4|^5.4|^6.0" }, "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "^1.0", From 169fb0742a68acfec06f4c3b7314ed6bca183722 Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Thu, 10 Jul 2025 18:13:00 -0400 Subject: [PATCH 22/30] Ensure that PHPUnit exists before running PHPStan in GitHub Actions --- .github/workflows/static-code-analysis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/static-code-analysis.yml b/.github/workflows/static-code-analysis.yml index 38397a9..745f15f 100644 --- a/.github/workflows/static-code-analysis.yml +++ b/.github/workflows/static-code-analysis.yml @@ -19,5 +19,10 @@ jobs: - name: Install Composer dependencies uses: ramsey/composer-install@v2 + # PHPUnit Bridge won't install a version of PHPUnit by default, but this will trick + # it into doing so. + - name: Install PHPUnit + run: composer test -- --version + - name: Run PHPStan run: composer static-analysis From 8d1e26ff0a22e3e675008742b91bbe6ab777a21e Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Thu, 10 Jul 2025 18:13:29 -0400 Subject: [PATCH 23/30] Formatting, empty() check to satisfy PHP_CodeSniffer and PHPStan --- src/MarkupAssertionsTrait.php | 2 +- tests/MarkupAssertionsTraitTest.php | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/MarkupAssertionsTrait.php b/src/MarkupAssertionsTrait.php index 59bb6fa..c580bc8 100644 --- a/src/MarkupAssertionsTrait.php +++ b/src/MarkupAssertionsTrait.php @@ -249,7 +249,7 @@ private function flattenAttributeArray(array $attributes) array_walk($attributes, function (&$value, $key) { // Boolean attributes. - if (null === $value) { + if (empty($value)) { $value = sprintf('[%s]', $key); } else { $value = sprintf('[%s="%s"]', $key, htmlspecialchars($value)); diff --git a/tests/MarkupAssertionsTraitTest.php b/tests/MarkupAssertionsTraitTest.php index bee0a6c..642927d 100644 --- a/tests/MarkupAssertionsTraitTest.php +++ b/tests/MarkupAssertionsTraitTest.php @@ -44,8 +44,9 @@ public function assertContainsSelector_should_pick_up_multiple_instances(): void * @testdox assertNotContainsSelector() should verify that the given selector does not exist * @dataProvider provideSelectorVariants */ - public function assertNotContainsSelector_should_verify_that_the_given_selector_does_not_exist(string $selector): void - { + public function assertNotContainsSelector_should_verify_that_the_given_selector_does_not_exist( + string $selector + ): void { $this->assertNotContainsSelector( $selector, '

This element has little to do with the link.

' @@ -270,8 +271,11 @@ public function flattenAttributeArray_should_throw_a_RiskyTestError_if_given_an_ * @testdox getInnerHtmlOfMatchedElements() should retrieve the inner HTML * @dataProvider provideInnerHtml */ - public function getInnerHtmlOfMatchedElements_should_retrieve_the_inner_HTML(string $markup, string $selector, string $expected): void - { + public function getInnerHtmlOfMatchedElements_should_retrieve_the_inner_HTML( + string $markup, + string $selector, + string $expected + ): void { $method = new \ReflectionMethod($this, 'getInnerHtmlOfMatchedElements'); $method->setAccessible(true); From 2c1e04655ade862021af8da501277110313002e1 Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Thu, 10 Jul 2025 18:23:26 -0400 Subject: [PATCH 24/30] Permit the 7.x branches of symfony/css-selector, symfony/dom-crawler --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 2979148..6ef589f 100644 --- a/composer.json +++ b/composer.json @@ -16,8 +16,8 @@ }, "require": { "php": "^7.1 || ^8.0", - "symfony/css-selector": "^4.4|^5.4|^6.0", - "symfony/dom-crawler": "^4.4|^5.4|^6.0" + "symfony/css-selector": "^4.4|^5.4|^6.0|^7.0", + "symfony/dom-crawler": "^4.4|^5.4|^6.0|^7.0" }, "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "^1.0", From f038f0afd8cecdc04f5d8f6dd5b2abbd95cd04b9 Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Thu, 10 Jul 2025 18:50:16 -0400 Subject: [PATCH 25/30] Require PHPStan 2.1 or newer --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2979148..f62c52d 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "^1.0", "phpcompatibility/php-compatibility": "^9.3", - "phpstan/phpstan": "^1.10", + "phpstan/phpstan": "^2.1", "squizlabs/php_codesniffer": "^3.7", "symfony/phpunit-bridge": "^5.2 || ^6.2 || ^7.0" }, From 919eb56c727bee7666d9a0754820864cbbdc0d2b Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Thu, 10 Jul 2025 18:52:17 -0400 Subject: [PATCH 26/30] Ensure that PHPStan can see PHPUnit Bridge, fix broken docblock in test class --- phpstan.neon.dist | 8 ++++++++ tests/MarkupAssertionsTraitTest.php | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index b980ecc..f7bec5d 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,7 +1,15 @@ parameters: level: 6 + + # Code to be analyzed paths: - src - tests + + # Don't worry about the coverage reports excludePaths: - tests/coverage + + # PHPUnit Bridge puts the PHPUnit source in an unconventional location + scanDirectories: + - vendor/bin/.phpunit/phpunit diff --git a/tests/MarkupAssertionsTraitTest.php b/tests/MarkupAssertionsTraitTest.php index 642927d..2666c8f 100644 --- a/tests/MarkupAssertionsTraitTest.php +++ b/tests/MarkupAssertionsTraitTest.php @@ -285,7 +285,7 @@ public function getInnerHtmlOfMatchedElements_should_retrieve_the_inner_HTML( /** * Data provider for testFlattenAttributeArray(). * - * @return array,string}> + * @return array,string}> */ public function provideAttributes(): array { From 0c957b336367046e4937496a9abd57c24d6bfbf0 Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Thu, 10 Jul 2025 18:53:38 -0400 Subject: [PATCH 27/30] Since we've effectively dropped PHPUnit 6.x and lower from the running, we no longer need to see whether or not assertStringContainsString() is defined --- src/MarkupAssertionsTrait.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/MarkupAssertionsTrait.php b/src/MarkupAssertionsTrait.php index c580bc8..b9b05d9 100644 --- a/src/MarkupAssertionsTrait.php +++ b/src/MarkupAssertionsTrait.php @@ -127,11 +127,7 @@ public function assertNotHasElementWithAttributes($attributes = [], $markup = '' */ public function assertElementContains($contents, $selector = '', $markup = '', $message = '') { - $method = method_exists($this, 'assertStringContainsString') - ? 'assertStringContainsString' - : 'assertContains'; // @codeCoverageIgnore - - $this->$method( + $this->assertStringContainsString( $contents, $this->getInnerHtmlOfMatchedElements($markup, $selector), $message @@ -152,11 +148,7 @@ public function assertElementContains($contents, $selector = '', $markup = '', $ */ public function assertElementNotContains($contents, $selector = '', $markup = '', $message = '') { - $method = method_exists($this, 'assertStringNotContainsString') - ? 'assertStringNotContainsString' - : 'assertNotContains'; // @codeCoverageIgnore - - $this->$method( + $this->assertStringNotContainsString( $contents, $this->getInnerHtmlOfMatchedElements($markup, $selector), $message @@ -177,6 +169,7 @@ public function assertElementNotContains($contents, $selector = '', $markup = '' */ public function assertElementRegExp($regexp, $selector = '', $markup = '', $message = '') { + // @phpstan-ignore function.alreadyNarrowedType (Introduced in PHPUnit 9.x, PHP 7.3+) $method = method_exists($this, 'assertMatchesRegularExpression') ? 'assertMatchesRegularExpression' : 'assertRegExp'; // @codeCoverageIgnore @@ -202,6 +195,7 @@ public function assertElementRegExp($regexp, $selector = '', $markup = '', $mess */ public function assertElementNotRegExp($regexp, $selector = '', $markup = '', $message = '') { + // @phpstan-ignore function.alreadyNarrowedType (Introduced in PHPUnit 9.x, PHP 7.3+) $method = method_exists($this, 'assertDoesNotMatchRegularExpression') ? 'assertDoesNotMatchRegularExpression' : 'assertNotRegExp'; // @codeCoverageIgnore From fd1be074762b3e820523a470f177c257534b9eaa Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Thu, 10 Jul 2025 18:57:59 -0400 Subject: [PATCH 28/30] Fix an outdated comment in the PHP_CodeSniffer config --- .phpcs.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 4b4510d..df2db46 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -18,7 +18,7 @@ tests/*
- + From c77a031704b2f103daa596ba24bff13fbb43bdaa Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Thu, 10 Jul 2025 18:58:28 -0400 Subject: [PATCH 29/30] =?UTF-8?q?Explicit=20type=20casting=20to=20get=20us?= =?UTF-8?q?=20to=20PHPStan=20level=2010!=20=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpstan.neon.dist | 2 +- src/MarkupAssertionsTrait.php | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index f7bec5d..9b90598 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,5 @@ parameters: - level: 6 + level: 10 # Code to be analyzed paths: diff --git a/src/MarkupAssertionsTrait.php b/src/MarkupAssertionsTrait.php index b9b05d9..ea94aea 100644 --- a/src/MarkupAssertionsTrait.php +++ b/src/MarkupAssertionsTrait.php @@ -246,7 +246,7 @@ private function flattenAttributeArray(array $attributes) if (empty($value)) { $value = sprintf('[%s]', $key); } else { - $value = sprintf('[%s="%s"]', $key, htmlspecialchars($value)); + $value = sprintf('[%s="%s"]', $key, htmlspecialchars((string) $value)); } }); @@ -270,10 +270,14 @@ private function getInnerHtmlOfMatchedElements($markup, $query) // Loop through results and collect their innerHTML values. foreach ($results as $result) { + if (!isset($result->firstChild)) { + continue; + } + $document = new \DOMDocument(); $document->appendChild($document->importNode($result->firstChild, true)); - $contents[] = trim(html_entity_decode($document->saveHTML())); + $contents[] = trim(html_entity_decode((string) $document->saveHTML())); } return implode(PHP_EOL, $contents); From fdca2a176dca12b780464303fa53efeb53f677ab Mon Sep 17 00:00:00 2001 From: Steve Grunwell <233836+stevegrunwell@users.noreply.github.com> Date: Thu, 10 Jul 2025 19:01:33 -0400 Subject: [PATCH 30/30] Indicate that tests/coverage may or may not exist --- phpstan.neon.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 9b90598..3cbe92e 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -8,7 +8,7 @@ parameters: # Don't worry about the coverage reports excludePaths: - - tests/coverage + - tests/coverage (?) # PHPUnit Bridge puts the PHPUnit source in an unconventional location scanDirectories: