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\Bundle\LocaleBundle\Tests\Resource; |
13
|
|
|
|
14
|
|
|
use Lug\Bundle\LocaleBundle\Resource\LocaleResource; |
15
|
|
|
use Lug\Bundle\ResourceBundle\Controller\Controller; |
16
|
|
|
use Lug\Component\Locale\Form\Type\Doctrine\MongoDB\LocaleChoiceType as DoctrineMongoDBLocaleChoiceType; |
17
|
|
|
use Lug\Component\Locale\Form\Type\Doctrine\ORM\LocaleChoiceType as DoctrineORMLocaleChoiceType; |
18
|
|
|
use Lug\Component\Locale\Form\Type\LocaleType; |
19
|
|
|
use Lug\Component\Locale\Resource\LocaleResource as LugLocaleResource; |
20
|
|
|
use Lug\Component\Locale\Model\Locale; |
21
|
|
|
use Lug\Component\Locale\Model\LocaleInterface; |
22
|
|
|
use Lug\Component\Resource\Domain\DomainManager; |
23
|
|
|
use Lug\Component\Resource\Factory\Factory; |
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
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
|
|
protected function setUp() |
41
|
|
|
{ |
42
|
|
|
$this->resource = new LocaleResource(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testInheritance() |
46
|
|
|
{ |
47
|
|
|
$this->assertInstanceOf(LugLocaleResource::class, $this->resource); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
View Code Duplication |
public function testDefaultState() |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$this->assertSame('locale', $this->resource->getName()); |
53
|
|
|
$this->assertSame(LocaleResource::DRIVER_DOCTRINE_ORM, $this->resource->getDriver()); |
54
|
|
|
$this->assertSame('default', $this->resource->getDriverManager()); |
55
|
|
|
$this->assertSame( |
56
|
|
|
realpath(__DIR__.'/../../../../Component/Locale/Resources/Doctrine'), |
57
|
|
|
$this->resource->getDriverMappingPath() |
58
|
|
|
); |
59
|
|
|
$this->assertSame(LocaleResource::DRIVER_MAPPING_FORMAT_XML, $this->resource->getDriverMappingFormat()); |
60
|
|
|
$this->assertSame([LocaleInterface::class], $this->resource->getInterfaces()); |
61
|
|
|
$this->assertSame(Locale::class, $this->resource->getModel()); |
62
|
|
|
$this->assertSame(Factory::class, $this->resource->getFactory()); |
63
|
|
|
$this->assertSame(DoctrineORMRepository::class, $this->resource->getRepository()); |
64
|
|
|
$this->assertSame(LocaleType::class, $this->resource->getForm()); |
65
|
|
|
$this->assertSame(DoctrineORMLocaleChoiceType::class, $this->resource->getChoiceForm()); |
66
|
|
|
$this->assertSame(Controller::class, $this->resource->getController()); |
67
|
|
|
$this->assertSame(DomainManager::class, $this->resource->getDomainManager()); |
68
|
|
|
$this->assertSame('code', $this->resource->getLabelPropertyPath()); |
69
|
|
|
$this->assertSame('code', $this->resource->getIdPropertyPath()); |
70
|
|
|
$this->assertNull($this->resource->getTranslation()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testMongoDBDriver() |
74
|
|
|
{ |
75
|
|
|
$this->resource = new LocaleResource($driver = LocaleResource::DRIVER_DOCTRINE_MONGODB); |
76
|
|
|
|
77
|
|
|
$this->assertSame('locale', $this->resource->getName()); |
78
|
|
|
$this->assertSame($driver, $this->resource->getDriver()); |
79
|
|
|
$this->assertSame( |
80
|
|
|
realpath(__DIR__.'/../../../../Component/Locale/Resources/Doctrine'), |
81
|
|
|
$this->resource->getDriverMappingPath() |
82
|
|
|
); |
83
|
|
|
$this->assertSame(LocaleResource::DRIVER_MAPPING_FORMAT_XML, $this->resource->getDriverMappingFormat()); |
84
|
|
|
$this->assertSame('default', $this->resource->getDriverManager()); |
85
|
|
|
$this->assertSame([LocaleInterface::class], $this->resource->getInterfaces()); |
86
|
|
|
$this->assertSame(Locale::class, $this->resource->getModel()); |
87
|
|
|
$this->assertSame(Factory::class, $this->resource->getFactory()); |
88
|
|
|
$this->assertSame(DoctrineMongoDBRepository::class, $this->resource->getRepository()); |
89
|
|
|
$this->assertSame(LocaleType::class, $this->resource->getForm()); |
90
|
|
|
$this->assertSame(DoctrineMongoDBLocaleChoiceType::class, $this->resource->getChoiceForm()); |
91
|
|
|
$this->assertSame(Controller::class, $this->resource->getController()); |
92
|
|
|
$this->assertSame(DomainManager::class, $this->resource->getDomainManager()); |
93
|
|
|
$this->assertSame('code', $this->resource->getLabelPropertyPath()); |
94
|
|
|
$this->assertSame('code', $this->resource->getIdPropertyPath()); |
95
|
|
|
$this->assertNull($this->resource->getTranslation()); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
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.