Skip to content

Commit 3ef741c

Browse files
lacatoirejaapio
authored andcommitted
Add ParseDirectoryHandler integration test for exclusion dispatch
1 parent 8556879 commit 3ef741c

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link https://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Guides\Handlers;
15+
16+
use Doctrine\Deprecations\Deprecation;
17+
use Flyfinder\Path;
18+
use Flyfinder\Specification\InPath;
19+
use League\Tactician\CommandBus;
20+
use phpDocumentor\FileSystem\FileSystem;
21+
use phpDocumentor\FileSystem\Finder\Exclude;
22+
use phpDocumentor\Guides\FileCollector;
23+
use phpDocumentor\Guides\Nodes\ProjectNode;
24+
use PHPUnit\Framework\TestCase;
25+
use Psr\EventDispatcher\EventDispatcherInterface;
26+
27+
final class ParseDirectoryHandlerTest extends TestCase
28+
{
29+
public function testHandlerForwardsExcludeToCollectorWithoutTriggeringSpecificationDeprecation(): void
30+
{
31+
$command = $this->createCommand(new Exclude(['/excluded']));
32+
$handler = $this->createHandler();
33+
34+
$before = Deprecation::getUniqueTriggeredDeprecationsCount();
35+
36+
$handler->handle($command);
37+
38+
self::assertSame($before, Deprecation::getUniqueTriggeredDeprecationsCount());
39+
}
40+
41+
public function testHandlerDoesNotTriggerDeprecationWhenNoExclusionIsConfigured(): void
42+
{
43+
$command = $this->createCommand();
44+
$handler = $this->createHandler();
45+
46+
$before = Deprecation::getUniqueTriggeredDeprecationsCount();
47+
48+
$handler->handle($command);
49+
50+
self::assertSame($before, Deprecation::getUniqueTriggeredDeprecationsCount());
51+
}
52+
53+
public function testHandlerForwardsLegacySpecificationWithoutFiringExtraDeprecation(): void
54+
{
55+
$command = $this->createCommand(new InPath(new Path('docs')));
56+
$handler = $this->createHandler();
57+
58+
$before = Deprecation::getUniqueTriggeredDeprecationsCount();
59+
60+
$handler->handle($command);
61+
62+
self::assertSame(
63+
$before,
64+
Deprecation::getUniqueTriggeredDeprecationsCount(),
65+
'Internal handler dispatch must not re-fire the deprecation already raised at construction.',
66+
);
67+
}
68+
69+
private function createCommand(Exclude|InPath|null $exclusion = null): ParseDirectoryCommand
70+
{
71+
$filesystem = $this->createMock(FileSystem::class);
72+
$filesystem->method('listContents')->willReturn([['basename' => 'index.rst']]);
73+
$filesystem->method('find')->willReturn([]);
74+
75+
return new ParseDirectoryCommand(
76+
$filesystem,
77+
'',
78+
'rst',
79+
new ProjectNode(),
80+
$exclusion,
81+
);
82+
}
83+
84+
private function createHandler(): ParseDirectoryHandler
85+
{
86+
$eventDispatcher = $this->createMock(EventDispatcherInterface::class);
87+
$eventDispatcher->method('dispatch')->willReturnCallback(
88+
static fn (object $event): object => $event,
89+
);
90+
91+
return new ParseDirectoryHandler(
92+
new FileCollector(),
93+
$this->createMock(CommandBus::class),
94+
$eventDispatcher,
95+
);
96+
}
97+
}

0 commit comments

Comments
 (0)