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

SessionSsoStateStoreTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 19
c 1
b 0
f 0
dl 0
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testGet() 0 8 1
A testGetNull() 0 12 1
A setUp() 0 9 1
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;
0 ignored issues
show
Bug introduced by
The type PHPStan\Testing\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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
Bug introduced by
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