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\Repository\TranslationRepository; |
||
6 | use Kunstmaan\TranslatorBundle\Tests\unit\WebTestCase; |
||
7 | |||
8 | class TranslationRepositoryTest extends WebTestCase |
||
9 | { |
||
10 | /** @var TranslationRepository */ |
||
11 | private $translationRepository; |
||
12 | |||
13 | View Code Duplication | public function setUp() |
|
0 ignored issues
–
show
|
|||
14 | { |
||
15 | static::bootKernel(['test_case' => 'TranslatorBundleTest', 'root_config' => 'config.yaml']); |
||
16 | $container = static::$kernel->getContainer(); |
||
17 | static::loadFixtures($container); |
||
0 ignored issues
–
show
It seems like
$container defined by static::$kernel->getContainer() on line 16 can be null ; however, Kunstmaan\TranslatorBund...estCase::loadFixtures() does not accept null , maybe add an additional type check?
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: /** @return stdClass|null */
function mayReturnNull() { }
function doesNotAcceptNull(stdClass $x) { }
// With potential error.
function withoutCheck() {
$x = mayReturnNull();
doesNotAcceptNull($x); // Potential error here.
}
// Safe - Alternative 1
function withCheck1() {
$x = mayReturnNull();
if ( ! $x instanceof stdClass) {
throw new \LogicException('$x must be defined.');
}
doesNotAcceptNull($x);
}
// Safe - Alternative 2
function withCheck2() {
$x = mayReturnNull();
if ($x instanceof stdClass) {
doesNotAcceptNull($x);
}
}
Loading history...
|
|||
18 | |||
19 | $this->translationRepository = $container->get('kunstmaan_translator.repository.translation'); |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | * @group translation-repository |
||
24 | */ |
||
25 | public function testGetAllDomainsByLocale() |
||
26 | { |
||
27 | $result = $this->translationRepository->getAllDomainsByLocale(); |
||
28 | $firstItem = reset($result); |
||
29 | $this->assertArrayHasKey('locale', $firstItem); |
||
30 | $this->assertArrayHasKey('name', $firstItem); |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * @group translation-repository |
||
35 | */ |
||
36 | public function testGetLastChangedTranslationDate() |
||
37 | { |
||
38 | $date = $this->translationRepository->getLastChangedTranslationDate(); |
||
39 | $this->assertInstanceOf('\DateTime', $date); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * @group translation-repository |
||
44 | */ |
||
45 | public function testGetTranslationsByLocalesAndDomains() |
||
46 | { |
||
47 | $result = $this->translationRepository->getTranslationsByLocalesAndDomains(array('nl'), array('messages')); |
||
48 | $this->assertInstanceOf('Kunstmaan\TranslatorBundle\Entity\Translation', $result[0]); |
||
49 | $this->assertGreaterThan(0, count($result)); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @group translation-repository |
||
54 | */ |
||
55 | public function testFindAllNotDisabled() |
||
56 | { |
||
57 | $result = $this->translationRepository->findAllNotDisabled('nl'); |
||
58 | $this->assertInstanceOf('Kunstmaan\TranslatorBundle\Entity\Translation', $result[0]); |
||
59 | $this->assertGreaterThan(0, count($result)); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @group translation-repository |
||
64 | */ |
||
65 | public function testFindAllDeprecated() |
||
66 | { |
||
67 | $result = $this->translationRepository->findDeprecatedTranslationsBeforeDate(new \DateTime('+5 minutes'), 'messages'); |
||
68 | $this->assertInstanceOf('Kunstmaan\TranslatorBundle\Entity\Translation', $result[0]); |
||
69 | $this->assertGreaterThan(0, count($result)); |
||
70 | } |
||
71 | } |
||
72 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.