Completed
Push — develop ( 521632...eb9c4a )
by Mike
06:46
created

testThatParsingStartIsLogged()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
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
Unused Code introduced by
The parameter $receivedCommand is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
60
                throw new \Exception('this is a test');
61
            }
62
        );
63
64
        $this->assertNull($result);
65
    }
66
}
67