Completed
Push — master ( b9fce4...98eb76 )
by Max
01:21
created

MetadataTest::testGetSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
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\MetaData;
8
9
/**
10
 * @author mendel
11
 */
12
class MetadataTest extends \PHPUnit\Framework\TestCase
13
{
14 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...
15
    {
16
        $helper = new MetaData(
0 ignored issues
show
Deprecated Code introduced by
The class drycart\data\MetaData has been deprecated with message: #see MetaDataHelper

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
17
            dummy\DummyModel::class,
18
            ['@var'=>'var','@param'=>'param', '@return'=>'return']);
19
        $fields = $helper->fields(true);
0 ignored issues
show
Unused Code introduced by
The call to MetaData::fields() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
20
        $this->assertIsArray($fields);
21
        $this->assertCount(2, $fields);
22
        $this->assertArrayHasKey('name', $fields);
23
        $this->assertArrayHasKey('age', $fields);
24
        
25
        $this->assertIsArray($fields['name']);
26
        $this->assertCount(1, $fields['name']);
27
        $this->assertArrayHasKey('var', $fields['name']);
28
        $this->assertEquals([['string','name']],$fields['name']['var']);
29
        
30
        $this->assertIsArray($fields['age']);
31
        $this->assertCount(1, $fields['age']);
32
        $this->assertArrayHasKey('var', $fields['age']);
33
        $this->assertEquals([['int','age']],$fields['age']['var']);
34
    }
35 View Code Duplication
    public function testDirectMethods()
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...
36
    {
37
        $helper = new MetaData(
0 ignored issues
show
Deprecated Code introduced by
The class drycart\data\MetaData has been deprecated with message: #see MetaDataHelper

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
38
            dummy\DummyModel::class,
39
            ['@var'=>'var','@param'=>'param', '@return'=>'return']);
40
        
41
        $this->assertEquals(
42
            $helper->methods(true),
0 ignored issues
show
Unused Code introduced by
The call to MetaData::methods() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
43
            [
44
                'hydrate'=>['return'=>[['void']],'param'=>[['array', '$data']]],
45
            ]
46
        );
47
    }
48
    
49 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...
50
    {
51
        $helper = new MetaData(
0 ignored issues
show
Deprecated Code introduced by
The class drycart\data\MetaData has been deprecated with message: #see MetaDataHelper

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
52
            dummy\DummyExtendedModel::class,
53
            ['@var'=>'var','@param'=>'param', '@return'=>'return']);
54
        $fields = $helper->fields(true);
0 ignored issues
show
Unused Code introduced by
The call to MetaData::fields() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
55
        $this->assertIsArray($fields);
56
        $this->assertCount(2, $fields);
57
        $this->assertArrayHasKey('name', $fields);
58
        $this->assertArrayHasKey('age', $fields);
59
        
60
        $this->assertIsArray($fields['name']);
61
        $this->assertCount(1, $fields['name']);
62
        $this->assertArrayHasKey('var', $fields['name']);
63
        $this->assertEquals([['string','name']],$fields['name']['var']);
64
        
65
        $this->assertIsArray($fields['age']);
66
        $this->assertCount(1, $fields['age']);
67
        $this->assertArrayHasKey('var', $fields['age']);
68
        $this->assertEquals([['int','age']],$fields['age']['var']);
69
    }
70
    
71 View Code Duplication
    public function testExtendedMethods()
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...
72
    {
73
        $helper = new MetaData(
0 ignored issues
show
Deprecated Code introduced by
The class drycart\data\MetaData has been deprecated with message: #see MetaDataHelper

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
74
            dummy\DummyExtendedModel::class,
75
            ['@var'=>'var','@param'=>'param', '@return'=>'return']);
76
        
77
        $this->assertEquals(
78
            $helper->methods(true),
0 ignored issues
show
Unused Code introduced by
The call to MetaData::methods() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
79
            [
80
                'hydrate'=>['return'=>[['void']],'param'=>[['array', '$data']]],
81
            ]
82
        );
83
    }
84
    
85
    public function testClassRules()
86
    {
87
        $helper = new \drycart\data\MetaDataHelper();
88
        $rules = $helper->classRules(dummy\DummyModel::class);
89
        
90
        $this->assertIsArray($rules);
91
        $this->assertArrayHasKey('@author', $rules);
92
        $this->assertEquals('mendel',$rules['@author'][0][0]);
93
    }
94
    
95
    public function testGetSet()
96
    {
97
        // Yes, it just for 100% coverage
98
        $helper = new \drycart\data\MetaDataHelper();
99
        $config = [
100
            'classMeta' => [
101
                "Description of DummyModel",
102
                '',
103
                "@author mendel"
104
            ],
105
            'classRules' => [
106
                '@author' => [['max']]
107
            ]
108
        ];
109
        $helper->setCache([dummy\DummyModel::class=>$config]);
110
        $rules = $helper->classRules(dummy\DummyModel::class);
111
        var_dump($helper->getCache());
0 ignored issues
show
Security Debugging Code introduced by
var_dump($helper->getCache()); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
112
        $this->assertEquals('max',$rules['@author'][0][0]);
113
        $this->assertEquals([dummy\DummyModel::class=>$config],$helper->getCache());
114
    }
115
}
116