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.
Completed
Push — master ( debb42...5fbcdf )
by Christian
01:32
created

AuthSuccessActionTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 98
Duplicated Lines 51.02 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 7 7 1
A testExecute() 0 34 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\Core23FacebookEvents;
14
use Core23\FacebookBundle\Event\AuthSuccessEvent;
15
use Core23\FacebookBundle\Session\SessionInterface;
16
use Core23\FacebookBundle\Session\SessionManagerInterface;
17
use PHPUnit\Framework\TestCase;
18
use Prophecy\Argument;
19
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
20
use Symfony\Component\HttpFoundation\RedirectResponse;
21
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
22
use Symfony\Component\Routing\RouterInterface;
23
use Twig\Environment;
24
25
class AuthSuccessActionTest extends TestCase
26
{
27
    private $twig;
28
29
    private $router;
30
31
    private $sessionManager;
32
33
    private $eventDispatcher;
34
35 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...
36
    {
37
        $this->twig            = $this->prophesize(Environment::class);
38
        $this->router          = $this->prophesize(RouterInterface::class);
39
        $this->sessionManager  = $this->prophesize(SessionManagerInterface::class);
40
        $this->eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
41
    }
42
43
    public function testExecute(): void
44
    {
45
        $session = $this->prophesize(SessionInterface::class);
46
47
        $this->sessionManager->isAuthenticated()
48
            ->willReturn(true)
49
        ;
50
        $this->sessionManager->getSession()
51
            ->willReturn($session)
52
        ;
53
        $this->sessionManager->getUsername()
54
            ->willReturn('FooUser')
55
        ;
56
57
        $this->eventDispatcher->dispatch(Core23FacebookEvents::AUTH_SUCCESS, Argument::type(AuthSuccessEvent::class))
58
            ->shouldBeCalled()
59
        ;
60
61
        $this->twig->render('@Core23Facebook/Auth/success.html.twig', [
62
            'name' => 'FooUser',
63
        ])->shouldBeCalled();
64
65
        $action = new AuthSuccessAction(
66
            $this->twig->reveal(),
67
            $this->router->reveal(),
68
            $this->sessionManager->reveal(),
69
            $this->eventDispatcher->reveal()
70
        );
71
72
        $response = $action();
73
74
        $this->assertNotInstanceOf(RedirectResponse::class, $response);
75
        $this->assertSame(200, $response->getStatusCode());
76
    }
77
78 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...
79
    {
80
        $this->sessionManager->isAuthenticated()
81
            ->willReturn(false)
82
        ;
83
84
        $this->router->generate('core23_facebook_error', [], UrlGeneratorInterface::ABSOLUTE_PATH)
85
            ->willReturn('/success')
86
            ->shouldBeCalled()
87
        ;
88
89
        $action = new AuthSuccessAction(
90
            $this->twig->reveal(),
91
            $this->router->reveal(),
92
            $this->sessionManager->reveal(),
93
            $this->eventDispatcher->reveal()
94
        );
95
96
        $this->assertInstanceOf(RedirectResponse::class, $action());
97
    }
98
99 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...
100
    {
101
        $this->sessionManager->isAuthenticated()
102
            ->willReturn(true)
103
        ;
104
        $this->sessionManager->getSession()
105
            ->willReturn(null)
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->reveal()
118
        );
119
120
        $this->assertInstanceOf(RedirectResponse::class, $action());
121
    }
122
}
123