Completed
Push — master ( dcaee8...dae57c )
by Max
01:11
created

MetadataTest::testExtendedFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
dl 21
loc 21
rs 9.584
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(
17
            dummy\DummyModel::class,
18
            ['@var'=>'var','@param'=>'param', '@return'=>'return']);
19
        $fields = $helper->fields(true);
20
        $this->assertIsArray($fields);
21
        $this->assertCount(2, $fields);
0 ignored issues
show
Documentation introduced by
$fields is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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(
38
            dummy\DummyModel::class,
39
            ['@var'=>'var','@param'=>'param', '@return'=>'return']);
40
        
41
        $this->assertEquals(
42
            $helper->methods(),
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(
52
            dummy\DummyExtendedModel::class,
53
            ['@var'=>'var','@param'=>'param', '@return'=>'return']);
54
        $fields = $helper->fields(true);
55
        $this->assertIsArray($fields);
56
        $this->assertCount(2, $fields);
0 ignored issues
show
Documentation introduced by
$fields is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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(
74
            dummy\DummyExtendedModel::class,
75
            ['@var'=>'var','@param'=>'param', '@return'=>'return']);
76
        
77
        $this->assertEquals(
78
            $helper->methods(),
79
            [
80
                'hydrate'=>['return'=>[['void']],'param'=>[['array', '$data']]],
81
            ]
82
        );
83
    }
84
}
85