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.

AuthErrorActionTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 88
Duplicated Lines 30.68 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 7 7 1
A testExecute() 0 22 1
A testExecuteWithCaughtEvent() 0 25 1
A testExecuteWithNoAuth() 20 20 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\LastFmBundle\Tests\Action;
11
12
use Core23\LastFmBundle\Action\AuthErrorAction;
13
use Core23\LastFmBundle\Session\SessionManagerInterface;
14
use Core23\LastFmBundle\Tests\EventDispatcher\TestEventDispatcher;
15
use PHPUnit\Framework\TestCase;
16
use Symfony\Component\HttpFoundation\RedirectResponse;
17
use Symfony\Component\HttpFoundation\Response;
18
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
19
use Symfony\Component\Routing\RouterInterface;
20
use Twig\Environment;
21
22
final class AuthErrorActionTest extends TestCase
23
{
24
    private $twig;
25
26
    private $router;
27
28
    private $sessionManager;
29
30
    private $eventDispatcher;
31
32 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...
33
    {
34
        $this->twig            = $this->prophesize(Environment::class);
35
        $this->router          = $this->prophesize(RouterInterface::class);
36
        $this->sessionManager  = $this->prophesize(SessionManagerInterface::class);
37
        $this->eventDispatcher = new TestEventDispatcher();
38
    }
39
40
    public function testExecute(): void
41
    {
42
        $this->sessionManager->isAuthenticated()
43
            ->willReturn(false)
44
        ;
45
46
        $this->sessionManager->clear()
47
            ->shouldBeCalled()
48
        ;
49
50
        $action = new AuthErrorAction(
51
            $this->twig->reveal(),
52
            $this->router->reveal(),
53
            $this->sessionManager->reveal(),
54
            $this->eventDispatcher
55
        );
56
57
        $response = $action();
58
59
        static::assertNotInstanceOf(RedirectResponse::class, $response);
60
        static::assertSame(200, $response->getStatusCode());
61
    }
62
63
    public function testExecuteWithCaughtEvent(): void
64
    {
65
        $this->sessionManager->isAuthenticated()
66
            ->willReturn(false)
67
        ;
68
69
        $this->sessionManager->clear()
70
            ->shouldBeCalled()
71
        ;
72
73
        $eventResponse = new Response();
74
75
        $this->eventDispatcher->setResponse($eventResponse);
76
77
        $action = new AuthErrorAction(
78
            $this->twig->reveal(),
79
            $this->router->reveal(),
80
            $this->sessionManager->reveal(),
81
            $this->eventDispatcher
82
        );
83
84
        $response = $action();
85
86
        static::assertSame($eventResponse, $response);
87
    }
88
89 View Code Duplication
    public function testExecuteWithNoAuth(): 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...
90
    {
91
        $this->sessionManager->isAuthenticated()
92
            ->willReturn(true)
93
        ;
94
95
        $this->router->generate('core23_lastfm_success', [], UrlGeneratorInterface::ABSOLUTE_PATH)
96
            ->willReturn('/success')
97
            ->shouldBeCalled()
98
        ;
99
100
        $action = new AuthErrorAction(
101
            $this->twig->reveal(),
102
            $this->router->reveal(),
103
            $this->sessionManager->reveal(),
104
            $this->eventDispatcher
105
        );
106
107
        static::assertInstanceOf(RedirectResponse::class, $action());
108
    }
109
}
110