Completed
Push — master ( d17154...1fc820 )
by Sullivan
11:02 queued 08:59
created

ModelPersonalTranslatable   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
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\AdminBundle\Tests\Traits;
13
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Sonata\TranslationBundle\Model\Gedmo\AbstractPersonalTranslation;
16
use Sonata\TranslationBundle\Model\Gedmo\TranslatableInterface;
17
use Sonata\TranslationBundle\Traits\Gedmo\PersonalTranslatable;
18
use Sonata\TranslationBundle\Traits\Translatable;
19
20
class ModelTranslatable implements TranslatableInterface
21
{
22
    use Translatable;
23
}
24
25
class ModelPersonalTranslatable implements TranslatableInterface
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
26
{
27
    use PersonalTranslatable;
28
29
    /**
30
     * @var ArrayCollection
31
     */
32
    protected $translations;
33
34
    public function __construct()
35
    {
36
        $this->translations = new ArrayCollection();
37
    }
38
}
39
40
class ModelPersonalTranslation extends AbstractPersonalTranslation
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
41
{
42
}
43
44
/**
45
 * @author Nicolas Bastien <[email protected]>
46
 */
47
class GedmoTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
48
{
49
    /**
50
     * @test Translatable
51
     */
52
    public function testTranslatableModel()
53
    {
54
        $model = new ModelTranslatable();
55
        $model->setLocale('fr');
56
57
        $this->assertSame('fr', $model->getLocale());
58
        $this->assertTrue($model instanceof \Sonata\TranslationBundle\Model\TranslatableInterface);
59
    }
60
61
    /**
62
     * @test PersonalTranslatable
63
     */
64
    public function testPersonalTranslatableModel()
65
    {
66
        $model = new ModelPersonalTranslatable();
67
        $model->setLocale('fr');
68
69
        $this->assertSame('fr', $model->getLocale());
70
        $this->assertTrue($model instanceof \Sonata\TranslationBundle\Model\TranslatableInterface);
71
72
        $model->addTranslation(new ModelPersonalTranslation('en', 'title', 'Title en'));
73
        $model->addTranslation(new ModelPersonalTranslation('it', 'title', 'Title it'));
74
        $model->addTranslation(new ModelPersonalTranslation('es', 'title', 'Title es'));
75
76
        $this->assertSame('Title en', $model->getTranslation('title', 'en'));
77
        $this->assertSame('Title it', $model->getTranslation('title', 'it'));
78
        $this->assertSame('Title es', $model->getTranslation('title', 'es'));
79
80
        $this->assertSame(3, count($model->getTranslations()));
81
    }
82
}
83