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

testIsExtensibilityElementOKNoGoodnik()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace AlgoWeb\ODataMetadata\Tests\v3\edm;
4
5
use AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType;
6
use AlgoWeb\ODataMetadata\MetadataV3\edm\TEnumTypeMemberType;
7
use AlgoWeb\ODataMetadata\Tests\TestCase;
8
use Mockery as m;
9
10
class TEnumTypeMemberTypeTest extends TestCase
11
{
12
    public function testPreserveString()
13
    {
14
        $foo = new TEnumTypeMemberType();
15
        $expected = " string ";
16
        $actual = $foo->preserveString($expected);
17
        $this->assertEquals($expected, $actual);
18
    }
19
20
    public function testSetDocumentationNotOk()
21
    {
22
        $expected = "";
23
        $actual = null;
24
        $foo = new TEnumTypeMemberType();
25
        $documentation = m::mock(TDocumentationType::class);
26
        $documentation->shouldReceive('isOK')->andReturn(false)->once();
1 ignored issue
show
Unused Code introduced by
The call to ExpectationInterface::andReturn() has too many arguments starting with false.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
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...
27
28
        try {
29
            $foo->setDocumentation($documentation);
30
        } catch (\InvalidArgumentException $e) {
31
            $actual = $e->getMessage();
32
        }
33
        $this->assertEquals($expected, $actual);
34
    }
35
36 View Code Duplication
    public function testIsExtensibilityElementOKNoGoodnik()
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...
37
    {
38
        $expected = "";
39
        $actual = null;
40
        $foo = new TEnumTypeMemberType();
41
        $documentation = m::mock(TDocumentationType::class);
42
        $documentation->shouldReceive('isOK')->andReturn(true, false)->twice();
1 ignored issue
show
Unused Code introduced by
The call to ExpectationInterface::andReturn() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
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...
43
44
        $foo->setDocumentation($documentation);
45
        $this->assertFalse($foo->isExtensibilityElementOK($actual));
46
        $this->assertEquals($expected, $actual);
47
    }
48
}
49