8000 Add functional test · symfony/symfony@b37ed12 · GitHub
[go: up one dir, main page]

Skip to content

Commit b37ed12

Browse files
committed
Add functional test
1 parent b9765eb commit b37ed12

File tree

12 files changed

+268
-1
lines changed

12 files changed

+268
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller;
13+
14+
use Symfony\Contracts\Translation\TranslatorInterface;
15+
16+
class TransController
17+
{
18+
public function index(TranslatorInterface $translator)
19+
{
20+
$translator->trans('hello_from_controller');
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection;
4+
5+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
8+
/**
9+
* Remove in Symfony 5.0 when the templates directory deprecation is gone.
10+
*/
11+
class TranslationDebugPass implements CompilerPassInterface
12+
{
13+
public function process(ContainerBuilder $container)
14+
{
15+
if ($container->hasDefinition('console.command.translation_debug')) {
16+
$container->getDefinition('console.command.translation_debug')
17+
->setArgument(4, '%kernel.project_dir%/Resources/views');
18+
}
19+
}
20+
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/TestBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection\AnnotationReaderPass;
1515
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection\Config\CustomConfig;
16+
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection\TranslationDebugPass;
1617
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
1718
use Symfony\Component\DependencyInjection\ContainerBuilder;
1819
use Symfony\Component\HttpKernel\Bundle\Bundle;
@@ -29,5 +30,6 @@ public function build(ContainerBuilder $container)
2930
$extension->setCustomConfig(new CustomConfig());
3031

3132
$container->addCompilerPass(new AnnotationReaderPass(), PassConfig::TYPE_AFTER_REMOVING);
33+
$container->addCompilerPass(new TranslationDebugPass());
3234
}
3335
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TransDebug;
13+
14+
use Symfony\Contracts\Translation\TranslatorInterface;
15+
16+
class TransConstructArgService
17+
{
18+
private $translator;
19+
20+
public function __construct(TranslatorInterface $translator)
21+
{
22+
$this->translator = $translator;
23+
}
24+
25+
public function hello(): string
26+
{
27+
return $this->translator->trans('hello_from_construct_arg_service');
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TransDebug;
13+
14+
use Symfony\Contracts\Translation\TranslatorInterface;
15+
16+
class TransMethodCallsService
17+
{
18+
private $translator;
19+
20+
public function setTranslator(TranslatorInterface $translator): void
21+
{
22+
$this->translator = $translator;
23+
}
24+
25+
public function hello(): string
26+
{
27+
return $this->translator->trans('hello_from_method_calls_service');
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TransDebug;
13+
14+
use Symfony\Contracts\Translation\TranslatorInterface;
15+
16+
class TransPropertyService
17+
{
18+
/** @var TranslatorInterface */
19+
public $translator;
20+
21+
public function hello(): string
22+
{
23+
return $this->translator->trans('hello_from_property_service');
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TransDebug;
13+
14+
use Psr\Container\ContainerInterface;
15+
use Symfony\Contracts\Service\ServiceSubscriberInterface;
16+
use Symfony\Contracts\Translation\TranslatorInterface;
17+
18+
class TransSubscriberService implements ServiceSubscriberInterface
19+
{
20+
private $container;
21+
1241 22+
public function __construct(ContainerInterface $container)
23+
{
24+
$this->container = $container;
25+
}
26+
27+
public static function getSubscribedServices()
28+
{
29+
return ['translator' => TranslatorInterface::class];
30+
}
31+
32+
public function hello(): string
33+
{
34+
return $this->container->get('translator')->trans('hello_from_subscriber_service');
35+
}
36+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
13+
14+
use Symfony\Bundle\FrameworkBundle\Console\Application;
15+
use Symfony\Component\Console\Tester\CommandTester;
16+
17+
/**
18+
* @group functional
19+
*/
20+
class TranslationDebugCommandTest extends WebTestCase
21+
{
22+
private $application;
23+
24+
protected function setUp()
25+
{
26+
$kernel = static::createKernel(['test_case' => 'TransDebug', 'root_config' => 'config.yml']);
27+
$this->application = new Application($kernel);
28+
}
29+
30+
public function testDumpAllTrans()
31+
{
32+
$tester = $this->createCommandTester();
33+
$ret = $tester->execute(['locale' => 'en']);
34+
35+
$this->assertSame(0, $ret, 'Returns 0 in case of success');
36+
$this->assertContains('missing messages hello_from_construct_arg_service', $tester->getDisplay());
37+
$this->assertContains('missing messages hello_from_subscriber_service', $tester->getDisplay());
38+
$this->assertContains('missing messages hello_from_property_service', $tester->getDisplay());
39+
$this->assertContains('missing messages hello_from_method_calls_service', $tester->getDisplay());
40+
$this->assertContains('missing messages hello_from_controller', $tester->getDisplay());
41+
$this->assertContains('unused validators This value should be blank.', $tester->getDisplay());
42+
$this->assertContains('unused security Invalid CSRF token.', $tester->getDisplay());
43+
}
44+
45+
private function createCommandTester(): CommandTester
46+
{
47+
$command = $this->application->find('debug:translation');
48+
49+
return new CommandTester($command);
50+
}
51+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
13+
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle;
14+
15+
return [
16+
new FrameworkBundle(),
17+
new TestBundle(),
18+
];
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
imports:
2+
- { resource: ../config/default.yml }
3+
- { resource: services.yml }
4+
5+
framework:
6+
secret: '%secret%'
7+
default_locale: '%env(LOCALE)%'
8+
translator:
9+
fallbacks:
10+
- '%env(LOCALE)%'
11+
12+
parameters:
13+
env(LOCALE): en
14+
secret: test
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
services:
2+
_defaults:
3+
public: true
4+
5+
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\TransController:
6+
tags: ['controller.service_arguments']
7+
8+
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TransDebug\TransConstructArgService:
9+
arguments: ['@translator']
10+
11+
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TransDebug\TransSubscriberService:
12+
arguments: ['@Psr\Container\ContainerInterface']
13+
tags: ['container.service_subscriber']
14+
15+
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TransDebug\TransPropertyService:
16+
properties:
17+
$translator: '@translator'
18+
19+
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TransDebug\TransMethodCallsService:
20+
calls:
21+
- [ setTranslator, ['@translator'] ]

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"symfony/property-info": "<3.4",
7575
"symfony/serializer": "<4.2",
7676
"symfony/stopwatch": "<3.4",
77-
"symfony/translation": "<4.2",
77+
"symfony/translation": "<4.3",
7878
"symfony/twig-bridge": "<4.1.1",
7979
"symfony/validator": "<4.1",
8080
"symfony/workflow": "<4.1"

0 commit comments

Comments
 (0)
0