Completed
Push — master ( 3e963f...fbd0cf )
by Yann
02:04
created

UserManagerTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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
/**
11
 * @author Yann Eugoné <[email protected]>
12
 */
13
class UserManagerTest extends \PHPUnit_Framework_TestCase
14
{
15
    /**
16
     * @var EntityManagerInterface|ObjectProphecy
17
     */
18
    private $entityManager;
19
20
    /**
21
     * @var ClassMetadata|ObjectProphecy
22
     */
23
    private $classMetadata;
24
25
    protected function setUp()
26
    {
27
        $this->entityManager = $this->prophesize(EntityManagerInterface::class);
28
        $this->classMetadata = $this->prophesize(ClassMetadata::class);
29
    }
30
31
    protected function tearDown()
32
    {
33
        unset(
34
            $this->entityManager,
35
            $this->classMetadata
36
        );
37
    }
38
39
    protected function manager()
40
    {
41
        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...
42
    }
43
44
    protected function user($id)
45
    {
46
        return new class($id) {
47
            private $id;
48
49
            public function __construct($id)
50
            {
51
                $this->id = $id;
52
            }
53
54
            public function getId()
55
            {
56
                return $this->id;
57
            }
58
        };
59
    }
60
61
    /**
62
     * @test
63
     */
64
    public function it_get_user()
65
    {
66
        $expected = $this->user('jdoe');
67
68
        $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...
69
            ->shouldBeCalledTimes(1)
70
            ->willReturn($expected);
71
72
        $user = $this->manager()->get(get_class($expected), 'jdoe');
73
74
        self::assertSame($expected, $user);
75
    }
76
77
    /**
78
     * @test
79
     */
80
    public function it_get_user_class()
81
    {
82
        $expected = $this->user('jdoe');
83
84
        $class = $this->manager()->getClass($expected);
85
86
        self::assertSame(get_class($expected), $class);
87
    }
88
89
    /**
90
     * @test
91
     */
92
    public function it_get_user_id()
93
    {
94
        $expected = $this->user('jdoe');
95
96
        $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...
97
            ->shouldBeCalledTimes(1)
98
            ->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...
99
100
        $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...
101
            ->shouldBeCalledTimes(1)
102
            ->willReturn(['id' => 'jdoe']);
103
104
        $id = $this->manager()->getId($expected);
105
106
        self::assertSame('jdoe', $id);
107
    }
108
}
109