Skip to content

Commit

Permalink
MAGETWO-41996: [GitHub] DI compilation fails on class keyword #1722
Browse files Browse the repository at this point in the history
  • Loading branch information
Joan He committed Aug 28, 2015
1 parent 18b6326 commit 623e201
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,4 @@ setup/src/Magento/Setup/Test/Unit/Module/Di/_files/app/code/Magento/SomeModule/M
setup/src/Magento/Setup/Test/Unit/Module/Di/_files/app/code/Magento/SomeModule/Helper/Test.php
setup/src/Magento/Setup/Test/Unit/Module/Di/_files/app/code/Magento/SomeModule/Element.php
setup/src/Magento/Setup/Test/Unit/Module/Di/_files/app/code/Magento/SomeModule/ElementFactory.php
setup/src/Magento/Setup/Test/Unit/Module/Di/_files/app/code/Magento/SomeModule/Model/DoubleColon.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ Model3
\Magento\Mtf\Client\Element
\Magento\Mtf\TestSuite\AppState
\Magento\Framework\A
\Magento\Framework\B
\Magento\Framework\B
DoubleColon
8 changes: 4 additions & 4 deletions setup/src/Magento/Setup/Module/Di/Code/Scanner/PhpScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,17 @@ protected function _fetchClasses($namespace, $tokenIterator, $count, $tokens)
protected function _getDeclaredClasses($file)
{
$classes = [];
$namespace = "";
$namespace = '';
$tokens = token_get_all(file_get_contents($file));
$count = count($tokens);

for ($tokenIterator = 0; $tokenIterator < $count; $tokenIterator++) {
if ($tokens[$tokenIterator][0] === T_NAMESPACE) {
if ($tokens[$tokenIterator][0] == T_NAMESPACE) {
$namespace .= $this->_fetchNamespace($tokenIterator, $count, $tokens);
}

if ($tokens[$tokenIterator][0] === T_CLASS
|| $tokens[$tokenIterator][0] === T_INTERFACE
if (($tokens[$tokenIterator][0] == T_CLASS || $tokens[$tokenIterator][0] == T_INTERFACE)
&& $tokens[$tokenIterator - 1][0] != T_DOUBLE_COLON
) {
$classes = array_merge($classes, $this->_fetchClasses($namespace, $tokenIterator, $count, $tokens));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

require_once __DIR__ . '/../../_files/app/code/Magento/SomeModule/Helper/Test.php';
require_once __DIR__ . '/../../_files/app/code/Magento/SomeModule/ElementFactory.php';
require_once __DIR__ . '/../../_files/app/code/Magento/SomeModule/Model/DoubleColon.php';

class PhpScannerTest extends \PHPUnit_Framework_TestCase
{
/**
Expand Down Expand Up @@ -35,7 +37,10 @@ protected function setUp()
$this->_logMock = $this->getMock('\Magento\Setup\Module\Di\Compiler\Log\Log', [], [], '', false)
);
$this->_testDir = str_replace('\\', '/', realpath(__DIR__ . '/../../') . '/_files');
$this->_testFiles = [$this->_testDir . '/app/code/Magento/SomeModule/Helper/Test.php'];
$this->_testFiles = [
$this->_testDir . '/app/code/Magento/SomeModule/Helper/Test.php',
$this->_testDir . '/app/code/Magento/SomeModule/Model/DoubleColon.php'
];
}

public function testCollectEntities()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\SomeModule\Model;

class DoubleColon
{
public function __construct()
{
DoubleColon::class;
}

public function method()
{
}
}

0 comments on commit 623e201

Please sign in to comment.