Completed
Push — 8.7 ( 3ac046...3ba805 )
by Markus
04:03
created

Tests/Unit/Store/SessionSsoStateStoreTest.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DMK\MKSamlAuth\Tests\Unit\Store;
6
7
use DMK\MKSamlAuth\Store\SessionSsoStateStore;
8
use LightSaml\State\Sso\SsoState;
9
use PHPStan\Testing\TestCase;
10
use Prophecy\Argument;
11
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
12
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
13
14
class SessionSsoStateStoreTest extends TestCase
15
{
16
    /**
17
     * @var SessionSsoStateStore
18
     */
19
    private $store;
20
    /**
21
     * @var \Prophecy\Prophecy\ObjectProphecy
22
     */
23
    private $user;
24
25
    protected function setUp()
26
    {
27
        $this->user = $this->prophesize(FrontendUserAuthentication::class);
28
29
        $fe = $this->prophesize(TypoScriptFrontendController::class);
30
        $fe->fe_user = $this->user->reveal();
31
        $GLOBALS['TSFE'] = $fe->reveal();
32
33
        $this->store = new SessionSsoStateStore();
0 ignored issues
show
The call to DMK\MKSamlAuth\Store\Ses...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

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

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...
34
    }
35
    public function testGet()
36
    {
37
        $state = new SsoState();
38
39
        $this->user->getSessionData(SessionSsoStateStore::SESSION_KEY)
40
            ->willReturn(serialize($state));
41
42
        self::assertEquals($state, $this->store->get());
43
    }
44
45
    public function testGetNull()
46
    {
47
        $this->user->getSessionData(SessionSsoStateStore::SESSION_KEY)
48
            ->willReturn(null);
49
50
        $this->user->setAndSaveSessionData(SessionSsoStateStore::SESSION_KEY, Argument::type('string'))
51
            ->shouldBeCalled();
52
53
        $this->user->getSessionId()->willReturn('foo');
54
55
        self::assertInstanceOf(SsoState::class, $state = $this->store->get());
56
        self::assertSame('foo', $state->getLocalSessionId());
57
    }
58
}
59