Skip to content

Commit

Permalink
Fixes #202 Remove null byte from anonymous class reflection name
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Multiply committed Aug 11, 2016
1 parent 54fb040 commit a7a64c0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ParaTest/Console/Testers/PHPUnit.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php
namespace ParaTest\Console\Testers;

use Symfony\Component\Console\Command\Command;
Expand Down
12 changes: 11 additions & 1 deletion src/ParaTest/Parser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,22 @@ public function getClass()
? null
: new ParsedClass(
$this->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
*
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/failing-tests/AnonymousClass.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

new class() {
/**
* @return class
*/
public function testAnonymousClass()
{
return new class()
{
};
}
};
10 changes: 10 additions & 0 deletions test/unit/ParaTest/Parser/ParserTest/GetClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ public function testParsedClassHasName()
$this->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'));
Expand Down

0 comments on commit a7a64c0

Please # to comment.