-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLogMiddlewareTest.php
More file actions
46 lines (36 loc) · 1.48 KB
/
Copy pathLogMiddlewareTest.php
File metadata and controls
46 lines (36 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace PhpMiddlewareTest\LogHttpMessages;
use PhpMiddleware\LogHttpMessages\Formatter\EmptyMessageFormatter;
use PhpMiddleware\LogHttpMessages\LogMiddleware;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
class LogMiddlewareTest extends TestCase
{
/** @var LogMiddleware */
private $middleware;
/** @var LoggerInterface|MockObject */
private $logger;
private $handler;
protected function setUp(): void
{
$response = $this->createMock(ResponseInterface::class);
$this->handler = $this->createMock(RequestHandlerInterface::class);
$this->handler->method('handle')->willReturn($response);
$formatter = new EmptyMessageFormatter();
$this->logger = $this->createMock(LoggerInterface::class);
$this->middleware = new LogMiddleware($formatter, $formatter, $this->logger, LogLevel::ALERT);
}
public function testLogFormattedMessages()
{
/** @var ServerRequestInterface|MockObject $request */
$request = $this->createMock(ServerRequestInterface::class);
$this->logger->expects($this->once())->method('log')
->with(LogLevel::ALERT, LogMiddleware::LOG_MESSAGE, ['request' => null, 'response' => null]);
$this->middleware->process($request, $this->handler);
}
}