Skip to content

Commit

Permalink
Merge pull request #216 from Multiply/reflection-name-without-nullbyte
Browse files Browse the repository at this point in the history
Fixes #202 Remove null byte from anonymous class reflection name
  • Loading branch information
julianseeger authored Aug 12, 2016
2 parents ea73dc9 + a7a64c0 commit d7038a8
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 d7038a8

Please sign in to comment.