66use Illuminate \Contracts \Foundation \Application ;
77use LastDragon_ru \LaraASP \Documentator \Processor \Contracts \Container ;
88use LastDragon_ru \LaraASP \Documentator \Processor \Contracts \File ;
9- use LastDragon_ru \LaraASP \Documentator \Processor \Contracts \Resolver as ResolverContract ;
109use LastDragon_ru \LaraASP \Documentator \Processor \Contracts \Tasks \FileTask ;
1110use LastDragon_ru \LaraASP \Documentator \Processor \Contracts \Tasks \HookTask ;
1211use LastDragon_ru \LaraASP \Documentator \Processor \Dispatcher ;
13- use LastDragon_ru \LaraASP \Documentator \Processor \Executor \Resolver ;
1412use LastDragon_ru \LaraASP \Documentator \Processor \FileSystem \Adapters \SymfonyFileSystem ;
1513use LastDragon_ru \LaraASP \Documentator \Processor \FileSystem \FileSystem ;
1614use LastDragon_ru \LaraASP \Documentator \Processor \Hook ;
1715use LastDragon_ru \Path \DirectoryPath ;
1816use LastDragon_ru \Path \FilePath ;
1917use Mockery ;
2018use Override ;
19+ use PHPUnit \Framework \Attributes \After ;
2120use Symfony \Component \Finder \Finder ;
2221
2322use function array_first ;
23+ use function count ;
2424use function is_array ;
2525
2626/**
2727 * @phpstan-require-extends TestCase
2828 * @internal
2929 */
3030trait 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}
0 commit comments