Completed
Push — master ( 39caf5...4ceab2 )
by Sam
02:39
created

LimitTraitTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 23
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A testTrait() 0 15 1
1
<?php
2
3
namespace Jalle19\StatusManager\Test\Database;
4
5
use Jalle19\StatusManager\Database\LimitTrait;
6
7
/**
8
 * Class LimitTraitTest
9
 * @package   Jalle19\StatusManager\Test\Database
10
 * @copyright Copyright &copy; Sam Stenvall 2016-
11
 * @license   https://www.gnu.org/licenses/gpl.html The GNU General Public License v2.0
12
 */
13
class LimitTraitTest extends \PHPUnit_Framework_TestCase
14
{
15
16
	/**
17
	 * Tests that limit() is actually called correctly
18
	 */
19
	public function testTrait()
20
	{
21
		/* @var \PHPUnit_Framework_MockObject_MockObject|LimitTrait $mock */
22
		$mock = $this->getMockForTrait('\Jalle19\StatusManager\Database\LimitTrait');
23
24
		$mock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Jalle19\StatusManager\Database\LimitTrait.

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...
25
		     ->method('limit');
26
27
		$mock->filterByLimit(10);
0 ignored issues
show
Bug introduced by
The method filterByLimit does only exist in Jalle19\StatusManager\Database\LimitTrait, but not in PHPUnit_Framework_MockObject_MockObject.

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...
28
29
		$mock->expects($this->never())
30
		     ->method('limit');
31
32
		$mock->filterByLimit(null);
33
	}
34
35
}
36