Completed
Branch master (c74b62)
by Max
01:08
created

MetadataTest::testExtendedMethods()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/*
3
 * @copyright (c) 2020 Mendel <[email protected]>
4
 * @license see license.txt
5
 */
6
namespace drycart\data\tests;
7
use drycart\data\MetaDataHelper;
8
9
/**
10
 * @author mendel
11
 */
12
class MetadataTest extends \PHPUnit\Framework\TestCase
13
{
14
    public function testGetSet()
15
    {
16
        // Yes, it just for 100% coverage, but thanks to it I find some small bug :)
17
        $helper = new MetaDataHelper();
18
        $config = [
19
            'classMeta' => [
20
                "Description of DummyModel",
21
                '',
22
                "@author mendel"
23
            ],
24
            'classRules' => [
25
                '@author' => [['max']]
26
            ]
27
        ];
28
        $helper->setCache([dummy\DummyModel::class=>$config]);
29
        $rules = $helper->classRules(dummy\DummyModel::class);
30
        
31
        $this->assertEquals('max',$rules['@author'][0][0]);
32
        $this->assertEquals([dummy\DummyModel::class=>$config],$helper->getCache());
33
    }
34
    
35
    public function testClassRules()
36
    {
37
        $helper = new MetaDataHelper();
38
        $rules = $helper->classRules(dummy\DummyModel::class);
39
        
40
        $this->assertIsArray($rules);
41
        $this->assertArrayHasKey('@author', $rules);
42
        $this->assertEquals('mendel',$rules['@author'][0][0]);
43
    }
44
    
45 View Code Duplication
    public function testDirectFields()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
46
    {
47
        $helper = new MetaDataHelper();
48
        $fields = $helper->fieldsRules(dummy\DummyModel::class);
49
        
50
        $this->assertIsArray($fields);
51
        $this->assertCount(2, $fields);
52
        $this->assertArrayHasKey('name', $fields);
53
        $this->assertArrayHasKey('age', $fields);
54
        
55
        $this->assertIsArray($fields['name']);
56
        $this->assertCount(1, $fields['name']);
57
        $this->assertArrayHasKey('@var', $fields['name']);
58
        $this->assertEquals([['string','name']],$fields['name']['@var']);
59
        
60
        $this->assertIsArray($fields['age']);
61
        $this->assertCount(1, $fields['age']);
62
        $this->assertArrayHasKey('@var', $fields['age']);
63
        $this->assertEquals([['int','age']],$fields['age']['@var']);
64
    }
65
    
66
    public function testDirectMethods()
67
    {
68
        $helper = new MetaDataHelper();
69
        $methods = $helper->methodsRules(dummy\DummyModel::class);
70
        
71
        $this->assertIsArray($methods);
72
        $this->assertCount(3, $methods);
73
        $this->assertArrayHasKey('getSomeString', $methods);
74
        $this->assertArrayHasKey('hydrate', $methods);
75
        $this->assertArrayHasKey('dehydrate', $methods);
76
        
77
        $this->assertIsArray($methods['getSomeString']);
78
        $this->assertCount(0, $methods['getSomeString']);
79
80
        $this->assertIsArray($methods['hydrate']);
81
        $this->assertCount(4, $methods['hydrate']);
82
        $this->assertArrayHasKey('@return', $methods['hydrate']);
83
        $this->assertArrayHasKey('@param', $methods['hydrate']);
84
        $this->assertEquals([['void']],$methods['hydrate']['@return']);
85
        $this->assertEquals([['array','$data']],$methods['hydrate']['@param']);
86
        
87
        $this->assertIsArray($methods['dehydrate']);
88
        $this->assertCount(3, $methods['dehydrate']);
89
        $this->assertArrayHasKey('@return', $methods['dehydrate']);
90
        $this->assertEquals([['array']],$methods['dehydrate']['@return']);
91
    }
92
    
93 View Code Duplication
    public function testExtendedFields()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
94
    {
95
        $helper = new MetaDataHelper();
96
        $fields = $helper->fieldsRules(dummy\DummyExtendedModel::class);
97
        
98
        $this->assertIsArray($fields);
99
        $this->assertCount(2, $fields);
100
        $this->assertArrayHasKey('name', $fields);
101
        $this->assertArrayHasKey('age', $fields);
102
        
103
        $this->assertIsArray($fields['name']);
104
        $this->assertCount(1, $fields['name']);
105
        $this->assertArrayHasKey('@var', $fields['name']);
106
        $this->assertEquals([['string','name']],$fields['name']['@var']);
107
        
108
        $this->assertIsArray($fields['age']);
109
        $this->assertCount(1, $fields['age']);
110
        $this->assertArrayHasKey('@var', $fields['age']);
111
        $this->assertEquals([['int','age']],$fields['age']['@var']);
112
    }
113
}
114