NameEntityTest::mock()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Created by PhpStorm.
5
 * User: benedikt
6
 * Date: 1/3/18
7
 * Time: 10:39 AM
8
 */
9
10
namespace Tfboe\FmLib\Tests\Unit\Entity\Helpers;
11
12
13
use PHPUnit\Framework\MockObject\MockObject;
14
use Tfboe\FmLib\Entity\Helpers\NameEntity;
15
use Tfboe\FmLib\Tests\Helpers\UnitTestCase;
16
17
/**
18
 * Class BaseEntityTest
19
 * @package Tfboe\FmLib\Tests\Unit\Entity\Helpers
20
 */
21
class NameEntityTest extends UnitTestCase
22
{
23
//<editor-fold desc="Public Methods">
24
  /**
25
   * @covers \Tfboe\FmLib\Entity\Helpers\NameEntity::getName
26
   * @covers \Tfboe\FmLib\Entity\Helpers\NameEntity::setName
27
   */
28
  public function testName()
29
  {
30
    $entity = $this->mock();
31
    $entity->setName("Name");
0 ignored issues
show
Bug introduced by
The method setName does only exist in Tfboe\FmLib\Entity\Helpers\NameEntity, 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...
32
    self::assertEquals("Name", $entity->getName());
0 ignored issues
show
Bug introduced by
The method getName does only exist in Tfboe\FmLib\Entity\Helpers\NameEntity, 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...
33
  }
34
//</editor-fold desc="Public Methods">
35
36
//<editor-fold desc="Private Methods">
37
  /**
38
   * @return MockObject|NameEntity
39
   */
40
  private function mock(): MockObject
41
  {
42
    return $this->getMockForTrait(NameEntity::class);
43
  }
44
//</editor-fold desc="Private Methods">
45
}