Completed
Push — master ( e8ad81...cc5898 )
by Alex
05:32
created

testIsDerivableTypeAttributesValidNameGoodBaseTypeNotGood()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 15
nc 2
nop 0
1
<?php
2
3
namespace AlgoWeb\ODataMetadata\Tests\v3\edm;
4
5
use AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityTypeType;
6
use AlgoWeb\ODataMetadata\Tests\TestCase;
7
use Mockery as m;
8
9
class TEntityTypeTypeTest extends TestCase
10
{
11 View Code Duplication
    public function testSetBaseTypeBadData()
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...
12
    {
13
        $expected = "Base type must be a valid TQualifiedName";
14
        $actual = null;
15
        $foo = new TEntityTypeType();
16
        $baseType = " _ ";
17
18
        try {
19
            $foo->setBaseType($baseType);
20
        } catch (\InvalidArgumentException $e) {
21
            $actual = $e->getMessage();
22
        }
23
        $this->assertEquals($expected, $actual);
24
    }
25
26 View Code Duplication
    public function testIsDerivableTypeAttributesValidNewCreation()
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...
27
    {
28
        $expected = "Name cannot be null: AlgoWeb\\ODataMetadata\\MetadataV3\\edm\\TEntityTypeType";
29
        $actual = null;
30
        $foo = new TEntityTypeType();
31
32
        try {
33
            $foo->isTDerivableTypeAttributesValid($actual);
34
        } catch (\InvalidArgumentException $e) {
35
            $actual = $e->getMessage();
36
        }
37
        $this->assertEquals($expected, $actual);
38
    }
39
40
    public function testIsDerivableTypeAttributesValidNameGoodBaseTypeNotGood()
41
    {
42
        $expectedStarts = "Base type must be a valid TQualifiedName:";
43
        $expectedEnds = "AlgoWeb_ODataMetadata_MetadataV3_edm_TEntityTypeType";
44
        $actual = null;
45
        $foo = m::mock(TEntityTypeType::class)->makePartial();
46
        $foo->shouldReceive('isTQualifiedNameValid')->withAnyArgs()->andReturn(true, false)->twice();
47
        $foo->shouldReceive('isTTypeAttributesValid')->andReturn(true)->atLeast(1);
48
49
        $foo->setName('Name');
50
        $foo->setBaseType('baseType');
51
52
        try {
53
            $foo->isTDerivableTypeAttributesValid($actual);
54
        } catch (\InvalidArgumentException $e) {
55
            $actual = $e->getMessage();
56
        }
57
        $this->assertStringStartsWith($expectedStarts, $actual);
58
        $this->assertStringEndsWith($expectedEnds, $actual);
59
    }
60
61 View Code Duplication
    public function testSetNameNull()
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...
62
    {
63
        $expected = "Name cannot be null";
64
        $actual = null;
65
        $name = null;
66
67
        $foo = new TEntityTypeType();
68
69
        try {
70
            $foo->setName($name);
71
        } catch (\InvalidArgumentException $e) {
72
            $actual = $e->getMessage();
73
        }
74
        $this->assertEquals($expected, $actual);
75
    }
76
77 View Code Duplication
    public function testSetNameNonString()
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...
78
    {
79
        $expected = "Name must be a valid TSimpleIdentifier";
80
        $actual = null;
81
        $name = new \DateTime();
82
83
        $foo = new TEntityTypeType();
84
85
        try {
86
            $foo->setName($name);
0 ignored issues
show
Documentation introduced by
$name is of type object<DateTime>, but the function expects a string.

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...
87
        } catch (\InvalidArgumentException $e) {
88
            $actual = $e->getMessage();
89
        }
90
        $this->assertEquals($expected, $actual);
91
    }
92
93 View Code Duplication
    public function testIsTTypeAttributesValidNameNotSimpleIdentifier()
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
        $expectedStarts = "Name must be a valid TSimpleIdentifier:";
96
        $expectedEnds = "AlgoWeb_ODataMetadata_MetadataV3_edm_TEntityTypeType";
97
        $actual = null;
98
        $name = " _ ";
99
100
        $foo = m::mock(TEntityTypeType::class)->makePartial();
101
        $foo->shouldReceive('isTSimpleIdentifierValid')->withAnyArgs()->andReturn(true, false)->twice();
102
        $foo->setName($name);
103
104
        $foo->isTTypeAttributesValid($actual);
105
        $this->assertStringStartsWith($expectedStarts, $actual);
106
        $this->assertStringEndsWith($expectedEnds, $actual);
107
    }
108
}
109