From bc03ab8d324f05c47bdefcfabacef7dc374075c0 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Mon, 11 Jan 2021 17:23:24 +0100 Subject: [PATCH 1/4] tests: Add suite name Modern PHPUnit does not run suites without names. --- phpunit.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index cd050a6..65987cf 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -4,7 +4,7 @@ convertErrorsToExceptions="false" > - + ./tests/ From 37b3afb8f0c39e35f211368c7843e2187ed7d83d Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Mon, 11 Jan 2021 16:38:35 +0100 Subject: [PATCH 2/4] tests: Use symfony/phpunit-bridge MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PHPUnit 7 is not compatible with PHP 8 and PHPUnit 8 adds return annotations to setUp method, requiring us to add those as well to pass return covariance checks. We can bypass that by renaming the setUp methods and using @before annotations but then there are other issues as well. For example, recent PHPUnit no longer supports @expectException annotations an other issues. Let’s use Symfony’s PHPUnit bridge, which will allow us the widest range of supported PHP versions. We will need to bump to PHP 5.6+ since that is what php-unit bridge requires but PHP 5.4 is not even supported by Debian Jessie (oldoldstable). We also need to set locale appropriately for the null passed to iconv to work, since phpunit-bridge uses C locale (ASCII) for consistency. --- .travis.yml | 5 +---- composer.json | 4 ++-- tests/IconvTranscoderTest.php | 21 ++++++++++++--------- tests/MbTranscoderTest.php | 25 +++++++++++-------------- tests/TranscoderTest.php | 7 +++++-- 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/.travis.yml b/.travis.yml index d61dc1d..be77dd5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,12 @@ language: php php: - - 5.4 - - 5.5 - 5.6 - - hhvm-nightly before_script: - composer install --dev -script: phpunit --coverage-clover=coverage.clover +script: vendor/bin/simple-phpunit --coverage-clover=coverage.clover after_script: - wget https://scrutinizer-ci.com/ocular.phar diff --git a/composer.json b/composer.json index ff11d45..4376c3a 100644 --- a/composer.json +++ b/composer.json @@ -14,10 +14,10 @@ } ], "require": { - "php": ">=5.4.0" + "php": ">=5.6.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "symfony/phpunit-bridge": "^5.2" }, "suggest": { "ext-mbstring": "For using the MbTranscoder", diff --git a/tests/IconvTranscoderTest.php b/tests/IconvTranscoderTest.php index 61b9855..fbd14d6 100644 --- a/tests/IconvTranscoderTest.php +++ b/tests/IconvTranscoderTest.php @@ -4,24 +4,29 @@ use Ddeboer\Transcoder\IconvTranscoder; -class IconvTranscoderTest extends \PHPUnit_Framework_TestCase +class IconvTranscoderTest extends \PHPUnit\Framework\TestCase { /** * @var IconvTranscoder */ private $transcoder; - protected function setUp() + /** + * @before + */ + protected function doSetUp() { $this->transcoder = new IconvTranscoder(); + // Passing null (empty encoding name) to iconv makes it detect encoding from locale. + // The phpunit-bridge sets locale to C for consistency but that implies ASCII. + // This file uses UTF-8 so we have to set the locale accordingly. + $this->setLocale(\LC_ALL, 'C.UTF-8'); } - /** - * @expectedException \Ddeboer\Transcoder\Exception\UnsupportedEncodingException - * @expectedExceptionMessage bad-encoding - */ public function testTranscodeUnsupportedFromEncoding() { + $this->expectException(\Ddeboer\Transcoder\Exception\UnsupportedEncodingException::class); + $this->expectExceptionMessage('bad-encoding'); $this->transcoder->transcode('bla', 'bad-encoding'); } @@ -30,11 +35,9 @@ public function testDetectEncoding() $this->transcoder->transcode('España', null, 'iso-8859-1'); } - /** - * @expectedException \Ddeboer\Transcoder\Exception\IllegalCharacterException - */ public function testTranscodeIllegalCharacter() { + $this->expectException(\Ddeboer\Transcoder\Exception\IllegalCharacterException::class); $this->transcoder->transcode('“', null, 'iso-8859-1'); } diff --git a/tests/MbTranscoderTest.php b/tests/MbTranscoderTest.php index 2eda5a6..97cf01a 100644 --- a/tests/MbTranscoderTest.php +++ b/tests/MbTranscoderTest.php @@ -4,33 +4,32 @@ use Ddeboer\Transcoder\MbTranscoder; -class MbTranscoderTest extends \PHPUnit_Framework_TestCase +class MbTranscoderTest extends \PHPUnit\Framework\TestCase { /** * @var MbTranscoder */ private $transcoder; - protected function setUp() + /** + * @before + */ + protected function doSetUp() { $this->transcoder = new MbTranscoder(); } - /** - * @expectedException \Ddeboer\Transcoder\Exception\UnsupportedEncodingException - * @expectedExceptionMessage bad-encoding - */ public function testTranscodeUnsupportedFromEncoding() { + $this->expectException(\Ddeboer\Transcoder\Exception\UnsupportedEncodingException::class); + $this->expectExceptionMessage('bad-encoding'); $this->transcoder->transcode('bla', 'bad-encoding'); } - /** - * @expectedException \Ddeboer\Transcoder\Exception\UnsupportedEncodingException - * @expectedExceptionMessage bad-encoding - */ public function testTranscodeUnsupportedToEncoding() { + $this->expectException(\Ddeboer\Transcoder\Exception\UnsupportedEncodingException::class); + $this->expectExceptionMessage('bad-encoding'); $this->transcoder->transcode('bla', null, 'bad-encoding'); } @@ -40,12 +39,10 @@ public function testDetectEncoding() $this->transcoder->transcode($result); } - /** - * @expectedException \Ddeboer\Transcoder\Exception\UndetectableEncodingException - * @expectedExceptionMessage is undetectable - */ public function testUndetectableEncoding() { + $this->expectException(\Ddeboer\Transcoder\Exception\UndetectableEncodingException::class); + $this->expectExceptionMessage('is undetectable'); $result = $this->transcoder->transcode( '‘curly quotes make this incompatible with 1252’', null, diff --git a/tests/TranscoderTest.php b/tests/TranscoderTest.php index 802b20e..3e2aae8 100644 --- a/tests/TranscoderTest.php +++ b/tests/TranscoderTest.php @@ -4,14 +4,17 @@ use Ddeboer\Transcoder\Transcoder; -class TranscoderTest extends \PHPUnit_Framework_TestCase +class TranscoderTest extends \PHPUnit\Framework\TestCase { /** * @var Transcoder */ private $transcoder; - protected function setUp() + /** + * @before + */ + protected function doSetUp() { $this->transcoder = Transcoder::create(); } From d3581bf68755e2c0d2288b22419d1d803ad166ed Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Wed, 16 Dec 2020 16:26:31 +0100 Subject: [PATCH 3/4] Bump PHP versions on Travis These are relevant now. Also had to explicitly set xdebug mode on versions using XDebug 3. --- .travis.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.travis.yml b/.travis.yml index be77dd5..ae435f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,18 @@ language: php php: - 5.6 + - 7.0 + - 7.1 + - 7.2 + - 7.3 + env: + - XDEBUG_MODE=coverage + - 7.4 + env: + - XDEBUG_MODE=coverage + - 8.0 + env: + - XDEBUG_MODE=coverage before_script: - composer install --dev From b0ca55d9d91a96647f763d448667a466b1b92fb0 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Mon, 11 Jan 2021 17:27:18 +0100 Subject: [PATCH 4/4] composer: Add test script For easier running of scripts. Now we can just execute `composer test`. --- .travis.yml | 2 +- composer.json | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ae435f5..f9ad71d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ php: before_script: - composer install --dev -script: vendor/bin/simple-phpunit --coverage-clover=coverage.clover +script: composer test -- --coverage-clover=coverage.clover after_script: - wget https://scrutinizer-ci.com/ocular.phar diff --git a/composer.json b/composer.json index 4376c3a..f4baed1 100644 --- a/composer.json +++ b/composer.json @@ -33,5 +33,8 @@ "branch-alias": { "dev-master": "1.0.x-dev" } + }, + "scripts": { + "test": "vendor/bin/simple-phpunit" } }