-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Yiisoft\Aliases\Aliases; | ||
|
||
|
||
function alias(string $path): string | ||
{ | ||
/** | ||
* @var Aliases $aliases | ||
Check failure on line 11 in src/alias.php GitHub Actions / PHP 8.1-ubuntu-latestUnnecessaryVarAnnotation
Check failure on line 11 in src/alias.php GitHub Actions / PHP 8.2-ubuntu-latestUnnecessaryVarAnnotation
|
||
*/ | ||
$aliases = container(Aliases::class); | ||
return $aliases->get($path); | ||
} | ||
|
||
function aliases(string ...$paths): array | ||
{ | ||
/** | ||
* @var Aliases $aliases | ||
Check failure on line 20 in src/alias.php GitHub Actions / PHP 8.1-ubuntu-latestUnnecessaryVarAnnotation
Check failure on line 20 in src/alias.php GitHub Actions / PHP 8.2-ubuntu-latestUnnecessaryVarAnnotation
|
||
*/ | ||
$aliases = container(Aliases::class); | ||
return $aliases->getArray($paths); | ||
} |
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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Xepozz\YiiShort\Tests; | ||
|
||
use Xepozz\YiiShort\State; | ||
use Yiisoft\Aliases\Aliases; | ||
use Yiisoft\Test\Support\Container\SimpleContainer; | ||
|
||
class AliasTest extends FunctionsTestCase | ||
{ | ||
public function testFunctionLoaded(): void | ||
{ | ||
$this->assertTrue(function_exists('alias')); | ||
$this->assertTrue(function_exists('aliases')); | ||
} | ||
|
||
public function testContainerIsUnset(): void | ||
{ | ||
State::$container = null; | ||
|
||
$this->expectException(\RuntimeException::class); | ||
alias('test'); | ||
} | ||
|
||
public function testAliases(): void | ||
{ | ||
State::$container = new SimpleContainer([ | ||
Aliases::class => new Aliases([ | ||
'@test1' => '/root/test1', | ||
'@test2' => '/root/test2', | ||
]), | ||
]); | ||
$this->assertEquals('/root/test1', alias('@test1')); | ||
$this->assertEquals('/root/test2', alias('@test2')); | ||
$this->assertEquals(['/root/test1', '/root/test2'], aliases('@test1', '@test2')); | ||
} | ||
|
||
public function bootstrapFiles(): iterable | ||
{ | ||
yield __DIR__ . '/../src/container.php'; | ||
yield __DIR__ . '/../src/alias.php'; | ||
} | ||
} |