Completed
Push — master ( 007b3d...3e6077 )
by
unknown
05:34
created

testAlterObjectForTranslatableObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
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\AdminExtension\Knplabs;
13
14
use Sonata\AdminBundle\Admin\AdminInterface;
15
use Sonata\TranslationBundle\Admin\Extension\Knplabs\TranslatableAdminExtension;
16
use Sonata\TranslationBundle\Checker\TranslatableChecker;
17
use Sonata\TranslationBundle\Tests\Fixtures\Model\Knplabs\TranslatableEntity;
18
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
19
20
/**
21
 * @group  translatable-knplabs
22
 */
23
class TranslatableAdminExtensionTest extends WebTestCase
24
{
25
    /**
26
     * @var AdminInterface
27
     */
28
    protected $admin;
29
30
    /**
31
     * @var TranslatableEntity
32
     */
33
    protected $object;
34
35
    /**
36
     * @var TranslatableAdminExtension
37
     */
38
    protected $extension;
39
40
    protected function setUp()
41
    {
42
        $translatableChecker = new TranslatableChecker();
43
        $translatableChecker->setSupportedInterfaces(array(
44
            'Sonata\TranslationBundle\Model\TranslatableInterface',
45
        ));
46
        $this->extension = new TranslatableAdminExtension($translatableChecker);
47
48
        $request = $this->prophesize('Symfony\Component\HttpFoundation\Request');
49
        $request->get('tl')->willReturn('es');
50
51
        $this->admin = $this->prophesize('Sonata\AdminBundle\Admin\AdminInterface');
52
        $this->admin->getRequest()->willReturn($request->reveal());
53
        $this->admin->hasRequest()->willReturn(true);
54
55
        $this->object = new TranslatableEntity();
56
    }
57
58
    public function testSetLocaleForTranslatableObject()
59
    {
60
        $this->extension->alterNewInstance($this->admin->reveal(), $this->object);
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
62
        $this->assertEquals('es', $this->object->getLocale());
63
    }
64
65
    public function testAlterObjectForTranslatableObject()
66
    {
67
        $this->extension->alterObject($this->admin->reveal(), $this->object);
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
68
69
        $this->assertEquals('es', $this->object->getLocale());
70
    }
71
72 View Code Duplication
    public function testPreUpdate()
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...
73
    {
74
        $object = $this->prophesize('Sonata\TranslationBundle\Tests\Fixtures\Model\Knplabs\TranslatableEntity');
75
        $object->mergeNewTranslations()->shouldBeCalled();
76
77
        $this->extension->preUpdate($this->admin->reveal(), $object->reveal());
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
78
    }
79
80 View Code Duplication
    public function testPrePersist()
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...
81
    {
82
        $object = $this->prophesize('Sonata\TranslationBundle\Tests\Fixtures\Model\Knplabs\TranslatableEntity');
83
        $object->mergeNewTranslations()->shouldBeCalled();
84
85
        $this->extension->prePersist($this->admin->reveal(), $object->reveal());
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
86
    }
87
}
88