|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace SlayerBirden\DFCodeGeneration\Tests; |
|
5
|
|
|
|
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
use SlayerBirden\DFCodeGeneration\Catalog\Entities\Category; |
|
8
|
|
|
use SlayerBirden\DFCodeGeneration\Catalog\Entities\Product; |
|
9
|
|
|
use SlayerBirden\DFCodeGeneration\Catalog\Entities\Stock; |
|
10
|
|
|
use SlayerBirden\DFCodeGeneration\Generator\Tests\FakerValueProvider; |
|
11
|
|
|
use SlayerBirden\DFCodeGeneration\Generator\Tests\IdRegistry; |
|
12
|
|
|
use SlayerBirden\DFCodeGeneration\Generator\Tests\ReflectionProvider; |
|
13
|
|
|
|
|
14
|
|
|
class ReflectionProviderTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var ReflectionProvider |
|
18
|
|
|
*/ |
|
19
|
|
|
private $provider; |
|
20
|
|
|
|
|
21
|
|
|
protected function setUp() |
|
22
|
|
|
{ |
|
23
|
|
|
$id = new IdRegistry(); |
|
24
|
|
|
$this->provider = new ReflectionProvider( |
|
25
|
|
|
Product::class, |
|
26
|
|
|
new FakerValueProvider(Product::class, $id), |
|
27
|
|
|
$id |
|
28
|
|
|
); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testGetId() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->assertInternalType('integer', $this->provider->getId()); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testGetPostParams() |
|
37
|
|
|
{ |
|
38
|
|
|
$params = $this->provider->getPostParams(); |
|
39
|
|
|
$this->assertCount(5, $params); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertArrayHasKey('name', $params); |
|
42
|
|
|
$this->assertArrayHasKey('sku', $params); |
|
43
|
|
|
$this->assertArrayHasKey('title', $params); |
|
44
|
|
|
$this->assertArrayHasKey('categories', $params); |
|
45
|
|
|
$this->assertArrayHasKey('stock', $params); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testGetParams() |
|
49
|
|
|
{ |
|
50
|
|
|
$params = $this->provider->getParams(); |
|
51
|
|
|
|
|
52
|
|
|
$this->assertCount(6, $params); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertArrayHasKey('id', $params); |
|
55
|
|
|
$this->assertArrayHasKey('name', $params); |
|
56
|
|
|
$this->assertArrayHasKey('sku', $params); |
|
57
|
|
|
$this->assertArrayHasKey('title', $params); |
|
58
|
|
|
$this->assertArrayHasKey('categories', $params); |
|
59
|
|
|
$this->assertArrayHasKey('stock', $params); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testGetIdName() |
|
63
|
|
|
{ |
|
64
|
|
|
$this->assertEquals('id', $this->provider->getIdName()); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function testHasUnique() |
|
68
|
|
|
{ |
|
69
|
|
|
$this->assertTrue($this->provider->hasUnique()); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function testGetEntityClassName() |
|
73
|
|
|
{ |
|
74
|
|
|
$this->assertEquals(Product::class, $this->provider->getEntityClassName()); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testGetShortName() |
|
78
|
|
|
{ |
|
79
|
|
|
$this->assertEquals('product', $this->provider->getShortName()); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function testGetBaseName() |
|
83
|
|
|
{ |
|
84
|
|
|
$this->assertEquals('Product', $this->provider->getBaseName()); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function testGetEntitySpec() |
|
88
|
|
|
{ |
|
89
|
|
|
$expected = [ |
|
90
|
|
|
[ |
|
91
|
|
|
'name' => 'id', |
|
92
|
|
|
'type' => 'integer', |
|
93
|
|
|
'nullable' => false, |
|
94
|
|
|
'reference' => null, |
|
95
|
|
|
], |
|
96
|
|
|
[ |
|
97
|
|
|
'name' => 'name', |
|
98
|
|
|
'type' => 'string', |
|
99
|
|
|
'nullable' => false, |
|
100
|
|
|
'reference' => null, |
|
101
|
|
|
], |
|
102
|
|
|
[ |
|
103
|
|
|
'name' => 'sku', |
|
104
|
|
|
'type' => 'string', |
|
105
|
|
|
'nullable' => false, |
|
106
|
|
|
'reference' => null, |
|
107
|
|
|
], |
|
108
|
|
|
[ |
|
109
|
|
|
'name' => 'title', |
|
110
|
|
|
'type' => 'string', |
|
111
|
|
|
'nullable' => true, |
|
112
|
|
|
'reference' => null, |
|
113
|
|
|
], |
|
114
|
|
|
[ |
|
115
|
|
|
'name' => 'categories', |
|
116
|
|
|
'type' => 'manytomany', |
|
117
|
|
|
'nullable' => true, |
|
118
|
|
|
'reference' => [ |
|
119
|
|
|
'entity' => '\\' . Category::class, |
|
120
|
|
|
'ref_column_key' => 'id', |
|
121
|
|
|
], |
|
122
|
|
|
], |
|
123
|
|
|
[ |
|
124
|
|
|
'name' => 'stock', |
|
125
|
|
|
'type' => 'onetoone', |
|
126
|
|
|
'nullable' => false, |
|
127
|
|
|
'reference' => [ |
|
128
|
|
|
'entity' => '\\' . Stock::class, |
|
129
|
|
|
'ref_column_key' => 'id', |
|
130
|
|
|
], |
|
131
|
|
|
], |
|
132
|
|
|
]; |
|
133
|
|
|
|
|
134
|
|
|
$this->assertEquals($expected, $this->provider->getEntitySpec()); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|