-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow multi static calls in one class
- Loading branch information
1 parent
c3295b7
commit 8e0a573
Showing
4 changed files
with
69 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
tests/Resolver/StaticClassConstResolver/Fixture/FileWithStaticConstCalls.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Rector\SwissKnife\Tests\Resolver\StaticClassConstResolver\Fixture; | ||
|
||
final class FileWithStaticConstCalls | ||
{ | ||
public const ITEM_NAME = '...'; | ||
|
||
public const ITEM_PRICE = 100; | ||
|
||
public function run() | ||
{ | ||
$hash = static::ITEM_NAME . '_' . static::ITEM_PRICE; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
tests/Resolver/StaticClassConstResolver/StaticClassConstResolverTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\SwissKnife\Tests\Resolver\StaticClassConstResolver; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Rector\SwissKnife\Resolver\StaticClassConstResolver; | ||
use Rector\SwissKnife\Tests\Resolver\StaticClassConstResolver\Fixture\FileWithStaticConstCalls; | ||
use Symfony\Component\Finder\SplFileInfo; | ||
|
||
final class StaticClassConstResolverTest extends TestCase | ||
{ | ||
private StaticClassConstResolver $staticClassConstResolver; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->staticClassConstResolver = new StaticClassConstResolver(); | ||
} | ||
|
||
public function test(): void | ||
{ | ||
$splFileInfo = new SplFileInfo(__DIR__ . '/Fixture/FileWithStaticConstCalls.php', '', ''); | ||
|
||
$classConstMatches = $this->staticClassConstResolver->resolve([$splFileInfo]); | ||
$this->assertCount(2, $classConstMatches); | ||
|
||
$firstClassConstMatch = $classConstMatches[0]; | ||
$this->assertSame(FileWithStaticConstCalls::class, $firstClassConstMatch->getClassName()); | ||
$this->assertSame('ITEM_NAME', $firstClassConstMatch->getConstantName()); | ||
|
||
$secondClassConstMatch = $classConstMatches[1]; | ||
$this->assertSame(FileWithStaticConstCalls::class, $secondClassConstMatch->getClassName()); | ||
$this->assertSame('ITEM_PRICE', $secondClassConstMatch->getConstantName()); | ||
} | ||
} |