Issues (35)

tests/unit/MemberExtensionTest.php (3 issues)

1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: simon
5
 * Date: 02-Dec-17
6
 * Time: 11:30
7
 */
8
9
namespace Firesphere\GraphQLJWT\Tests;
10
11
use Firesphere\GraphQLJWT\Extensions\MemberExtension;
12
use SilverStripe\Core\Config\Config;
13
use SilverStripe\Core\Convert;
14
use SilverStripe\Dev\SapphireTest;
15
use SilverStripe\Security\Member;
16
17
class MemberExtensionTest extends SapphireTest
18
{
19
    protected static $fixture_file = '../fixtures/JWTAuthenticatorTest.yml';
20
21
    public function testMemberExists()
22
    {
23
        /** @var Member|MemberExtension $member */
24
        $member = $this->objFromFixture(Member::class, 'admin');
25
26
        $data = $member->getJWTData();
27
        $result = Convert::json2obj($data);
0 ignored issues
show
Deprecated Code introduced by
The function SilverStripe\Core\Convert::json2obj() has been deprecated: 4.4.0:5.0.0 Use json_decode() instead ( Ignorable by Annotation )

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

27
        $result = /** @scrutinizer ignore-deprecated */ Convert::json2obj($data);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
28
29
        $this->assertEquals($member->Email, $result->userName);
30
    }
31
32
    public function testExtraMemberData()
33
    {
34
        /** @var Member|MemberExtension $member */
35
        $member = $this->objFromFixture(Member::class, 'admin');
36
        $member->Surname = 'Member';
37
        Config::modify()->set(Member::class, 'jwt_subject_fields', ['FirstName', 'Surname']);
38
39
        $data = $member->getJWTData();
40
        $result = Convert::json2obj($data);
0 ignored issues
show
Deprecated Code introduced by
The function SilverStripe\Core\Convert::json2obj() has been deprecated: 4.4.0:5.0.0 Use json_decode() instead ( Ignorable by Annotation )

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

40
        $result = /** @scrutinizer ignore-deprecated */ Convert::json2obj($data);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
41
42
        $this->assertEquals('Admin', $result->firstName);
43
        $this->assertEquals('Member', $result->surname);
44
    }
45
46
    public function testNoMember()
47
    {
48
        /** @var Member|MemberExtension $memberl */
49
        $memberl = Member::create();
50
        $data = $memberl->getJWTData();
51
        $result = Convert::json2array($data);
0 ignored issues
show
Deprecated Code introduced by
The function SilverStripe\Core\Convert::json2array() has been deprecated: 4.4.0:5.0.0 Use json_decode() instead ( Ignorable by Annotation )

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

51
        $result = /** @scrutinizer ignore-deprecated */ Convert::json2array($data);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
52
53
        $this->assertEquals(0, $result['id']);
54
    }
55
}
56