Skip to content

Commit

Permalink
Test: EncapsedStringsToSprintfRector + RemoveDeadInstanceOfRector (
Browse files Browse the repository at this point in the history
  • Loading branch information
Androbin committed Jun 12, 2021
1 parent 4b41e97 commit 7bbbed1
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,7 @@ parameters:

# cache hacking
- '#"@var_export\(new \\Symplify\\EasyCodingStandard\\Caching\\ValueObject\\CacheItem\(\$variableKey, \$data\), true\)" is forbidden to use#'

-
message: '#Missing sprintf\(\) function for a mask#'
path: rules/CodingStyle/Rector/Encapsed/EncapsedStringsToSprintfRector.php #124
36 changes: 36 additions & 0 deletions tests/Issues/Issue6481/EncapsedStringsInsideDeadInstanceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Rector\Core\Tests\Issues\Issue6481;

use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;

/**
* @see https://github.com/rectorphp/rector/issues/6481
*/
final class EncapsedStringsInsideDeadInstanceTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}

/**
* @return Iterator<SmartFileInfo>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
33 changes: 33 additions & 0 deletions tests/Issues/Issue6481/Fixture/fixture.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Rector\Core\Tests\Issues\Issue6481\Fixture;

class Fixture
{
public function test(): void {
$lorem = new \DateTime();
$ipsum = "";

if ($lorem instanceof \DateTime) {
echo "$ipsum";
}
}
}

?>
-----
<?php

namespace Rector\Core\Tests\Issues\Issue6481\Fixture;

class Fixture
{
public function test(): void {
$lorem = new \DateTime();
$ipsum = "";

echo sprintf('%s', $ipsum);
}
}

?>
13 changes: 13 additions & 0 deletions tests/Issues/Issue6481/config/configured_rule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
use Rector\DeadCode\Rector\If_\RemoveDeadInstanceOfRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(EncapsedStringsToSprintfRector::class);
$services->set(RemoveDeadInstanceOfRector::class);
};

0 comments on commit 7bbbed1

Please sign in to comment.