Completed
Pull Request — 2.x (#121)
by
unknown
02:25
created

GedmoORMTest::testPersonalTranslatableEntity()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 34
rs 8.8571
cc 1
eloc 24
nc 1
nop 0
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 Doctrine\Common\EventManager;
15
use Gedmo\Translatable\TranslatableListener;
16
use Sonata\TranslationBundle\Tests\Fixtures\Personal\Article;
17
use Sonata\TranslationBundle\Tests\Fixtures\Personal\ArticleTranslation;
18
use Sonata\TranslationBundle\Tests\Tool\BaseTestCaseORM;
19
20
class GedmoORMTest extends BaseTestCaseORM
21
{
22
    const ARTICLE = 'Sonata\TranslationBundle\Tests\Fixtures\Personal\Article';
23
    const TRANSLATION = 'Sonata\TranslationBundle\Tests\Fixtures\Personal\ArticleTranslation';
24
25
    /** @var TranslatableListener */
26
    private $translatableListener;
27
28
    protected function setUp()
29
    {
30
        parent::setUp();
31
32
        $evm = new EventManager();
33
        $this->translatableListener = new TranslatableListener();
34
        $this->translatableListener->setTranslatableLocale('en');
35
        $this->translatableListener->setDefaultLocale('en');
36
        $evm->addEventSubscriber($this->translatableListener);
37
38
        $this->getMockSqliteEntityManager($evm);
39
    }
40
41
    public function testPersonalTranslatableEntity()
42
    {
43
        $article = new Article();
44
        $article->setTitle('en');
45
46
        $this->em->persist($article);
47
        $this->em->flush();
48
49
        $this->translatableListener->setTranslatableLocale('de');
50
        $article->setTitle('de');
51
52
        $ltTranslation = new ArticleTranslation();
53
        $ltTranslation
54
            ->setField('title')
55
            ->setContent('lt')
56
            ->setObject($article)
0 ignored issues
show
Documentation introduced by
$article is of type object<Sonata\Translatio...tures\Personal\Article>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57
            ->setLocale('lt')
58
        ;
59
        $this->em->persist($ltTranslation);
60
        $this->em->persist($article);
61
        $this->em->flush();
62
63
        // Tests if Gedmo\Locale annotation exists
64
        $article->setLocale('pl');
65
        $article->setTitle('pl');
66
        $this->em->persist($article);
67
        $this->em->flush();
68
69
        $this->em->clear();
70
71
        $article = $this->em->find(self::ARTICLE, array('id' => 1));
72
        $translations = $article->getTranslations();
73
        $this->assertCount(3, $translations);
74
    }
75
76
    protected function getUsedEntityFixtures()
77
    {
78
        return array(
79
            self::ARTICLE,
80
            self::TRANSLATION,
81
        );
82
    }
83
}
84