1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Cubiche/Metadata component. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) Cubiche |
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 Cubiche\Core\Metadata\Tests\Units\Factory; |
13
|
|
|
|
14
|
|
|
use Cubiche\Core\Metadata\Factory\DriverFactory; |
15
|
|
|
use Cubiche\Core\Metadata\Locator\DefaultFileLocator; |
16
|
|
|
use Cubiche\Core\Metadata\Tests\Fixtures\Driver\AnnotationDriver; |
17
|
|
|
use Cubiche\Core\Metadata\Tests\Fixtures\Driver\XmlDriver; |
18
|
|
|
use Cubiche\Core\Metadata\Tests\Fixtures\Driver\YamlDriver; |
19
|
|
|
use Cubiche\Core\Metadata\Tests\Fixtures\User; |
20
|
|
|
use Cubiche\Core\Metadata\Tests\Units\TestCase; |
21
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* DriverFactoryTests class. |
25
|
|
|
* |
26
|
|
|
* Generated by TestGenerator on 2017-05-16 at 13:17:21. |
27
|
|
|
*/ |
28
|
|
|
class DriverFactoryTests extends TestCase |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @return DriverFactory |
32
|
|
|
*/ |
33
|
|
|
protected function createFactory() |
34
|
|
|
{ |
35
|
|
|
return DriverFactory::instance(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Test RegisterAnnotationDriver method. |
40
|
|
|
*/ |
41
|
|
|
public function testRegisterAnnotationDriver() |
42
|
|
|
{ |
43
|
|
|
$this |
44
|
|
|
->given($factory = $this->createFactory()) |
45
|
|
|
->then() |
46
|
|
|
->exception(function () { |
47
|
|
|
DriverFactory::registerAnnotationDriver(User::class); |
48
|
|
|
})->isInstanceOf(\InvalidArgumentException::class) |
49
|
|
|
; |
50
|
|
|
|
51
|
|
|
$this |
52
|
|
|
->given($factory = $this->createFactory()) |
53
|
|
|
->and(DriverFactory::registerAnnotationDriver(AnnotationDriver::class)) |
54
|
|
|
->then() |
55
|
|
|
->array($drivers = $factory->createAnnotationDriver(new AnnotationReader())) |
56
|
|
|
->hasSize(1) |
57
|
|
|
; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Test RegisterYamlDriver method. |
62
|
|
|
*/ |
63
|
|
View Code Duplication |
public function testRegisterYamlDriver() |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
$mappingDirectory = __DIR__.'/../../Fixtures/mapping'; |
66
|
|
|
|
67
|
|
|
$this |
68
|
|
|
->given($factory = $this->createFactory()) |
69
|
|
|
->and(DriverFactory::registerYamlDriver(YamlDriver::class)) |
70
|
|
|
->then() |
71
|
|
|
->array( |
72
|
|
|
$drivers = $factory->createYamlDriver( |
73
|
|
|
new DefaultFileLocator([ |
74
|
|
|
$mappingDirectory => 'Cubiche\Core\Metadata\Tests\Fixtures', |
75
|
|
|
]) |
76
|
|
|
) |
77
|
|
|
)->hasSize(1) |
78
|
|
|
; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Test RegisterXmlDriver method. |
83
|
|
|
*/ |
84
|
|
View Code Duplication |
public function testRegisterXmlDriver() |
|
|
|
|
85
|
|
|
{ |
86
|
|
|
$mappingDirectory = __DIR__.'/../../Fixtures/mapping'; |
87
|
|
|
|
88
|
|
|
$this |
89
|
|
|
->given($factory = $this->createFactory()) |
90
|
|
|
->and(DriverFactory::registerXmlDriver(XmlDriver::class)) |
91
|
|
|
->then() |
92
|
|
|
->array( |
93
|
|
|
$drivers = $factory->createXmlDriver( |
94
|
|
|
new DefaultFileLocator([ |
95
|
|
|
$mappingDirectory => 'Cubiche\Core\Metadata\Tests\Fixtures', |
96
|
|
|
]) |
97
|
|
|
) |
98
|
|
|
)->hasSize(1) |
99
|
|
|
; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
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.