From a7a64c0f14037ebeec0bc9ca7f24885568e3a2cf Mon Sep 17 00:00:00 2001 From: Jens Ulrich Hjuler Pedersen Date: Wed, 13 Jul 2016 14:17:10 +0200 Subject: [PATCH] Fixes #202 Remove null byte from anonymous class reflection name Since php7's anonymous class names contain null bytes, we've encountered some issues with paratests' Parser-class. This fix remove said null byte, to avoid obscure failures. --- src/ParaTest/Console/Testers/PHPUnit.php | 2 +- src/ParaTest/Parser/Parser.php | 12 +++++++++++- test/fixtures/failing-tests/AnonymousClass.inc | 13 +++++++++++++ .../ParaTest/Parser/ParserTest/GetClassTest.php | 10 ++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/failing-tests/AnonymousClass.inc diff --git a/src/ParaTest/Console/Testers/PHPUnit.php b/src/ParaTest/Console/Testers/PHPUnit.php index 45b62e64..5390003c 100644 --- a/src/ParaTest/Console/Testers/PHPUnit.php +++ b/src/ParaTest/Console/Testers/PHPUnit.php @@ -1,4 +1,4 @@ -refl->getDocComment(), - $this->refl->getName(), + $this->getCleanReflectionName(), $this->refl->getNamespaceName(), $this->getMethods() ); } + /** + * Return reflection name with null bytes stripped + * + * @return string + */ + private function getCleanReflectionName() + { + return str_replace("\x00", '', $this->refl->getName()); + } + /** * Return all test methods present in the file * diff --git a/test/fixtures/failing-tests/AnonymousClass.inc b/test/fixtures/failing-tests/AnonymousClass.inc new file mode 100644 index 00000000..c192dbb9 --- /dev/null +++ b/test/fixtures/failing-tests/AnonymousClass.inc @@ -0,0 +1,13 @@ +assertEquals('Fixtures\\Tests\\UnitTestWithClassAnnotationTest', $class->getName()); } + public function testParsedAnonymousClassNameHasNoNullByte() + { + if (PHP_VERSION_ID < 70000) { + return $this->markTestSkipped('php versions prior to php7 does not support anonymous classes'); + } + + $class = $this->parseFile($this->fixture('failing-tests/AnonymousClass.inc')); + $this->assertNotContains("\x00", $class->getName()); + } + public function testParsedClassHasDocBlock() { $class = $this->parseFile($this->fixture('failing-tests/UnitTestWithClassAnnotationTest.php'));