From 79b3f017301008f6de48dfe866c631accf06740b Mon Sep 17 00:00:00 2001 From: Bastian Hofmann Date: Thu, 17 Sep 2015 12:22:59 +0200 Subject: [PATCH] Filter out heredocs --- src/rg/tools/phpnsc/ClassScanner.php | 1 + test/rg/tools/phpnsc/ClassScannerTest.php | 63 +++++++++++++---------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/rg/tools/phpnsc/ClassScanner.php b/src/rg/tools/phpnsc/ClassScanner.php index 5d41d16..3c121cb 100644 --- a/src/rg/tools/phpnsc/ClassScanner.php +++ b/src/rg/tools/phpnsc/ClassScanner.php @@ -115,6 +115,7 @@ private function cleanContent($fileContent) { $fileContent = $cleanWithWhitespaces("/(\'.*\')/sU", $fileContent); $fileContent = $cleanWithWhitespaces("/(\".*\")/sU", $fileContent); $fileContent = $cleanWithWhitespaces("/(\/\/.*)/", $fileContent); + $fileContent = $cleanWithWhitespaces("/(<<<(?P[A-Za-z_]+).*\g;)/sU", $fileContent); if (false) { $fileContent = preg_replace("/(\/\*.*\*\/)/sU", '', $fileContent); diff --git a/test/rg/tools/phpnsc/ClassScannerTest.php b/test/rg/tools/phpnsc/ClassScannerTest.php index 5b3578e..6e26c05 100644 --- a/test/rg/tools/phpnsc/ClassScannerTest.php +++ b/test/rg/tools/phpnsc/ClassScannerTest.php @@ -5,24 +5,24 @@ class ClassScannerTest extends PHPUnit_Framework_TestCase { /** * - * @var ClassScannerFilesystemMock + * @var ClassScannerFilesystemMock */ private $filesystem; /** * - * @var rg\tools\phpnsc\ClassScanner + * @var rg\tools\phpnsc\ClassScanner */ private $classScanner; - + protected function setUp() { parent::setUp(); $output = new Symfony\Component\Console\Output\NullOutput(); $outputClass = new rg\tools\phpnsc\ConsoleOutput($output); $this->filesystem = new ClassScannerFilesystemMock('/root/folder'); - $this->classScanner = new rg\tools\phpnsc\ClassScanner($this->filesystem, '/root/folder', + $this->classScanner = new rg\tools\phpnsc\ClassScanner($this->filesystem, '/root/folder', 'vendor', $outputClass); } - + public function testParseDefinedEntities() { $this->filesystem->filesystem = array( '/root/folder/namespace/ClassOne.php' => ' @@ -48,16 +48,16 @@ class %%^daga abstract class ClassTwo interface InterfaceTwo -', +', '/root/folder/namespace/InterfaceOne.php' => ' filesystem->filesystem); - + $this->classScanner->parseFilesForClassesAndInterfaces($files); - + $expectedEntities = array( 'ClassOne' => array( 'namespaces' => array('vendor\namespace'), @@ -75,10 +75,10 @@ interface InterfaceOne 'namespaces' => array('vendor\namespace'), ), ); - + $this->assertEquals($expectedEntities, $this->classScanner->getDefinedEntities()); } - + public function testParseDefinedEntitiesWithDoubleEntityRaisesException() { $this->filesystem->filesystem = array( '/root/folder/namespace/ClassOne.php' => ' @@ -95,12 +95,12 @@ class %%^daga abstract class ClassOne interface InterfaceTwo -', +', ); $files = array_keys($this->filesystem->filesystem); - + $this->classScanner->parseFilesForClassesAndInterfaces($files); - + $expectedEntities = array( 'ClassOne' => array( 'namespaces' => array('vendor\namespace', 'vendor\namespaceTwo'), @@ -109,10 +109,10 @@ interface InterfaceTwo 'namespaces' => array('vendor\namespaceTwo'), ), ); - + $this->assertEquals($expectedEntities, $this->classScanner->getDefinedEntities()); } - + public function testParseUsedEntities() { $this->filesystem->filesystem = array( '/root/folder/namespace/ClassOne.php' => ' @@ -121,30 +121,39 @@ class ClassOne implements Bar extends Foo ', '/root/folder/namespace/ClassTwo.php' => ' filesystem->filesystem); - + $this->classScanner->parseFilesForClassesAndInterfaces($files); - + $expectedEntities = array( '/root/folder/namespace/ClassOne.php' => array( - 'Foo' => array(3), 'Bar' => array(3), + 'Foo' => array(3), + 'Bar' => array(3), ), '/root/folder/namespace/ClassTwo.php' => array( - 'ClassOne' => array(5), 'ClassTwo' => array(6,9), 'ClassThree' => array(5), 'OutOfNamespace' => array(9), 'TypeHintClass' => array(5), - 'OtherNamespace' => array(9), 'Bar' => array(3), + 'ClassOne' => array(8), + 'ClassTwo' => array(9,12), + 'ClassThree' => array(8), + 'OutOfNamespace' => array(12), + 'TypeHintClass' => array(8), + 'OtherNamespace' => array(12), + 'Bar' => array(3), ), ); - + foreach ($files as $file) { $this->assertEquals($expectedEntities[$file], $this->classScanner->getUsedEntities($file)); } @@ -154,8 +163,8 @@ interface InterfaceTwo class ClassScannerFilesystemMock extends \rg\tools\phpnsc\FilesystemAccess { public $filesystem = array(); - + public function getFile($filename) { return $this->filesystem[$filename]; } -} \ No newline at end of file +}