add FQNize same-namespace test

This commit is contained in:
Tomas Votruba 2019-09-15 20:45:58 +02:00
parent 57bc309d5a
commit abf9ced755
7 changed files with 49 additions and 4 deletions

View File

@ -83,8 +83,6 @@ final class FileMover
}
}
// @todo: nodes must be sometimes FQNized
// 3. return changed nodes and new file destination
$newFileDestination = $this->fileRelocationResolver->createNewFileDestination(
$smartFileInfo,

View File

@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace Rector\Autodiscovery\Tests\Rector\FileSystem\MoveServicesBySuffixToDirectoryRector\Source\Command;
final class BananaCommand
{
public function run()
{
return new \Rector\Autodiscovery\Tests\Rector\FileSystem\MoveServicesBySuffixToDirectoryRector\Source\Controller\Orange();
}
}

View File

@ -35,13 +35,19 @@ final class MoveServicesBySuffixToDirectoryRectorTest extends AbstractFileSystem
__DIR__ . '/Source/Fixture/Repository/AppleRepository.php',
__DIR__ . '/Fixture/ExpectedAppleRepository.php',
];
yield 'prefix_same_namespace' => [
__DIR__ . '/Source/Controller/BananaCommand.php',
__DIR__ . '/Source/Fixture/Command/BananaCommand.php',
__DIR__ . '/Fixture/Command/ExpectedBananaCommand.php',
];
}
protected function getRectorsWithConfiguration(): array
{
return [
MoveServicesBySuffixToDirectoryRector::class => [
'$groupNamesBySuffix' => ['Repository'],
'$groupNamesBySuffix' => ['Repository', 'Command'],
],
];
}

View File

@ -0,0 +1,11 @@
<?php declare(strict_types=1);
namespace Rector\Autodiscovery\Tests\Rector\FileSystem\MoveServicesBySuffixToDirectoryRector\Source\Controller;
final class BananaCommand
{
public function run()
{
return new Orange();
}
}

View File

@ -0,0 +1,8 @@
<?php declare(strict_types=1);
namespace Rector\Autodiscovery\Tests\Rector\FileSystem\MoveServicesBySuffixToDirectoryRector\Source\Controller;
final class Orange
{
}

View File

@ -12,6 +12,7 @@ use PhpParser\Node\Scalar\EncapsedStringPart;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Declare_;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Nop;
use PhpParser\Node\Stmt\TraitUse;
@ -225,6 +226,16 @@ final class BetterStandardPrinter extends Standard
return parent::pStmt_Class($class);
}
/**
* It remove all spaces extra to parent
*/
protected function pStmt_Declare(Declare_ $declare): string
{
$declareString = parent::pStmt_Declare($declare);
return Strings::replace($declareString, '#\s+#');
}
/**
* @param Node[] $nodes
*/

View File

@ -3,7 +3,7 @@
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
declare (strict_types=1);
declare(strict_types=1);
namespace NettePostfixedToUniqueAutoload\Utils;
/**