Completed
Push — master ( a2a7f2...f21cde )
by John
9s
created

EncoderTest::willDecodeTestCasesFromJwtDotIo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
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
namespace KleijnWeb\JwtBundle\Tests\Authenticator;
9
10
use KleijnWeb\JwtBundle\Authenticator\Encoder;
11
12
/**
13
 * @author John Kleijn <[email protected]>
14
 */
15
class EncoderTest extends \PHPUnit_Framework_TestCase
16
{
17
    /**
18
     * @param string $data
19
     * @param array  $source
20
     *
21
     * @test
22
     * @dataProvider testSetProvider
23
     */
24
    public function willDecodeTestCasesFromJwtDotIo($source, $data)
25
    {
26
        $encoder = new Encoder();
27
        $this->assertSame($data, $encoder->encode($source));
28
    }
29
30
    /**
31
     * @test
32
     * @expectedException \RuntimeException
33
     */
34
    public function willThrowExceptionWhenJsonDecodeFails()
35
    {
36
        $decoder = new Encoder();
37
        $decoder->jsonEncode("\xB1\x31");
0 ignored issues
show
Documentation introduced by
'±1' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
38
    }
39
40
    /**
41
     * @see          http://jwt.io/
42
     * @return array
43
     */
44 View Code Duplication
    public static function testSetProvider()
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...
45
    {
46
        return [
47
            [
48
                [
49
                    'alg' => 'HS256',
50
                    'typ' => 'JWT',
51
                ],
52
                'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9'
53
            ],
54
            [
55
                [
56
                    'sub'   => '1234567890',
57
                    'name'  => 'John Doe',
58
                    'admin' => true,
59
                ]
60
                ,
61
                'eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9'
62
            ]
63
        ];
64
    }
65
}
66