Skip to content

Commit bfafd6c

Browse files
authored
Merge pull request #530 from franmomu/symfony5
Allow Symfony 5 and Twig 3
2 parents 88450b4 + c018d3c commit bfafd6c

23 files changed

+218
-43
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ matrix:
3535
env: SYMFONY_VERSION=^4.3
3636
- php: 7.4
3737
env: SYMFONY_VERSION=^4.3
38+
- php: 7.2
39+
env: SYMFONY_VERSION=^5.0
40+
- php: 7.3
41+
env: SYMFONY_VERSION=^5.0
42+
- php: 7.4
43+
env: SYMFONY_VERSION=^5.0
3844

3945
install:
4046
- if [ -x .travis/install_${TARGET}.sh ]; then .travis/install_${TARGET}.sh; fi;

Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Changelog
2+
### 1.4.3 to UNRELEASED
3+
* Added support for SF5
4+
* Dropped support for SF < 3.4
5+
26
### 1.4.2 to 1.4.3
37
* Added support for SF4
48
* Fixed jms.js error

Command/ExtractTranslationCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@ protected function configure()
8989
/**
9090
* @param InputInterface $input
9191
* @param OutputInterface $output
92-
* @return void
9392
*/
94-
protected function execute(InputInterface $input, OutputInterface $output)
93+
protected function execute(InputInterface $input, OutputInterface $output): int
9594
{
9695
$builder = $input->getOption('config') ?
9796
$this->configFactory->getBuilder($input->getOption('config'))
@@ -148,13 +147,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
148147
}
149148
}
150149

151-
return;
150+
return 0;
152151
}
153152

154153
$this->updater->process($config);
155154
}
156155

157156
$output->writeln('done!');
157+
158+
return 0;
158159
}
159160

160161
/**

Command/ResourcesListCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ protected function configure()
6969
/**
7070
* @param \Symfony\Component\Console\Input\InputInterface $input
7171
* @param \Symfony\Component\Console\Output\OutputInterface $output
72-
* @return void
7372
*/
74-
protected function execute(InputInterface $input, OutputInterface $output)
73+
protected function execute(InputInterface $input, OutputInterface $output): int
7574
{
7675
$directoriesToSearch = [];
7776

@@ -95,7 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9594

9695
$output->writeln('done!');
9796

98-
return;
97+
return 0;
9998
}
10099

101100
$output->writeln('<info>Resources list :</info>');
@@ -108,6 +107,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
108107
}
109108

110109
$output->writeln('done!');
110+
111+
return 0;
111112
}
112113

113114
/**

Tests/Functional/BaseTestCase.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@
2121
namespace JMS\TranslationBundle\Tests\Functional;
2222

2323
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
24+
use Symfony\Component\HttpKernel\Kernel;
2425

2526
class BaseTestCase extends WebTestCase
2627
{
2728
protected static function createKernel(array $options = [])
2829
{
30+
$isSf5 = version_compare(Kernel::VERSION, '5.0.0') >= 0;
31+
32+
$default = $isSf5 ? 'default_sf5.yml' : 'default.yml';
33+
2934
return new AppKernel(
30-
$options['config'] ?? 'default.yml'
35+
$options['config'] ?? $default
3136
);
3237
}
3338
}

Tests/Functional/Fixture/TestBundle/Controller/AppleController.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,13 @@ public function viewAction()
2121
{
2222
return ['nbApples' => 5];
2323
}
24+
25+
/**
26+
* @Route("/view_sf5")
27+
* @Template("@Test/Apple/view_sf5.html.twig")
28+
*/
29+
public function viewsf5Action()
30+
{
31+
return ['nbApples' => 5];
32+
}
2433
}

Tests/Functional/Fixture/TestBundle/Resources/views/Apple/view.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
{# This translation does exist in our messages.en.yml file #}
66
{{ "text.apples_remaining"|transchoice(nbApples)
7-
|desc("Some default message which should never be applied because it instead is coming from the messages file.") }}
7+
|desc("Some default message which should never be applied because it instead is coming from the messages file.") }}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{ "text.apples_remaining"|trans({'%count%': nbApples})
2+
|desc("Some default message which should never be applied because it instead is coming from the messages file.") }}

Tests/Functional/TranslationTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@
44

55
namespace JMS\TranslationBundle\Tests\Functional;
66

7+
use Symfony\Component\HttpKernel\Kernel;
8+
79
class TranslationTest extends BaseTestCase
810
{
911
public function testTranschoiceWhenTranslationNotYetExtracted()
1012
{
13+
$isSf5 = version_compare(Kernel::VERSION, '5.0.0') >= 0;
14+
15+
$url = $isSf5 ? '/apples/view_sf5' : '/apples/view';
1116
$client = $this->createClient();
12-
$client->request('GET', '/apples/view');
17+
$client->request('GET', $url);
1318
$response = $client->getResponse();
1419

1520
$this->assertEquals(200, $response->getStatusCode(), $response->getContent());
16-
$this->assertEquals("There are 5 apples\n\nThere are 5 apples", $response->getContent());
21+
$expected = $isSf5 ? "There are 5 apples\n" : "There are 5 apples\n\nThere are 5 apples\n";
22+
$this->assertEquals($expected, $response->getContent());
1723
}
1824
}

Tests/Functional/config/default.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ imports:
33
- { resource: twig.yml }
44
- { resource: bundle.yml }
55

6+
framework:
7+
templating:
8+
engines: [twig, php]
9+
610
parameters:
7-
translation_output_dir: "%kernel.root_dir%/Fixture/TestBundle/Resources/translations"
11+
translation_output_dir: "%kernel.project_dir%/Fixture/TestBundle/Resources/translations"
812

913
services:
1014
logger:

0 commit comments

Comments
 (0)