Completed
Pull Request — master (#7)
by Yann
11:20
created

UserManagerTest.php$0 ➔ __construct()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
1
<?php
2
3
namespace Yokai\SecurityTokenBundle\Tests\Manager;
4
5
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
6
use Doctrine\ORM\EntityManagerInterface;
7
use Prophecy\Prophecy\ObjectProphecy;
8
use Yokai\SecurityTokenBundle\Manager\UserManager;
9
10
class UserManagerTest extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @var EntityManagerInterface|ObjectProphecy
14
     */
15
    private $entityManager;
16
17
    /**
18
     * @var ClassMetadata|ObjectProphecy
19
     */
20
    private $classMetadata;
21
22
    protected function setUp()
23
    {
24
        $this->entityManager = $this->prophesize(EntityManagerInterface::class);
25
        $this->classMetadata = $this->prophesize(ClassMetadata::class);
26
    }
27
28
    protected function tearDown()
29
    {
30
        unset(
31
            $this->entityManager,
32
            $this->classMetadata
33
        );
34
    }
35
36
    protected function manager()
37
    {
38
        return new UserManager($this->entityManager->reveal());
0 ignored issues
show
Bug introduced by
The method reveal does only exist in Prophecy\Prophecy\ObjectProphecy, but not in Doctrine\ORM\EntityManagerInterface.

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...
39
    }
40
41
    protected function user($id)
42
    {
43
        return new class($id) {
44
            private $id;
45
46
            public function __construct($id)
47
            {
48
                $this->id = $id;
49
            }
50
51
            public function getId()
52
            {
53
                return $this->id;
54
            }
55
        };
56
    }
57
58
    /**
59
     * @test
60
     */
61
    public function it_get_user()
62
    {
63
        $expected = $this->user('jdoe');
64
65
        $this->entityManager->find(get_class($expected), 'jdoe')
0 ignored issues
show
Bug introduced by
The method find does only exist in Doctrine\ORM\EntityManagerInterface, but not in Prophecy\Prophecy\ObjectProphecy.

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...
66
            ->shouldBeCalledTimes(1)
67
            ->willReturn($expected);
68
69
        $user = $this->manager()->get(get_class($expected), 'jdoe');
70
71
        self::assertSame($expected, $user);
72
    }
73
74
    /**
75
     * @test
76
     */
77
    public function it_get_user_class()
78
    {
79
        $expected = $this->user('jdoe');
80
81
        $class = $this->manager()->getClass($expected);
82
83
        self::assertSame(get_class($expected), $class);
84
    }
85
86
    /**
87
     * @test
88
     */
89
    public function it_get_user_id()
90
    {
91
        $expected = $this->user('jdoe');
92
93
        $this->entityManager->getClassMetadata(get_class($expected))
0 ignored issues
show
Bug introduced by
The method getClassMetadata does only exist in Doctrine\ORM\EntityManagerInterface, but not in Prophecy\Prophecy\ObjectProphecy.

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...
94
            ->shouldBeCalledTimes(1)
95
            ->willReturn($this->classMetadata->reveal());
0 ignored issues
show
Bug introduced by
The method reveal does only exist in Prophecy\Prophecy\ObjectProphecy, but not in Doctrine\Common\Persistence\Mapping\ClassMetadata.

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...
96
97
        $this->classMetadata->getIdentifierValues($expected)
0 ignored issues
show
Bug introduced by
The method getIdentifierValues does only exist in Doctrine\Common\Persistence\Mapping\ClassMetadata, but not in Prophecy\Prophecy\ObjectProphecy.

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...
98
            ->shouldBeCalledTimes(1)
99
            ->willReturn(['id' => 'jdoe']);
100
101
        $id = $this->manager()->getId($expected);
102
103
        self::assertSame('jdoe', $id);
104
    }
105
}
106