Completed
Pull Request — 2.x (#124)
by Christian
02:37
created

GedmoTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 1
cbo 2
dl 36
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testTranslatableModel() 8 8 1
A testPersonalTranslatableModel() 18 18 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
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\TranslationBundle\Tests\Traits;
13
14
use Sonata\TranslationBundle\Tests\Gedmo\ModelPersonalTranslatable;
15
use Sonata\TranslationBundle\Tests\Gedmo\ModelTranslatable;
16
use Sonata\TranslationBundle\Traits\Gedmo\PersonalTranslatableTrait;
17
use Sonata\TranslationBundle\Traits\TranslatableTrait;
18
19
/**
20
 * @author Nicolas Bastien <[email protected]>
21
 */
22 View Code Duplication
class GedmoTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Duplication introduced by
This class 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...
23
{
24
    /**
25
     * @test TranslatableTrait
26
     */
27
    public function testTranslatableModel()
28
    {
29
        $model = new ModelTranslatable();
30
        $model->setLocale('fr');
31
32
        $this->assertSame('fr', $model->getLocale());
33
        $this->assertTrue($model instanceof \Sonata\TranslationBundle\Model\TranslatableInterface);
34
    }
35
36
    /**
37
     * @test PersonalTranslatableTrait
38
     */
39
    public function testPersonalTranslatableModel()
40
    {
41
        $model = new ModelPersonalTranslatable();
42
        $model->setLocale('fr');
43
44
        $this->assertSame('fr', $model->getLocale());
45
        $this->assertTrue($model instanceof \Sonata\TranslationBundle\Model\TranslatableInterface);
46
47
        $model->addTranslation(new ModelPersonalTranslation('en', 'title', 'Title en'));
48
        $model->addTranslation(new ModelPersonalTranslation('it', 'title', 'Title it'));
49
        $model->addTranslation(new ModelPersonalTranslation('es', 'title', 'Title es'));
50
51
        $this->assertSame('Title en', $model->getTranslation('title', 'en'));
52
        $this->assertSame('Title it', $model->getTranslation('title', 'it'));
53
        $this->assertSame('Title es', $model->getTranslation('title', 'es'));
54
55
        $this->assertSame(3, count($model->getTranslations()));
56
    }
57
}
58