1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Xmf\Test\Jwt; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
8
|
|
|
|
9
|
|
|
|
10
|
|
|
use Xmf\Jwt\JsonWebToken; |
11
|
|
|
use Xmf\Jwt\KeyFactory; |
12
|
|
|
use Xmf\Jwt\TokenFactory; |
13
|
|
|
use Xmf\Key\ArrayStorage; |
14
|
|
|
use Xmf\Key\KeyAbstract; |
15
|
|
|
|
16
|
|
|
class TokenFactoryTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var ArrayStorage |
20
|
|
|
*/ |
21
|
|
|
protected $storage; |
22
|
|
|
/** |
23
|
|
|
* @var KeyAbstract |
24
|
|
|
*/ |
25
|
|
|
protected $testKey; |
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $testKeyName = 'x-unit-test-key'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Sets up the fixture, for example, opens a network connection. |
33
|
|
|
* This method is called before a test is executed. |
34
|
|
|
*/ |
35
|
|
|
protected function setUp(): void |
36
|
|
|
{ |
37
|
|
|
$this->storage = new ArrayStorage(); |
38
|
|
|
$this->testKey = KeyFactory::build($this->testKeyName, $this->storage); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Tears down the fixture, for example, closes a network connection. |
43
|
|
|
* This method is called after a test is executed. |
44
|
|
|
*/ |
45
|
|
|
protected function tearDown(): void |
46
|
|
|
{ |
47
|
|
|
$this->storage->delete($this->testKeyName); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testBuild() |
51
|
|
|
{ |
52
|
|
|
$claims = ['rat' => 'cute']; |
53
|
|
|
$token = TokenFactory::build($this->testKey, $claims); |
54
|
|
|
|
55
|
|
|
$this->assertIsString($token); |
56
|
|
|
|
57
|
|
|
$jwt = new JsonWebToken($this->testKey); |
58
|
|
|
|
59
|
|
|
$actual = $jwt->decode($token, $claims); |
60
|
|
|
|
61
|
|
|
foreach ($claims as $name => $value) { |
62
|
|
|
$this->assertEquals($value, $actual->$name); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$claims = ['rat' => 'cute', 'exp' => (time() - 30)]; |
66
|
|
|
$token = TokenFactory::build($this->testKey, $claims); |
67
|
|
|
//$this->expectException('\PHPUnit\Framework\Error\Notice'); |
68
|
|
|
$actual = @$jwt->decode($token); |
69
|
|
|
$this->assertFalse($actual); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths