Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<exclude-pattern>tests/*</exclude-pattern>
</rule>

<!-- Ensure we're compatible with PHP 5.6+ -->
<!-- Ensure we're compatible with PHP 7.1+ -->
<rule ref="PHPCompatibility"/>
<config name="testVersion" value="7.1-"/>
</ruleset>
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
12 changes: 10 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
parameters:
level: 6
level: 10

# Code to be analyzed
paths:
- src
- tests

# Don't worry about the coverage reports
excludePaths:
- tests/coverage
- tests/coverage (?)

# PHPUnit Bridge puts the PHPUnit source in an unconventional location
scanDirectories:
- vendor/bin/.phpunit/phpunit
22 changes: 10 additions & 12 deletions src/MarkupAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -252,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));
}
});

Expand All @@ -276,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);
Expand Down
2 changes: 1 addition & 1 deletion tests/MarkupAssertionsTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public function getInnerHtmlOfMatchedElements_should_retrieve_the_inner_HTML(
/**
* Data provider for testFlattenAttributeArray().
*
* @return array<string,array{array<string,string>,string}>
* @return array<string,array{array<string,?string>,string}>
*/
public function provideAttributes(): array
{
Expand Down