These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\TranslatorBundle\Tests\Service\Importer; |
||
4 | |||
5 | use Kunstmaan\TranslatorBundle\Tests\unit\WebTestCase; |
||
6 | use Symfony\Component\Finder\Finder; |
||
7 | |||
8 | class ImporterTest extends WebTestCase |
||
9 | { |
||
10 | private $rootDir; |
||
11 | |||
12 | private $importer; |
||
13 | |||
14 | private $translationRepository; |
||
15 | |||
16 | public function setUp() |
||
17 | { |
||
18 | static::bootKernel(['test_case' => 'TranslatorBundleTest', 'root_config' => 'config.yaml']); |
||
19 | $container = static::$kernel->getContainer(); |
||
20 | static::loadFixtures($container); |
||
0 ignored issues
–
show
|
|||
21 | |||
22 | $this->translationRepository = $container->get('kunstmaan_translator.repository.translation'); |
||
23 | $this->importer = $container->get('kunstmaan_translator.service.importer.importer'); |
||
24 | $this->rootDir = $container->getParameter('kernel.root_dir'); |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * @group importer |
||
29 | */ |
||
30 | View Code Duplication | public function testImportNewDomainFileForced() |
|
31 | { |
||
32 | foreach ($this->getNewDomainTestFinder() as $file) { |
||
33 | $this->importer->import($file, true); |
||
34 | } |
||
35 | |||
36 | $translation = $this->translationRepository->findOneBy(array('keyword' => 'newdomain.name', 'locale' => 'de')); |
||
37 | $this->assertEquals('a new domain', $translation->getText()); |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * @group importer |
||
42 | */ |
||
43 | View Code Duplication | public function testImportExistingDomainFileNonForced() |
|
44 | { |
||
45 | foreach ($this->getExistingDomainTestFinder() as $file) { |
||
46 | $this->importer->import($file, false); |
||
47 | } |
||
48 | |||
49 | $translation = $this->translationRepository->findOneBy(array('keyword' => 'headers.frontpage', 'locale' => 'en')); |
||
50 | $this->assertEquals('a not yet updated frontpage header', $translation->getText()); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @group importer-isolated |
||
55 | */ |
||
56 | View Code Duplication | public function testImportExistingDomainFileForced() |
|
57 | { |
||
58 | foreach ($this->getExistingDomainTestFinder() as $file) { |
||
59 | $this->importer->import($file, true); |
||
60 | } |
||
61 | |||
62 | $translation = $this->translationRepository->findOneBy(array('keyword' => 'headers.frontpage', 'locale' => 'en')); |
||
63 | $this->assertEquals('FrontPage', $translation->getText()); |
||
64 | } |
||
65 | |||
66 | public function getNewDomainTestFinder() |
||
67 | { |
||
68 | $finder = new Finder(); |
||
69 | |||
70 | $finder->files() |
||
71 | ->name('newdomain.de.yml') |
||
72 | ->in($this->rootDir.'/Resources/translations/'); |
||
73 | |||
74 | return $finder; |
||
75 | } |
||
76 | |||
77 | public function getExistingDomainTestFinder() |
||
78 | { |
||
79 | $finder = new Finder(); |
||
80 | |||
81 | $finder->files() |
||
82 | ->name('messages.en.yml') |
||
83 | ->in($this->rootDir.'/Resources/translations/'); |
||
84 | |||
85 | return $finder; |
||
86 | } |
||
87 | } |
||
88 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: