1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yoghi\Bundle\MaddaBundle\Model; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the MADDA project. |
7
|
|
|
* |
8
|
|
|
* (c) Stefano Tamagnini <> |
9
|
|
|
* |
10
|
|
|
* This source file is subject to the GPLv3 license that is bundled |
11
|
|
|
* with this source code in the file LICENSE. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author Stefano Tamagnini <> |
16
|
|
|
*/ |
17
|
|
|
class ReaderTest extends \PHPUnit_Framework_TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @expectedException Yoghi\Bundle\MaddaBundle\Exception\MaddaException |
21
|
|
|
*/ |
22
|
|
View Code Duplication |
public function testReadNotExistFile() |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
$baseDirectory = __DIR__.'/'; |
25
|
|
|
$fileName = 'nonEsite.yml'; |
26
|
|
|
$rym = new Reader(); |
27
|
|
|
$rym->readYaml($baseDirectory.'/'.$fileName); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testEmptyReadFile() |
31
|
|
|
{ |
32
|
|
|
$baseDirectory = __DIR__.'/../Resources/finder'; |
33
|
|
|
$fileName = 'emptyModel.yml'; |
34
|
|
|
$rym = new Reader(); |
35
|
|
|
$rym->readYaml($baseDirectory.'/'.$fileName); |
36
|
|
|
$prop = $rym->getProperties(); |
|
|
|
|
37
|
|
|
$propExpected = [ |
38
|
|
|
'ddd' => [], |
39
|
|
|
'classes' => [], |
40
|
|
|
]; |
41
|
|
|
$this->assertEquals($propExpected, $prop, 'corretta lettura yml'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @expectedException Yoghi\Bundle\MaddaBundle\Exception\MaddaException |
46
|
|
|
*/ |
47
|
|
View Code Duplication |
public function testReadInvalidFile() |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$baseDirectory = __DIR__.'/../Resources/'; |
50
|
|
|
$fileName = 'invalidModel.yml'; |
51
|
|
|
$rym = new Reader(); |
52
|
|
|
$rym->readYaml($baseDirectory.'/'.$fileName); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @slowThreshold 10 |
57
|
|
|
*/ |
58
|
|
|
public function testReadFile() |
59
|
|
|
{ |
60
|
|
|
$baseDirectory = __DIR__.'/../Resources/finder/basemodel'; |
61
|
|
|
$fileName = 'model.yml'; |
62
|
|
|
$rym = new Reader(); |
63
|
|
|
$rym->readYaml($baseDirectory.'/'.$fileName); |
64
|
|
|
$prop = $rym->getProperties(); |
|
|
|
|
65
|
|
|
$propExpected = [ |
66
|
|
|
'ddd' => [ |
67
|
|
|
'vo' => [ |
68
|
|
|
'package' => "Yoghi\Bundle\Madda\Domain\ValueObject", |
|
|
|
|
69
|
|
|
'getter' => 1, |
70
|
|
|
], |
71
|
|
|
], |
72
|
|
|
'classes' => [ |
73
|
|
|
'TestEnum' => [ |
74
|
|
|
'ddd' => ['type' => 'vo'], |
75
|
|
|
'name' => 'TestEnum', |
76
|
|
|
'description' => 'Test Enum', |
77
|
|
|
'namespace' => 'Yoghi\Bundle\Madda\Domain\ValueObject', |
78
|
|
|
'enum' => [ |
79
|
|
|
'TEST', |
80
|
|
|
], |
81
|
|
|
], |
82
|
|
|
], |
83
|
|
|
]; |
84
|
|
|
$this->assertEquals($propExpected, $prop, 'corretta lettura yml'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
View Code Duplication |
public function testReadDomainDefinition() |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
$baseDirectory = __DIR__.'/../Resources/finder/basemodel'; |
90
|
|
|
$fileName = 'model.yml'; |
91
|
|
|
$rym = new Reader(); |
92
|
|
|
$rym->readYaml($baseDirectory.'/'.$fileName); |
93
|
|
|
$testVoProperties = $rym->getDomainDefinitionAttributes('vo'); |
94
|
|
|
$this->assertEquals('Yoghi\Bundle\Madda\Domain\ValueObject', $testVoProperties['package'], 'package non letto corretamente'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function testReadAllClassDefinition() |
98
|
|
|
{ |
99
|
|
|
$baseDirectory = __DIR__.'/../Resources/finder/basemodel'; |
100
|
|
|
$fileName = 'model.yml'; |
101
|
|
|
$rym = new Reader(); |
102
|
|
|
$rym->readYaml($baseDirectory.'/'.$fileName); |
103
|
|
|
$prop = $rym->getClassesDefinition(); |
104
|
|
|
$propExpected = [ |
105
|
|
|
'TestEnum' => [ |
106
|
|
|
'ddd' => ['type' => 'vo'], |
107
|
|
|
'name' => 'TestEnum', |
108
|
|
|
'description' => 'Test Enum', |
109
|
|
|
'namespace' => 'Yoghi\Bundle\Madda\Domain\ValueObject', |
110
|
|
|
'enum' => ['TEST'], |
111
|
|
|
], |
112
|
|
|
]; |
113
|
|
|
$this->assertEquals($propExpected, $prop, 'corretta lettura yml'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
View Code Duplication |
public function testReadClassDefinition() |
|
|
|
|
117
|
|
|
{ |
118
|
|
|
$baseDirectory = __DIR__.'/../Resources/finder/basemodel'; |
119
|
|
|
$fileName = 'model.yml'; |
120
|
|
|
$rym = new Reader(); |
121
|
|
|
$rym->readYaml($baseDirectory.'/'.$fileName); |
122
|
|
|
$testEnumProperties = $rym->getClassDefinitionAttributes('TestEnum'); |
123
|
|
|
$this->assertEquals('Yoghi\Bundle\Madda\Domain\ValueObject', $testEnumProperties['namespace'], 'namespace non letto corretamente'); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
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.