1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2018 Spomky-Labs |
9
|
|
|
* |
10
|
|
|
* This software may be modified and distributed under the terms |
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace OAuth2Framework\Component\Server\TokenEndpoint\Tests; |
15
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\Server\Core\Client\Client; |
17
|
|
|
use OAuth2Framework\Component\Server\Core\Client\ClientId; |
18
|
|
|
use OAuth2Framework\Component\Server\Core\DataBag\DataBag; |
19
|
|
|
use OAuth2Framework\Component\Server\TokenEndpoint\GrantType; |
20
|
|
|
use OAuth2Framework\Component\Server\TokenEndpoint\GrantTypeData; |
21
|
|
|
use OAuth2Framework\Component\Server\TokenEndpoint\Processor\ProcessorManager; |
22
|
|
|
use OAuth2Framework\Component\Server\TokenEndpoint\Processor\ScopeProcessor; |
23
|
|
|
use OAuth2Framework\Component\Server\TokenEndpoint\Processor\TokenTypeProcessor; |
24
|
|
|
use OAuth2Framework\Component\Server\TokenType\TokenType; |
25
|
|
|
use PHPUnit\Framework\TestCase; |
26
|
|
|
use Prophecy\Argument; |
27
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @group TokenEndpoint |
31
|
|
|
* @group Processor |
32
|
|
|
*/ |
33
|
|
|
final class ProcessorTest extends TestCase |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @test |
37
|
|
|
*/ |
38
|
|
|
public function theProcessorManagerCanHandleCalls() |
39
|
|
|
{ |
40
|
|
|
$client = Client::createEmpty(); |
41
|
|
|
$client = $client->create( |
42
|
|
|
ClientId::create('CLIENT_ID'), |
43
|
|
|
DataBag::create([]), |
44
|
|
|
null |
45
|
|
|
); |
46
|
|
|
$client->eraseMessages(); |
47
|
|
|
$tokenType = $this->prophesize(TokenType::class); |
48
|
|
|
$tokenType->name()->willReturn('foo'); |
49
|
|
|
$tokenType->getInformation()->willReturn([ |
50
|
|
|
'token_type' => 'foo', |
51
|
|
|
'foo' => 'bar', |
52
|
|
|
]); |
53
|
|
|
$request = $this->prophesize(ServerRequestInterface::class); |
54
|
|
|
$request->getAttribute('token_type')->willReturn($tokenType->reveal()); |
55
|
|
|
|
56
|
|
|
$grantTypeData = GrantTypeData::create($client); |
57
|
|
|
$grantType = $this->prophesize(GrantType::class); |
58
|
|
|
$grantType->grant(Argument::type(ServerRequestInterface::class), Argument::type(GrantTypeData::class))->will(function ($args) { |
59
|
|
|
return $args[1]; |
60
|
|
|
}); |
61
|
|
|
|
62
|
|
|
$result = $this->getProcessorManager()->handle($request->reveal(), $grantTypeData, $grantType->reveal()); |
63
|
|
|
|
64
|
|
|
self::assertNotSame($grantTypeData, $result); |
65
|
|
|
self::assertEquals(['token_type' => 'foo', 'foo' => 'bar'], $result->getParameters()->all()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var null|ProcessorManager |
70
|
|
|
*/ |
71
|
|
|
private $processorManager; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return ProcessorManager |
75
|
|
|
*/ |
76
|
|
|
private function getProcessorManager(): ProcessorManager |
77
|
|
|
{ |
78
|
|
|
if (null === $this->processorManager) { |
79
|
|
|
$this->processorManager = new ProcessorManager(); |
80
|
|
|
$this->processorManager |
81
|
|
|
->add(new TokenTypeProcessor()) |
82
|
|
|
//->add(new ScopeProcessor()) |
|
|
|
|
83
|
|
|
; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $this->processorManager; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.