From c699c931827fd5b7072859a32bc28f82b49be60c Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Fri, 19 Jun 2020 10:39:34 +0200 Subject: [PATCH 1/3] Run tests on PHPUnit 9 --- composer.json | 2 +- phpunit.xml.dist | 2 +- tests/FilterTest.php | 50 +++++++++++++++++++++++++++++-------------- tests/FunTest.php | 24 +++++++++++++++------ tests/FunZlibTest.php | 2 +- 5 files changed, 54 insertions(+), 26 deletions(-) diff --git a/composer.json b/composer.json index 834f2d4..888700b 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "php": ">=5.3" }, "require-dev": { - "phpunit/phpunit": "^5.0 || ^4.8" + "phpunit/phpunit": "^9.0 || ^5.7 || ^4.8.36" }, "autoload": { "psr-4": { "Clue\\StreamFilter\\": "src/" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f373698..def9a32 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -7,7 +7,7 @@ convertWarningsToExceptions="true" > - + ./tests/ diff --git a/tests/FilterTest.php b/tests/FilterTest.php index 02aa3a4..780fa6a 100644 --- a/tests/FilterTest.php +++ b/tests/FilterTest.php @@ -2,7 +2,7 @@ use Clue\StreamFilter; -class FilterTest extends PHPUnit_Framework_TestCase +class FilterTest extends PHPUnit\Framework\TestCase { public function testAppendSimpleCallback() { @@ -254,9 +254,12 @@ public function testAppendThrows() $this->removeErrorHandler(); $this->assertCount(1, $errors); - $this->assertContains('test', $errors[0]); + $this->assertContainsString('test', $errors[0]); } + /** + * @doesNotPerformAssertions + */ public function testAppendThrowsDuringEnd() { $stream = $this->createStream(); @@ -305,7 +308,7 @@ public function testAppendThrowsShouldTriggerEnd() $this->removeErrorHandler(); $this->assertCount(1, $errors); - $this->assertContains('test', $errors[0]); + $this->assertContainsString('test', $errors[0]); } public function testAppendThrowsShouldTriggerEndButIgnoreExceptionDuringEnd() @@ -326,41 +329,33 @@ public function testAppendThrowsShouldTriggerEndButIgnoreExceptionDuringEnd() $this->removeErrorHandler(); $this->assertCount(1, $errors); - $this->assertContains('test', $errors[0]); + $this->assertContainsString('test', $errors[0]); } - /** - * @expectedException RuntimeException - */ public function testAppendInvalidStreamIsRuntimeError() { + $this->setExpectedException('RuntimeException'); if (defined('HHVM_VERSION')) $this->markTestSkipped('Not supported on HHVM (does not reject invalid stream)'); StreamFilter\append(false, function () { }); } - /** - * @expectedException RuntimeException - */ public function testPrependInvalidStreamIsRuntimeError() { + $this->setExpectedException('RuntimeException'); if (defined('HHVM_VERSION')) $this->markTestSkipped('Not supported on HHVM (does not reject invalid stream)'); StreamFilter\prepend(false, function () { }); } - /** - * @expectedException RuntimeException - */ public function testRemoveInvalidFilterIsRuntimeError() { + $this->setExpectedException('RuntimeException'); if (defined('HHVM_VERSION')) $this->markTestSkipped('Not supported on HHVM (does not reject invalid filters)'); StreamFilter\remove(false); } - /** - * @expectedException InvalidArgumentException - */ public function testInvalidCallbackIsInvalidArgument() { + $this->setExpectedException('InvalidArgumentException'); $stream = $this->createStream(); StreamFilter\append($stream, 'a-b-c'); @@ -383,4 +378,27 @@ private function removeErrorHandler() { restore_error_handler(); } + + public function setExpectedException($exception, $message = '', $code = 0) + { + if (method_exists($this, 'expectException')) { + $this->expectException($exception); + if ($message !== '') { + $this->expectExceptionMessage($message); + } + $this->expectExceptionCode($code); + } else { + parent::setExpectedException($exception, $message, $code); + } + } + + public function assertContainsString($needle, $haystack) + { + if (method_exists($this, 'assertStringContainsString')) { + $this->assertStringContainsString($needle, $haystack); + } else { + $this->assertContains($needle, $haystack); + } + } + } diff --git a/tests/FunTest.php b/tests/FunTest.php index d0812e8..a510761 100644 --- a/tests/FunTest.php +++ b/tests/FunTest.php @@ -2,7 +2,7 @@ use Clue\StreamFilter as Filter; -class FunTest extends PHPUnit_Framework_TestCase +class FunTest extends PHPUnit\Framework\TestCase { public function testFunInRot13() { @@ -23,22 +23,18 @@ public function testFunInQuotedPrintable() $this->assertEquals(null, $encode()); } - /** - * @expectedException RuntimeException - */ public function testFunWriteAfterCloseRot13() { + $this->setExpectedException('RuntimeException'); $rot = Filter\fun('string.rot13'); $this->assertEquals(null, $rot()); $rot('test'); } - /** - * @expectedException RuntimeException - */ public function testFunInvalid() { + $this->setExpectedException('RuntimeException'); Filter\fun('unknown'); } @@ -58,4 +54,18 @@ public function testFunInBase64() $encode = Filter\fun('convert.base64-encode'); $this->assertEquals(null, $encode()); } + + public function setExpectedException($exception, $message = '', $code = 0) + { + if (method_exists($this, 'expectException')) { + $this->expectException($exception); + if ($message !== '') { + $this->expectExceptionMessage($message); + } + $this->expectExceptionCode($code); + } else { + parent::setExpectedException($exception, $message, $code); + } + } + } diff --git a/tests/FunZlibTest.php b/tests/FunZlibTest.php index 752c8a2..5471f80 100644 --- a/tests/FunZlibTest.php +++ b/tests/FunZlibTest.php @@ -2,7 +2,7 @@ use Clue\StreamFilter; -class BuiltInZlibTest extends PHPUnit_Framework_TestCase +class BuiltInZlibTest extends PHPUnit\Framework\TestCase { public function testFunZlibDeflateHelloWorld() { From 276956d68f0006a746092dc1b188edf47902322c Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Fri, 19 Jun 2020 11:20:43 +0200 Subject: [PATCH 2/3] Add .gitattributes to exclude dev files from exports --- .gitattributes | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..0925d33 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +/.gitattributes export-ignore +/.gitignore export-ignore +/.travis.yml export-ignore +/examples/ export-ignore +/phpunit.xml.dist export-ignore +/tests/ export-ignore From 91825b10edef100eb322aa41231303d7a1d7ae04 Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Fri, 19 Jun 2020 12:08:24 +0200 Subject: [PATCH 3/3] Clean up test suite --- composer.json | 3 +++ phpunit.xml.dist | 7 +------ tests/FilterTest.php | 5 ++++- tests/FunTest.php | 5 ++++- tests/FunZlibTest.php | 5 ++++- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 888700b..6a0083d 100644 --- a/composer.json +++ b/composer.json @@ -19,5 +19,8 @@ "autoload": { "psr-4": { "Clue\\StreamFilter\\": "src/" }, "files": [ "src/functions_include.php" ] + }, + "autoload-dev": { + "psr-4": { "Clue\\Tests\\StreamFilter\\": "tests/" } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index def9a32..0edd97b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,11 +1,6 @@ - + ./tests/ diff --git a/tests/FilterTest.php b/tests/FilterTest.php index 780fa6a..bbf95c0 100644 --- a/tests/FilterTest.php +++ b/tests/FilterTest.php @@ -1,8 +1,11 @@