GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AuthSuccessActionTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 124
Duplicated Lines 40.32 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 7 7 1
A testExecute() 0 30 1
A testExecuteWithCaughtEvent() 0 29 1
A testExecuteNoAuth() 20 20 1
A testExecuteNoSession() 23 23 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
/*
4
 * (c) Christian Gripp <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Core23\FacebookBundle\Tests\Action;
11
12
use Core23\FacebookBundle\Action\AuthSuccessAction;
13
use Core23\FacebookBundle\Session\SessionInterface;
14
use Core23\FacebookBundle\Session\SessionManagerInterface;
15
use Core23\FacebookBundle\Tests\EventDispatcher\TestEventDispatcher;
16
use PHPUnit\Framework\TestCase;
17
use Symfony\Component\HttpFoundation\RedirectResponse;
18
use Symfony\Component\HttpFoundation\Response;
19
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
20
use Symfony\Component\Routing\RouterInterface;
21
use Twig\Environment;
22
23
final class AuthSuccessActionTest extends TestCase
24
{
25
    private $twig;
26
27
    private $router;
28
29
    private $sessionManager;
30
31
    private $eventDispatcher;
32
33 View Code Duplication
    protected function setUp(): void
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...
34
    {
35
        $this->twig            = $this->prophesize(Environment::class);
36
        $this->router          = $this->prophesize(RouterInterface::class);
37
        $this->sessionManager  = $this->prophesize(SessionManagerInterface::class);
38
        $this->eventDispatcher = new TestEventDispatcher();
39
    }
40
41
    public function testExecute(): void
42
    {
43
        $session = $this->prophesize(SessionInterface::class);
44
45
        $this->sessionManager->isAuthenticated()
46
            ->willReturn(true)
47
        ;
48
        $this->sessionManager->getSession()
49
            ->willReturn($session)
50
        ;
51
        $this->sessionManager->getUsername()
52
            ->willReturn('FooUser')
53
        ;
54
55
        $this->twig->render('@Core23Facebook/Auth/success.html.twig', [
56
            'name' => 'FooUser',
57
        ])->shouldBeCalled();
58
59
        $action = new AuthSuccessAction(
60
            $this->twig->reveal(),
61
            $this->router->reveal(),
62
            $this->sessionManager->reveal(),
63
            $this->eventDispatcher
64
        );
65
66
        $response = $action();
67
68
        static::assertNotInstanceOf(RedirectResponse::class, $response);
69
        static::assertSame(200, $response->getStatusCode());
70
    }
71
72
    public function testExecuteWithCaughtEvent(): void
73
    {
74
        $session = $this->prophesize(SessionInterface::class);
75
76
        $this->sessionManager->isAuthenticated()
77
            ->willReturn(true)
78
        ;
79
        $this->sessionManager->getSession()
80
            ->willReturn($session)
81
        ;
82
        $this->sessionManager->getUsername()
83
            ->willReturn('FooUser')
84
        ;
85
86
        $eventResponse = new Response();
87
88
        $this->eventDispatcher->setResponse($eventResponse);
89
90
        $action = new AuthSuccessAction(
91
            $this->twig->reveal(),
92
            $this->router->reveal(),
93
            $this->sessionManager->reveal(),
94
            $this->eventDispatcher
95
        );
96
97
        $response = $action();
98
99
        static::assertSame($eventResponse, $response);
100
    }
101
102 View Code Duplication
    public function testExecuteNoAuth(): void
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...
103
    {
104
        $this->sessionManager->isAuthenticated()
105
            ->willReturn(false)
106
        ;
107
108
        $this->router->generate('core23_facebook_error', [], UrlGeneratorInterface::ABSOLUTE_PATH)
109
            ->willReturn('/success')
110
            ->shouldBeCalled()
111
        ;
112
113
        $action = new AuthSuccessAction(
114
            $this->twig->reveal(),
115
            $this->router->reveal(),
116
            $this->sessionManager->reveal(),
117
            $this->eventDispatcher
118
        );
119
120
        static::assertInstanceOf(RedirectResponse::class, $action());
121
    }
122
123 View Code Duplication
    public function testExecuteNoSession(): void
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...
124
    {
125
        $this->sessionManager->isAuthenticated()
126
            ->willReturn(true)
127
        ;
128
        $this->sessionManager->getSession()
129
            ->willReturn(null)
130
        ;
131
132
        $this->router->generate('core23_facebook_error', [], UrlGeneratorInterface::ABSOLUTE_PATH)
133
            ->willReturn('/success')
134
            ->shouldBeCalled()
135
        ;
136
137
        $action = new AuthSuccessAction(
138
            $this->twig->reveal(),
139
            $this->router->reveal(),
140
            $this->sessionManager->reveal(),
141
            $this->eventDispatcher
142
        );
143
144
        static::assertInstanceOf(RedirectResponse::class, $action());
145
    }
146
}
147