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

TAssociationEndTypeTest::testBadMultiplicity()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 0
1
<?php
2
3
namespace AlgoWeb\ODataMetadata\Tests\v3\edm;
4
5
use AlgoWeb\ODataMetadata\MetadataV3\edm\TAssociationEndType;
6
use AlgoWeb\ODataMetadata\MetadataV3\edm\TOnActionType;
7
use AlgoWeb\ODataMetadata\Tests\TestCase;
8
use Mockery as m;
9
10
class TAssociationEndTypeTest extends TestCase
11
{
12 View Code Duplication
    public function testBadMultiplicity()
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...
13
    {
14
        $expected = "Multiplicity must be a valid TMultiplicity";
15
        $actual = null;
16
17
        $foo = new TAssociationEndType();
18
        $mult = 'abc';
19
20
        try {
21
            $foo->setMultiplicity($mult);
22
        } catch (\InvalidArgumentException $e) {
23
            $actual = $e->getMessage();
24
        }
25
        $this->assertEquals($expected, $actual);
26
    }
27
28
    public function testAddToOnDeleteBadData()
29
    {
30
        $expected = "";
31
        $actual = null;
32
33
        $foo = new TAssociationEndType();
34
        $onDelete = m::mock(TOnActionType::class)->makePartial();
35
        $onDelete->shouldReceive('isOK')->andReturn(false)->once();
36
37
        try {
38
            $foo->addToOnDelete($onDelete);
1 ignored issue
show
Documentation introduced by
$onDelete is of type object<Mockery\Mock>, but the function expects a object<AlgoWeb\ODataMeta...taV3\edm\TOnActionType>.

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...
39
        } catch (\InvalidArgumentException $e) {
40
            $actual = $e->getMessage();
41
        }
42
        $this->assertEquals($expected, $actual);
43
    }
44
45
    public function testAddToOnDeleteGoodData()
46
    {
47
        $foo = new TAssociationEndType();
48
        $onDelete = m::mock(TOnActionType::class)->makePartial();
49
        $onDelete->shouldReceive('isOK')->andReturn(true)->once();
50
51
        $foo->addToOnDelete($onDelete);
1 ignored issue
show
Documentation introduced by
$onDelete is of type object<Mockery\Mock>, but the function expects a object<AlgoWeb\ODataMeta...taV3\edm\TOnActionType>.

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...
52
        $this->assertTrue($foo->issetOnDelete(0));
53
        $this->assertFalse($foo->issetOnDelete(1));
54
55
        $foo->unsetOnDelete(0);
56
        $this->assertFalse($foo->issetOnDelete(0));
57
        $this->assertFalse($foo->issetOnDelete(1));
58
    }
59
60 View Code Duplication
    public function testSetOnDeleteBadItem()
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...
61
    {
62
        $expected = "";
63
        $actual = null;
64
65
        $foo = new TAssociationEndType();
66
        $onDelete = m::mock(TOnActionType::class)->makePartial();
67
        $onDelete->shouldReceive('isOK')->andReturn(false)->once();
68
        $delete = [$onDelete];
69
70
        try {
71
            $foo->setOnDelete($delete);
1 ignored issue
show
Documentation introduced by
$delete is of type array<integer,object<Moc...bject<Mockery\\Mock>"}>, but the function expects a array<integer,object<Alg...aV3\edm\TOnActionType>>.

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...
72
        } catch (\InvalidArgumentException $e) {
73
            $actual = $e->getMessage();
74
        }
75
        $this->assertEquals($expected, $actual);
76
    }
77
78 View Code Duplication
    public function testIsTOperationsOKBadData()
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...
79
    {
80
        $expected = "";
81
        $actual = null;
82
83
        $foo = new TAssociationEndType();
84
        $onDelete = m::mock(TOnActionType::class)->makePartial();
85
        $onDelete->shouldReceive('isOK')->andReturn(true, false)->twice();
86
        $delete = [$onDelete];
87
88
        $foo->setOnDelete($delete);
1 ignored issue
show
Documentation introduced by
$delete is of type array<integer,object<Moc...bject<Mockery\\Mock>"}>, but the function expects a array<integer,object<Alg...aV3\edm\TOnActionType>>.

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...
89
90
        $this->assertFalse($foo->isTOperationsOK($actual));
91
        $this->assertEquals($expected, $actual);
92
    }
93
}
94