Passed
Push — master ( e2e498...121175 )
by Simon
03:29
created

CreateTokenMutationCreatorTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Firesphere\GraphQLJWT\Tests;
4
5
use Firesphere\GraphQLJWT\CreateTokenMutationCreator;
6
use Firesphere\GraphQLJWT\JWTAuthenticator;
7
use GraphQL\Type\Definition\ResolveInfo;
0 ignored issues
show
Bug introduced by
The type GraphQL\Type\Definition\ResolveInfo 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...
8
use SilverStripe\Core\Config\Config;
9
use SilverStripe\Core\Injector\Injector;
10
use SilverStripe\Dev\SapphireTest;
11
use SilverStripe\Security\Member;
12
13
class CreateTokenMutationCreatorTest extends SapphireTest
14
{
15
    protected static $fixture_file = '../fixtures/JWTAuthenticatorTest.yml';
16
17
    protected $member;
18
19
    public function setUp()
20
    {
21
        putenv('JWT_SIGNER_KEY=test_signer');
22
23
        parent::setUp();
24
        $this->member = $this->objFromFixture(Member::class, 'admin');
25
    }
26
27
    public function tearDown()
28
    {
29
        parent::tearDown();
30
    }
31
32
    public function testResolveValid()
33
    {
34
        $createToken = Injector::inst()->get(CreateTokenMutationCreator::class);
35
36
        $response = $createToken->resolve(null, ['Email' => '[email protected]', 'Password' => 'error'], [],
37
            new ResolveInfo([]));
38
39
        $this->assertTrue($response instanceof Member);
40
        $this->assertNotNull($response->Token);
41
    }
42
43 View Code Duplication
    public function testResolveInvalidWithAllowedAnonymous()
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...
44
    {
45
        Config::modify()->set(JWTAuthenticator::class, 'anonymous_allowed', true);
46
        $authenticator = Injector::inst()->get(CreateTokenMutationCreator::class);
47
48
        $response = $authenticator->resolve(null, ['Email' => '[email protected]', 'Password' => 'wrong'], [],
49
            new ResolveInfo([]));
50
51
        $this->assertTrue($response instanceof Member);
52
        $this->assertEquals(0, $response->ID);
53
        $this->assertNotNull($response->Token);
54
    }
55
56 View Code Duplication
    public function testResolveInvalidWithoutAllowedAnonymous()
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...
57
    {
58
        Config::modify()->set(JWTAuthenticator::class, 'anonymous_allowed', false);
59
        $authenticator = Injector::inst()->get(CreateTokenMutationCreator::class);
60
61
        $response = $authenticator->resolve(null, ['Email' => '[email protected]', 'Password' => 'wrong'], [],
62
            new ResolveInfo([]));
63
64
        $this->assertTrue($response instanceof Member);
65
        $this->assertNull($response->Token);
66
    }
67
}
68