1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Slick\Mvc\Http; |
4
|
|
|
|
5
|
|
|
use Aura\Router\Route; |
6
|
|
|
use Psr\Http\Message\ResponseInterface; |
7
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
8
|
|
|
use Slick\Http\Server\MiddlewareInterface; |
9
|
|
|
use Slick\Http\Stream; |
10
|
|
|
use Slick\Mvc\Http\Renderer\ViewInflectorInterface; |
11
|
|
|
use Slick\Mvc\Http\RendererMiddleware; |
12
|
|
|
use PhpSpec\ObjectBehavior; |
13
|
|
|
use Prophecy\Argument; |
14
|
|
|
use Slick\Template\Template; |
15
|
|
|
use Slick\Template\TemplateEngineInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* RendererMiddlewareSpec |
19
|
|
|
* |
20
|
|
|
* @package spec\Slick\Mvc\Http |
21
|
|
|
* @author Filipe Silva <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class RendererMiddlewareSpec extends ObjectBehavior |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
function let( |
27
|
|
|
TemplateEngineInterface $templateEngine, |
28
|
|
|
ViewInflectorInterface $inflector |
29
|
|
|
) { |
30
|
|
|
$this->beConstructedWith($templateEngine, $inflector); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function it_is_initializable() |
34
|
|
|
{ |
35
|
|
|
$this->shouldHaveType(RendererMiddleware::class); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
function its_a_http_server_middleware() |
39
|
|
|
{ |
40
|
|
|
$this->shouldBeAnInstanceOf(MiddlewareInterface::class); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
function it_skips_its_turn_if_a_302_status_code_is_already_set( |
44
|
|
|
ServerRequestInterface $request, |
45
|
|
|
ResponseInterface $response |
46
|
|
|
) |
47
|
|
|
{ |
48
|
|
|
$response->getStatusCode() |
49
|
|
|
->shouldBeCalled() |
50
|
|
|
->willReturn(302); |
51
|
|
|
|
52
|
|
|
$this->handle($request, $response)->shouldBe($response); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
function it_uses_inflector_to_determine_the_template_file_name( |
56
|
|
|
ServerRequestInterface $request, |
57
|
|
|
ResponseInterface $response, |
58
|
|
|
TemplateEngineInterface $templateEngine, |
59
|
|
|
ViewInflectorInterface $inflector, |
60
|
|
|
Route $route |
61
|
|
|
) { |
62
|
|
|
$request->getAttribute('viewData', []) |
63
|
|
|
->shouldBeCalled() |
64
|
|
|
->willReturn([]); |
65
|
|
|
$request->getAttribute('route') |
66
|
|
|
->shouldBeCalled() |
67
|
|
|
->willReturn($route); |
68
|
|
|
$inflector->inflect($route) |
69
|
|
|
->shouldBeCalled() |
70
|
|
|
->willReturn('test/file.twig'); |
71
|
|
|
$templateEngine->parse('test/file.twig') |
72
|
|
|
->shouldBeCalled() |
73
|
|
|
->willReturn($templateEngine); |
74
|
|
|
$templateEngine->process([]) |
75
|
|
|
->shouldBeCalled() |
76
|
|
|
->willReturn('Hello world!'); |
77
|
|
|
$response->getStatusCode()->willReturn(200); |
78
|
|
|
$response->withBody( |
|
|
|
|
79
|
|
|
Argument::that(function (Stream $argument) { |
80
|
|
|
$argument->rewind(); |
81
|
|
|
return $argument->getContents() === 'Hello world!'; |
82
|
|
|
}) |
83
|
|
|
) |
84
|
|
|
->shouldBeCalled() |
85
|
|
|
->willReturn($response); |
86
|
|
|
|
87
|
|
|
$this->handle($request, $response)->shouldBe($response); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.