Skip to content

Commit

Permalink
tests(kernel): add tests testFunctionLang
Browse files Browse the repository at this point in the history
  • Loading branch information
doyouhaobaby committed Oct 23, 2020
1 parent 01d3949 commit 5daf718
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/Kernel/FunctionsTest.php
Expand Up @@ -23,6 +23,7 @@
use App as Apps;
use Leevel;
use Leevel\Di\Container;
use Leevel\I18n\II18n;
use Leevel\Kernel\App;
use Tests\TestCase;

Expand Down Expand Up @@ -102,6 +103,39 @@ public function testAppWithContainerMethod(): void
$this->assertSame('foo', Apps::make('foo'));
}

/**
* @api(
* zh-CN:title="鍏ㄥ眬璇█鍑芥暟 __()",
* zh-CN:description="",
* zh-CN:note="",
* )
*/
public function testFunctionLang(): void
{
$container = $this->createContainer();
$this->assertSame('foo', Apps::make('foo'));

$i18n = $this->createMock(II18n::class);
$map = [
['hello', 'hello'],
['hello %s', 'foo', 'hello foo'],
['hello %d', 5, 'hello 5'],
];
$i18n->method('gettext')->willReturnMap($map);
$this->assertSame('hello', $i18n->gettext('hello'));
$this->assertSame('hello foo', $i18n->gettext('hello %s', 'foo'));
$this->assertSame('hello 5', $i18n->gettext('hello %d', 5));

$container = $this->createContainer();
$container->singleton('i18n', function () use ($i18n) {
return $i18n;
});

$this->assertSame('hello', __('hello'));
$this->assertSame('hello foo', __('hello %s', 'foo'));
$this->assertSame('hello 5', __('hello %d', 5));
}

protected function createContainer(): Container
{
$container = Container::singletons();
Expand Down

0 comments on commit 5daf718

Please sign in to comment.