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

TokenManagerTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Yokai\SecurityTokenBundle\Tests\Manager;
4
5
use Prophecy\Prophecy\ObjectProphecy;
6
use Yokai\SecurityTokenBundle\Entity\Token;
7
use Yokai\SecurityTokenBundle\Factory\TokenFactoryInterface;
8
use Yokai\SecurityTokenBundle\InformationGuesser\InformationGuesserInterface;
9
use Yokai\SecurityTokenBundle\Manager\TokenManager;
10
use Yokai\SecurityTokenBundle\Manager\UserManagerInterface;
11
use Yokai\SecurityTokenBundle\Repository\TokenRepositoryInterface;
12
13
/**
14
 * @author Yann Eugoné <[email protected]>
15
 */
16
class TokenManagerTest extends \PHPUnit_Framework_TestCase
17
{
18
    /**
19
     * @var \PHPUnit_Framework_MockObject_MockObject
20
     */
21
    private $factory;
22
23
    /**
24
     * @var TokenRepositoryInterface|ObjectProphecy
25
     */
26
    private $repository;
27
28
    /**
29
     * @var InformationGuesserInterface|ObjectProphecy
30
     */
31
    private $informationGuesser;
32
33
    /**
34
     * @var UserManagerInterface|ObjectProphecy
35
     */
36
    private $userManager;
37
38
    protected function setUp()
39
    {
40
        $this->factory = $this->createMock(TokenFactoryInterface::class);
41
        $this->repository = $this->prophesize(TokenRepositoryInterface::class);
42
        $this->informationGuesser = $this->prophesize(InformationGuesserInterface::class);
43
        $this->userManager = $this->prophesize(UserManagerInterface::class);
44
    }
45
46
    protected function tearDown()
47
    {
48
        unset(
49
            $this->factory,
50
            $this->repository,
51
            $this->informationGuesser,
52
            $this->userManager
53
        );
54
    }
55
56
    protected function manager()
57
    {
58
        return new TokenManager(
59
            $this->factory,
60
            $this->repository->reveal(),
0 ignored issues
show
Bug introduced by
The method reveal does only exist in Prophecy\Prophecy\ObjectProphecy, but not in Yokai\SecurityTokenBundl...okenRepositoryInterface.

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...
61
            $this->informationGuesser->reveal(),
0 ignored issues
show
Bug introduced by
The method reveal does only exist in Prophecy\Prophecy\ObjectProphecy, but not in Yokai\SecurityTokenBundl...rmationGuesserInterface.

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...
62
            $this->userManager->reveal()
0 ignored issues
show
Bug introduced by
The method reveal does only exist in Prophecy\Prophecy\ObjectProphecy, but not in Yokai\SecurityTokenBundl...er\UserManagerInterface.

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...
63
        );
64
    }
65
66
    /**
67
     * @test
68
     */
69
    public function it_get_token_from_repository()
70
    {
71
        $this->repository->get('unique-token', 'forgot_password')
0 ignored issues
show
Bug introduced by
The method get does only exist in Yokai\SecurityTokenBundl...okenRepositoryInterface, 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...
72
            ->shouldBeCalledTimes(1)
73
            ->willReturn($expected = $this->prophesize(Token::class)->reveal());
74
75
        $token = $this->manager()->get('forgot_password', 'unique-token');
76
77
        self::assertSame($expected, $token);
78
    }
79
80
    /**
81
     * @test
82
     */
83
    public function it_create_unique_token()
84
    {
85
        $token1 = new Token('string', 'jdoe','unique-token-1', 'reset-password',  '+1 day', []);
86
        $token2 = new Token('string', 'jdoe','unique-token-2', 'reset-password',  '+1 day', []);
87
88
        $this->factory->expects($this->exactly(2))
89
                      ->method('create')
90
                      ->will($this->onConsecutiveCalls($token1, $token2));
91
92
        $this->repository->exists('unique-token-1', 'forgot_password')
0 ignored issues
show
Bug introduced by
The method exists does only exist in Yokai\SecurityTokenBundl...okenRepositoryInterface, 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...
93
            ->shouldBeCalledTimes(1)
94
            ->willReturn(true);
95
        $this->repository->exists('unique-token-2', 'forgot_password')
96
            ->shouldBeCalledTimes(1)
97
            ->willReturn(false);
98
99
        $this->repository->create($token1)
0 ignored issues
show
Bug introduced by
The method create does only exist in Yokai\SecurityTokenBundl...okenRepositoryInterface, 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...
100
            ->shouldNotBeCalled();
101
        $this->repository->create($token2)
102
            ->shouldBeCalledTimes(1);
103
104
        $token = $this->manager()->create('forgot_password', 'john-doe');
105
106
        self::assertSame($token2, $token);
107
    }
108
109
    /**
110
     * @test
111
     */
112
    public function it_consume_token()
113
    {
114
        $token = new Token('string', 'jdoe','unique-token', 'reset-password',  '+1 day', []);
115
116
        $this->informationGuesser->get()
0 ignored issues
show
Bug introduced by
The method get does only exist in Yokai\SecurityTokenBundl...rmationGuesserInterface, 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...
117
            ->shouldBeCalledTimes(1)
118
            ->willReturn(['some', 'precious', 'information']);
119
120
        $this->repository->update($token)
0 ignored issues
show
Bug introduced by
The method update does only exist in Yokai\SecurityTokenBundl...okenRepositoryInterface, 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...
121
            ->shouldBeCalledTimes(1);
122
123
        $this->manager()->setUsed($token);
124
125
        self::assertSame(['some', 'precious', 'information'], $token->getUsedInformation());
126
        self::assertInstanceOf(\DateTime::class, $token->getUsedAt());
127
    }
128
129
    /**
130
     * @test
131
     */
132
    public function it_extract_user_from_token()
133
    {
134
        $token = new Token('string', 'jdoe','unique-token', 'reset-password',  '+1 day', []);
135
136
        $this->userManager->get('string', 'jdoe')
0 ignored issues
show
Bug introduced by
The method get does only exist in Yokai\SecurityTokenBundl...er\UserManagerInterface, 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...
137
            ->shouldBeCalledTimes(1)
138
            ->willReturn('john doe');
139
140
        $user = $this->manager()->getUser($token);
141
142
        self::assertSame('john doe', $user);
143
    }
144
}
145