Skip to content

Commit 69804d9

Browse files
committed
tests: Use symfony/phpunit-bridge
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).
1 parent bc03ab8 commit 69804d9

File tree

5 files changed

+29
-31
lines changed

5 files changed

+29
-31
lines changed

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
language: php
22

33
php:
4-
- 5.4
5-
- 5.5
64
- 5.6
7-
- hhvm-nightly
85

96
before_script:
107
- composer install --dev
118

12-
script: phpunit --coverage-clover=coverage.clover
9+
script: vendor/bin/simple-phpunit --coverage-clover=coverage.clover
1310

1411
after_script:
1512
- wget https://scrutinizer-ci.com/ocular.phar

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
}
1515
],
1616
"require": {
17-
"php": ">=5.4.0"
17+
"php": ">=5.6.0"
1818
},
1919
"require-dev": {
20-
"phpunit/phpunit": "~4.0"
20+
"symfony/phpunit-bridge": "^5.2"
2121
},
2222
"suggest": {
2323
"ext-mbstring": "For using the MbTranscoder",

tests/IconvTranscoderTest.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,27 @@
44

55
use Ddeboer\Transcoder\IconvTranscoder;
66

7-
class IconvTranscoderTest extends \PHPUnit_Framework_TestCase
7+
class IconvTranscoderTest extends \PHPUnit\Framework\TestCase
88
{
99
/**
1010
* @var IconvTranscoder
1111
*/
1212
private $transcoder;
1313

14-
protected function setUp()
14+
/**
15+
* @before
16+
*/
17+
protected function doSetUp()
1518
{
1619
$this->transcoder = new IconvTranscoder();
20+
// iconv requires a UTF-8 locale but phpunit-bridge sets it to C
21+
$this->setLocale(\LC_ALL, 'C.UTF-8');
1722
}
1823

19-
/**
20-
* @expectedException \Ddeboer\Transcoder\Exception\UnsupportedEncodingException
21-
* @expectedExceptionMessage bad-encoding
22-
*/
2324
public function testTranscodeUnsupportedFromEncoding()
2425
{
26+
$this->expectException(\Ddeboer\Transcoder\Exception\UnsupportedEncodingException::class);
27+
$this->expectExceptionMessage('bad-encoding');
2528
$this->transcoder->transcode('bla', 'bad-encoding');
2629
}
2730

@@ -30,11 +33,9 @@ public function testDetectEncoding()
3033
$this->transcoder->transcode('España', null, 'iso-8859-1');
3134
}
3235

33-
/**
34-
* @expectedException \Ddeboer\Transcoder\Exception\IllegalCharacterException
35-
*/
3636
public function testTranscodeIllegalCharacter()
3737
{
38+
$this->expectException(\Ddeboer\Transcoder\Exception\IllegalCharacterException::class);
3839
$this->transcoder->transcode('', null, 'iso-8859-1');
3940
}
4041

tests/MbTranscoderTest.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,32 @@
44

55
use Ddeboer\Transcoder\MbTranscoder;
66

7-
class MbTranscoderTest extends \PHPUnit_Framework_TestCase
7+
class MbTranscoderTest extends \PHPUnit\Framework\TestCase
88
{
99
/**
1010
* @var MbTranscoder
1111
*/
1212
private $transcoder;
1313

14-
protected function setUp()
14+
/**
15+
* @before
16+
*/
17+
protected function doSetUp()
1518
{
1619
$this->transcoder = new MbTranscoder();
1720
}
1821

19-
/**
20-
* @expectedException \Ddeboer\Transcoder\Exception\UnsupportedEncodingException
21-
* @expectedExceptionMessage bad-encoding
22-
*/
2322
public function testTranscodeUnsupportedFromEncoding()
2423
{
24+
$this->expectException(\Ddeboer\Transcoder\Exception\UnsupportedEncodingException::class);
25+
$this->expectExceptionMessage('bad-encoding');
2526
$this->transcoder->transcode('bla', 'bad-encoding');
2627
}
2728

28-
/**
29-
* @expectedException \Ddeboer\Transcoder\Exception\UnsupportedEncodingException
30-
* @expectedExceptionMessage bad-encoding
31-
*/
3229
public function testTranscodeUnsupportedToEncoding()
3330
{
31+
$this->expectException(\Ddeboer\Transcoder\Exception\UnsupportedEncodingException::class);
32+
$this->expectExceptionMessage('bad-encoding');
3433
$this->transcoder->transcode('bla', null, 'bad-encoding');
3534
}
3635

@@ -40,12 +39,10 @@ public function testDetectEncoding()
4039
$this->transcoder->transcode($result);
4140
}
4241

43-
/**
44-
* @expectedException \Ddeboer\Transcoder\Exception\UndetectableEncodingException
45-
* @expectedExceptionMessage is undetectable
46-
*/
4742
public function testUndetectableEncoding()
4843
{
44+
$this->expectException(\Ddeboer\Transcoder\Exception\UndetectableEncodingException::class);
45+
$this->expectExceptionMessage('is undetectable');
4946
$result = $this->transcoder->transcode(
5047
'‘curly quotes make this incompatible with 1252’',
5148
null,

tests/TranscoderTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44

55
use Ddeboer\Transcoder\Transcoder;
66

7-
class TranscoderTest extends \PHPUnit_Framework_TestCase
7+
class TranscoderTest extends \PHPUnit\Framework\TestCase
88
{
99
/**
1010
* @var Transcoder
1111
*/
1212
private $transcoder;
1313

14-
protected function setUp()
14+
/**
15+
* @before
16+
*/
17+
protected function doSetUp()
1518
{
1619
$this->transcoder = Transcoder::create();
1720
}

0 commit comments

Comments
 (0)