Passed
Push — master ( 743cc2...6ffec3 )
by Oleg
02:50
created

ConfigProviderTest::testGetSpec()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 14
nc 1
nop 0
dl 0
loc 32
rs 8.8571
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DFCodeGeneration;
5
6
use Doctrine\Common\Annotations\AnnotationRegistry;
7
use PHPUnit\Framework\TestCase;
8
use SlayerBirden\DFCodeGeneration\Catalog\Entities\Product;
9
use SlayerBirden\DFCodeGeneration\Generator\Config\StandardProvider;
10
11
class ConfigProviderTest extends TestCase
12
{
13
    /** @var StandardProvider */
14
    private $provider;
15
16
    protected function setUp()
17
    {
18
        // This is required for annotations to work
19
        AnnotationRegistry::registerLoader('class_exists');
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\Common\Annotati...istry::registerLoader() has been deprecated: this method is deprecated and will be removed in doctrine/annotations 2.0 autoloading should be deferred to the globally registered autoloader by then. For now, use @example AnnotationRegistry::registerLoader('class_exists') ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

19
        /** @scrutinizer ignore-deprecated */ AnnotationRegistry::registerLoader('class_exists');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
20
21
        $this->provider = new StandardProvider(Product::class);
22
    }
23
24
    public function testGetRouteFactoryName()
25
    {
26
        $this->assertSame(
27
            'SlayerBirden\\DFCodeGeneration\\Catalog\\Factory\\ProductRoutesDelegator',
28
            $this->provider->getRouteFactoryName()
29
        );
30
    }
31
32
    public function testGetSpec()
33
    {
34
        $expected = [
35
            'name' => [
36
                'required' => true,
37
                'filters' => [
38
                    [
39
                        'name' => 'stringtrim',
40
                    ]
41
                ],
42
                'validators' => [
43
                    [
44
                        'name' => 'notempty',
45
                    ]
46
                ],
47
            ],
48
            'sku' => [
49
                'required' => true,
50
                'filters' => [
51
                    [
52
                        'name' => 'stringtrim',
53
                    ]
54
                ],
55
                'validators' => [
56
                    [
57
                        'name' => 'notempty',
58
                    ]
59
                ],
60
            ],
61
        ];
62
63
        $this->assertEquals($expected, $this->provider->getInputFilterSpec());
64
    }
65
66
    public function testGetSpecName()
67
    {
68
        $this->assertSame('ProductInputFilter', $this->provider->getInputFilterName());
69
    }
70
71
    public function testGetCurrentConfig()
72
    {
73
        $this->assertEmpty($this->provider->getCurrentConfig());
74
    }
75
76
    public function testGetConfigNameSpace()
77
    {
78
        $this->assertEquals('SlayerBirden\\DFCodeGeneration\\Catalog', $this->provider->getConfigNameSpace());
79
    }
80
81
    public function testGetEntitiesSrc()
82
    {
83
        $this->assertSame('src/Catalog/Entities', $this->provider->getEntitiesSrc());
84
    }
85
86
    /**
87
     * @dataProvider controllerNameProvider
88
     *
89
     * @param string $type
90
     * @param string $expected
91
     * @throws \ReflectionException
92
     */
93
    public function testGetControllerName(string $type, string $expected)
94
    {
95
        $this->assertSame($expected, $this->provider->getControllerName($type));
96
    }
97
98
    public function controllerNameProvider(): array
99
    {
100
        return [
101
            [
102
                'get',
103
                'SlayerBirden\\DFCodeGeneration\\Catalog\\Controller\\GetProductAction',
104
            ],
105
            [
106
                'gets',
107
                'SlayerBirden\\DFCodeGeneration\\Catalog\\Controller\\GetProductsAction',
108
            ],
109
            [
110
                'add',
111
                'SlayerBirden\\DFCodeGeneration\\Catalog\\Controller\\AddProductAction',
112
            ],
113
            [
114
                'update',
115
                'SlayerBirden\\DFCodeGeneration\\Catalog\\Controller\\UpdateProductAction',
116
            ],
117
            [
118
                'delete',
119
                'SlayerBirden\\DFCodeGeneration\\Catalog\\Controller\\DeleteProductAction',
120
            ],
121
        ];
122
    }
123
}
124