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
5 changes: 5 additions & 0 deletions .github/workflows/static-code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@

<!-- Ensure we're compatible with PHP 5.6+ -->
<rule ref="PHPCompatibility"/>
<config name="testVersion" value="5.6-"/>
<config name="testVersion" value="7.1-"/>
</ruleset>
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"source": "https://github.com/stevegrunwell/phpunit-markup-assertions/"
},
"require": {
"php": "^5.6 || ^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",
Expand Down
2 changes: 1 addition & 1 deletion src/MarkupAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
58 changes: 33 additions & 25 deletions tests/MarkupAssertionsTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand All @@ -44,8 +44,9 @@ 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,
'<h1 id="page-title" class="foo bar">This element has little to do with the link.</h1>'
Expand All @@ -56,7 +57,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,
Expand All @@ -69,7 +70,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(
[
Expand All @@ -85,7 +86,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(
[
Expand All @@ -99,7 +100,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(
[
Expand All @@ -114,7 +115,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',
Expand All @@ -127,7 +128,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',
Expand All @@ -140,7 +141,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".');
Expand All @@ -159,7 +160,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,
Expand All @@ -172,7 +173,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',
Expand All @@ -187,7 +188,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,
Expand All @@ -200,7 +201,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-]+/',
Expand All @@ -213,7 +214,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]+/',
Expand All @@ -226,7 +227,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-]+/',
Expand All @@ -240,8 +241,10 @@ public function testAssertElementNotRegExp()
* @test
* @testdox flattenAttributeArray() should flatten an array of attributes
* @dataProvider provideAttributes
*
* @param array<string,string> $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);
Expand All @@ -254,7 +257,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);

Expand All @@ -268,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($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);

Expand All @@ -278,8 +284,10 @@ public function getInnerHtmlOfMatchedElements_should_retrieve_the_inner_HTML($ma

/**
* Data provider for testFlattenAttributeArray().
*
* @return array<string,array{array<string,string>,string}>
*/
public function provideAttributes()
public function provideAttributes(): array
{
return [
'Single attribute' => [
Expand Down Expand Up @@ -321,7 +329,7 @@ public function provideAttributes()
*
* @return array<string,array<string>>
*/
public function provideInnerHtml()
public function provideInnerHtml(): array
{
return [
'A single match' => [
Expand All @@ -347,7 +355,7 @@ public function provideInnerHtml()
*
* @return array<string,array<string>>
*/
public function provideSelectorVariants()
public function provideSelectorVariants(): array
{
return [
'Simple tag name' => ['a'],
Expand All @@ -365,7 +373,7 @@ public function provideSelectorVariants()
*
* @return array<string,array<string>>
*/
public function provideGreetingsInDifferentLanguages()
public function provideGreetingsInDifferentLanguages(): array
{
return [
'Arabic' => ['مرحبا!'],
Expand Down