Completed
Push — master ( ff92f6...3ef1d3 )
by John
09:08
created

HmacValidatorTest::testSetProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 55
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 55
rs 9.7692
c 0
b 0
f 0
cc 1
eloc 36
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 * This file is part of the KleijnWeb\JwtBundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\JwtBundle\Tests\Jwt\SignatureValidator;
10
11
use KleijnWeb\JwtBundle\Jwt\SignatureValidator\HmacValidator;
12
13
/**
14
 * @author John Kleijn <[email protected]>
15
 */
16
class HmacValidatorTest extends \PHPUnit_Framework_TestCase
17
{
18
    /**
19
     * @var string
20
     */
21
    private static $secret = 'Mary had a little lamb';
22
23
    /**
24
     * @param string $type
25
     * @param string $expected
26
     * @param string $payload
27
     * @param string $signature
28
     *
29
     * @test
30
     * @dataProvider testSetProvider
31
     */
32
    public function willPassTestDataSetUsingSha256($type, $expected, $payload, $signature)
33
    {
34
        $validator = new HmacValidator($type);
35
        $this->assertSame($expected, $validator->isValid($payload, self::$secret, $signature));
36
    }
37
38
    /**
39
     * Test data created using:
40
     *  - https://quickhash.com/
41
     *  - http://www.freeformatter.com/hmac-generator.html
42
     *
43
     * @return array
44
     */
45
    public static function testSetProvider()
46
    {   // @codingStandardsIgnoreStart
47
        return [
48
            [HmacValidator::SHA512, false, ';lkjlkjlkj', 'lkjlkjhlkjh'],
49
            [
50
                HmacValidator::SHA512,
51
                true,
52
                'fcgtvbhjnkmlijhuiygftdrse53aes64d75f68g7u8hijohugyiftudr',
53
                hex2bin('a527da4bd11a4be4c2c40173abca314633dee5fd106dac0ecdfdb7e341b483fb5eb480504b3292f7dfddc32838e99440a3c1ef6b5d3deb8575e49197ee4da45a')
54
            ],
55
            [
56
                HmacValidator::SHA512,
57
                true,
58
                'bhyuf76fhgyuftydxcfgxh',
59
                hex2bin('ebc146f2241440452459d149d94ad9cb31d0da2a27cbcf1aef10470576b726a0de710cc0d752d2730273039fb329ffd63705fef9df37d3a7a5d6277696a49c29')
60
            ],
61
            [
62
                HmacValidator::SHA512,
63
                false,
64
                '1hyuf76fhgyuftydxcfgxh',
65
                hex2bin('a527da4bd11a4be4c2c40173abca314633dee5fd106dac0ecdfdb7e341b483fb5eb480504b3292f7dfddc32838e99440a3c1ef6b5d3deb8575e49197ee4da45a')
66
            ],
67
            [
68
                HmacValidator::SHA512,
69
                false,
70
                'fcgtvbhjnkmlijhuiygftdrse53aes64d75f68g7u8hijohugyiftud1',
71
                hex2bin('ebc146f2241440452459d149d94ad9cb31d0da2a27cbcf1aef10470576b726a0de710cc0d752d2730273039fb329ffd63705fef9df37d3a7a5d6277696a49c29')
72
            ],
73
            [HmacValidator::SHA256, false, ';lkjlkjlkj', 'lkjlkjhlkjh'],
74
            [
75
                HmacValidator::SHA256,
76
                true,
77
                'fcgtvbhjnkmlijhuiygftdrse53aes64d75f68g7u8hijohugyiftudr',
78
                hex2bin('8e2ed246e3b0bf02fbd3746f6992e9e5237d72269e3df436019ac3c494db4613')
79
            ],
80
            [
81
                HmacValidator::SHA256,
82
                true,
83
                'bhyuf76fhgyuftydxcfgxh',
84
                hex2bin('fc086d830f0191838f310f3ed3d254b356bcff5d158ebdb69f20581d48210e45')
85
            ],
86
            [
87
                HmacValidator::SHA256,
88
                false,
89
                '1hyuf76fhgyuftydxcfgxh',
90
                hex2bin('fc086d830f0191838f310f3ed3d254b356bcff5d158ebdb69f20581d48210e45')
91
            ],
92
            [
93
                HmacValidator::SHA256,
94
                false,
95
                'fcgtvbhjnkmlijhuiygftdrse53aes64d75f68g7u8hijohugyiftud1',
96
                hex2bin('8a3a90de37b15bf8667e6f69170973087d4673bd99e15ca8a67791187c224d19')
97
            ],
98
        ];
99
    }// @codingStandardsIgnoreEnd
100
}
101