Passed
Pull Request — master (#10)
by
unknown
01:49
created

MethodRegistryTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testInvalidMethodsThrowExceptions() 0 5 1
A testGetAllMethodsReturnsRegisteredMethods() 0 8 1
1
<?php
2
3
namespace SilverStripe\MFA\Tests\Service;
4
5
use SilverStripe\Core\Config\Config;
6
use SilverStripe\Dev\SapphireTest;
7
use SilverStripe\MFA\Service\MethodRegistry;
8
use SilverStripe\MFA\Tests\Stub\BasicMath\Method;
9
use SilverStripe\Security\Member;
10
use UnexpectedValueException;
11
12
class MethodRegistryTest extends SapphireTest
13
{
14
    public function testGetAllMethodsReturnsRegisteredMethods()
15
    {
16
        Config::modify()->set(MethodRegistry::class, 'methods', [Method::class]);
17
        $registry = MethodRegistry::singleton();
18
        $methods = $registry->getAllMethods();
19
20
        $this->assertCount(1, $methods);
21
        $this->assertInstanceOf(Method::class, reset($methods));
0 ignored issues
show
Bug introduced by
It seems like $methods can also be of type Countable and Traversable; however, parameter $array of reset() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

21
        $this->assertInstanceOf(Method::class, reset(/** @scrutinizer ignore-type */ $methods));
Loading history...
22
    }
23
24
    /**
25
     * @expectedException UnexpectedValueException
26
     * @expectedExceptionMessage Given method "SilverStripe\Security\Member" does not implement SilverStripe\MFA\Method\MethodInterface
27
     */
28
    public function testInvalidMethodsThrowExceptions()
29
    {
30
        Config::modify()->set(MethodRegistry::class, 'methods', [Member::class]);
31
        $registry = MethodRegistry::singleton();
32
        $registry->getAllMethods();
33
    }
34
}
35