From 1cb7b94fc226b161287e802479b58a107837ce2c Mon Sep 17 00:00:00 2001 From: Jakob Buis Date: Sun, 26 Apr 2020 18:50:55 +0200 Subject: [PATCH 01/17] fix PHPUnit warning for using assert(Not)Contains on strings --- src/MarkupAssertionsTrait.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MarkupAssertionsTrait.php b/src/MarkupAssertionsTrait.php index 14767a7..6806b94 100644 --- a/src/MarkupAssertionsTrait.php +++ b/src/MarkupAssertionsTrait.php @@ -114,7 +114,7 @@ public function assertNotHasElementWithAttributes($attributes = [], $output = '' */ public function assertElementContains($contents, $selector = '', $output = '', $message = '') { - $this->assertContains( + $this->assertStringContainsString( $contents, $this->getInnerHtmlOfMatchedElements($output, $selector), $message @@ -133,7 +133,7 @@ public function assertElementContains($contents, $selector = '', $output = '', $ */ public function assertElementNotContains($contents, $selector = '', $output = '', $message = '') { - $this->assertNotContains( + $this->assertStringNotContainsString( $contents, $this->getInnerHtmlOfMatchedElements($output, $selector), $message From 1d6675c5fd2d559fbe71688b240bd230efd25fac Mon Sep 17 00:00:00 2001 From: Jakob Buis Date: Sun, 26 Apr 2020 19:05:20 +0200 Subject: [PATCH 02/17] preserve compatability with PHPUnit < 8.0 which do not support the assertString(Not)ContainsString assertion --- src/MarkupAssertionsTrait.php | 37 +++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/MarkupAssertionsTrait.php b/src/MarkupAssertionsTrait.php index 6806b94..2aa11d8 100644 --- a/src/MarkupAssertionsTrait.php +++ b/src/MarkupAssertionsTrait.php @@ -114,11 +114,19 @@ public function assertNotHasElementWithAttributes($attributes = [], $output = '' */ public function assertElementContains($contents, $selector = '', $output = '', $message = '') { - $this->assertStringContainsString( - $contents, - $this->getInnerHtmlOfMatchedElements($output, $selector), - $message - ); + if (method_exists($this, 'assertStringContainsString')) { + $this->assertStringContainsString( + $contents, + $this->getInnerHtmlOfMatchedElements($output, $selector), + $message + ); + } else { + $this->assertContains( + $contents, + $this->getInnerHtmlOfMatchedElements($output, $selector), + $message + ); + } } /** @@ -133,11 +141,20 @@ public function assertElementContains($contents, $selector = '', $output = '', $ */ public function assertElementNotContains($contents, $selector = '', $output = '', $message = '') { - $this->assertStringNotContainsString( - $contents, - $this->getInnerHtmlOfMatchedElements($output, $selector), - $message - ); + if (method_exists($this, 'assertStringContainsString')) { + $this->assertStringNotContainsString( + $contents, + $this->getInnerHtmlOfMatchedElements($output, $selector), + $message + ); + } + else { + $this->assertNotContains( + $contents, + $this->getInnerHtmlOfMatchedElements($output, $selector), + $message + ); + } } /** From 8655ff637be124a9876822d66eea320225f6cb97 Mon Sep 17 00:00:00 2001 From: Jakob Buis Date: Sun, 26 Apr 2020 19:13:09 +0200 Subject: [PATCH 03/17] use the right method in the method_exists check This technically worked, as the two methods were introduced in the same PHPUnit release, but this is more accurate. --- src/MarkupAssertionsTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MarkupAssertionsTrait.php b/src/MarkupAssertionsTrait.php index 2aa11d8..3cae94f 100644 --- a/src/MarkupAssertionsTrait.php +++ b/src/MarkupAssertionsTrait.php @@ -141,7 +141,7 @@ public function assertElementContains($contents, $selector = '', $output = '', $ */ public function assertElementNotContains($contents, $selector = '', $output = '', $message = '') { - if (method_exists($this, 'assertStringContainsString')) { + if (method_exists($this, 'assertStringNotContainsString')) { $this->assertStringNotContainsString( $contents, $this->getInnerHtmlOfMatchedElements($output, $selector), From 378208e1b9e18031cb29956c22105f349d28d523 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Tue, 29 Dec 2020 22:47:13 -0500 Subject: [PATCH 04/17] Move from Travis CI to GitHub Actions --- .github/workflows/unit-tests.yml | 52 ++++++++++++++++++++++++++++++++ .travis.yml | 27 ----------------- 2 files changed, 52 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/unit-tests.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml new file mode 100644 index 0000000..85fd1eb --- /dev/null +++ b/.github/workflows/unit-tests.yml @@ -0,0 +1,52 @@ +name: Unit Tests + +on: [push, pull_request] + +jobs: + run: + runs-on: ${{ matrix.operating-system }} + strategy: + matrix: + operating-system: [ubuntu-latest] + php-versions: ['5.6', '7.0', 7.1', '7.2', '7.3', '7.4', '8.0'] + name: PHP ${{ matrix.php-versions }} + + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + if: ${{ matrix.php != '7.4' }} + with: + php-version: ${{ matrix.php-versions }} + coverage: none + + - name: Setup PHP w/ Code Coverage + uses: shivammathur/setup-php@v2 + if: ${{ matrix.php == '7.4' }} + with: + php-version: ${{ matrix.php-versions }} + coverage: xdebug + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + run: composer install --no-interaction --prefer-dist --no-suggest --no-progress + + - name: Run test suite + if: ${{ matrix.php != '7.4' }} + run: composer test + + - name: Run test suite with code coverage + if: ${{ matrix.php == '7.4' }} + run: composer test --coverage-text diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index af2584a..0000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -language: php - -php: - - 7.0 - - 7.1 - - 7.2 - - 7.3 - - 7.4 - -sudo: false - -env: - matrix: - - PREFER_LOWEST="--prefer-lowest --prefer-stable" - - PREFER_LOWEST="" - -install: - - wget https://github.com/php-coveralls/php-coveralls/releases/download/v1.0.0/coveralls.phar - - chmod +x coveralls.phar - - composer update --no-interaction --prefer-dist $PREFER_LOWEST - -script: - - mkdir -p build/logs - - vendor/bin/phpunit --coverage-clover build/logs/clover.xml - -after_success: - - travis_retry php coveralls.phar From 2f71058a909af8c12d70d917b98cee17680c0e2e Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Tue, 29 Dec 2020 22:48:12 -0500 Subject: [PATCH 05/17] In order to test against multiple versions of PHPUnit, use Symfony's PHPUnit Bridge --- .gitignore | 6 +++++- composer.json | 10 ++++++---- tests/MarkupAssertionsTraitTest.php | 19 ++++++++++--------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index c6d1959..384aae8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ -composer.lock tests/coverage vendor +.phpunit.result.cache + +# The composer.lock file is not needed, as this is a library whose dependencies +# will depend on the version of PHP being used. +composer.lock diff --git a/composer.json b/composer.json index c30d59c..3690c45 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "laminas/laminas-dom": "^2.7" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "symfony/phpunit-bridge": "^5.2" }, "autoload": { "psr-4": { @@ -32,10 +32,10 @@ }, "scripts": { "test": [ - "phpunit" + "simple-phpunit" ], "test-coverage": [ - "phpunit --coverage-html=tests/coverage" + "simple-phpunit --coverage-html=tests/coverage" ] }, "scripts-descriptions": { @@ -45,6 +45,8 @@ "config": { "preferred-install": "dist", "sort-packages": true, - "optimize-autoloader": true + "platform": { + "php": "7.4" + } } } diff --git a/tests/MarkupAssertionsTraitTest.php b/tests/MarkupAssertionsTraitTest.php index a8ef54c..163f533 100644 --- a/tests/MarkupAssertionsTraitTest.php +++ b/tests/MarkupAssertionsTraitTest.php @@ -13,13 +13,16 @@ class MarkupAssertionsTraitTest extends TestCase /** * Holds a clean instance of TestCaseWithMarkupAssertions. * - * @var TestCaseWithMarkupAssertions + * @var \Tests\TestFiles\TestCaseWithMarkupAssertions */ protected $testcase; - public function setUp() + /** + * @before + */ + protected function buildInstance() { - $this->testcase = new TestCaseWithMarkupAssertions; + $this->testcase = new TestCaseWithMarkupAssertions(); } /** @@ -168,18 +171,16 @@ public function testAssertElementNotRegExp() */ public function testFlattenAttributeArray($attributes, $expected) { - $method = new ReflectionMethod($this->testcase, 'flattenAttributeArray'); + $method = new \ReflectionMethod($this->testcase, 'flattenAttributeArray'); $method->setAccessible(true); $this->assertEquals($expected, $method->invoke($this->testcase, $attributes)); } - /** - * @expectedException PHPUnit\Framework\RiskyTestError - */ public function testFlattenAttributeArrayThrowsRiskyTestError() { - $method = new ReflectionMethod($this->testcase, 'flattenAttributeArray'); + $this->expectException(RiskyTestError::class); + $method = new \ReflectionMethod($this->testcase, 'flattenAttributeArray'); $method->setAccessible(true); $method->invoke($this->testcase, []); @@ -189,7 +190,7 @@ public function testFlattenAttributeArrayThrowsRiskyTestError() * @dataProvider innerHtmlProvider(). */ public function testGetInnerHtmlOfMatchedElements($markup, $selector, $expected) { - $method = new ReflectionMethod($this->testcase, 'getInnerHtmlOfMatchedElements'); + $method = new \ReflectionMethod($this->testcase, 'getInnerHtmlOfMatchedElements'); $method->setAccessible(true); $this->assertEquals($expected, $method->invoke($this->testcase, $markup, $selector)); From e80f82bc6c1a47422ba40eea2c9d08bece70257a Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Tue, 29 Dec 2020 23:13:34 -0500 Subject: [PATCH 06/17] Move from camelCase to snake_case (with @test annotations) for the test suite --- composer.json | 4 +- tests/MarkupAssertionsTraitTest.php | 116 +++++++++++++++++++++------- 2 files changed, 91 insertions(+), 29 deletions(-) diff --git a/composer.json b/composer.json index 3690c45..21ab4dc 100644 --- a/composer.json +++ b/composer.json @@ -32,10 +32,10 @@ }, "scripts": { "test": [ - "simple-phpunit" + "simple-phpunit --testdox" ], "test-coverage": [ - "simple-phpunit --coverage-html=tests/coverage" + "phpdbg -qrr -d memory_limit=-1 ./vendor/bin/simple-phpunit --coverage-html=tests/coverage --colors=always" ] }, "scripts-descriptions": { diff --git a/tests/MarkupAssertionsTraitTest.php b/tests/MarkupAssertionsTraitTest.php index 163f533..3fc0ed9 100644 --- a/tests/MarkupAssertionsTraitTest.php +++ b/tests/MarkupAssertionsTraitTest.php @@ -5,9 +5,11 @@ use PHPUnit\Framework\AssertionFailedError; use PHPUnit\Framework\RiskyTestError; use PHPUnit\Framework\TestCase; -use ReflectionMethod; use Tests\TestFiles\TestCaseWithMarkupAssertions; +/** + * @covers SteveGrunwell\PHPUnit_Markup_Assertions\MarkupAssertionsTrait + */ class MarkupAssertionsTraitTest extends TestCase { /** @@ -26,9 +28,11 @@ protected function buildInstance() } /** - * @dataProvider selectorVariantProvider() + * @test + * @testdox assertContainsSelector() should find matching selectors + * @dataProvider provideSelectorVariants */ - public function testAssertContainsSelector($selector) + public function assertContainsSelector_should_find_matching_selectors($selector) { $this->testcase->assertContainsSelector( $selector, @@ -36,7 +40,11 @@ public function testAssertContainsSelector($selector) ); } - public function testAssertContainsWithMultipleMatches() + /** + * @test + * @testdox assertContainsSelector() should pick up multiple instances of a selector + */ + public function assertContainsSelector_should_pick_up_multiple_instances() { $this->testcase->assertContainsSelector( 'a', @@ -45,9 +53,11 @@ public function testAssertContainsWithMultipleMatches() } /** - * @dataProvider selectorVariantProvider() + * @test + * @testdox assertNotContainsSelector() should verify that the given selector does not exist + * @dataProvider provideSelectorVariants */ - public function testAssertNotContainsSelector($selector) + public function assertNotContainsSelector_should_verify_that_the_given_selector_does_not_exist($selector) { $this->testcase->assertNotContainsSelector( $selector, @@ -55,7 +65,11 @@ public function testAssertNotContainsSelector($selector) ); } - public function testAssertSelectorCount() + /** + * @test + * @testdox assertSelectorCount() should count the instances of a selector + */ + public function assertSelectorCount_should_count_the_number_of_instances() { $this->testcase->assertSelectorCount( 3, @@ -64,7 +78,11 @@ public function testAssertSelectorCount() ); } - public function testAssertHasElementWithAttributes() + /** + * @test + * @testdox assertHasElementWithAttributes() should find an element with the given attributes + */ + public function assertHasElementWithAttributes_should_find_elements_with_matching_attributes() { $this->testcase->assertHasElementWithAttributes( [ @@ -76,9 +94,11 @@ public function testAssertHasElementWithAttributes() } /** - * @link https://github.com/stevegrunwell/phpunit-markup-assertions/issues/13 + * @test + * @testdox assertHasElementWithAttributes() should be able to parse spaces in attribute values + * @ticket https://github.com/stevegrunwell/phpunit-markup-assertions/issues/13 */ - public function testAssertHasElementWithAttributesWithSpacesInTheAttributeValue() + public function assertHasElementWithAttributes_should_be_able_to_handle_spaces() { $this->testcase->assertHasElementWithAttributes( [ @@ -88,7 +108,11 @@ public function testAssertHasElementWithAttributesWithSpacesInTheAttributeValue( ); } - public function testAssertNotHasElementWithAttributes() + /** + * @test + * @testdox assertNotHasElementWithAttributes() should ensure no element has the provided attributes + */ + public function assertNotHasElementWithAttributes_should_find_no_elements_with_matching_attributes() { $this->testcase->assertNotHasElementWithAttributes( [ @@ -99,7 +123,11 @@ public function testAssertNotHasElementWithAttributes() ); } - public function testAssertElementContains() + /** + * @test + * @testdox assertElementContains() should be able to search for a selector + */ + public function assertElementContains_can_match_a_selector() { $this->testcase->assertElementContains( 'ipsum', @@ -108,7 +136,11 @@ public function testAssertElementContains() ); } - public function testAssertElementContainsMultipleSelectors() + /** + * @test + * @testdox assertElementContains() should be able to chain multiple selectors + */ + public function assertElementContains_can_chain_multiple_selectors() { $this->testcase->assertElementContains( 'ipsum', @@ -117,7 +149,11 @@ public function testAssertElementContainsMultipleSelectors() ); } - public function testAssertElementContainsScopesToSelector() + /** + * @test + * @testdox assertElementContains() should scope text to the selected element + */ + public function assertElementContains_should_scope_matches_to_selector() { $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('The #main div does not contain the string "ipsum".'); @@ -130,7 +166,11 @@ public function testAssertElementContainsScopesToSelector() ); } - public function testAssertElementNotContains() + /** + * @test + * @testdox assertElementNotContains() should be able to search for a selector + */ + public function assertElementNotContains_can_match_a_selector() { $this->testcase->assertElementNotContains( 'ipsum', @@ -139,7 +179,11 @@ public function testAssertElementNotContains() ); } - public function testAssertElementRegExp() + /** + * @test + * @testdox assertElementRegExp() should use regular expression matching + */ + public function assertElementRegExp_should_use_regular_expression_matching() { $this->testcase->assertElementRegExp( '/[A-Z0-9-]+/', @@ -148,7 +192,11 @@ public function testAssertElementRegExp() ); } - public function testAssertElementRegExpWithNestedElements() + /** + * @test + * @testdox assertElementRegExp() should be able to search for nested contents + */ + public function assertElementRegExp_should_be_able_to_match_nested_contents() { $this->testcase->assertElementRegExp( '/[A-Z]+/', @@ -157,6 +205,10 @@ public function testAssertElementRegExpWithNestedElements() ); } + /** + * @test + * @testdox assertElementNotRegExp() should use regular expression matching + */ public function testAssertElementNotRegExp() { $this->testcase->assertElementNotRegExp( @@ -166,30 +218,40 @@ public function testAssertElementNotRegExp() ); } + /** - * @dataProvider attributeProvider() + * @test + * @testdox flattenAttributeArray() should flatten an array of attributes + * @dataProvider provideAttributes */ - public function testFlattenAttributeArray($attributes, $expected) + public function flattenArrayAttribute_should_flatten_arrays_of_attributes($attributes, $expected) { $method = new \ReflectionMethod($this->testcase, 'flattenAttributeArray'); $method->setAccessible(true); - $this->assertEquals($expected, $method->invoke($this->testcase, $attributes)); + $this->assertSame($expected, $method->invoke($this->testcase, $attributes)); } - public function testFlattenAttributeArrayThrowsRiskyTestError() + /** + * @test + * @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() { $this->expectException(RiskyTestError::class); + $method = new \ReflectionMethod($this->testcase, 'flattenAttributeArray'); $method->setAccessible(true); - $method->invoke($this->testcase, []); } /** - * @dataProvider innerHtmlProvider(). + * @test + * @testdox getInnerHtmlOfMatchedElements() should retrieve the inner HTML + * @dataProvider provideInnerHtml */ - public function testGetInnerHtmlOfMatchedElements($markup, $selector, $expected) { + public function getInnerHtmlOfMatchedElements_should_retrieve_the_inner_HTML($markup, $selector, $expected) { $method = new \ReflectionMethod($this->testcase, 'getInnerHtmlOfMatchedElements'); $method->setAccessible(true); @@ -199,7 +261,7 @@ public function testGetInnerHtmlOfMatchedElements($markup, $selector, $expected) /** * Data provider for testFlattenAttributeArray(). */ - public function attributeProvider() + public function provideAttributes() { return [ 'Single attribute' => [ @@ -239,7 +301,7 @@ public function attributeProvider() /** * Data provider for testGetInnerHtmlOfMatchedElements(). */ - public function innerHtmlProvider() + public function provideInnerHtml() { return [ 'A single match' => [ @@ -263,7 +325,7 @@ public function innerHtmlProvider() /** * Data provider for testAssertContainsSelector(). */ - public function selectorVariantProvider() + public function provideSelectorVariants() { return [ 'Simple tag name' => ['a'], From f5978dbe6c2b06f03c2646b7c0a07f3e1219c61e Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Tue, 29 Dec 2020 23:18:05 -0500 Subject: [PATCH 07/17] Instead of loading a second testcase to gain access to the MarkupAssertionsTrait, apply it directly --- tests/MarkupAssertionsTraitTest.php | 57 +++++++------------ .../TestCaseWithMarkupAssertions.php | 11 ---- 2 files changed, 22 insertions(+), 46 deletions(-) delete mode 100644 tests/TestFiles/TestCaseWithMarkupAssertions.php diff --git a/tests/MarkupAssertionsTraitTest.php b/tests/MarkupAssertionsTraitTest.php index 3fc0ed9..4692388 100644 --- a/tests/MarkupAssertionsTraitTest.php +++ b/tests/MarkupAssertionsTraitTest.php @@ -5,27 +5,14 @@ use PHPUnit\Framework\AssertionFailedError; use PHPUnit\Framework\RiskyTestError; use PHPUnit\Framework\TestCase; -use Tests\TestFiles\TestCaseWithMarkupAssertions; +use SteveGrunwell\PHPUnit_Markup_Assertions\MarkupAssertionsTrait; /** * @covers SteveGrunwell\PHPUnit_Markup_Assertions\MarkupAssertionsTrait */ class MarkupAssertionsTraitTest extends TestCase { - /** - * Holds a clean instance of TestCaseWithMarkupAssertions. - * - * @var \Tests\TestFiles\TestCaseWithMarkupAssertions - */ - protected $testcase; - - /** - * @before - */ - protected function buildInstance() - { - $this->testcase = new TestCaseWithMarkupAssertions(); - } + use MarkupAssertionsTrait; /** * @test @@ -34,7 +21,7 @@ protected function buildInstance() */ public function assertContainsSelector_should_find_matching_selectors($selector) { - $this->testcase->assertContainsSelector( + $this->assertContainsSelector( $selector, 'Example' ); @@ -46,7 +33,7 @@ public function assertContainsSelector_should_find_matching_selectors($selector) */ public function assertContainsSelector_should_pick_up_multiple_instances() { - $this->testcase->assertContainsSelector( + $this->assertContainsSelector( 'a', 'Home | About | Contact' ); @@ -59,7 +46,7 @@ public function assertContainsSelector_should_pick_up_multiple_instances() */ public function assertNotContainsSelector_should_verify_that_the_given_selector_does_not_exist($selector) { - $this->testcase->assertNotContainsSelector( + $this->assertNotContainsSelector( $selector, '

This element has little to do with the link.

' ); @@ -71,7 +58,7 @@ public function assertNotContainsSelector_should_verify_that_the_given_selector_ */ public function assertSelectorCount_should_count_the_number_of_instances() { - $this->testcase->assertSelectorCount( + $this->assertSelectorCount( 3, 'li', '
  • 1
  • 2
  • 3
' @@ -84,7 +71,7 @@ public function assertSelectorCount_should_count_the_number_of_instances() */ public function assertHasElementWithAttributes_should_find_elements_with_matching_attributes() { - $this->testcase->assertHasElementWithAttributes( + $this->assertHasElementWithAttributes( [ 'type' => 'email', 'value' => 'test@example.com', @@ -100,7 +87,7 @@ public function assertHasElementWithAttributes_should_find_elements_with_matchin */ public function assertHasElementWithAttributes_should_be_able_to_handle_spaces() { - $this->testcase->assertHasElementWithAttributes( + $this->assertHasElementWithAttributes( [ 'data-attr' => 'foo bar baz', ], @@ -114,7 +101,7 @@ public function assertHasElementWithAttributes_should_be_able_to_handle_spaces() */ public function assertNotHasElementWithAttributes_should_find_no_elements_with_matching_attributes() { - $this->testcase->assertNotHasElementWithAttributes( + $this->assertNotHasElementWithAttributes( [ 'type' => 'email', 'value' => 'test@example.com', @@ -129,7 +116,7 @@ public function assertNotHasElementWithAttributes_should_find_no_elements_with_m */ public function assertElementContains_can_match_a_selector() { - $this->testcase->assertElementContains( + $this->assertElementContains( 'ipsum', '#main', '
Lorem ipsum
Lorem ipsum
' @@ -142,7 +129,7 @@ public function assertElementContains_can_match_a_selector() */ public function assertElementContains_can_chain_multiple_selectors() { - $this->testcase->assertElementContains( + $this->assertElementContains( 'ipsum', '#main .foo', '
Lorem ipsum
' @@ -158,7 +145,7 @@ public function assertElementContains_should_scope_matches_to_selector() $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('The #main div does not contain the string "ipsum".'); - $this->testcase->assertElementContains( + $this->assertElementContains( 'ipsum', '#main', '
Lorem ipsum
Foo bar baz
', @@ -172,7 +159,7 @@ public function assertElementContains_should_scope_matches_to_selector() */ public function assertElementNotContains_can_match_a_selector() { - $this->testcase->assertElementNotContains( + $this->assertElementNotContains( 'ipsum', '#main', '
Foo bar baz
Some string
' @@ -185,7 +172,7 @@ public function assertElementNotContains_can_match_a_selector() */ public function assertElementRegExp_should_use_regular_expression_matching() { - $this->testcase->assertElementRegExp( + $this->assertElementRegExp( '/[A-Z0-9-]+/', '#main', '
Lorem ipsum
ABC123
' @@ -198,7 +185,7 @@ public function assertElementRegExp_should_use_regular_expression_matching() */ public function assertElementRegExp_should_be_able_to_match_nested_contents() { - $this->testcase->assertElementRegExp( + $this->assertElementRegExp( '/[A-Z]+/', '#main', '
Lorem ipsum
ABC
' @@ -211,7 +198,7 @@ public function assertElementRegExp_should_be_able_to_match_nested_contents() */ public function testAssertElementNotRegExp() { - $this->testcase->assertElementNotRegExp( + $this->assertElementNotRegExp( '/[0-9-]+/', '#main', '
Foo bar baz
ABC
' @@ -226,10 +213,10 @@ public function testAssertElementNotRegExp() */ public function flattenArrayAttribute_should_flatten_arrays_of_attributes($attributes, $expected) { - $method = new \ReflectionMethod($this->testcase, 'flattenAttributeArray'); + $method = new \ReflectionMethod($this, 'flattenAttributeArray'); $method->setAccessible(true); - $this->assertSame($expected, $method->invoke($this->testcase, $attributes)); + $this->assertSame($expected, $method->invoke($this, $attributes)); } /** @@ -241,9 +228,9 @@ public function flattenAttributeArray_should_throw_a_RiskyTestError_if_given_an_ { $this->expectException(RiskyTestError::class); - $method = new \ReflectionMethod($this->testcase, 'flattenAttributeArray'); + $method = new \ReflectionMethod($this, 'flattenAttributeArray'); $method->setAccessible(true); - $method->invoke($this->testcase, []); + $method->invoke($this, []); } /** @@ -252,10 +239,10 @@ public function flattenAttributeArray_should_throw_a_RiskyTestError_if_given_an_ * @dataProvider provideInnerHtml */ public function getInnerHtmlOfMatchedElements_should_retrieve_the_inner_HTML($markup, $selector, $expected) { - $method = new \ReflectionMethod($this->testcase, 'getInnerHtmlOfMatchedElements'); + $method = new \ReflectionMethod($this, 'getInnerHtmlOfMatchedElements'); $method->setAccessible(true); - $this->assertEquals($expected, $method->invoke($this->testcase, $markup, $selector)); + $this->assertEquals($expected, $method->invoke($this, $markup, $selector)); } /** diff --git a/tests/TestFiles/TestCaseWithMarkupAssertions.php b/tests/TestFiles/TestCaseWithMarkupAssertions.php deleted file mode 100644 index b794515..0000000 --- a/tests/TestFiles/TestCaseWithMarkupAssertions.php +++ /dev/null @@ -1,11 +0,0 @@ - Date: Tue, 29 Dec 2020 23:45:19 -0500 Subject: [PATCH 08/17] Remove PHP 8.0 from the test matrix We can't officially support it until laminas/laminas-dom isn't throwing errors everywhere. See https://github.com/stevegrunwell/phpunit-markup-assertions/issues/23 --- .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 85fd1eb..94b90c0 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-versions: ['5.6', '7.0', 7.1', '7.2', '7.3', '7.4', '8.0'] + php-versions: ['5.6', '7.0', 7.1', '7.2', '7.3', '7.4'] name: PHP ${{ matrix.php-versions }} steps: From b69060cf9b20d831851ddaae7adba73399eb71cd Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Tue, 29 Dec 2020 23:49:47 -0500 Subject: [PATCH 09/17] Add missing opening single-quote --- .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 94b90c0..d805800 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-versions: ['5.6', '7.0', 7.1', '7.2', '7.3', '7.4'] + php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4'] name: PHP ${{ matrix.php-versions }} steps: From d84808bfdb08c371c2fd3f69f7236074ee5ccf4c Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Tue, 29 Dec 2020 23:56:47 -0500 Subject: [PATCH 10/17] Don't worry about code coverage for now, update badges --- .github/workflows/unit-tests.yml | 11 ----------- README.md | 3 +-- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index d805800..2af545e 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -22,13 +22,6 @@ jobs: php-version: ${{ matrix.php-versions }} coverage: none - - name: Setup PHP w/ Code Coverage - uses: shivammathur/setup-php@v2 - if: ${{ matrix.php == '7.4' }} - with: - php-version: ${{ matrix.php-versions }} - coverage: xdebug - - name: Get composer cache directory id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" @@ -46,7 +39,3 @@ jobs: - name: Run test suite if: ${{ matrix.php != '7.4' }} run: composer test - - - name: Run test suite with code coverage - if: ${{ matrix.php == '7.4' }} - run: composer test --coverage-text diff --git a/README.md b/README.md index 8c66e88..7a5a113 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # PHPUnit Markup Assertions -[![Build Status](https://travis-ci.org/stevegrunwell/phpunit-markup-assertions.svg?branch=develop)](https://travis-ci.org/stevegrunwell/phpunit-markup-assertions) -[![Coverage Status](https://coveralls.io/repos/github/stevegrunwell/phpunit-markup-assertions/badge.svg?branch=develop)](https://coveralls.io/github/stevegrunwell/phpunit-markup-assertions?branch=develop) +![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) This library introduces the `MarkupAssertionsTrait` trait for use in [PHPUnit](https://phpunit.de) tests. From be07b8cecc9a5fa9afa858a402b8ad13b8b08b7e Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Thu, 14 Jan 2021 10:38:44 -0500 Subject: [PATCH 11/17] Add PHP 8.0 to the 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 2af545e..e63e81b 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4'] + php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0'] name: PHP ${{ matrix.php-versions }} steps: From cca71b5517649134036679fca56fe1f9c1817870 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Thu, 14 Jan 2021 10:39:36 -0500 Subject: [PATCH 12/17] Remove the PHP 7.4 exclusions, as there's no reason for them --- .github/workflows/unit-tests.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index e63e81b..0990819 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -17,7 +17,6 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 - if: ${{ matrix.php != '7.4' }} with: php-version: ${{ matrix.php-versions }} coverage: none @@ -37,5 +36,4 @@ jobs: run: composer install --no-interaction --prefer-dist --no-suggest --no-progress - name: Run test suite - if: ${{ matrix.php != '7.4' }} run: composer test From fef1d3d460a923dce38cd0285ba93ee9d828bf89 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Thu, 14 Jan 2021 10:41:28 -0500 Subject: [PATCH 13/17] Adjust the laminas/laminas-dom constraints so older versions of PHP may still install 2.7.x --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 21ab4dc..d7da586 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "source": "https://github.com/stevegrunwell/phpunit-markup-assertions/" }, "require": { - "laminas/laminas-dom": "^2.7" + "laminas/laminas-dom": "^2.7.0|^2.8" }, "require-dev": { "symfony/phpunit-bridge": "^5.2" From 142f418e433b08d40718a3e32a3a19c67bcbd7d8 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Thu, 14 Jan 2021 10:55:53 -0500 Subject: [PATCH 14/17] Adjust version constraints and remove the explicit 'platform' declaration --- composer.json | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index d7da586..c8d2ae6 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,8 @@ "source": "https://github.com/stevegrunwell/phpunit-markup-assertions/" }, "require": { - "laminas/laminas-dom": "^2.7.0|^2.8" + "php": "^5.6 || ^7.0 || ^8.0", + "laminas/laminas-dom": "~2.7.2 || ^2.8" }, "require-dev": { "symfony/phpunit-bridge": "^5.2" @@ -44,9 +45,6 @@ }, "config": { "preferred-install": "dist", - "sort-packages": true, - "platform": { - "php": "7.4" - } + "sort-packages": true } } From 4a9621bba48bf22ff13ad57bc224fd4f6a60ace5 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Thu, 14 Jan 2021 11:01:10 -0500 Subject: [PATCH 15/17] Update regular expression methods When running `$this->assert[Not]RegExp()` on the latest versions of PHPUnit, we get the following warning: > assertRegExp() is deprecated and will be removed in PHPUnit 10. Refactor your code to use assertMatchesRegularExpression() instead. This commit updates `assertElementRegExp()` and `assertElementNotRegExp()` to check for the newer method and use it if it's available. --- src/MarkupAssertionsTrait.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/MarkupAssertionsTrait.php b/src/MarkupAssertionsTrait.php index 3cae94f..508aa72 100644 --- a/src/MarkupAssertionsTrait.php +++ b/src/MarkupAssertionsTrait.php @@ -169,7 +169,11 @@ public function assertElementNotContains($contents, $selector = '', $output = '' */ public function assertElementRegExp($regexp, $selector = '', $output = '', $message = '') { - $this->assertRegExp( + $method = method_exists($this, 'assertMatchesRegularExpression') + ? 'assertMatchesRegularExpression' + : 'assertRegExp'; + + $this->$method( $regexp, $this->getInnerHtmlOfMatchedElements($output, $selector), $message @@ -188,7 +192,11 @@ public function assertElementRegExp($regexp, $selector = '', $output = '', $mess */ public function assertElementNotRegExp($regexp, $selector = '', $output = '', $message = '') { - $this->assertNotRegExp( + $method = method_exists($this, 'assertDoesNotMatchRegularExpression') + ? 'assertDoesNotMatchRegularExpression' + : 'assertNotRegExp'; + + $this->$method( $regexp, $this->getInnerHtmlOfMatchedElements($output, $selector), $message From 8b2635585941ceb8479cde9b8eb0054970c7c6bd Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Thu, 14 Jan 2021 11:18:15 -0500 Subject: [PATCH 16/17] Refactor assertElementContains to match assertElementRegExp Two PRs, #20 and #27, refactored the `assertElementContains()` and `assertElementRegExp()` methods, respectively, to avoid warnings about deprecated PHPUnit methods. This commit updates the changes made in #20 to match those made in #27 for consistency, using a `$method` variable instead of an if/else statement with two separate method calls. --- src/MarkupAssertionsTrait.php | 45 ++++++++++++++--------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/src/MarkupAssertionsTrait.php b/src/MarkupAssertionsTrait.php index 508aa72..2af9fe6 100644 --- a/src/MarkupAssertionsTrait.php +++ b/src/MarkupAssertionsTrait.php @@ -114,19 +114,15 @@ public function assertNotHasElementWithAttributes($attributes = [], $output = '' */ public function assertElementContains($contents, $selector = '', $output = '', $message = '') { - if (method_exists($this, 'assertStringContainsString')) { - $this->assertStringContainsString( - $contents, - $this->getInnerHtmlOfMatchedElements($output, $selector), - $message - ); - } else { - $this->assertContains( - $contents, - $this->getInnerHtmlOfMatchedElements($output, $selector), - $message - ); - } + $method = method_exists($this, 'assertStringContainsString') + ? 'assertStringContainsString' + : 'assertContains'; + + $this->$method( + $contents, + $this->getInnerHtmlOfMatchedElements($output, $selector), + $message + ); } /** @@ -141,20 +137,15 @@ public function assertElementContains($contents, $selector = '', $output = '', $ */ public function assertElementNotContains($contents, $selector = '', $output = '', $message = '') { - if (method_exists($this, 'assertStringNotContainsString')) { - $this->assertStringNotContainsString( - $contents, - $this->getInnerHtmlOfMatchedElements($output, $selector), - $message - ); - } - else { - $this->assertNotContains( - $contents, - $this->getInnerHtmlOfMatchedElements($output, $selector), - $message - ); - } + $method = method_exists($this, 'assertStringNotContainsString') + ? 'assertStringNotContainsString' + : 'assertNotContains'; + + $this->$method( + $contents, + $this->getInnerHtmlOfMatchedElements($output, $selector), + $message + ); } /** From 686273337f3861cf3174db0b16c68601022ff3b3 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Thu, 14 Jan 2021 11:25:20 -0500 Subject: [PATCH 17/17] Add changelog for v1.3.1 --- CHANGELOG.md | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 042a879..80ff798 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,24 +1,34 @@ # Changelog + All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.3.1] — 2020-01-14 + +* Fix PHPUnit warnings regarding `assertContains()` and `assertRegExp()`. Props [@jakobbuis](https://github.com/jakobbuis) ([#20], [#27], [#28]) +* Refactor the internal test scaffolding, including a move from Travis CI to GitHub Actions. Props [@peter279k](https://github.com/peter279k) for the assist with GitHub Actions ([#24]) +* Added PHP 8.0 support ([#26]) + ## [1.3.0] — 2020-01-27 -* Replace `zendframework/zend-dom` with `laminas/laminas-dom` ([#16]). -* Update Composer dependencies, add a `composer test` script ([#15]). +* Replace `zendframework/zend-dom` with `laminas/laminas-dom` ([#16]) +* Update Composer dependencies, add a `composer test` script ([#15]) + ## [1.2.0] - 2018-03-27 * Bumped the minimum version of zendframework/zend-dom to 2.7, which includes a fix for attribute values that include spaces ([#13]). + ## [1.1.0] - 2018-01-14 -* Added the `assertElementContains()`, `assertElementNotContains()`, `assertElementRegExp()`, and `assertElementNotRegExp()` assertions, for verifying the contents of elements that match the given DOM query ([#6]). -* Moved the `Tests` namespace into a development-only autoloader, to prevent them from potentially being included in projects using this library ([#7]). -* [Based on this article by Martin Hujer](https://blog.martinhujer.cz/17-tips-for-using-composer-efficiently/#tip-%236%3A-put-%60composer.lock%60-into-%60.gitignore%60-in-libraries), remove the `composer.lock` file from the library ([#8]). -* _Lower_ the minimum version of [zendframework/zend-dom](https://packagist.org/packages/zendframework/zend-dom) to 2.2.5 for maximum portability ([#9]). +* Added the `assertElementContains()`, `assertElementNotContains()`, `assertElementRegExp()`, and `assertElementNotRegExp()` assertions, for verifying the contents of elements that match the given DOM query ([#6]) +* Moved the `Tests` namespace into a development-only autoloader, to prevent them from potentially being included in projects using this library ([#7]) +* [Based on this article by Martin Hujer](https://blog.martinhujer.cz/17-tips-for-using-composer-efficiently/#tip-%236%3A-put-%60composer.lock%60-into-%60.gitignore%60-in-libraries), remove the `composer.lock` file from the library ([#8]) +* _Lower_ the minimum version of [zendframework/zend-dom](https://packagist.org/packages/zendframework/zend-dom) to 2.2.5 for maximum portability ([#9]) + ## [1.0.0] - 2017-10-24 @@ -26,6 +36,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. [Unreleased]: https://github.com/stevegrunwell/phpunit-markup-assertions/compare/master...develop +[1.3.1]: https://github.com/stevegrunwell/phpunit-markup-assertions/releases/tag/v1.3.1 [1.3.0]: https://github.com/stevegrunwell/phpunit-markup-assertions/releases/tag/v1.3.0 [1.2.0]: https://github.com/stevegrunwell/phpunit-markup-assertions/releases/tag/v1.2.0 [1.1.0]: https://github.com/stevegrunwell/phpunit-markup-assertions/releases/tag/v1.1.0 @@ -37,3 +48,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. [#13]: https://github.com/stevegrunwell/phpunit-markup-assertions/issues/13 [#15]: https://github.com/stevegrunwell/phpunit-markup-assertions/pull/15 [#16]: https://github.com/stevegrunwell/phpunit-markup-assertions/issues/16 +[#20]: https://github.com/stevegrunwell/phpunit-markup-assertions/pull/20 +[#24]: https://github.com/stevegrunwell/phpunit-markup-assertions/pull/24 +[#26]: https://github.com/stevegrunwell/phpunit-markup-assertions/pull/26 +[#27]: https://github.com/stevegrunwell/phpunit-markup-assertions/pull/27 +[#28]: https://github.com/stevegrunwell/phpunit-markup-assertions/pull/28