Files
archived-framework-bundle/Tests/Command/XliffLintCommandTest.php
Nicolas Grekas 2274485ede Merge branch '7.4' into 8.0
* 7.4:
  bump symfony/type-info dependency
  remove usages of the deprecated any() invoked count expectation
  [Console] Fix profiling commands that use #[Ask]
  remove usages of the deprecated any() invoked count expectation
  [Serializer] Fix constructor parameter type override when property type extractor returns a different type
  Minor: Fix Portuguese (pt) translations for validators
  [Serializer] Fix passing context option to property-info
  [CssSelector] Add LRU cache to CssSelectorConverter
2026-02-17 14:07:04 +01:00

121 lines
3.5 KiB
PHP

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Command\XliffLintCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Application as BaseApplication;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\HttpKernel\KernelInterface;
/**
* Tests the part of the XliffLintCommand managed by the FrameworkBundle. The
* rest of the features are tested in the Translation component.
*
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
*/
class XliffLintCommandTest extends TestCase
{
private array $files;
public function testGetHelp()
{
$command = new XliffLintCommand();
$expected = <<<EOF
Or find all files in a bundle:
<info>php %command.full_name% @AcmeDemoBundle</info>
EOF;
$this->assertStringContainsString($expected, $command->getHelp());
}
public function testLintFilesFromBundleDirectory()
{
$tester = $this->createCommandTester($this->getKernelAwareApplicationMock());
$tester->execute(
['filename' => '@AppBundle/Resources'],
['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]
);
$tester->assertCommandIsSuccessful('Returns 0 in case of success');
$this->assertStringContainsString('[OK] All 0 XLIFF files contain valid syntax', trim($tester->getDisplay()));
}
private function createCommandTester($application = null): CommandTester
{
if (!$application) {
$application = new BaseApplication();
$application->addCommand(new XliffLintCommand());
}
$command = $application->find('lint:xliff');
$command->setApplication($application);
return new CommandTester($command);
}
private function getKernelAwareApplicationMock()
{
$kernel = $this->createMock(KernelInterface::class);
$kernel
->expects($this->once())
->method('locateResource')
->with('@AppBundle/Resources')
->willReturn(sys_get_temp_dir().'/xliff-lint-test');
$application = $this->createMock(Application::class);
$application
->expects($this->once())
->method('getKernel')
->willReturn($kernel);
$application
->expects($this->once())
->method('getHelperSet')
->willReturn(new HelperSet());
$application
->method('getDefinition')
->willReturn(new InputDefinition());
$application
->expects($this->once())
->method('find')
->with('lint:xliff')
->willReturn(new XliffLintCommand());
return $application;
}
protected function setUp(): void
{
@mkdir(sys_get_temp_dir().'/xliff-lint-test');
$this->files = [];
}
protected function tearDown(): void
{
foreach ($this->files as $file) {
if (file_exists($file)) {
@unlink($file);
}
}
@rmdir(sys_get_temp_dir().'/xliff-lint-test');
}
}