Passed
Push — master ( 1c3995...861401 )
by Alex
48s
created

TEdmxTypeTest::testIsObjectWithoutDataServiceOK()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace AlgoWeb\ODataMetadata\Tests\v3\edmx;
4
5
use AlgoWeb\ODataMetadata\MetadataV3\edmx\TDataServicesType;
6
use AlgoWeb\ODataMetadata\MetadataV3\edmx\TDesignerType;
7
use AlgoWeb\ODataMetadata\MetadataV3\edmx\TEdmxType;
8
use AlgoWeb\ODataMetadata\MetadataV3\edmx\TRuntimeType;
9
use AlgoWeb\ODataMetadata\Tests\TestCase;
10
use Mockery as m;
11
12
class TEdmxTypeTest extends TestCase
13
{
14
    public function testSetEmptyVersion()
15
    {
16
        $version = " ";
17
        $foo = new TEdmxType();
18
19
        $expected = "Version cannot be null or empty";
20
        $actual = null;
21
22
        try {
23
            $foo->setVersion($version);
24
        } catch (\InvalidArgumentException $e) {
25
            $actual = $e->getMessage();
26
        }
27
        $this->assertEquals($expected, $actual);
28
    }
29
30 View Code Duplication
    public function testSetDataServiceTypeNotOK()
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...
31
    {
32
        $dataServiceType = m::mock(TDataServicesType::class);
33
        $dataServiceType->shouldReceive('isOK')->andReturn(false)->once();
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
34
        $foo = new TEdmxType();
35
36
        $expected = "";
37
        $actual = null;
38
39
        try {
40
            $foo->setDataServiceType($dataServiceType);
41
        } catch (\InvalidArgumentException $e) {
42
            $actual = $e->getMessage();
43
        }
44
        $this->assertEquals($expected, $actual);
45
    }
46
47 View Code Duplication
    public function testSetDesignerTypeNotOK()
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...
48
    {
49
        $designer = m::mock(TDesignerType::class);
50
        $designer->shouldReceive('isOK')->andReturn(false)->once();
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
51
        $foo = new TEdmxType();
52
53
        $expected = "";
54
        $actual = null;
55
56
        try {
57
            $foo->setDesigner($designer);
58
        } catch (\InvalidArgumentException $e) {
59
            $actual = $e->getMessage();
60
        }
61
        $this->assertEquals($expected, $actual);
62
    }
63
64 View Code Duplication
    public function testSetDesignerTypeOK()
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...
65
    {
66
        $designer = m::mock(TDesignerType::class);
67
        $designer->shouldReceive('isOK')->andReturn(true)->twice();
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
68
        $foo = new TEdmxType();
69
70
        $foo->setDesigner($designer);
71
        $this->assertTrue($foo->getDesigner()->isOK());
72
    }
73
74 View Code Duplication
    public function testSetRuntimeNotOK()
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...
75
    {
76
        $runtime = m::mock(TRuntimeType::class);
77
        $runtime->shouldReceive('isOK')->andReturn(false)->once();
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
78
        $foo = new TEdmxType();
79
80
        $expected = "";
81
        $actual = null;
82
83
        try {
84
            $foo->setRuntime($runtime);
85
        } catch (\InvalidArgumentException $e) {
86
            $actual = $e->getMessage();
87
        }
88
        $this->assertEquals($expected, $actual);
89
    }
90
91 View Code Duplication
    public function testSetRuntimeOK()
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...
92
    {
93
        $runtime = m::mock(TRuntimeType::class);
94
        $runtime->shouldReceive('isOK')->andReturn(true)->twice();
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
95
        $foo = new TEdmxType();
96
97
        $foo->setRuntime($runtime);
98
        $this->assertTrue($foo->getRuntime()->isOK());
99
    }
100
101 View Code Duplication
    public function testIsNewObjectOK()
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...
102
    {
103
        $expected = "Version cannot be null or empty";
104
        $actual = null;
105
        $foo = new TEdmxType();
106
107
        $this->assertFalse($foo->isOK($actual));
108
        $this->assertEquals($expected, $actual);
109
    }
110
111 View Code Duplication
    public function testIsObjectWithoutDataServiceOK()
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...
112
    {
113
        $expected = "Data service type cannot be null";
114
        $actual = null;
115
        $foo = new TEdmxType();
116
        $foo->setVersion("1.5");
117
118
        $this->assertFalse($foo->isOK($actual));
119
        $this->assertEquals($expected, $actual);
120
    }
121
122 View Code Duplication
    public function testIsObjectWithBadDataServiceOK()
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...
123
    {
124
        $unwanted2 = "Version cannot be null or empty";
125
        $actual = null;
126
        $dataServiceType = m::mock(TDataServicesType::class);
127
        $dataServiceType->shouldReceive('isOK')->andReturn(true, false)->twice();
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
128
        $foo = new TEdmxType();
129
        $foo->setVersion("1.5");
130
        $foo->setDataServiceType($dataServiceType);
131
132
        $this->assertFalse($foo->isOK($actual));
133
        $this->assertNotEquals($unwanted2, $actual);
134
    }
135
136
137 View Code Duplication
    public function testIsObjectWithBadDesignerServiceOK()
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...
138
    {
139
        $unwanted = "Data service type cannot be null";
140
        $unwanted2 = "Version cannot be null or empty";
141
        $actual = null;
142
        $designer = m::mock(TDesignerType::class);
143
        $designer->shouldReceive('isOK')->andReturn(true, false)->twice();
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
144
        $dataServiceType = m::mock(TDataServicesType::class);
145
        $dataServiceType->shouldReceive('isOK')->andReturn(true)->once();
146
        $foo = new TEdmxType();
147
        $foo->setVersion("1.5");
148
        $foo->setDataServiceType($dataServiceType);
149
        $foo->setDesigner($designer);
150
151
        $this->assertFalse($foo->isOK($actual));
152
        $this->assertNotEquals($unwanted, $actual);
153
        $this->assertNotEquals($unwanted2, $actual);
154
    }
155
156 View Code Duplication
    public function testIsObjectWithBadRuntimeServiceOK()
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...
157
    {
158
        $unwanted = "Data service type cannot be null";
159
        $unwanted2 = "Version cannot be null or empty";
160
        $actual = null;
161
        $runtime = m::mock(TRuntimeType::class);
162
        $runtime->shouldReceive('isOK')->andReturn(true, false)->twice();
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
163
        $dataServiceType = m::mock(TDataServicesType::class);
164
        $dataServiceType->shouldReceive('isOK')->andReturn(true)->once();
165
        $foo = new TEdmxType();
166
        $foo->setVersion("1.5");
167
        $foo->setDataServiceType($dataServiceType);
168
        $foo->setRuntime($runtime);
169
170
        $this->assertFalse($foo->isOK($actual));
171
        $this->assertNotEquals($unwanted, $actual);
172
        $this->assertNotEquals($unwanted2, $actual);
173
    }
174
}
175