Completed
Push — master ( 74c3c7...591b88 )
by Eric
08:09
created

LocaleResourceTest::testMongoDBDriver()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 25
rs 8.8571
cc 1
eloc 21
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Lug package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Lug\Component\Locale\Tests\Resource;
13
14
use Lug\Bundle\ResourceBundle\Controller\Controller;
15
use Lug\Component\Locale\Form\Type\Doctrine\MongoDB\LocaleChoiceType as DoctrineMongoDBLocaleChoiceType;
16
use Lug\Component\Locale\Form\Type\Doctrine\ORM\LocaleChoiceType as DoctrineORMLocaleChoiceType;
17
use Lug\Component\Locale\Form\Type\LocaleType;
18
use Lug\Component\Locale\Resource\LocaleResource;
19
use Lug\Component\Locale\Model\Locale;
20
use Lug\Component\Locale\Model\LocaleInterface;
21
use Lug\Component\Resource\Domain\DomainManager;
22
use Lug\Component\Resource\Factory\Factory;
23
use Lug\Component\Resource\Model\Resource;
24
use Lug\Component\Resource\Repository\Doctrine\MongoDB\Repository as DoctrineMongoDBRepository;
25
use Lug\Component\Resource\Repository\Doctrine\ORM\Repository as DoctrineORMRepository;
26
27
/**
28
 * @author GeLo <[email protected]>
29
 */
30
class LocaleResourceTest extends \PHPUnit_Framework_TestCase
31
{
32
    /**
33
     * @var LocaleResource
34
     */
35
    private $resource;
36
37
    /**
38
     * @var string
39
     */
40
    private $controller;
41
42
    /**
43
     * @var string
44
     */
45
    private $resourcePath;
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    protected function setUp()
51
    {
52
        $this->controller = \stdClass::class;
53
        $this->resourcePath = realpath(__DIR__.'/../../');
54
55
        $this->resource = new LocaleResource($this->controller, $this->resourcePath);
56
    }
57
58
    public function testInheritance()
59
    {
60
        $this->assertInstanceOf(Resource::class, $this->resource);
61
    }
62
63
    public function testDefaultState()
64
    {
65
        $this->assertSame('locale', $this->resource->getName());
66
        $this->assertSame(LocaleResource::DRIVER_DOCTRINE_ORM, $this->resource->getDriver());
67
        $this->assertSame('default', $this->resource->getDriverManager());
68
        $this->assertSame($this->resourcePath, $this->resource->getDriverMappingPath());
69
        $this->assertSame(LocaleResource::DRIVER_MAPPING_FORMAT_XML, $this->resource->getDriverMappingFormat());
70
        $this->assertSame([LocaleInterface::class], $this->resource->getInterfaces());
71
        $this->assertSame(Locale::class, $this->resource->getModel());
72
        $this->assertSame(Factory::class, $this->resource->getFactory());
73
        $this->assertSame(DoctrineORMRepository::class, $this->resource->getRepository());
74
        $this->assertSame(LocaleType::class, $this->resource->getForm());
75
        $this->assertSame(DoctrineORMLocaleChoiceType::class, $this->resource->getChoiceForm());
76
        $this->assertSame($this->controller, $this->resource->getController());
77
        $this->assertSame(DomainManager::class, $this->resource->getDomainManager());
78
        $this->assertSame('code', $this->resource->getLabelPropertyPath());
79
        $this->assertSame('code', $this->resource->getIdPropertyPath());
80
        $this->assertNull($this->resource->getTranslation());
81
    }
82
83
    public function testMongoDBDriver()
84
    {
85
        $this->resource = new LocaleResource(
86
            $this->controller,
87
            $this->resourcePath,
88
            $driver = LocaleResource::DRIVER_DOCTRINE_MONGODB
89
        );
90
91
        $this->assertSame('locale', $this->resource->getName());
92
        $this->assertSame($driver, $this->resource->getDriver());
93
        $this->assertSame($this->resourcePath, $this->resource->getDriverMappingPath());
94
        $this->assertSame(LocaleResource::DRIVER_MAPPING_FORMAT_XML, $this->resource->getDriverMappingFormat());
95
        $this->assertSame('default', $this->resource->getDriverManager());
96
        $this->assertSame([LocaleInterface::class], $this->resource->getInterfaces());
97
        $this->assertSame(Locale::class, $this->resource->getModel());
98
        $this->assertSame(Factory::class, $this->resource->getFactory());
99
        $this->assertSame(DoctrineMongoDBRepository::class, $this->resource->getRepository());
100
        $this->assertSame(LocaleType::class, $this->resource->getForm());
101
        $this->assertSame(DoctrineMongoDBLocaleChoiceType::class, $this->resource->getChoiceForm());
102
        $this->assertSame($this->controller, $this->resource->getController());
103
        $this->assertSame(DomainManager::class, $this->resource->getDomainManager());
104
        $this->assertSame('code', $this->resource->getLabelPropertyPath());
105
        $this->assertSame('code', $this->resource->getIdPropertyPath());
106
        $this->assertNull($this->resource->getTranslation());
107
    }
108
}
109