Skip to content

Commit 957fe67

Browse files
authored
Merge pull request #616 from deguif/bump-composer-requirements
Bump composer requirements
2 parents 45c2434 + 69fa13c commit 957fe67

25 files changed

+153
-214
lines changed

.github/workflows/ci.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ jobs:
2222
fail-fast: false
2323
matrix:
2424
symfony-version:
25-
- '^5.4'
2625
- '^6.4'
2726
- '^7.2'
2827
php-version:
@@ -45,11 +44,6 @@ jobs:
4544
tools: 'flex'
4645
ini-values: "zend.assertions=1"
4746

48-
- name: 'Remove sensio/framework-extra-bundle'
49-
if: matrix.symfony-version == '^7.2'
50-
run: |
51-
composer remove --dev --no-update sensio/framework-extra-bundle
52-
5347
- name: "Install dependencies with Composer"
5448
uses: "ramsey/composer-install@v3"
5549
with:

.github/workflows/coding-standards.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
matrix:
1616
php-version:
17-
- "8.4"
17+
- '8.4'
1818

1919
steps:
2020
- name: "Checkout"

Controller/ApiController.php

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,22 @@
2626
use JMS\TranslationBundle\Util\FileUtils;
2727
use Symfony\Component\HttpFoundation\Request;
2828
use Symfony\Component\HttpFoundation\Response;
29-
use Symfony\Component\Routing\Annotation\Route;
29+
use Symfony\Component\Routing\Attribute\Route;
3030

3131
/**
3232
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
33-
*
34-
* @Route("/api")
3533
*/
3634
#[Route('/api')]
3735
class ApiController
3836
{
39-
private ConfigFactory $configFactory;
40-
41-
private Updater $updater;
42-
43-
public function __construct(ConfigFactory $configFactory, Updater $updater)
44-
{
45-
$this->configFactory = $configFactory;
46-
$this->updater = $updater;
37+
public function __construct(
38+
private ConfigFactory $configFactory,
39+
private Updater $updater,
40+
) {
4741
}
4842

49-
/**
50-
* @param Request $request
51-
* @param string $config
52-
* @param string $domain
53-
* @param string $locale
54-
*
55-
* @return Response
56-
*
57-
* @Route("/configs/{config}/domains/{domain}/locales/{locale}/messages",
58-
* methods={"PUT"},
59-
* name="jms_translation_update_message",
60-
* defaults = {"id" = null},
61-
* options = {"i18n" = false})
62-
*/
6343
#[Route('/configs/{config}/domains/{domain}/locales/{locale}/messages', name: 'jms_translation_update_message', methods: [Request::METHOD_PUT], defaults: ['id' => null], options: ['i18n' => false])]
64-
public function updateMessageAction(Request $request, $config, $domain, $locale)
44+
public function updateMessageAction(Request $request, string $config, string $domain, string $locale): Response
6545
{
6646
$id = $request->query->get('id');
6747

Controller/TranslateController.php

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
2424
use JMS\TranslationBundle\Translation\ConfigFactory;
2525
use JMS\TranslationBundle\Translation\LoaderManager;
2626
use JMS\TranslationBundle\Util\FileUtils;
27-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
2827
use Symfony\Component\HttpFoundation\Request;
2928
use Symfony\Component\HttpFoundation\Response;
30-
use Symfony\Component\Routing\Annotation\Route;
29+
use Symfony\Component\Routing\Attribute\Route;
3130
use Twig\Environment;
3231

3332
/**
@@ -37,39 +36,24 @@
3736
*/
3837
class TranslateController
3938
{
40-
private ConfigFactory $configFactory;
41-
42-
private LoaderManager $loader;
43-
44-
private Environment|null $twig;
45-
4639
private string|null $sourceLanguage = null;
4740

48-
public function __construct(ConfigFactory $configFactory, LoaderManager $loader, ?Environment $twig = null)
49-
{
50-
$this->configFactory = $configFactory;
51-
$this->loader = $loader;
52-
$this->twig = $twig;
41+
public function __construct(
42+
private ConfigFactory $configFactory,
43+
private LoaderManager $loader,
44+
private Environment $twig,
45+
) {
5346
}
5447

55-
/**
56-
* @param string $lang
57-
*/
58-
public function setSourceLanguage($lang)
48+
public function setSourceLanguage(string $lang): static
5949
{
6050
$this->sourceLanguage = $lang;
51+
52+
return $this;
6153
}
6254

63-
/**
64-
* @param Request $request
65-
*
66-
* @return Response|array
67-
*
68-
* @Route("/", name="jms_translation_index", options = {"i18n" = false})
69-
* @Template("@JMSTranslation/Translate/index.html.twig")
70-
*/
7155
#[Route('/', name: 'jms_translation_index', options: ['i18n' => false])]
72-
public function indexAction(Request $request)
56+
public function indexAction(Request $request): Response
7357
{
7458
$configs = $this->configFactory->getNames();
7559
$config = $request->query->get('config') ?: reset($configs);
@@ -133,7 +117,7 @@ public function indexAction(Request $request)
133117
$existingMessages[$id] = $message;
134118
}
135119

136-
$variables = [
120+
return new Response($this->twig->render('@JMSTranslation/Translate/index.html.twig', [
137121
'selectedConfig' => $config,
138122
'configs' => $configs,
139123
'selectedDomain' => $domain,
@@ -147,12 +131,6 @@ public function indexAction(Request $request)
147131
'isWriteable' => is_writable((string) $files[$domain][$locale][1]),
148132
'file' => (string) $files[$domain][$locale][1],
149133
'sourceLanguage' => $this->sourceLanguage,
150-
];
151-
152-
if (null !== $this->twig) {
153-
return new Response($this->twig->render('@JMSTranslation/Translate/index.html.twig', $variables));
154-
}
155-
156-
return $variables;
134+
]));
157135
}
158136
}

Tests/Functional/AppKernel.php

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,68 +20,56 @@
2020

2121
namespace JMS\TranslationBundle\Tests\Functional;
2222

23-
use JMS\TranslationBundle\Exception\RuntimeException;
2423
use JMS\TranslationBundle\JMSTranslationBundle;
2524
use JMS\TranslationBundle\Tests\Functional\Fixture\TestBundle\TestBundle;
26-
use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle;
2725
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
26+
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
2827
use Symfony\Bundle\TwigBundle\TwigBundle;
2928
use Symfony\Component\Config\Loader\LoaderInterface;
30-
use Symfony\Component\Filesystem\Filesystem;
29+
use Symfony\Component\DependencyInjection\ContainerBuilder;
30+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
3131
use Symfony\Component\HttpKernel\Kernel;
32+
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
3233

3334
class AppKernel extends Kernel
3435
{
35-
private string|null $config;
36+
use MicroKernelTrait;
3637

37-
private string $fwConfig;
38-
39-
public function __construct(string $fwConfig, ?string $config)
40-
{
38+
public function __construct(
39+
private string $frameworkConfig,
40+
private string|null $config = null
41+
) {
4142
parent::__construct('test', true);
42-
43-
$fs = new Filesystem();
44-
if ($config) {
45-
if (!$fs->isAbsolutePath($config)) {
46-
$config = __DIR__ . '/config/' . $config;
47-
}
48-
49-
if (!file_exists($config)) {
50-
throw new RuntimeException(sprintf('The config file "%s" does not exist.', $config));
51-
}
52-
}
53-
$this->config = $config;
54-
55-
if (!$fs->isAbsolutePath($fwConfig)) {
56-
$fwConfig = __DIR__ . '/config/' . $fwConfig;
57-
}
58-
$this->fwConfig = $fwConfig;
5943
}
6044

6145
public function registerBundles(): iterable
6246
{
63-
$bundles = [
47+
return [
6448
new TestBundle(),
6549
new FrameworkBundle(),
6650
new TwigBundle(),
6751
new JMSTranslationBundle(),
6852
];
53+
}
54+
55+
private function configureContainer(ContainerConfigurator $container, LoaderInterface $loader, ContainerBuilder $builder): void
56+
{
57+
$configDir = $this->getConfigDir();
6958

70-
if (class_exists(SensioFrameworkExtraBundle::class)) {
71-
$bundles[] = new SensioFrameworkExtraBundle();
59+
$container->import($configDir . '/' . $this->frameworkConfig);
60+
61+
if (null !== $this->config) {
62+
$loader->load($configDir . '/' . $this->config);
7263
}
7364

74-
return $bundles;
65+
$container->import($configDir . '/services.yaml');
7566
}
7667

77-
public function registerContainerConfiguration(LoaderInterface $loader): void
68+
private function configureRoutes(RoutingConfigurator $routes): void
7869
{
79-
$loader->load($this->fwConfig);
80-
if ($this->config) {
81-
$loader->load($this->config);
82-
}
70+
$configDir = $this->getConfigDir();
8371

84-
$loader->load($this->getProjectDir() . '/config/services.yaml');
72+
$routes->import($configDir . '/routes.yaml');
8573
}
8674

8775
public function getCacheDir(): string
@@ -104,13 +92,16 @@ private function getBaseDir(): string
10492
return sys_get_temp_dir() . '/JMSTranslationBundle';
10593
}
10694

107-
public function serialize()
95+
public function __serialize(): array
10896
{
109-
return $this->config;
97+
return [
98+
'framework_config' => $this->frameworkConfig,
99+
'config' => $this->config,
100+
];
110101
}
111102

112-
public function unserialize($config)
103+
public function __unserialize(array $data): void
113104
{
114-
$this->__construct($config);
105+
$this->__construct($data['framework_config'], $data['config']);
115106
}
116107
}

Tests/Functional/BaseTestCase.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@ class BaseTestCase extends WebTestCase
2828
{
2929
protected static function createKernel(array $options = []): KernelInterface
3030
{
31-
if (version_compare(Kernel::VERSION, '7.0.0') >= 0) {
32-
$conf = 'framework_sf7.yaml';
33-
} elseif (version_compare(Kernel::VERSION, '6.0.0') >= 0) {
34-
$conf = 'framework_sf6.yml';
35-
} else {
36-
$conf = 'framework.yml';
31+
$conf = 'framework.yaml';
32+
33+
if (version_compare(Kernel::VERSION, '7.0.0', '<')) {
34+
$conf = 'framework_sf6.yaml';
3735
}
3836

39-
return new AppKernel($conf, $options['config'] ?? 'default.yml');
37+
return new AppKernel($conf, $options['config'] ?? 'default.yaml');
4038
}
4139
}

Tests/Functional/Controller/ApiControllerTest.php

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ class ApiControllerTest extends BaseTestCase
1515
public function testUpdateAction(): void
1616
{
1717
// Start application
18-
$client = static::createClient();
19-
$outputDir = $client->getContainer()->getParameter('translation_output_dir');
18+
$client = static::createClient();
19+
$container = $client->getContainer();
20+
$outputDir = $container->getParameter('translation_output_dir');
2021

2122
// Add a file
2223
$file = $outputDir . '/navigation.en.yaml';
2324
$written = file_put_contents($file, 'main.home: Home');
2425
$this->assertTrue($written !== false && $written > 0);
2526

26-
$client->request('POST', '/_trans/api/configs/app/domains/navigation/locales/en/messages?id=main.home', ['_method' => 'PUT', 'message' => 'Away']);
27+
$client->request('PUT', '/_trans/api/configs/app/domains/navigation/locales/en/messages?id=main.home', ['message' => 'Away']);
2728

2829
$fileContent = is_file($file) ? file_get_contents($file) : '';
2930
unlink($file);
@@ -35,4 +36,34 @@ public function testUpdateAction(): void
3536
$this->assertTrue(isset($array['main.home']), print_r($array, true));
3637
$this->assertEquals('Away', $array['main.home']);
3738
}
39+
40+
public function testUpdateWithHttpOverrideAction(): void
41+
{
42+
// Start application
43+
$client = static::createClient();
44+
$container = $client->getContainer();
45+
46+
if (!$container->getParameter('kernel.http_method_override')) {
47+
$this->markTestSkipped('This test does not work with http method override disabled.');
48+
}
49+
50+
$outputDir = $container->getParameter('translation_output_dir');
51+
52+
// Add a file
53+
$file = $outputDir . '/navigation.en.yaml';
54+
$written = file_put_contents($file, 'main.home: Home');
55+
$this->assertTrue($written !== false && $written > 0);
56+
57+
$client->request('POST', '/_trans/api/configs/app/domains/navigation/locales/en/messages?id=main.home', ['_method' => 'PUT', 'message' => 'Back']);
58+
59+
$fileContent = is_file($file) ? file_get_contents($file) : '';
60+
unlink($file);
61+
$this->assertEquals(200, $client->getResponse()->getStatusCode());
62+
63+
// Verify that the file has new content
64+
$array = Yaml::parse($fileContent);
65+
66+
$this->assertTrue(isset($array['main.home']), print_r($array, true));
67+
$this->assertEquals('Back', $array['main.home']);
68+
}
3869
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
88
use Symfony\Component\HttpFoundation\Response;
99
use Symfony\Component\HttpKernel\Attribute\AsController;
10-
use Symfony\Component\Routing\Annotation\Route;
10+
use Symfony\Component\Routing\Attribute\Route;
1111

1212
/**
1313
* @author Johannes
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
jms_translation:
2+
configs:
3+
app:
4+
dirs:
5+
- '%kernel.project_dir%'
6+
- '%kernel.project_dir%/Fixture/TestBundle'
7+
output_dir: '%translation_output_dir%'
8+
ignored_domains: ['routes']
9+
excluded_names: ['*TestCase.php', '*Test.php']
10+
excluded_dirs: ['cache', 'data', 'logs']

Tests/Functional/config/bundle.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)