- Replace global $translator variable with Translator::getInstance() method - Add singleton instance management to Translator class - Update compiler.php to use singleton pattern instead of global variable - Update gen_stub.php to use getTranslator() helper function - Add translator instance test to verify singleton behavior - Remove unnecessary global declarations throughout codebasemaster
parent
b61b59f808
commit
718c3dad25
4 changed files with 34 additions and 7 deletions
@ -0,0 +1,19 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
use TypePhp\CompilerTest; |
||||||
|
use TypePhp\Translator; |
||||||
|
use function TypePhp\StubGenerator\getTranslator; |
||||||
|
|
||||||
|
final class TranslatorInstanceTest extends BaseTest |
||||||
|
{ |
||||||
|
public function testLatestTranslatorInstanceIsUsedByStubGenerator(): void |
||||||
|
{ |
||||||
|
$first = CompilerTest::create(TYPEPHP_ROOT_PATH); |
||||||
|
self::assertSame($first, Translator::getInstance()); |
||||||
|
self::assertSame($first, getTranslator()); |
||||||
|
|
||||||
|
$second = CompilerTest::create(TYPEPHP_ROOT_PATH); |
||||||
|
self::assertSame($second, Translator::getInstance()); |
||||||
|
self::assertSame($second, getTranslator()); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue