1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* This file is part of phpDocumentor. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @copyright 2010-2018 Mike van Riel<[email protected]> |
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
10
|
|
|
* @link http://phpdoc.org |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace phpDocumentor\Parser\Middleware; |
14
|
|
|
|
15
|
|
|
use phpDocumentor\Event\Dispatcher; |
16
|
|
|
use phpDocumentor\Parser\Event\PreFileEvent; |
17
|
|
|
use phpDocumentor\Reflection\File\LocalFile; |
18
|
|
|
use phpDocumentor\Reflection\Php\Factory\File\CreateCommand; |
19
|
|
|
use phpDocumentor\Reflection\Php\ProjectFactoryStrategies; |
20
|
|
|
use PHPUnit\Framework\TestCase; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @coversDefaultClass \phpDocumentor\Parser\Middleware\EmittingMiddleware |
24
|
|
|
* @covers ::<private> |
25
|
|
|
*/ |
26
|
|
|
final class EmittingMiddlewareTest extends TestCase |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @covers ::execute |
30
|
|
|
*/ |
31
|
|
|
public function testEmitsPreParsingEvent() |
32
|
|
|
{ |
33
|
|
|
$filename = __FILE__; |
34
|
|
|
$command = new CreateCommand(new LocalFile($filename), new ProjectFactoryStrategies([])); |
35
|
|
|
|
36
|
|
|
Dispatcher::getInstance()->addListener( |
37
|
|
|
'parser.file.pre', |
38
|
|
|
function(PreFileEvent $event) use ($filename) { |
39
|
|
|
$this->assertSame($event->getFile(), $filename); |
40
|
|
|
} |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
$middleware = new EmittingMiddleware(); |
44
|
|
|
$result = $middleware->execute( |
45
|
|
|
$command, |
46
|
|
|
function(CreateCommand $receivedCommand) use ($command) { |
47
|
|
|
$this->assertSame($command, $receivedCommand); |
48
|
|
|
|
49
|
|
|
return 'result'; |
50
|
|
|
} |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
$this->assertSame('result', $result); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|