Completed
Pull Request — master (#7)
by Yann
05:59
created

anonymous//Tests/Manager/UserManagerTest.php$0   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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