Completed
Push — 8.7 ( b6d8c1...3ac046 )
by Markus
06:49
created

RequestStateStoreTest::testSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DMK\MKSamlAuth\Tests\Unit\Store;
6
7
use DMK\MKSamlAuth\Store\RequestStateStore;
8
use LightSaml\State\Request\RequestState;
9
use PHPUnit\Framework\TestCase;
10
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
11
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
12
13
class RequestStateStoreTest extends TestCase
14
{
15
    /**
16
     * @var RequestStateStore
17
     */
18
    private $store;
19
    /**
20
     * @var \Prophecy\Prophecy\ObjectProphecy
21
     */
22
    private $user;
23
24
    protected function setUp()
25
    {
26
        $this->user = $this->prophesize(FrontendUserAuthentication::class);
27
28
        $fe = $this->prophesize(TypoScriptFrontendController::class);
29
        $fe->fe_user = $this->user->reveal();
30
        $GLOBALS['TSFE'] = $fe->reveal();
31
32
        $this->store = new RequestStateStore();
0 ignored issues
show
Bug introduced by
The call to DMK\MKSamlAuth\Store\Req...ateStore::__construct() has too few arguments starting with session. ( Ignorable by Annotation )

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

32
        $this->store = /** @scrutinizer ignore-call */ new RequestStateStore();

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
33
    }
34
35
    public function testSet()
36
    {
37
        $state = new RequestState('test');
38
39
        $this->user->getSessionData(RequestStateStore::SESSION_KEY)
40
            ->willReturn(null);
41
42
        $this->user->setAndSaveSessionData(RequestStateStore::SESSION_KEY, ['test' => $state])
43
            ->shouldBeCalled();
44
45
        $this->store->set($state);
46
    }
47
48
    public function testGet()
49
    {
50
        $state = new RequestState('test');
51
52
        $this->user->getSessionData(RequestStateStore::SESSION_KEY)
53
            ->willReturn(['test' => $state]);
54
55
        self::assertSame($state, $this->store->get('test'));
56
    }
57
}
58