Completed
Pull Request — master (#108)
by Alex
04:49
created

testSetNumericDefaultValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace AlgoWeb\ODataMetadata\Tests\v3\edm;
4
5
use AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityPropertyType;
6
use AlgoWeb\ODataMetadata\Tests\TestCase;
7
use Mockery as m;
8
9
class TEntityPropertyTypeTest extends TestCase
10
{
11
    public function testSetNullDefaultValue()
12
    {
13
        $foo = new TEntityPropertyType();
14
        $foo->setDefaultValue(null);
15
        $this->assertEquals(null, $foo->getDefaultValue());
16
    }
17
18
    public function testSetStringDefaultValue()
19
    {
20
        $foo = new TEntityPropertyType();
21
        $foo->setDefaultValue('abc');
22
        $this->assertEquals('abc', $foo->getDefaultValue());
23
    }
24
25
    public function testSetNumericDefaultValue()
26
    {
27
        $foo = new TEntityPropertyType();
28
        $foo->setDefaultValue(1234);
29
        $this->assertEquals('1234', $foo->getDefaultValue());
30
    }
31
32
    public function testSetObjectDefaultValue()
33
    {
34
        $expected = "Default value must be resolvable to a string";
35
        $actual = null;
36
37
        $foo = new TEntityPropertyType();
38
        try {
39
            $foo->setDefaultValue(new \DateTime());
40
        } catch (\InvalidArgumentException $e) {
41
            $actual = $e->getMessage();
42
        }
43
        $this->assertEquals($expected, $actual);
44
    }
45
46
    public function testSetEmptyArrayDefaultValue()
47
    {
48
        $expected = "Default value must be resolvable to a string";
49
        $actual = null;
50
51
        $foo = new TEntityPropertyType();
52
        try {
53
            $foo->setDefaultValue([]);
1 ignored issue
show
Documentation introduced by
array() is of type array, 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...
54
        } catch (\InvalidArgumentException $e) {
55
            $actual = $e->getMessage();
56
        }
57
        $this->assertEquals($expected, $actual);
58
    }
59
60
    public function testSetNonEmptyArrayDefaultValue()
61
    {
62
        $expected = "Default value must be resolvable to a string";
63
        $actual = null;
64
65
        $foo = new TEntityPropertyType();
66
        try {
67
            $foo->setDefaultValue(['a']);
1 ignored issue
show
Documentation introduced by
array('a') is of type array<integer,string,{"0":"string"}>, 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...
68
        } catch (\InvalidArgumentException $e) {
69
            $actual = $e->getMessage();
70
        }
71
        $this->assertEquals($expected, $actual);
72
    }
73
}
74