Passed
Push — master ( 40feff...710ff4 )
by Michael
01:41
created

DefaultControllerTest   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 527
Duplicated Lines 11.76 %

Importance

Changes 2
Bugs 2 Features 0
Metric Value
wmc 25
c 2
b 2
f 0
dl 62
loc 527
rs 10

25 Methods

Rating   Name   Duplication   Size   Complexity  
B testReadTextnodeActionForValidTextnode() 0 38 1
A createRouterMock() 0 8 1
A testBackActionSuccess() 0 23 1
A createReadpathMock() 0 3 1
A createTextnodeRepositoryMock() 0 3 1
A createTokenStorageMock() 0 3 1
A testReadTextnodeActionForInvalidId() 13 13 1
A testBackActionUnsuccessfulForGuestUser() 0 18 1
A createTemplatingMock() 0 3 1
A testReadTopicActionForInvalidTopicId() 13 13 1
A testImprintAction() 0 8 1
A createAuthorizationCheckerMock() 0 3 1
B testReadTopicActionForValidTopicIdAndGuestUser() 0 28 1
A createReadpathUndoServiceMock() 0 3 1
A createFeatureToggleMock() 0 3 1
B testReadTopicActionForValidTopicIdAndLoggedInUser() 0 40 1
B setUp() 0 24 1
A testReadTopicActionWithLoggedOutUserAndEnabledLoginFeature() 16 16 1
A createFavoriteManagerMock() 0 3 1
A createUserRepositoryMock() 0 3 1
A testReadTopicActionForValidTopicIdAndGuestUserForAFinanceNode() 0 23 1
A testReadTextnodeActionForFinanceNode() 0 17 1
B testBackActionUnsuccessfulForLoggedInUser() 0 29 1
A testReadTextnodeActionWithGuestUserAndEnabledLoginFeature() 16 16 1
A createTokenMock() 0 3 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
declare(strict_types = 1);
4
5
/* Copyright (C) 2015-2017 Michael Giesler, Stephan Kreutzer
6
 *
7
 * This file is part of Dembelo.
8
 *
9
 * Dembelo is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as published by
11
 * the Free Software Foundation, either version 3 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * Dembelo is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
 * GNU Affero General Public License 3 for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License 3
20
 * along with Dembelo. If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
24
/**
25
 * @package DembeloMain
26
 */
27
28
namespace DembeloMain\Tests\Controller;
29
30
use DembeloMain\Document\Textnode;
31
use DembeloMain\Document\User;
32
use DembeloMain\Model\FavoriteManager;
33
use DembeloMain\Model\FeatureToggle;
34
use DembeloMain\Model\Readpath;
35
use DembeloMain\Model\Repository\TextNodeRepositoryInterface;
36
use DembeloMain\Model\Repository\UserRepositoryInterface;
37
use DembeloMain\Service\ReadpathUndoService;
38
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
39
use DembeloMain\Controller\DefaultController;
40
use Symfony\Bundle\FrameworkBundle\Routing\Router;
41
use Symfony\Component\HttpFoundation\RedirectResponse;
42
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
43
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface as Templating;
44
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
45
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
46
47
/**
48
 * Class DefaultControllerTest
49
 */
50
class DefaultControllerTest extends WebTestCase
51
{
52
    /**
53
     * @var DefaultController
54
     */
55
    private $controller;
56
57
    /**
58
     * @var FeatureToggle|\PHPUnit_Framework_MockObject_MockObject
59
     */
60
    private $featureToggleMock;
61
62
    /**
63
     * @var AuthorizationCheckerInterface|\PHPUnit_Framework_MockObject_MockObject
64
     */
65
    private $authorizationCheckerMock;
66
67
    /**
68
     * @var UserRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
69
     */
70
    private $userRepositoryMock;
71
72
    /**
73
     * @var TextNodeRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
74
     */
75
    private $textnodeRepositoryMock;
76
77
    /**
78
     * @var Templating|\PHPUnit_Framework_MockObject_MockObject
79
     */
80
    private $templatingMock;
81
82
    /**
83
     * @var Router|\PHPUnit_Framework_MockObject_MockObject
84
     */
85
    private $routerMock;
86
87
    /**
88
     * @var TokenStorage|\PHPUnit_Framework_MockObject_MockObject
89
     */
90
    private $tokenStorageMock;
91
92
    /**
93
     * @var ReadPath|\PHPUnit_Framework_MockObject_MockObject
94
     */
95
    private $readpathMock;
96
97
    /**
98
     * @var FavoriteManager|\PHPUnit_Framework_MockObject_MockObject
99
     */
100
    private $favoriteManagerMock;
101
102
    /**
103
     * @var ReadpathUndoService|\PHPUnit_Framework_MockObject_MockObject
104
     */
105
    private $readpathUndoServiceMock;
106
107
    /**
108
     * @inheritdoc
109
     */
110
    public function setUp(): void
111
    {
112
        $this->featureToggleMock = $this->createFeatureToggleMock();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createFeatureToggleMock() of type DembeloMain\Model\FeatureToggle is incompatible with the declared type DembeloMain\Model\Featur...k_MockObject_MockObject of property $featureToggleMock.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
113
        $this->authorizationCheckerMock = $this->createAuthorizationCheckerMock();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createAuthorizationCheckerMock() of type Symfony\Component\Securi...izationCheckerInterface is incompatible with the declared type Symfony\Component\Securi...k_MockObject_MockObject of property $authorizationCheckerMock.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
114
        $this->userRepositoryMock = $this->createUserRepositoryMock();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createUserRepositoryMock() of type DembeloMain\Model\Reposi...UserRepositoryInterface is incompatible with the declared type DembeloMain\Model\Reposi...k_MockObject_MockObject of property $userRepositoryMock.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
115
        $this->textnodeRepositoryMock = $this->createTextnodeRepositoryMock();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createTextnodeRepositoryMock() of type DembeloMain\Model\Reposi...NodeRepositoryInterface is incompatible with the declared type DembeloMain\Model\Reposi...k_MockObject_MockObject of property $textnodeRepositoryMock.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
116
        $this->templatingMock = $this->createTemplatingMock();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createTemplatingMock() of type Symfony\Bundle\Framework...plating\EngineInterface is incompatible with the declared type Symfony\Bundle\Framework...k_MockObject_MockObject of property $templatingMock.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
117
        $this->routerMock = $this->createRouterMock();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createRouterMock() of type Symfony\Bundle\FrameworkBundle\Routing\Router is incompatible with the declared type PHPUnit_Framework_MockOb...rkBundle\Routing\Router of property $routerMock.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
118
        $this->tokenStorageMock = $this->createTokenStorageMock();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createTokenStorageMock() of type Symfony\Component\Securi...en\Storage\TokenStorage is incompatible with the declared type Symfony\Component\Securi...k_MockObject_MockObject of property $tokenStorageMock.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
119
        $this->readpathMock = $this->createReadpathMock();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createReadpathMock() of type DembeloMain\Model\Readpath is incompatible with the declared type DembeloMain\Model\Readpa...k_MockObject_MockObject of property $readpathMock.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
120
        $this->favoriteManagerMock = $this->createFavoriteManagerMock();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createFavoriteManagerMock() of type DembeloMain\Model\FavoriteManager is incompatible with the declared type DembeloMain\Model\Favori...k_MockObject_MockObject of property $favoriteManagerMock.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
121
        $this->readpathUndoServiceMock = $this->createReadpathUndoServiceMock();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createReadpathUndoServiceMock() of type DembeloMain\Service\ReadpathUndoService is incompatible with the declared type DembeloMain\Service\Read...k_MockObject_MockObject of property $readpathUndoServiceMock.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
122
123
        $this->controller = new DefaultController(
124
            $this->featureToggleMock,
125
            $this->authorizationCheckerMock,
126
            $this->userRepositoryMock,
127
            $this->textnodeRepositoryMock,
128
            $this->templatingMock,
129
            $this->routerMock,
130
            $this->tokenStorageMock,
131
            $this->readpathMock,
132
            $this->favoriteManagerMock,
133
            $this->readpathUndoServiceMock
134
        );
135
    }
136
137
    /**
138
     * tests readTopicAction with guest user and enabled login feature
139
     * Tests the index action.
140
     */
141 View Code Duplication
    public function testReadTopicActionWithLoggedOutUserAndEnabledLoginFeature(): 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...
142
    {
143
        $topicId = 'someTopicId';
144
145
        $this->featureToggleMock->expects(self::once())
146
            ->method('hasFeature')
147
            ->willReturn(true);
148
        $this->authorizationCheckerMock->expects(self::any())
149
            ->method('isGranted')
150
            ->willReturn(false);
151
        $this->routerMock->expects(self::once())
152
            ->method('generate')
153
            ->with('login_route', []);
0 ignored issues
show
Bug introduced by
'login_route' of type string is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

153
            ->with(/** @scrutinizer ignore-type */ 'login_route', []);
Loading history...
154
155
        $result = $this->controller->readTopicAction($topicId);
156
        self::assertInstanceOf(RedirectResponse::class, $result);
157
    }
158
159
    /**
160
     * tests readTOpicAction for invalid topic id
161
     * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
162
     */
163 View Code Duplication
    public function testReadTopicActionForInvalidTopicId(): 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...
164
    {
165
        $topicId = 'someTopicId';
166
167
        $this->featureToggleMock->expects(self::once())
168
            ->method('hasFeature')
169
            ->willReturn(false);
170
        $this->textnodeRepositoryMock->expects(self::once())
171
            ->method('getTextnodeToRead')
172
            ->with($topicId)
0 ignored issues
show
Bug introduced by
$topicId of type string is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

172
            ->with(/** @scrutinizer ignore-type */ $topicId)
Loading history...
173
            ->willReturn(null);
174
175
        $this->controller->readTopicAction($topicId);
176
    }
177
178
    /**
179
     * test readtopicAction for valid topic and guest user
180
     */
181
    public function testReadTopicActionForValidTopicIdAndGuestUser(): void
182
    {
183
        $topicId = 'someTopicId';
184
185
        $textnode = new Textnode();
186
        $textnode->setArbitraryId('someArbitraryId');
187
        $textnode->appendHitch([
188
            'textnodeId' => '1',
189
            'description' => 2,
190
            'status' => Textnode::HITCH_STATUS_ACTIVE,
191
        ]);
192
193
        $this->featureToggleMock->expects(self::once())
194
            ->method('hasFeature')
195
            ->willReturn(false);
196
        $this->textnodeRepositoryMock->expects(self::once())
197
            ->method('getTextnodeToRead')
198
            ->with($topicId)
0 ignored issues
show
Bug introduced by
$topicId of type string is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

198
            ->with(/** @scrutinizer ignore-type */ $topicId)
Loading history...
199
            ->willReturn($textnode);
200
        $this->tokenStorageMock->expects(self::once())
201
            ->method('getToken')
202
            ->willReturn(null);
203
        $this->routerMock->expects(self::once())
204
            ->method('generate')
205
            ->with('text', ['textnodeArbitraryId' => 'someArbitraryId']);
206
207
        $result = $this->controller->readTopicAction($topicId);
208
        self::assertInstanceOf(RedirectResponse::class, $result);
209
    }
210
211
    /**
212
     * tests readTopicACtion for valid topic id and guest user for a finance node
213
     */
214
    public function testReadTopicActionForValidTopicIdAndGuestUserForAFinanceNode(): void
215
    {
216
        $topicId = 'someTopicId';
217
218
        $textnode = new Textnode();
219
        $textnode->setArbitraryId('someArbitraryId');
220
221
        $this->featureToggleMock->expects(self::once())
222
            ->method('hasFeature')
223
            ->willReturn(false);
224
        $this->textnodeRepositoryMock->expects(self::once())
225
            ->method('getTextnodeToRead')
226
            ->with($topicId)
0 ignored issues
show
Bug introduced by
$topicId of type string is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

226
            ->with(/** @scrutinizer ignore-type */ $topicId)
Loading history...
227
            ->willReturn($textnode);
228
        $this->tokenStorageMock->expects(self::once())
229
            ->method('getToken')
230
            ->willReturn(null);
231
        $this->routerMock->expects(self::once())
232
            ->method('generate')
233
            ->with('financenode', ['textnodeArbitraryId' => 'someArbitraryId']);
234
235
        $result = $this->controller->readTopicAction($topicId);
236
        self::assertInstanceOf(RedirectResponse::class, $result);
237
    }
238
239
    /**
240
     * tests readTopicAction for valid topic Id and logged in user
241
     */
242
    public function testReadTopicActionForValidTopicIdAndLoggedInUser(): void
243
    {
244
        $topicId = 'someTopicId';
245
246
        $textnode = new Textnode();
247
        $textnode->setArbitraryId('someArbitraryId');
248
        $textnode->appendHitch([
249
            'textnodeId' => '1',
250
            'description' => 2,
251
            'status' => Textnode::HITCH_STATUS_ACTIVE,
252
        ]);
253
254
        $user = new User();
255
256
        $this->userRepositoryMock->expects(self::once())
257
            ->method('save')
258
            ->with($user);
0 ignored issues
show
Bug introduced by
$user of type DembeloMain\Document\User is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

258
            ->with(/** @scrutinizer ignore-type */ $user);
Loading history...
259
260
        $tokenMock = $this->createTokenMock();
261
        $tokenMock->expects(self::once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Symfony\Component\Securi...on\Token\TokenInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

261
        $tokenMock->/** @scrutinizer ignore-call */ expects(self::once())

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
262
            ->method('getUser')
263
            ->willReturn($user);
264
265
        $this->featureToggleMock->expects(self::once())
266
            ->method('hasFeature')
267
            ->willReturn(false);
268
        $this->textnodeRepositoryMock->expects(self::once())
269
            ->method('getTextnodeToRead')
270
            ->with($topicId)
0 ignored issues
show
Bug introduced by
$topicId of type string is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

270
            ->with(/** @scrutinizer ignore-type */ $topicId)
Loading history...
271
            ->willReturn($textnode);
272
        $this->tokenStorageMock->expects(self::once())
273
            ->method('getToken')
274
            ->willReturn($tokenMock);
275
        $this->routerMock->expects(self::once())
276
            ->method('generate')
277
            ->with('text', ['textnodeArbitraryId' => 'someArbitraryId']);
278
279
        $result = $this->controller->readTopicAction($topicId);
280
        self::assertInstanceOf(RedirectResponse::class, $result);
281
        self::assertSame($topicId, $user->getLastTopicId());
282
    }
283
284
    /**
285
     * tests imprint action
286
     */
287
    public function testImprintAction(): void
288
    {
289
        $this->templatingMock->expects(self::once())
290
            ->method('renderResponse')
291
            ->with('DembeloMain::default/imprint.html.twig')
0 ignored issues
show
Bug introduced by
'DembeloMain::default/imprint.html.twig' of type string is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

291
            ->with(/** @scrutinizer ignore-type */ 'DembeloMain::default/imprint.html.twig')
Loading history...
292
            ->willReturn('responseString');
293
        $result = $this->controller->imprintAction();
294
        self::assertSame('responseString', $result);
295
    }
296
297
    /**
298
     * tests back action
299
     */
300
    public function testBackActionSuccess(): void
301
    {
302
        $textnode = new Textnode();
303
        $textnode->setArbitraryId('someArbitraryId');
304
305
        $this->readpathUndoServiceMock->expects(self::once())
306
            ->method('undo')
307
            ->willReturn(true);
308
        $this->readpathUndoServiceMock->expects(self::once())
309
            ->method('getCurrentItem')
310
            ->willReturn(5);
311
        $this->textnodeRepositoryMock->expects(self::once())
312
            ->method('find')
313
            ->with(5)
0 ignored issues
show
Bug introduced by
5 of type integer is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

313
            ->with(/** @scrutinizer ignore-type */ 5)
Loading history...
314
            ->willReturn($textnode);
315
        $this->routerMock->expects(self::once())
316
            ->method('generate')
317
            ->with('text', ['textnodeArbitraryId' => 'someArbitraryId'])
0 ignored issues
show
Bug introduced by
'text' of type string is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

317
            ->with(/** @scrutinizer ignore-type */ 'text', ['textnodeArbitraryId' => 'someArbitraryId'])
Loading history...
318
            ->willReturn('someUrl');
319
320
        $result = $this->controller->backAction();
321
        self::assertInstanceOf(RedirectResponse::class, $result);
322
        self::assertSame('someUrl', $result->getTargetUrl());
323
    }
324
325
    /**
326
     * tests back action when undo() ist not successful
327
     */
328
    public function testBackActionUnsuccessfulForGuestUser(): void
329
    {
330
        $textnode = new Textnode();
331
        $textnode->setArbitraryId('someArbitraryId');
332
333
        $this->readpathUndoServiceMock->expects(self::once())
334
            ->method('undo')
335
            ->willReturn(false);
336
        $this->readpathUndoServiceMock->expects(self::never())
337
            ->method('getCurrentItem');
338
        $this->routerMock->expects(self::once())
339
            ->method('generate')
340
            ->with('mainpage')
0 ignored issues
show
Bug introduced by
'mainpage' of type string is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

340
            ->with(/** @scrutinizer ignore-type */ 'mainpage')
Loading history...
341
            ->willReturn('someUrl');
342
343
        $result = $this->controller->backAction();
344
        self::assertInstanceOf(RedirectResponse::class, $result);
345
        self::assertSame('someUrl', $result->getTargetUrl());
346
    }
347
348
    /**
349
     * tests back action when undo() ist not successful
350
     */
351
    public function testBackActionUnsuccessfulForLoggedInUser(): void
352
    {
353
        $textnode = new Textnode();
354
        $textnode->setArbitraryId('someArbitraryId');
355
356
        $user = new User();
357
        $user->setLastTopicId('someLastTopicId');
358
359
        $tokenMock = $this->createTokenMock();
360
        $tokenMock->expects(self::once())
361
            ->method('getUser')
362
            ->willReturn($user);
363
364
        $this->tokenStorageMock->expects(self::once())
365
            ->method('getToken')
366
            ->willReturn($tokenMock);
367
        $this->readpathUndoServiceMock->expects(self::once())
368
            ->method('undo')
369
            ->willReturn(false);
370
        $this->readpathUndoServiceMock->expects(self::never())
371
            ->method('getCurrentItem');
372
        $this->routerMock->expects(self::once())
373
            ->method('generate')
374
            ->with('themenfeld', ['topicId' => 'someLastTopicId'])
0 ignored issues
show
Bug introduced by
'themenfeld' of type string is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

374
            ->with(/** @scrutinizer ignore-type */ 'themenfeld', ['topicId' => 'someLastTopicId'])
Loading history...
375
            ->willReturn('someUrl');
376
377
        $result = $this->controller->backAction();
378
        self::assertInstanceOf(RedirectResponse::class, $result);
379
        self::assertSame('someUrl', $result->getTargetUrl());
380
    }
381
    /**
382
     * tests readTextnodeAction with guest user and enabled login feature
383
     */
384 View Code Duplication
    public function testReadTextnodeActionWithGuestUserAndEnabledLoginFeature(): 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...
385
    {
386
        $textnodeArbitraryId = 'someTopicId';
387
388
        $this->featureToggleMock->expects(self::once())
389
            ->method('hasFeature')
390
            ->willReturn(true);
391
        $this->authorizationCheckerMock->expects(self::any())
392
            ->method('isGranted')
393
            ->willReturn(false);
394
        $this->routerMock->expects(self::once())
395
            ->method('generate')
396
            ->with('login_route', []);
0 ignored issues
show
Bug introduced by
'login_route' of type string is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

396
            ->with(/** @scrutinizer ignore-type */ 'login_route', []);
Loading history...
397
398
        $result = $this->controller->readTextnodeAction($textnodeArbitraryId);
399
        self::assertInstanceOf(RedirectResponse::class, $result);
400
    }
401
402
    /**
403
     * tests readTextnodeAction for invalid Id
404
     * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
405
     */
406 View Code Duplication
    public function testReadTextnodeActionForInvalidId(): 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...
407
    {
408
        $textnodeArbitraryId = 'someId';
409
410
        $this->featureToggleMock->expects(self::once())
411
            ->method('hasFeature')
412
            ->willReturn(false);
413
        $this->textnodeRepositoryMock->expects(self::once())
414
            ->method('findOneActiveByArbitraryId')
415
            ->with($textnodeArbitraryId)
0 ignored issues
show
Bug introduced by
$textnodeArbitraryId of type string is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

415
            ->with(/** @scrutinizer ignore-type */ $textnodeArbitraryId)
Loading history...
416
            ->willReturn(null);
417
418
        $this->controller->readTextnodeAction($textnodeArbitraryId);
419
    }
420
421
    /**
422
     * test readTextnodeAction for valid textnode
423
     */
424
    public function testReadTextnodeActionForValidTextnode(): void
425
    {
426
        $textnodeArbitraryId = 'someArbitraryId';
427
        $textnodeId = 'someId';
428
429
        $textnode = new Textnode();
430
        $textnode->setId($textnodeId);
431
        $textnode->setArbitraryId($textnodeArbitraryId);
432
        $textnode->appendHitch([
433
            'textnodeId' => '1',
434
            'description' => 2,
435
            'status' => Textnode::HITCH_STATUS_ACTIVE,
436
        ]);
437
438
        $this->featureToggleMock->expects(self::once())
439
            ->method('hasFeature')
440
            ->willReturn(false);
441
        $this->textnodeRepositoryMock->expects(self::once())
442
            ->method('findOneActiveByArbitraryId')
443
            ->with($textnodeArbitraryId)
0 ignored issues
show
Bug introduced by
$textnodeArbitraryId of type string is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

443
            ->with(/** @scrutinizer ignore-type */ $textnodeArbitraryId)
Loading history...
444
            ->willReturn($textnode);
445
        $this->tokenStorageMock->expects(self::once())
446
            ->method('getToken')
447
            ->willReturn(null);
448
        $this->templatingMock->expects(self::once())
449
            ->method('renderResponse')
450
            ->with(
451
                'DembeloMain::default/read.html.twig',
452
                [
453
                    'textnode' => $textnode,
454
                    'hitches' => [],
455
                ]
456
            );
457
        $this->readpathUndoServiceMock->expects(self::once())
458
            ->method('add')
459
            ->with($textnodeId);
460
461
        $this->controller->readTextnodeAction($textnodeArbitraryId);
462
    }
463
464
    /**
465
     * tests readTextnodeAction for finance node
466
     */
467
    public function testReadTextnodeActionForFinanceNode(): void
468
    {
469
        $textnodeArbitraryId = 'someId';
470
471
        $textnode = new Textnode();
472
        $textnode->setArbitraryId('someArbId');
473
474
        $this->featureToggleMock->expects(self::once())
475
            ->method('hasFeature')
476
            ->willReturn(false);
477
        $this->textnodeRepositoryMock->expects(self::once())
478
            ->method('findOneActiveByArbitraryId')
479
            ->with($textnodeArbitraryId)
0 ignored issues
show
Bug introduced by
$textnodeArbitraryId of type string is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

479
            ->with(/** @scrutinizer ignore-type */ $textnodeArbitraryId)
Loading history...
480
            ->willReturn($textnode);
481
482
        $result = $this->controller->readTextnodeAction($textnodeArbitraryId);
483
        self::assertInstanceOf(RedirectResponse::class, $result);
484
    }
485
486
    /**
487
     * @return TokenInterface|\PHPUnit_Framework_MockObject_MockObject
488
     */
489
    private function createTokenMock(): TokenInterface
490
    {
491
        return $this->createMock(TokenInterface::class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createMock...\TokenInterface::class) returns the type PHPUnit_Framework_MockObject_MockObject which is incompatible with the type-hinted return Symfony\Component\Securi...on\Token\TokenInterface.
Loading history...
492
    }
493
494
    /**
495
     * @return FeatureToggle|\PHPUnit_Framework_MockObject_MockObject
496
     */
497
    private function createFeatureToggleMock(): FeatureToggle
498
    {
499
        return $this->createMock(FeatureToggle::class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createMock...l\FeatureToggle::class) returns the type PHPUnit_Framework_MockObject_MockObject which is incompatible with the type-hinted return DembeloMain\Model\FeatureToggle.
Loading history...
500
    }
501
502
    /**
503
     * @return AuthorizationCheckerInterface|\PHPUnit_Framework_MockObject_MockObject
504
     */
505
    private function createAuthorizationCheckerMock(): AuthorizationCheckerInterface
506
    {
507
        return $this->createMock(AuthorizationCheckerInterface::class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createMock...heckerInterface::class) returns the type PHPUnit_Framework_MockObject_MockObject which is incompatible with the type-hinted return Symfony\Component\Securi...izationCheckerInterface.
Loading history...
508
    }
509
510
    /**
511
     * @return UserRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
512
     */
513
    private function createUserRepositoryMock(): UserRepositoryInterface
514
    {
515
        return $this->createMock(UserRepositoryInterface::class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createMock...sitoryInterface::class) returns the type PHPUnit_Framework_MockObject_MockObject which is incompatible with the type-hinted return DembeloMain\Model\Reposi...UserRepositoryInterface.
Loading history...
516
    }
517
518
    /**
519
     * @return TextNodeRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
520
     */
521
    private function createTextnodeRepositoryMock(): TextNodeRepositoryInterface
522
    {
523
        return $this->createMock(TextNodeRepositoryInterface::class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createMock...sitoryInterface::class) returns the type PHPUnit_Framework_MockObject_MockObject which is incompatible with the type-hinted return DembeloMain\Model\Reposi...NodeRepositoryInterface.
Loading history...
524
    }
525
526
    /**
527
     * @return Templating|\PHPUnit_Framework_MockObject_MockObject
528
     */
529
    private function createTemplatingMock(): Templating
530
    {
531
        return $this->createMock(Templating::class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createMock...EngineInterface::class) returns the type PHPUnit_Framework_MockObject_MockObject which is incompatible with the type-hinted return Symfony\Bundle\Framework...plating\EngineInterface.
Loading history...
532
    }
533
534
    /**
535
     * @return Router|\PHPUnit_Framework_MockObject_MockObject
536
     */
537
    private function createRouterMock(): Router
538
    {
539
        $mock = $this->createMock(Router::class);
540
        $mock->expects(self::any())
541
            ->method('generate')
542
            ->willReturn('someUrl');
543
544
        return $mock;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $mock returns the type PHPUnit_Framework_MockObject_MockObject which is incompatible with the type-hinted return Symfony\Bundle\FrameworkBundle\Routing\Router.
Loading history...
545
    }
546
547
    /**
548
     * @return TokenStorage|\PHPUnit_Framework_MockObject_MockObject
549
     */
550
    private function createTokenStorageMock(): TokenStorage
551
    {
552
        return $this->createMock(TokenStorage::class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createMock...ge\TokenStorage::class) returns the type PHPUnit_Framework_MockObject_MockObject which is incompatible with the type-hinted return Symfony\Component\Securi...en\Storage\TokenStorage.
Loading history...
553
    }
554
555
    /**
556
     * @return ReadPath|\PHPUnit_Framework_MockObject_MockObject
557
     */
558
    private function createReadpathMock(): Readpath
559
    {
560
        return $this->createMock(Readpath::class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createMock...\Model\Readpath::class) returns the type PHPUnit_Framework_MockObject_MockObject which is incompatible with the type-hinted return DembeloMain\Model\Readpath.
Loading history...
561
    }
562
563
    /**
564
     * @return FavoriteManager|\PHPUnit_Framework_MockObject_MockObject
565
     */
566
    private function createFavoriteManagerMock(): FavoriteManager
567
    {
568
        return $this->createMock(FavoriteManager::class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createMock...FavoriteManager::class) returns the type PHPUnit_Framework_MockObject_MockObject which is incompatible with the type-hinted return DembeloMain\Model\FavoriteManager.
Loading history...
569
    }
570
571
    /**
572
     * @return ReadpathUndoService|\PHPUnit_Framework_MockObject_MockObject
573
     */
574
    private function createReadpathUndoServiceMock(): ReadpathUndoService
575
    {
576
        return $this->createMock(ReadpathUndoService::class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createMock...pathUndoService::class) returns the type PHPUnit_Framework_MockObject_MockObject which is incompatible with the type-hinted return DembeloMain\Service\ReadpathUndoService.
Loading history...
577
    }
578
}
579