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

it_get_valid_token()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace Yokai\SecurityTokenBundle\Tests\Repository;
4
5
use Doctrine\ORM\EntityManager;
6
use Doctrine\ORM\EntityRepository;
7
use Prophecy\Prophecy\ObjectProphecy;
8
use Yokai\SecurityTokenBundle\Entity\Token;
9
use Yokai\SecurityTokenBundle\Repository\DoctrineORMTokenRepository;
10
11
/**
12
 * @author Yann Eugoné <[email protected]>
13
 */
14
class DoctrineORMTokenRepositoryTest extends \PHPUnit_Framework_TestCase
15
{
16
    /**
17
     * @var EntityManager|ObjectProphecy
18
     */
19
    private $manager;
20
21
    /**
22
     * @var EntityRepository|ObjectProphecy
23
     */
24
    private $repository;
25
26
    protected function setUp()
27
    {
28
        $this->manager = $this->prophesize(EntityManager::class);
29
        $this->repository = $this->prophesize(EntityRepository::class);
30
    }
31
32
    protected function tearDown()
33
    {
34
        unset(
35
            $this->manager,
36
            $this->repository
37
        );
38
    }
39
40
    protected function repository()
41
    {
42
        return new DoctrineORMTokenRepository($this->manager->reveal(), $this->repository->reveal());
0 ignored issues
show
Bug introduced by
The method reveal does only exist in Prophecy\Prophecy\ObjectProphecy, but not in Doctrine\ORM\EntityManager.

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...
Bug introduced by
The method reveal does only exist in Prophecy\Prophecy\ObjectProphecy, but not in Doctrine\ORM\EntityRepository.

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
    /**
46
     * @test
47
     * @expectedException \Yokai\SecurityTokenBundle\Exception\TokenNotFoundException
48
     */
49
    public function it_throw_exception_if_token_not_found()
50
    {
51
        $this->repository->findOneBy(['value' => 'unique', 'purpose' => 'init_password'])
0 ignored issues
show
Bug introduced by
The method findOneBy does only exist in Doctrine\ORM\EntityRepository, 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...
52
            ->shouldBeCalledTimes(1)
53
            ->willReturn(null);
54
55
        $this->repository()->get('unique', 'init_password');
56
    }
57
58
    /**
59
     * @test
60
     * @expectedException \Yokai\SecurityTokenBundle\Exception\TokenExpiredException
61
     */
62
    public function it_throw_exception_if_token_expired()
63
    {
64
        $token = new Token('string', 'jdoe','unique', 'init_password',  '-1 day', []);
65
66
        $this->repository->findOneBy(['value' => 'unique', 'purpose' => 'init_password'])
0 ignored issues
show
Bug introduced by
The method findOneBy does only exist in Doctrine\ORM\EntityRepository, 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...
67
            ->shouldBeCalledTimes(1)
68
            ->willReturn($token);
69
70
        $this->repository()->get('unique', 'init_password');
71
    }
72
73
    /**
74
     * @test
75
     * @expectedException \Yokai\SecurityTokenBundle\Exception\TokenUsedException
76
     */
77
    public function it_throw_exception_if_token_used()
78
    {
79
        $token = new Token('string', 'jdoe','unique', 'init_password',  '+1 day', []);
80
        $token->setUsedAt(new \DateTime());
81
        $token->setUsedInformation(['info']);
82
83
        $this->repository->findOneBy(['value' => 'unique', 'purpose' => 'init_password'])
0 ignored issues
show
Bug introduced by
The method findOneBy does only exist in Doctrine\ORM\EntityRepository, 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...
84
            ->shouldBeCalledTimes(1)
85
            ->willReturn($token);
86
87
        $this->repository()->get('unique', 'init_password');
88
    }
89
90
    /**
91
     * @test
92
     */
93
    public function it_get_valid_token()
94
    {
95
        $token = new Token('string', 'jdoe','unique', 'init_password',  '+1 day', []);
96
97
        $this->repository->findOneBy(['value' => 'unique', 'purpose' => 'init_password'])
0 ignored issues
show
Bug introduced by
The method findOneBy does only exist in Doctrine\ORM\EntityRepository, 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($token);
100
101
        $got = $this->repository()->get('unique', 'init_password');
102
103
        self::assertSame($token, $got);
104
    }
105
106
    /**
107
     * @test
108
     */
109 View Code Duplication
    public function it_create_token()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
    {
111
        $token = new Token('string', 'jdoe','unique', 'init_password',  '+1 day', []);
112
113
        $this->manager->persist($token)
0 ignored issues
show
Bug introduced by
The method persist does only exist in Doctrine\ORM\EntityManager, 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...
114
            ->shouldBeCalledTimes(1);
115
        $this->manager->flush($token)
0 ignored issues
show
Bug introduced by
The method flush does only exist in Doctrine\ORM\EntityManager, 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...
116
            ->shouldBeCalledTimes(1);
117
118
        $this->repository()->create($token);
119
    }
120
121
    /**
122
     * @test
123
     */
124 View Code Duplication
    public function it_update_token()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
125
    {
126
        $token = new Token('string', 'jdoe','unique', 'init_password',  '+1 day', []);
127
128
        $this->manager->persist($token)
0 ignored issues
show
Bug introduced by
The method persist does only exist in Doctrine\ORM\EntityManager, 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...
129
            ->shouldBeCalledTimes(1);
130
        $this->manager->flush($token)
0 ignored issues
show
Bug introduced by
The method flush does only exist in Doctrine\ORM\EntityManager, 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...
131
            ->shouldBeCalledTimes(1);
132
133
        $this->repository()->update($token);
134
    }
135
}
136