These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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(LogLevel::ALERT, ' Unable to parse file "' . __FILE__ . '", an error was detected: this is a test', [])->shouldBeCalled(); |
||
55 | |||
56 | $middleware = new ErrorHandlingMiddleware($logger->reveal()); |
||
57 | $result = $middleware->execute( |
||
58 | $command, |
||
59 | function(CreateCommand $receivedCommand) use ($command) { |
||
0 ignored issues
–
show
|
|||
60 | throw new \Exception('this is a test'); |
||
61 | } |
||
62 | ); |
||
63 | |||
64 | $this->assertNull($result); |
||
65 | } |
||
66 | } |
||
67 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.