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 ( f0acc7...5428b1 )
by Christian
07:08
created

testExecuteWithCaughtEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 9.392
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\LastFm\Session\SessionInterface;
13
use Core23\LastFmBundle\Action\AuthSuccessAction;
14
use Core23\LastFmBundle\Core23LastFmEvents;
15
use Core23\LastFmBundle\Event\AuthSuccessEvent;
16
use Core23\LastFmBundle\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\HttpFoundation\Response;
22
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
23
use Symfony\Component\Routing\RouterInterface;
24
use Twig\Environment;
25
26
class AuthSuccessActionTest extends TestCase
27
{
28
    private $twig;
29
30
    private $router;
31
32
    private $sessionManager;
33
34
    private $eventDispatcher;
35
36 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...
37
    {
38
        $this->twig            = $this->prophesize(Environment::class);
39
        $this->router          = $this->prophesize(RouterInterface::class);
40
        $this->sessionManager  = $this->prophesize(SessionManagerInterface::class);
41
        $this->eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
42
    }
43
44
    public function testExecute(): void
45
    {
46
        $session = $this->prophesize(SessionInterface::class);
47
48
        $this->sessionManager->isAuthenticated()
49
            ->willReturn(true)
50
        ;
51
        $this->sessionManager->getSession()
52
            ->willReturn($session)
53
        ;
54
        $this->sessionManager->getUsername()
55
            ->willReturn('FooUser')
56
        ;
57
58
        $this->eventDispatcher->dispatch(Core23LastFmEvents::AUTH_SUCCESS, Argument::type(AuthSuccessEvent::class))
59
            ->shouldBeCalled()
60
        ;
61
62
        $this->twig->render('@Core23LastFm/Auth/success.html.twig', [
63
            'name' => 'FooUser',
64
        ])->shouldBeCalled();
65
66
        $action = new AuthSuccessAction(
67
            $this->twig->reveal(),
68
            $this->router->reveal(),
69
            $this->sessionManager->reveal(),
70
            $this->eventDispatcher->reveal()
71
        );
72
73
        $response = $action();
74
75
        $this->assertNotInstanceOf(RedirectResponse::class, $response);
76
        $this->assertSame(200, $response->getStatusCode());
77
    }
78
79
    public function testExecuteWithCaughtEvent(): void
80
    {
81
        $session = $this->prophesize(SessionInterface::class);
82
83
        $this->sessionManager->isAuthenticated()
84
            ->willReturn(true)
85
        ;
86
        $this->sessionManager->getSession()
87
            ->willReturn($session)
88
        ;
89
        $this->sessionManager->getUsername()
90
            ->willReturn('FooUser')
91
        ;
92
93
        $eventResponse = new Response();
94
95
        $this->eventDispatcher->dispatch(Core23LastFmEvents::AUTH_SUCCESS, Argument::type(AuthSuccessEvent::class))
96
            ->will(function ($args) use ($eventResponse) {
97
                $args[1]->setResponse($eventResponse);
98
            })
99
        ;
100
101
        $action = new AuthSuccessAction(
102
            $this->twig->reveal(),
103
            $this->router->reveal(),
104
            $this->sessionManager->reveal(),
105
            $this->eventDispatcher->reveal()
106
        );
107
108
        $response = $action();
109
110
        $this->assertSame($eventResponse, $response);
111
    }
112
113 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...
114
    {
115
        $this->sessionManager->isAuthenticated()
116
            ->willReturn(false)
117
        ;
118
119
        $this->router->generate('core23_lastfm_error', [], UrlGeneratorInterface::ABSOLUTE_PATH)
120
            ->willReturn('/success')
121
            ->shouldBeCalled()
122
        ;
123
124
        $action = new AuthSuccessAction(
125
            $this->twig->reveal(),
126
            $this->router->reveal(),
127
            $this->sessionManager->reveal(),
128
            $this->eventDispatcher->reveal()
129
        );
130
131
        $this->assertInstanceOf(RedirectResponse::class, $action());
132
    }
133
134 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...
135
    {
136
        $this->sessionManager->isAuthenticated()
137
            ->willReturn(true)
138
        ;
139
        $this->sessionManager->getSession()
140
            ->willReturn(null)
141
        ;
142
143
        $this->router->generate('core23_lastfm_error', [], UrlGeneratorInterface::ABSOLUTE_PATH)
144
            ->willReturn('/success')
145
            ->shouldBeCalled()
146
        ;
147
148
        $action = new AuthSuccessAction(
149
            $this->twig->reveal(),
150
            $this->router->reveal(),
151
            $this->sessionManager->reveal(),
152
            $this->eventDispatcher->reveal()
153
        );
154
155
        $this->assertInstanceOf(RedirectResponse::class, $action());
156
    }
157
}
158