Skip to content

Commit c8dce0e

Browse files
committed
test: app translate
1 parent 16f8b48 commit c8dce0e

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

tests/ApplicationTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,23 @@ public function test_on_exception()
326326
$app->handle(['test', 'cmd']);
327327
}
328328

329+
public function test_app_translated()
330+
{
331+
$app = $this->newApp('test');
332+
$app->addLocale('fr', [
333+
'Show version' => 'Afficher la version',
334+
'Verbosity level' => 'Niveau de verbocité',
335+
'%s [default: %s]' => '%s [par défaut: %s]',
336+
], true);
337+
$app->command('rmdir');
338+
339+
$app->handle(['test', 'rmdir', '--help']);
340+
$o = file_get_contents(static::$ou);
341+
342+
$this->assertStringContainsString('Afficher la version', $o);
343+
$this->assertStringContainsString('Niveau de verbocité [par défaut: 0]', $o);
344+
}
345+
329346
protected function newApp(string $name, string $version = '')
330347
{
331348
$app = new Application($name, $version ?: '0.0.1', fn () => false);

tests/Helper/InflectsStringTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Ahc\Cli\Test\Helper;
1313

14+
use Ahc\Cli\Application;
1415
use Ahc\Cli\Helper\InflectsString;
1516
use PHPUnit\Framework\TestCase;
1617

@@ -31,4 +32,28 @@ public function test_to_words()
3132
$this->assertSame('The Long Name', $this->toWords('--the_long-name'));
3233
$this->assertSame('A BC', $this->toWords('a_bC'));
3334
}
35+
36+
public function test_default_translate(): void
37+
{
38+
$this->assertSame('Show version', $this->translate('Show version'));
39+
$this->assertSame('Verbosity level [default: 0]', $this->translate('%s [default: %s]', ['Verbosity level', 0]));
40+
$this->assertSame('Command "rmdir" already added', $this->translate('Command "%s" already added', ['rmdir']));
41+
}
42+
43+
public function test_custom_translations(): void
44+
{
45+
Application::addLocale('fr', [
46+
'Show version' => 'Afficher la version',
47+
'%s [default: %s]' => '%s [par défaut: %s]',
48+
'Command "%s" already added' => 'La commande "%s" a déjà été ajoutée'
49+
], true);
50+
51+
52+
$this->assertSame('Afficher la version', $this->translate('Show version'));
53+
$this->assertSame('Verbosity level [par défaut: 0]', $this->translate('%s [default: %s]', ['Verbosity level', 0]));
54+
$this->assertSame('La commande "rmdir" a déjà été ajoutée', $this->translate('Command "%s" already added', ['rmdir']));
55+
56+
// untranslated key
57+
$this->assertSame('Show help', $this->translate('Show help'));
58+
}
3459
}

0 commit comments

Comments
 (0)