RememberMeServiceTest   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 176
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 5
dl 0
loc 176
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 15 1
A testCreateNew() 0 19 1
A testCreateNewWithValidity() 0 20 1
A testRemoveSerie() 0 11 1
A testGetNextSerieWhenRefreshDisabled() 0 14 1
A testGetNextSerie() 0 12 1
A testSerieExpired() 0 9 1
A testNoSerieFound() 0 9 1
A testSerieWithInvalidTokenResets() 0 14 1
A testNoLongerValidTokenResets() 0 10 1
A assumeSerie() 0 7 1
1
<?php
2
3
namespace JwPersistentUserTest\Service;
4
5
use JwPersistentUser\Test\TestCase;
6
use JwPersistentUser\Model\SerieToken;
7
use JwPersistentUser\Model\ModuleOptions;
8
use JwPersistentUser\Service\RememberMeService;
9
use JwPersistentUser\Mapper\SerieTokenMapperInterface;
10
use JwPersistentUser\Service\UserValidityInterface;
11
12
class RememberMeServiceTest extends TestCase
13
{
14
    /**
15
     * @var RememberMeService
16
     */
17
    protected $service;
18
19
    /**
20
     * @var SerieTokenMapperInterface|\PHPUnit_Framework_MockObject_MockObject
21
     */
22
    protected $mapper;
23
24
    /**
25
     * @var ModuleOptions|\PHPUnit_Framework_MockObject_MockObject
26
     */
27
    protected $options;
28
29
    /**
30
     * @var UserValidityInterface|\PHPUnit_Framework_MockObject_MockObject
31
     */
32
    protected $userValidityInterface;
33
34
    public function setUp()
35
    {
36
        parent::setUp();
37
38
        $this->service = new RememberMeService;
39
40
        $this->mapper = $this->getMock('JwPersistentUser\Mapper\SerieTokenMapperInterface');
41
        $this->service->setMapper($this->mapper);
42
43
        $this->userValidityInterface = $this->getMock(UserValidityInterface::class);
44
        $this->service->setUserValidityInterface($this->userValidityInterface);
45
46
        $this->service->setModuleOptions($this->options = new ModuleOptions);
47
        $this->options->setSerieTokenEntityClass('JwPersistentUser\Model\SerieToken');
48
    }
49
50
    public function testCreateNew()
51
    {
52
        $this->mapper->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in JwPersistentUser\Mapper\SerieTokenMapperInterface.

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...
53
            ->method('persist');
54
55
        $this
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in JwPersistentUser\Service\UserValidityInterface.

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...
56
            ->userValidityInterface
57
            ->expects($this->any())
58
            ->method('getValidUntilForUser')
59
            ->with(3)
60
            ->willReturn(null);
61
62
        $response = $this->service->createNew(3);
63
64
        $this->assertEquals(3, $response->getUserId());
65
        $this->assertEquals(10, strlen($response->getSerie()));
66
        $this->assertEquals(10, strlen($response->getToken()));
67
        $this->assertNull($response->getValidUntil());
68
    }
69
70
    public function testCreateNewWithValidity()
71
    {
72
        $this->mapper->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in JwPersistentUser\Mapper\SerieTokenMapperInterface.

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...
73
            ->method('persist');
74
75
        $validUntil = new \DateTime('tomorrow');
76
        $this
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in JwPersistentUser\Service\UserValidityInterface.

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...
77
            ->userValidityInterface
78
            ->expects($this->any())
79
            ->method('getValidUntilForUser')
80
            ->with(3)
81
            ->willReturn($validUntil);
82
83
        $response = $this->service->createNew(3);
84
85
        $this->assertEquals(3, $response->getUserId());
86
        $this->assertEquals(10, strlen($response->getSerie()));
87
        $this->assertEquals(10, strlen($response->getToken()));
88
        $this->assertEquals($validUntil, $response->getValidUntil());
89
    }
90
91
    public function testRemoveSerie()
92
    {
93
        $this->assumeSerie($serie = new SerieToken(3, 'abc', 'def'));
94
        $serie->setExpiresAt(new \DateTime('tomorrow'));
95
96
        $this->mapper->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in JwPersistentUser\Mapper\SerieTokenMapperInterface.

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
            ->method('remove')
98
            ->with($serie);
99
100
        $this->service->removeSerie(3, 'abc');
101
    }
102
103
    public function testGetNextSerieWhenRefreshDisabled()
104
    {
105
        $this->options->setTokenRefreshedAfterLogin(false);
0 ignored issues
show
Bug introduced by
The method setTokenRefreshedAfterLogin does only exist in JwPersistentUser\Model\ModuleOptions, but not in PHPUnit_Framework_MockObject_MockObject.

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...
106
107
        $this->assumeSerie($serie = new SerieToken(3, 'abc', 'def'));
108
        $serie->setExpiresAt(new \DateTime('tomorrow'));
109
110
        $nextSerie = $this->service->getNextInSerie($serie);
111
112
        $this->assertSame($serie, $nextSerie);
113
        $this->assertEquals('def', $serie->getToken());
114
115
        $this->assertDateTimeEquals(new \DateTime('+1 year'), $serie->getExpiresAt());
116
    }
117
118
    public function testGetNextSerie()
119
    {
120
        $this->assumeSerie($serie = new SerieToken(3, 'abc', 'def'));
121
        $serie->setExpiresAt(new \DateTime('tomorrow'));
122
123
        $nextSerie = $this->service->getNextInSerie($serie);
124
125
        $this->assertSame($serie, $nextSerie);
126
        $this->assertNotEquals('def', $serie->getToken());
127
128
        $this->assertDateTimeEquals(new \DateTime('+1 year'), $serie->getExpiresAt());
129
    }
130
131
    public function testSerieExpired()
132
    {
133
        $this->assumeSerie($serie = new SerieToken(3, 'abc', 'def'));
134
        $serie->setExpiresAt(new \DateTime('yesterday'));
135
136
        $nextSerie = $this->service->getNextInSerie($serie);
137
138
        $this->assertNull($nextSerie);
139
    }
140
141
    public function testNoSerieFound()
142
    {
143
        $serie = new SerieToken(3, 'abc', 'def');
144
        $serie->setExpiresAt(new \DateTime('tomorrow'));
145
146
        $nextSerie = $this->service->getNextInSerie($serie);
147
148
        $this->assertNull($nextSerie);
149
    }
150
151
    public function testSerieWithInvalidTokenResets()
152
    {
153
        $this->assumeSerie($correctSerie = new SerieToken(3, 'abc', 'def'));
154
        $correctSerie->setExpiresAt(new \DateTime('tomorrow'));
155
        $falseSerie = new SerieToken(3, 'abc', 'gdaf');
156
157
        $this->mapper->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in JwPersistentUser\Mapper\SerieTokenMapperInterface.

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...
158
            ->method('remove')
159
            ->with($correctSerie);
160
161
        $nextSerie = $this->service->getNextInSerie($falseSerie);
162
163
        $this->assertNull($nextSerie);
164
    }
165
166
    public function testNoLongerValidTokenResets()
167
    {
168
        $this->assumeSerie($serie = new SerieToken(3, 'abc', 'def'));
169
        $serie->setExpiresAt(new \DateTime('tomorrow'));
170
        $serie->setValidUntil(new \DateTime('yesterday'));
171
172
        $nextSerie = $this->service->getNextInSerie($serie);
173
174
        $this->assertNull($nextSerie);
175
    }
176
177
    /**
178
     * @param SerieToken $serie
179
     */
180
    protected function assumeSerie(SerieToken $serie)
181
    {
182
        $this->mapper->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in JwPersistentUser\Mapper\SerieTokenMapperInterface.

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...
183
            ->method('find')
184
            ->with($serie->getUserId(), $serie->getSerie())
185
            ->will($this->returnValue($serie));
186
    }
187
}
188