Completed
Push — master ( 4c45e0...1a7b7a )
by Дмитрий
02:22
created

MethodRSASHA1Test::testCreatingSignatureWorks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 21
rs 9.7998
c 1
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * SocialConnect project
4
 * @author: Andreas Heigl https://github.com/heiglandreas <[email protected]>
5
 */
6
7
namespace Test\OAuth1\Signature;
8
9
use SocialConnect\OAuth1\Request;
10
use SocialConnect\OAuth1\Signature\MethodRSASHA1;
11
use SocialConnect\OAuth1\Token;
12
use SocialConnect\Provider\Consumer;
13
14
class MethodRSASHA1Test extends \Test\TestCase
15
{
16
    /** @expectedException \InvalidArgumentException */
17
    public function testConstructorThrowsExceptionOnNonexistnetKey()
18
    {
19
        new MethodRSASHA1(__DIR__ . '/nonexistent.pem');
20
    }
21
22
    public function testConstructorWorks()
23
    {
24
        $signer = new MethodRSASHA1(__DIR__ . '/../_assets/testkey.pem');
25
        $this->assertAttributeEquals(
26
            __DIR__ . '/../_assets/testkey.pem',
27
            'privateKey',
28
            $signer
29
        );
30
    }
31
32
    public function testGettingNameWorks()
33
    {
34
        $signer = new MethodRSASHA1(__DIR__ . '/../_assets/testkey.pem');
35
        $this->assertEquals('RSA-SHA1', $signer->getName());
36
    }
37
38
    public function testCreatingSignatureWorks()
39
    {
40
        $signer = new MethodRSASHA1(__DIR__ . '/../_assets/testkey.pem');
41
42
        $request = self::getMockBuilder(Request::class)->disableOriginalConstructor()->getMock();
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::getMockBuilder() is not static, but was called statically. ( Ignorable by Annotation )

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

42
        $request = self::/** @scrutinizer ignore-call */ getMockBuilder(Request::class)->disableOriginalConstructor()->getMock();
Loading history...
43
        $request->method('getSignatureBaseString')->willReturn('baseString');
0 ignored issues
show
Bug introduced by
The method method() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

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

43
        $request->/** @scrutinizer ignore-call */ 
44
                  method('getSignatureBaseString')->willReturn('baseString');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
45
        $consumer = self::getMockBuilder(Consumer::class)->disableOriginalConstructor()->getMock();
46
        $consumer->method('getSecret')->willReturn('consumerSecret');
47
48
        $token = self::getMockBuilder(Token::class)->disableOriginalConstructor()->getMock();
49
        $token->method('getSecret')->willReturn('tokenSecret');
50
51
        $signature = $signer->buildSignature($request, $consumer, $token);
52
53
        $this->assertEquals('HSA65Gc1jqAxgFj2uqiFBMwERymYoPswTS4ij+zc6'
54
        . 'SMZzw3P5FZDORkUEZ1iTfbZn1dQvLPnIaEIpf1f6sCjdrKFSnA5TIDJC8Gxhyp7YYE8TI'
55
        . 'XjtyyeAjERiU/nGZLoOlcwUZr2dI65deGiWcLH6x+7JpB5XQJCMZRFuYLZkB4sfbI4Knk'
56
        . 'e96e0VFjCqHHPFQKZxmgdahWQ+bQFHbMjsNf42uyZVj7ujX78wq8zkCMxaD4etOFOVE0z'
57
        . 'MKEf23JfcEQqky7NKVwUKp5yuJ5cRjA8IOyVVO9X7+m15q2nTAirR2XyZnoUlyZN5Aquq'
58
        . 'rFyOP8CROORrv45Uv4F9bBGOA==', $signature);
59
    }
60
}
61