Skip to content

Commit 7fa0619

Browse files
committed
test(lara-asp-documentator/Processor): \LastDragon_ru\LaraASP\Documentator\Package\WithProcessor assertions to check resolved paths and better arguments order for \LastDragon_ru\LaraASP\Documentator\Package\WithProcessor::runProcessorHookTask() (the $hook moved to the end).
1 parent bd62862 commit 7fa0619

2 files changed

Lines changed: 132 additions & 21 deletions

File tree

packages/lara-asp-documentator/src/Package/WithProcessor.php

Lines changed: 79 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,37 @@
66
use Illuminate\Contracts\Foundation\Application;
77
use LastDragon_ru\LaraASP\Documentator\Processor\Contracts\Container;
88
use LastDragon_ru\LaraASP\Documentator\Processor\Contracts\File;
9-
use LastDragon_ru\LaraASP\Documentator\Processor\Contracts\Resolver as ResolverContract;
109
use LastDragon_ru\LaraASP\Documentator\Processor\Contracts\Tasks\FileTask;
1110
use LastDragon_ru\LaraASP\Documentator\Processor\Contracts\Tasks\HookTask;
1211
use LastDragon_ru\LaraASP\Documentator\Processor\Dispatcher;
13-
use LastDragon_ru\LaraASP\Documentator\Processor\Executor\Resolver;
1412
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Adapters\SymfonyFileSystem;
1513
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\FileSystem;
1614
use LastDragon_ru\LaraASP\Documentator\Processor\Hook;
1715
use LastDragon_ru\Path\DirectoryPath;
1816
use LastDragon_ru\Path\FilePath;
1917
use Mockery;
2018
use Override;
19+
use PHPUnit\Framework\Attributes\After;
2120
use Symfony\Component\Finder\Finder;
2221

2322
use function array_first;
23+
use function count;
2424
use function is_array;
2525

2626
/**
2727
* @phpstan-require-extends TestCase
2828
* @internal
2929
*/
3030
trait WithProcessor {
31+
private ?WithProcessorResolver $withProcessorResolver = null;
32+
3133
abstract protected function app(): Application;
3234

35+
#[After]
36+
protected function withProcessorAfter(): void {
37+
$this->withProcessorResolver = null;
38+
}
39+
3340
protected function getFileSystem(
3441
DirectoryPath|string $input,
3542
DirectoryPath|string|null $output = null,
@@ -64,8 +71,8 @@ public function write(FilePath $path, string $content): void {
6471
protected function runProcessorHookTask(
6572
HookTask $task,
6673
FileSystem $fs,
67-
?Hook $hook = null,
6874
?File $file = null,
75+
?Hook $hook = null,
6976
): void {
7077
$file ??= Mockery::mock(File::class);
7178
$hook ??= $task::hook();
@@ -78,24 +85,75 @@ protected function runProcessorFileTask(FileTask $task, FileSystem $fs, File $fi
7885
$task($this->getProcessorResolver($fs), $file);
7986
}
8087

81-
protected function getProcessorResolver(FileSystem $filesystem): ResolverContract {
82-
$dispatcher = new Dispatcher(null);
83-
$container = $this->app()->make(Container::class);
84-
$callback = static function (): void {
85-
// empty
86-
};
87-
$resolver = new class(
88-
$container,
89-
$dispatcher,
90-
$filesystem,
91-
$callback,
92-
$callback,
93-
$callback,
94-
$callback,
95-
) extends Resolver {
96-
// empty
97-
};
88+
private function getProcessorResolver(FileSystem $filesystem): WithProcessorResolver {
89+
$dispatcher = new Dispatcher(null);
90+
$container = $this->app()->make(Container::class);
91+
$this->withProcessorResolver = new WithProcessorResolver($container, $dispatcher, $filesystem);
92+
93+
return $this->withProcessorResolver;
94+
}
95+
96+
protected function assertProcessorResolvedPathsCount(int $count): void {
97+
self::assertSame(
98+
$count,
99+
$this->withProcessorResolver !== null
100+
? count($this->withProcessorResolver->resolved)
101+
: null,
102+
);
103+
}
104+
105+
/**
106+
* @param list<FilePath> $paths
107+
*/
108+
protected function assertProcessorResolvedPaths(array $paths): void {
109+
self::assertEquals($paths, $this->withProcessorResolver->resolved ?? null);
110+
}
111+
112+
protected function assertProcessorSavedPathsCount(int $count): void {
113+
self::assertSame(
114+
$count,
115+
$this->withProcessorResolver !== null
116+
? count($this->withProcessorResolver->saved)
117+
: null,
118+
);
119+
}
120+
121+
/**
122+
* @param list<FilePath> $paths
123+
*/
124+
protected function assertProcessorSavedPaths(array $paths): void {
125+
self::assertEquals($paths, $this->withProcessorResolver->saved ?? null);
126+
}
127+
128+
protected function assertProcessorQueuedPathsCount(int $count): void {
129+
self::assertSame(
130+
$count,
131+
$this->withProcessorResolver !== null
132+
? count($this->withProcessorResolver->queued)
133+
: null,
134+
);
135+
}
136+
137+
/**
138+
* @param list<FilePath> $paths
139+
*/
140+
protected function assertProcessorQueuedPaths(array $paths): void {
141+
self::assertEquals($paths, $this->withProcessorResolver->queued ?? null);
142+
}
143+
144+
protected function assertProcessorDeletedPathsCount(int $count): void {
145+
self::assertSame(
146+
$count,
147+
$this->withProcessorResolver !== null
148+
? count($this->withProcessorResolver->deleted)
149+
: null,
150+
);
151+
}
98152

99-
return $resolver;
153+
/**
154+
* @param list<DirectoryPath|FilePath> $paths
155+
*/
156+
protected function assertProcessorDeletedPaths(array $paths): void {
157+
self::assertEquals($paths, $this->withProcessorResolver->deleted ?? null);
100158
}
101159
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace LastDragon_ru\LaraASP\Documentator\Package;
4+
5+
use LastDragon_ru\LaraASP\Documentator\Processor\Contracts\Container;
6+
use LastDragon_ru\LaraASP\Documentator\Processor\Contracts\File;
7+
use LastDragon_ru\LaraASP\Documentator\Processor\Dispatcher;
8+
use LastDragon_ru\LaraASP\Documentator\Processor\Executor\Resolver;
9+
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\FileSystem;
10+
use LastDragon_ru\Path\DirectoryPath;
11+
use LastDragon_ru\Path\FilePath;
12+
13+
/**
14+
* @internal
15+
*/
16+
class WithProcessorResolver extends Resolver {
17+
/**
18+
* @var list<FilePath>
19+
*/
20+
public array $resolved = [];
21+
/**
22+
* @var list<FilePath>
23+
*/
24+
public array $saved = [];
25+
/**
26+
* @var list<FilePath>
27+
*/
28+
public array $queued = [];
29+
/**
30+
* @var list<DirectoryPath|FilePath>
31+
*/
32+
public array $deleted = [];
33+
34+
public function __construct(Container $container, Dispatcher $dispatcher, FileSystem $fs) {
35+
parent::__construct(
36+
$container,
37+
$dispatcher,
38+
$fs,
39+
function (File $file): void {
40+
$this->resolved[] = $file->path;
41+
},
42+
function (File $file): void {
43+
$this->saved[] = $file->path;
44+
},
45+
function (File $file): void {
46+
$this->queued[] = $file->path;
47+
},
48+
function (DirectoryPath|FilePath $path): void {
49+
$this->deleted[] = $path;
50+
},
51+
);
52+
}
53+
}

0 commit comments

Comments
 (0)