1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Parser\Middleware; |
4
|
|
|
|
5
|
|
|
use phpDocumentor\Parser\Middleware\ErrorHandlingMiddleware; |
6
|
|
|
use phpDocumentor\Reflection\File\LocalFile; |
7
|
|
|
use phpDocumentor\Reflection\Php\Factory\File\CreateCommand; |
8
|
|
|
use phpDocumentor\Reflection\Php\ProjectFactoryStrategies; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
use Psr\Log\LoggerInterface; |
11
|
|
|
use Psr\Log\LogLevel; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @coversDefaultClass \phpDocumentor\Parser\Middleware\ErrorHandlingMiddleware |
15
|
|
|
* @covers ::<private> |
16
|
|
|
* @covers ::__construct |
17
|
|
|
*/ |
18
|
|
|
final class ErrorHandlingMiddlewareTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @covers ::execute |
22
|
|
|
*/ |
23
|
|
|
public function testThatParsingStartIsLogged() |
24
|
|
|
{ |
25
|
|
|
$filename = __FILE__; |
26
|
|
|
$command = new CreateCommand(new LocalFile($filename), new ProjectFactoryStrategies([])); |
27
|
|
|
|
28
|
|
|
$logger = $this->prophesize(LoggerInterface::class); |
29
|
|
|
$logger->log(LogLevel::INFO, 'Starting to parse file: ' . __FILE__, [])->shouldBeCalled(); |
30
|
|
|
|
31
|
|
|
$middleware = new ErrorHandlingMiddleware($logger->reveal()); |
32
|
|
|
$result = $middleware->execute( |
33
|
|
|
$command, |
34
|
|
|
function (CreateCommand $receivedCommand) use ($command) { |
35
|
|
|
$this->assertSame($command, $receivedCommand); |
36
|
|
|
|
37
|
|
|
return 'result'; |
38
|
|
|
} |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
$this->assertSame('result', $result); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @covers ::execute |
46
|
|
|
*/ |
47
|
|
|
public function testThatAnErrorIsLogged() |
48
|
|
|
{ |
49
|
|
|
$filename = __FILE__; |
50
|
|
|
$command = new CreateCommand(new LocalFile($filename), new ProjectFactoryStrategies([])); |
51
|
|
|
|
52
|
|
|
$logger = $this->prophesize(LoggerInterface::class); |
53
|
|
|
$logger->log(LogLevel::INFO, 'Starting to parse file: ' . __FILE__, [])->shouldBeCalled(); |
54
|
|
|
$logger->log( |
55
|
|
|
LogLevel::ALERT, |
56
|
|
|
' Unable to parse file "' . __FILE__ . '", an error was detected: this is a test', |
57
|
|
|
[] |
58
|
|
|
)->shouldBeCalled(); |
59
|
|
|
|
60
|
|
|
$middleware = new ErrorHandlingMiddleware($logger->reveal()); |
61
|
|
|
$result = $middleware->execute( |
62
|
|
|
$command, |
63
|
|
|
function (CreateCommand $receivedCommand) use ($command) { |
|
|
|
|
64
|
|
|
throw new \Exception('this is a test'); |
65
|
|
|
} |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
$this->assertNull($result); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.