1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace SlayerBirden\DFCodeGeneration\Controllers; |
5
|
|
|
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use SlayerBirden\DFCodeGeneration\Catalog\Entities\Product; |
8
|
|
|
use SlayerBirden\DFCodeGeneration\Generator\Controllers\DecoratedProvider; |
9
|
|
|
use SlayerBirden\DFCodeGeneration\Generator\Controllers\RelationsProviderDecorator; |
10
|
|
|
use SlayerBirden\DFCodeGeneration\Generator\Controllers\UniqueProviderDecorator; |
11
|
|
|
|
12
|
|
|
class DataProviderTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var DecoratedProvider |
16
|
|
|
*/ |
17
|
|
|
private $provider; |
18
|
|
|
|
19
|
|
|
protected function setUp() |
20
|
|
|
{ |
21
|
|
|
$name = Product::class; |
22
|
|
|
$this->provider = new DecoratedProvider( |
23
|
|
|
$name, |
24
|
|
|
new UniqueProviderDecorator($name), |
25
|
|
|
new RelationsProviderDecorator($name) |
26
|
|
|
); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testProvider() |
30
|
|
|
{ |
31
|
|
|
$expected = [ |
32
|
|
|
'ns' => 'SlayerBirden\\DFCodeGeneration\\Catalog\\Controller', |
33
|
|
|
'useStatement' => Product::class, |
34
|
|
|
'entityName' => 'Product', |
35
|
|
|
'hasUnique' => true, |
36
|
|
|
'uniqueIdxMessage' => 'Provided sku already exists.', |
37
|
|
|
'dataRelationship' => '//TODO process data relationship' |
38
|
|
|
]; |
39
|
|
|
$this->assertEquals($expected, $this->provider->provide()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @dataProvider classNameProvider |
44
|
|
|
* |
45
|
|
|
* @param string $type |
46
|
|
|
* @param string $expected |
47
|
|
|
* @throws \ReflectionException |
48
|
|
|
*/ |
49
|
|
|
public function testGetClassName(string $type, string $expected) |
50
|
|
|
{ |
51
|
|
|
$this->assertEquals($expected, $this->provider->getClassName($type)); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function classNameProvider(): array |
55
|
|
|
{ |
56
|
|
|
return [ |
57
|
|
|
[ |
58
|
|
|
'get', |
59
|
|
|
'SlayerBirden\\DFCodeGeneration\\Catalog\\Controller\\GetProductAction', |
60
|
|
|
], |
61
|
|
|
[ |
62
|
|
|
'gets', |
63
|
|
|
'SlayerBirden\\DFCodeGeneration\\Catalog\\Controller\\GetProductsAction', |
64
|
|
|
], |
65
|
|
|
[ |
66
|
|
|
'add', |
67
|
|
|
'SlayerBirden\\DFCodeGeneration\\Catalog\\Controller\\AddProductAction', |
68
|
|
|
], |
69
|
|
|
[ |
70
|
|
|
'update', |
71
|
|
|
'SlayerBirden\\DFCodeGeneration\\Catalog\\Controller\\UpdateProductAction', |
72
|
|
|
], |
73
|
|
|
[ |
74
|
|
|
'delete', |
75
|
|
|
'SlayerBirden\\DFCodeGeneration\\Catalog\\Controller\\DeleteProductAction', |
76
|
|
|
], |
77
|
|
|
]; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|