1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yiisoft\Yii\Web\Middleware; |
4
|
|
|
|
5
|
|
|
use Nyholm\Psr7\Response; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use Psr\Container\ContainerInterface; |
8
|
|
|
use Psr\Http\Message\ResponseInterface; |
9
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
10
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
11
|
|
|
|
12
|
|
|
class WebActionsCallerTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
/** @var ServerRequestInterface */ |
15
|
|
|
private $request; |
16
|
|
|
|
17
|
|
|
/** @var RequestHandlerInterface */ |
18
|
|
|
private $handler; |
19
|
|
|
|
20
|
|
|
/** @var ContainerInterface */ |
21
|
|
|
private $container; |
22
|
|
|
|
23
|
|
|
protected function setUp() |
24
|
|
|
{ |
25
|
|
|
$this->request = $this->createMock(ServerRequestInterface::class); |
|
|
|
|
26
|
|
|
$this->handler = $this->createMock(RequestHandlerInterface::class); |
|
|
|
|
27
|
|
|
$this->container = $this->createMock(ContainerInterface::class); |
|
|
|
|
28
|
|
|
$this->container->method('get')->willReturn($this); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testProcess() |
32
|
|
|
{ |
33
|
|
|
$this->request |
34
|
|
|
->method('getAttribute') |
|
|
|
|
35
|
|
|
->with($this->equalTo('action')) |
36
|
|
|
->willReturn('example'); |
37
|
|
|
|
38
|
|
|
$response = (new WebActionsCaller('this', $this->container))->process($this->request, $this->handler); |
39
|
|
|
$this->assertEquals(204, $response->getStatusCode()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testExceptionOnNullAction() |
43
|
|
|
{ |
44
|
|
|
$this->request |
45
|
|
|
->method('getAttribute') |
46
|
|
|
->with($this->equalTo('action')) |
47
|
|
|
->willReturn(null); |
48
|
|
|
|
49
|
|
|
$this->expectException(\RuntimeException::class); |
50
|
|
|
(new WebActionsCaller('this', $this->container))->process($this->request, $this->handler); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testHandlerInvocation() |
54
|
|
|
{ |
55
|
|
|
$this->request |
56
|
|
|
->method('getAttribute') |
57
|
|
|
->with($this->equalTo('action')) |
58
|
|
|
->willReturn('notExistant'); |
59
|
|
|
|
60
|
|
|
$this->handler |
61
|
|
|
->expects($this->once()) |
|
|
|
|
62
|
|
|
->method('handle'); |
63
|
|
|
|
64
|
|
|
(new WebActionsCaller('this', $this->container))->process($this->request, $this->handler); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function example(): ResponseInterface |
68
|
|
|
{ |
69
|
|
|
return new Response(204); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..