Completed
Push — master ( aba493...5356ed )
by Ruud
315:38 queued 305:00
created

TranslationRepositoryTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 12.5 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 8
loc 64
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 8 8 1
A testGetAllDomainsByLocale() 0 7 1
A testGetLastChangedTranslationDate() 0 5 1
A testGetTranslationsByLocalesAndDomains() 0 6 1
A testFindAllNotDisabled() 0 6 1
A testFindAllDeprecated() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
14
    {
15
        static::bootKernel(['test_case' => 'TranslatorBundleTest', 'root_config' => 'config.yaml']);
16
        $container = static::$kernel->getContainer();
17
        static::loadFixtures($container);
0 ignored issues
show
Bug introduced by
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