Skip to content

Commit 5eab820

Browse files
Prepare for first release
1 parent 0255937 commit 5eab820

File tree

9 files changed

+30
-10
lines changed

9 files changed

+30
-10
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"require-dev": {
2323
"nyholm/symfony-bundle-test": "^1.4",
2424
"phpunit/phpunit": "~7.5",
25-
"symfony/templating": "^4.3",
2625
"symfony/twig-bundle": "^4.3",
2726
"scrutinizer/ocular": "^1.5"
2827
},

src/Resources/config/services.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ services:
99
n2w_standard_dictionary:
1010
class: PHPViet\NumberToWords\Dictionary
1111
public: true
12+
n2w_twig_extension:
13+
class: PHPViet\Symfony\NumberToWords\Twig\Extension\N2WExtension
14+
arguments: ['@n2w']
15+
tags:
16+
- { name: twig.extension }
1217
PHPViet\NumberToWords\DictionaryInterface:
1318
class: PHPViet\NumberToWords\Dictionary
14-
public: true

src/Twig/Extension/N2WExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ class N2WExtension extends AbstractExtension
2929
/**
3030
* Khởi tạo extension
3131
*
32-
* @param Service $helper Phone number helper.
32+
* @param Service $service
3333
*/
34-
public function __construct(Service $helper)
34+
public function __construct(Service $service)
3535
{
36-
$this->service = $helper;
36+
$this->service = $service;
3737
}
3838

3939
/**

tests/Resources/test.twig

Whitespace-only changes.

tests/Resources/twig-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
twig:
2-
default_path: '%kernel.project_dir%/templates'
2+
default_path: '%kernel.project_dir%/Resources/twig-template'
33
debug: '%kernel.debug%'
44
strict_variables: '%kernel.debug%'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ 1000 | n2w('south') }}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ 123.3 | n2c(['vàng', 'bạc']) }}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ 123 | n2w }}

tests/TwigTest.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,33 @@ class TwigTest extends TestCase
2020

2121
protected function setUp(): void
2222
{
23+
$this->addCompilerPass(new PublicServicePass());
2324
$kernel = $this->createKernel();
2425
$kernel->addBundle(TwigBundle::class);
25-
$this->addCompilerPass(new PublicServicePass());
26+
$kernel->setProjectDir(__DIR__);
27+
$kernel->addConfigFile(__DIR__ . '/Resources/twig-config.yaml');
2628
$this->bootKernel();
2729
}
2830

29-
public function testFilters()
31+
public function testTransformFilter(): void
3032
{
33+
$container = $this->getContainer();
34+
$twig = $container->get('twig');
35+
$this->assertEquals('một trăm hai mươi ba', trim($twig->render('words.twig')));
36+
}
3137

38+
public function testCurrencyTransformFilter(): void
39+
{
3240
$container = $this->getContainer();
41+
$twig = $container->get('twig');
42+
$this->assertEquals('một trăm hai mươi ba vàng ba bạc', trim($twig->render('currency.twig')));
43+
}
3344

34-
var_dump($container->get('twig')->render(__DIR__ .'/Resources/test.twig'));
35-
die;
45+
public function testChangeDictionary(): void
46+
{
47+
$container = $this->getContainer();
48+
$twig = $container->get('twig');
49+
$this->assertEquals('một ngàn', trim($twig->render('change-dictionary.twig')));
3650
}
3751

3852
}

0 commit comments

Comments
 (0)