Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/MigratorUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public static function getClassNameFromFile($file)
}

if ($tokens[$i][0] === T_CLASS) {
// If we have something like Test::class, we want to ignore that
if (($tokens[$i - 1][1] ?? '') === '::') {
continue;
}

for ($j = $i + 1;$j < count($tokens);$j++) {
if ($tokens[$j] === '{') {
$class = $tokens[$i + 2][1];
Expand Down
8 changes: 8 additions & 0 deletions tests/Unit/MigratorUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@ public function testGetClassName()
$className = MigratorUtil::getClassNameFromFile(__DIR__ . '/migrations/Version201511240843.php');
$this->assertEquals('\Sulu\Bundle\ContentBundle\Version201511240843', $className);
}

/**
* It should not be confused by ::class in a file
*/
public function testGetClassNameWithClassElsewhere() {
$className = MigratorUtil::getClassNameFromFile(__DIR__ . '/migrations/Version201712120843.php');
$this->assertEquals('\Sulu\Bundle\ContentBundle\Version201712120843', $className);
}
}
31 changes: 31 additions & 0 deletions tests/Unit/migrations/Version201712120843.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* This file is part of the PHPCR Migrations package
*
* (c) Daniel Leech <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sulu\Bundle\ContentBundle;

use PHPCR\Migrations\VersionInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;

/**
* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
*
* Created: 2015-12-10 10:04
*/
class Version201712120843 implements VersionInterface, ContainerAwareInterface
{
public function someFunction(): string {
return self::class;
}

public function someOtherFunctionWeNeedForMoreConfustion() {

}
}