Completed
Pull Request — master (#11)
by Eugene
45:13
created

AzineHybridAuthTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 44.07 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 26
loc 59
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 26 1
A testIsExpiredSession() 13 13 1
A testIsNotExpiredSession() 13 13 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Azine\HybridAuthBundle\Tests\Services;
4
5
use Azine\HybridAuthBundle\Entity\HybridAuthSessionData;
6
use Azine\HybridAuthBundle\Services\AzineHybridAuth;
7
use Azine\HybridAuthBundle\Tests\AzineTestCase;
8
9
class AzineHybridAuthTest extends AzineTestCase
10
{
11
    private $azineHybridAuth;
12
13
    protected function setUp()
14
    {
15
        $router = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Routing\Router')
16
            ->disableOriginalConstructor()
17
            ->getMock();
18
19
        $entityManager = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')
20
            ->disableOriginalConstructor()
21
            ->getMock();
22
23
        $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')
24
            ->disableOriginalConstructor()
25
            ->getMock();
26
27
        $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken')
28
            ->disableOriginalConstructor()
29
            ->getMock();
30
31
        $tokenStorage->expects($this->any())
32
            ->method('getToken')
33
            ->will($this->returnValue($token));
34
35
        $config = array('endpoint_route' => 'route', 'providers' => 'providers', 'debug_mode' => 'debug_mode', 'debug_file' => 'debug_file');
36
        $this->azineHybridAuth = new AzineHybridAuth($router, $tokenStorage, $entityManager,
37
            $config, false, true, 55);
38
    }
39
40 View Code Duplication
    public function testIsExpiredSession()
41
    {
42
        $sessionData = new HybridAuthSessionData();
43
        $sessionData->setUsername('dominik');
44
45
        $expirationDate = new \DateTime();
46
        $expirationDate->modify('- 1 day');
47
48
        $sessionData->setExpiresAt($expirationDate);
49
        $isExpired = $this->azineHybridAuth->isExpiredSession($sessionData);
50
51
        $this->assertTrue($isExpired);
52
    }
53
54 View Code Duplication
    public function testIsNotExpiredSession()
55
    {
56
        $sessionData = new HybridAuthSessionData();
57
        $sessionData->setUsername('dominik');
58
59
        $expirationDate = new \DateTime();
60
        $expirationDate->modify('+ 1 day');
61
62
        $sessionData->setExpiresAt($expirationDate);
63
        $isExpired = $this->azineHybridAuth->isExpiredSession($sessionData);
64
65
        $this->assertFalse($isExpired);
66
    }
67
}
68