diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml new file mode 100644 index 0000000..0990819 --- /dev/null +++ b/.github/workflows/unit-tests.yml @@ -0,0 +1,39 @@ +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 + with: + php-version: ${{ matrix.php-versions }} + coverage: none + + - 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 + run: composer test 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/.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 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 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. diff --git a/composer.json b/composer.json index c30d59c..c8d2ae6 100644 --- a/composer.json +++ b/composer.json @@ -15,10 +15,11 @@ "source": "https://github.com/stevegrunwell/phpunit-markup-assertions/" }, "require": { - "laminas/laminas-dom": "^2.7" + "php": "^5.6 || ^7.0 || ^8.0", + "laminas/laminas-dom": "~2.7.2 || ^2.8" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "symfony/phpunit-bridge": "^5.2" }, "autoload": { "psr-4": { @@ -32,10 +33,10 @@ }, "scripts": { "test": [ - "phpunit" + "simple-phpunit --testdox" ], "test-coverage": [ - "phpunit --coverage-html=tests/coverage" + "phpdbg -qrr -d memory_limit=-1 ./vendor/bin/simple-phpunit --coverage-html=tests/coverage --colors=always" ] }, "scripts-descriptions": { @@ -44,7 +45,6 @@ }, "config": { "preferred-install": "dist", - "sort-packages": true, - "optimize-autoloader": true + "sort-packages": true } } diff --git a/src/MarkupAssertionsTrait.php b/src/MarkupAssertionsTrait.php index 14767a7..2af9fe6 100644 --- a/src/MarkupAssertionsTrait.php +++ b/src/MarkupAssertionsTrait.php @@ -114,7 +114,11 @@ public function assertNotHasElementWithAttributes($attributes = [], $output = '' */ public function assertElementContains($contents, $selector = '', $output = '', $message = '') { - $this->assertContains( + $method = method_exists($this, 'assertStringContainsString') + ? 'assertStringContainsString' + : 'assertContains'; + + $this->$method( $contents, $this->getInnerHtmlOfMatchedElements($output, $selector), $message @@ -133,7 +137,11 @@ public function assertElementContains($contents, $selector = '', $output = '', $ */ public function assertElementNotContains($contents, $selector = '', $output = '', $message = '') { - $this->assertNotContains( + $method = method_exists($this, 'assertStringNotContainsString') + ? 'assertStringNotContainsString' + : 'assertNotContains'; + + $this->$method( $contents, $this->getInnerHtmlOfMatchedElements($output, $selector), $message @@ -152,7 +160,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 @@ -171,7 +183,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 diff --git a/tests/MarkupAssertionsTraitTest.php b/tests/MarkupAssertionsTraitTest.php index a8ef54c..4692388 100644 --- a/tests/MarkupAssertionsTraitTest.php +++ b/tests/MarkupAssertionsTraitTest.php @@ -5,65 +5,73 @@ use PHPUnit\Framework\AssertionFailedError; use PHPUnit\Framework\RiskyTestError; use PHPUnit\Framework\TestCase; -use ReflectionMethod; -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 TestCaseWithMarkupAssertions - */ - protected $testcase; - - public function setUp() - { - $this->testcase = new TestCaseWithMarkupAssertions; - } + use MarkupAssertionsTrait; /** - * @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( + $this->assertContainsSelector( $selector, 'Example' ); } - 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( + $this->assertContainsSelector( 'a', 'Home | About | Contact' ); } /** - * @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( + $this->assertNotContainsSelector( $selector, '