-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed file visitor for extracting exception messages (#232)
* Fixed file visitor for extracting exception messages * Fixed translation configuration (#237)
- Loading branch information
1 parent
73cd091
commit e40d311
Showing
15 changed files
with
470 additions
and
359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 19 additions & 96 deletions
115
src/bundle/Core/Resources/translations/fielddefinition.en.xlf
Large diffs are not rendered by default.
Oops, something went wrong.
126 changes: 63 additions & 63 deletions
126
...ore/Resources/translations/forms.en.xliff → .../Core/Resources/translations/forms.en.xlf
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
262 changes: 80 additions & 182 deletions
262
src/bundle/Core/Resources/translations/repository_exceptions.en.xlf
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
tests/lib/MVC/Symfony/Translation/ExceptionMessageTemplateFileVisitorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Tests\Core\MVC\Symfony\Translation; | ||
|
||
use Doctrine\Common\Annotations\DocParser; | ||
use Ibexa\Core\MVC\Symfony\Translation\ExceptionMessageTemplateFileVisitor; | ||
use JMS\TranslationBundle\Model\Message; | ||
use JMS\TranslationBundle\Model\MessageCatalogue; | ||
use JMS\TranslationBundle\Translation\FileSourceFactory; | ||
use PhpParser\Lexer; | ||
use PhpParser\Parser; | ||
use PhpParser\ParserFactory; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Log\LoggerInterface; | ||
use SplFileInfo; | ||
|
||
final class ExceptionMessageTemplateFileVisitorTest extends TestCase | ||
{ | ||
private const FIXTURES_DIR = __DIR__ . '/fixtures/'; | ||
|
||
private Parser $phpParser; | ||
|
||
private ExceptionMessageTemplateFileVisitor $exceptionMessageTemplateFileVisitor; | ||
|
||
protected function setUp(): void | ||
{ | ||
$docParser = new DocParser(); | ||
$fileSourceFactory = new FileSourceFactory( | ||
self::FIXTURES_DIR, | ||
); | ||
$lexer = new Lexer(); | ||
$factory = new ParserFactory(); | ||
$this->phpParser = $factory->create(ParserFactory::PREFER_PHP7, $lexer); | ||
$this->exceptionMessageTemplateFileVisitor = new ExceptionMessageTemplateFileVisitor( | ||
$docParser, | ||
$fileSourceFactory | ||
); | ||
} | ||
|
||
public function testExtractTranslation(): void | ||
{ | ||
$messageCatalogue = new MessageCatalogue(); | ||
$file = self::FIXTURES_DIR . 'SetMessageTemplate.php'; | ||
$fileInfo = new SplFileInfo($file); | ||
|
||
$ast = $this->phpParser->parse(file_get_contents($file)); | ||
$this->exceptionMessageTemplateFileVisitor->visitPhpFile( | ||
$fileInfo, | ||
$messageCatalogue, | ||
$ast | ||
); | ||
|
||
$expectedMessage = new Message('Foo exception', 'repository_exceptions'); | ||
|
||
self::assertTrue( | ||
$messageCatalogue->has($expectedMessage) | ||
); | ||
} | ||
|
||
public function testNoTranslationToExtract(): void | ||
{ | ||
$messageCatalogue = new MessageCatalogue(); | ||
$file = self::FIXTURES_DIR . 'NoTranslationToExtract.php'; | ||
$fileInfo = new SplFileInfo($file); | ||
|
||
$ast = $this->phpParser->parse(file_get_contents($file)); | ||
$this->exceptionMessageTemplateFileVisitor->visitPhpFile( | ||
$fileInfo, | ||
$messageCatalogue, | ||
$ast | ||
); | ||
|
||
self::assertEmpty($messageCatalogue->getDomains()); | ||
} | ||
|
||
public function testWrongTranslationId(): void | ||
{ | ||
$messageCatalogue = new MessageCatalogue(); | ||
$file = self::FIXTURES_DIR . 'WrongTranslationId.php'; | ||
$fileInfo = new SplFileInfo($file); | ||
|
||
$ast = $this->phpParser->parse(file_get_contents($file)); | ||
|
||
$logger = $this->createMock(LoggerInterface::class); | ||
$logger | ||
->expects($this->once()) | ||
->method('error'); | ||
|
||
$this->exceptionMessageTemplateFileVisitor->setLogger($logger); | ||
$this->exceptionMessageTemplateFileVisitor->visitPhpFile( | ||
$fileInfo, | ||
$messageCatalogue, | ||
$ast | ||
); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/lib/MVC/Symfony/Translation/fixtures/NoTranslationToExtract.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Tests\Core\MVC\Symfony\Translation\fixtures; | ||
|
||
use Exception; | ||
use Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException as APIInvalidArgumentException; | ||
use Ibexa\Core\Base\Translatable; | ||
use Ibexa\Core\Base\TranslatableBase; | ||
|
||
final class NoTranslationToExtract extends APIInvalidArgumentException implements Translatable | ||
{ | ||
use TranslatableBase; | ||
|
||
public function __construct(?Exception $previous = null) | ||
{ | ||
parent::__construct($this->getBaseTranslation(), 0, $previous); | ||
} | ||
} |
Oops, something went wrong.