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 testDirect() |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
$helper = new MetaData( |
17
|
|
|
dummy\DummyModel::class, |
18
|
|
|
['@var'=>'var','@param'=>'param', '@return'=>'return']); |
19
|
|
|
$fields = $helper->fields(); |
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
|
|
|
$this->assertEquals( |
36
|
|
|
$helper->methods(), |
37
|
|
|
[ |
38
|
|
|
'hydrate'=>['return'=>[['void']],'param'=>[['array', '$data']]], |
39
|
|
|
] |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
View Code Duplication |
public function testExtended() |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
$helper = new MetaData( |
46
|
|
|
dummy\DummyExtendedModel::class, |
47
|
|
|
['@var'=>'var','@param'=>'param', '@return'=>'return']); |
48
|
|
|
$fields = $helper->fields(); |
49
|
|
|
$this->assertIsArray($fields); |
50
|
|
|
$this->assertCount(2, $fields); |
|
|
|
|
51
|
|
|
$this->assertArrayHasKey('name', $fields); |
52
|
|
|
$this->assertArrayHasKey('age', $fields); |
53
|
|
|
|
54
|
|
|
$this->assertIsArray($fields['name']); |
55
|
|
|
$this->assertCount(1, $fields['name']); |
56
|
|
|
$this->assertArrayHasKey('var', $fields['name']); |
57
|
|
|
$this->assertEquals([['string','name']],$fields['name']['var']); |
58
|
|
|
|
59
|
|
|
$this->assertIsArray($fields['age']); |
60
|
|
|
$this->assertCount(1, $fields['age']); |
61
|
|
|
$this->assertArrayHasKey('var', $fields['age']); |
62
|
|
|
$this->assertEquals([['int','age']],$fields['age']['var']); |
63
|
|
|
|
64
|
|
|
$this->assertEquals( |
65
|
|
|
$helper->methods(), |
66
|
|
|
[ |
67
|
|
|
'hydrate'=>['return'=>[['void']],'param'=>[['array', '$data']]], |
68
|
|
|
] |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
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.