Skip to content

Commit

Permalink
refactor(documentator)!: `\LastDragon_ru\LaraASP\Documentator\Process…
Browse files Browse the repository at this point in the history
…or\Tasks\Preprocess\Context` will contain `\LastDragon_ru\LaraASP\Documentator\Markdown\Document` and `\LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Reference\Block` instead of `$target` and `$parameters`.
  • Loading branch information
LastDragon-ru committed Nov 28, 2024
1 parent 5ac7b11 commit 8d4d60a
Show file tree
Hide file tree
Showing 17 changed files with 53 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\ReferencesInline;
use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\ReferencesPrefix;
use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\SelfLinksRemove;
use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Reference\Block;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File;

class Context {
public function __construct(
public readonly Directory $root,
public readonly File $file,
public readonly string $target,
public readonly ?string $parameters,
public readonly Document $document,
public readonly Block $node,
private readonly Mutation $mutation,
) {
// empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct(
$context,
sprintf(
'Artisan command `%s` failed (in `%s`).',
$context->target,
$context->node->getDestination(),
$context->root->getRelativePath($context->file),
),
$previous,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(
$context,
sprintf(
'Artisan command `%s` exited with status code `%s` (in `%s`).',
$context->target,
$context->node->getDestination(),
$this->result,
$context->root->getRelativePath($context->file),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
use LastDragon_ru\LaraASP\Core\Application\ApplicationResolver;
use LastDragon_ru\LaraASP\Core\Path\DirectoryPath;
use LastDragon_ru\LaraASP\Core\Path\FilePath;
use LastDragon_ru\LaraASP\Documentator\Markdown\Document;
use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Nop;
use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Reference\Block;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File;
use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Context;
Expand Down Expand Up @@ -36,7 +38,7 @@ public function testInvoke(): void {
$params = new Parameters('...');
$expected = 'result';
$command = 'command to execute';
$context = new Context($root, $file, $command, '{...}', new Nop());
$context = new Context($root, $file, new Document(''), new Block(), new Nop());
$instance = $this->app()->make(Instruction::class);

$this->override(Kernel::class, static function (MockInterface $mock) use ($command, $expected): void {
Expand Down Expand Up @@ -82,9 +84,15 @@ static function (InputInterface $input, OutputInterface $output) use ($expected)
public function testInvokeFailed(): void {
$root = new Directory((new DirectoryPath(__DIR__))->getNormalizedPath(), false);
$file = new File((new FilePath(__FILE__))->getNormalizedPath(), false);
$node = new class() extends Block {
#[Override]
public function getDestination(): string {
return 'command to execute';
}
};
$params = new Parameters('...');
$command = 'command to execute';
$context = new Context($root, $file, $command, '{...}', new Nop());
$command = $node->getDestination();
$context = new Context($root, $file, new Document(''), $node, new Nop());
$instance = $this->app()->make(Instruction::class);

$this->override(Kernel::class, static function (MockInterface $mock) use ($command): void {
Expand Down Expand Up @@ -140,7 +148,7 @@ public function testGetCommand(): void {
$file = new File((new FilePath(__FILE__))->getNormalizedPath(), false);
$params = new Parameters('...');
$command = 'artisan:command $directory {$directory} "{$directory}" $file {$file} "{$file}"';
$context = new Context($root, $file, $command, '{...}', new Nop());
$context = new Context($root, $file, new Document(''), new Block(), new Nop());
$instance = new class (Mockery::mock(ApplicationResolver::class)) extends Instruction {
#[Override]
public function getCommand(Context $context, string $target, Parameters $parameters): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(Context $context, ?Throwable $previous = null) {
$context,
sprintf(
'The `%s` is not a valid PHP file (in `%s`).',
$context->target,
$context->node->getDestination(),
$context->root->getRelativePath($context->file),
),
$previous,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use LastDragon_ru\LaraASP\Core\Path\FilePath;
use LastDragon_ru\LaraASP\Documentator\Markdown\Document;
use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Nop;
use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Reference\Block;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File;
use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Context;
Expand Down Expand Up @@ -34,7 +35,7 @@ public function testInvoke(Closure|string $expected, string $file, Parameters $p
$root = new Directory($path->getDirectoryPath(), false);
$file = new File($path, false);
$target = $file->getName();
$context = new Context($root, $file, $target, null, new Nop());
$context = new Context($root, $file, new Document(''), new Block(), new Nop());
$instance = $this->app()->make(Instruction::class);

if ($expected instanceof Closure) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Instructions\IncludeDocumentList;

use LastDragon_ru\LaraASP\Core\Path\FilePath;
use LastDragon_ru\LaraASP\Documentator\Markdown\Document;
use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Nop;
use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Reference\Block;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File;
use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Context;
Expand All @@ -25,7 +27,7 @@ public function testInvokeSameDirectory(): void {
$file = new File($path, false);
$params = new Parameters('...');
$target = './';
$context = new Context($root, $file, $target, '{...}', new Nop());
$context = new Context($root, $file, new Document(''), new Block(), new Nop());
$instance = $this->app()->make(Instruction::class);
$actual = ProcessorHelper::runInstruction($instance, $context, $target, $params);

Expand All @@ -45,7 +47,7 @@ public function testInvokeAnotherDirectory(): void {
$file = new File($path, false);
$params = new Parameters('...');
$target = basename(self::getTestData()->path('/'));
$context = new Context($root, $file, $target, '', new Nop());
$context = new Context($root, $file, new Document(''), new Block(), new Nop());

$instance = $this->app()->make(Instruction::class);
$actual = ProcessorHelper::runInstruction($instance, $context, $target, $params);
Expand All @@ -66,7 +68,7 @@ public function testInvokeNestedDirectories(): void {
$file = new File($path, false);
$params = new Parameters('...', null, order: SortOrder::Desc);
$target = './';
$context = new Context($root, $file, $target, '', new Nop());
$context = new Context($root, $file, new Document(''), new Block(), new Nop());
$instance = $this->app()->make(Instruction::class);
$actual = ProcessorHelper::runInstruction($instance, $context, $target, $params);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Instructions\IncludeExample;

use LastDragon_ru\LaraASP\Core\Path\FilePath;
use LastDragon_ru\LaraASP\Documentator\Markdown\Document;
use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Nop;
use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Reference\Block;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File;
use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Context;
Expand Down Expand Up @@ -32,7 +34,7 @@ public function testInvoke(string $expected, string $output): void {
$file = new File($path, false);
$params = new Parameters('...');
$target = self::getTestData()->path('Example.md');
$context = new Context($root, $file, $target, '{...}', new Nop());
$context = new Context($root, $file, new Document(''), new Block(), new Nop());

$this->override(Runner::class, static function (MockInterface $mock) use ($target, $output): void {
$mock
Expand All @@ -58,7 +60,7 @@ public function testInvokeNoRun(): void {
$file = new File($path, false);
$params = new Parameters('...');
$target = $file->getName();
$context = new Context($root, $file, $target, '{...}', new Nop());
$context = new Context($root, $file, new Document(''), new Block(), new Nop());
$expected = trim($file->getContent());
$instance = $this->app()->make(Instruction::class);
$actual = ProcessorHelper::runInstruction($instance, $context, $target, $params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(Context $context, ?Throwable $previous = null) {
$context,
sprintf(
'Failed to execute the `%s` command (in `%s`).',
$context->target,
$context->node->getDestination(),
$context->root->getRelativePath($context->file),
),
$previous,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
use Illuminate\Process\PendingProcess;
use LastDragon_ru\LaraASP\Core\Path\DirectoryPath;
use LastDragon_ru\LaraASP\Core\Path\FilePath;
use LastDragon_ru\LaraASP\Documentator\Markdown\Document;
use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Nop;
use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Reference\Block;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File;
use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Context;
Expand All @@ -25,7 +27,7 @@ public function testInvoke(): void {
$params = new Parameters('...');
$expected = 'result';
$command = 'command to execute';
$context = new Context($root, $file, $command, '{...}', new Nop());
$context = new Context($root, $file, new Document(''), new Block(), new Nop());
$factory = $this->override(Factory::class, function () use ($command, $expected): Factory {
$factory = $this->app()->make(Factory::class);
$factory->preventStrayProcesses();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use LastDragon_ru\LaraASP\Core\Path\FilePath;
use LastDragon_ru\LaraASP\Documentator\Markdown\Document;
use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Nop;
use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Reference\Block;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File;
use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Context;
Expand All @@ -31,7 +32,7 @@ public function testInvoke(string $expected, string $source): void {
$file = new File((new FilePath(__FILE__))->getNormalizedPath(), false);
$params = new Parameters('...');
$target = self::getTestData()->path($source);
$context = new Context($root, $file, $target, '{...}', new Nop());
$context = new Context($root, $file, new Document(''), new Block(), new Nop());
$instance = $this->app()->make(Instruction::class);
$expected = self::getTestData()->content($expected);
$actual = ProcessorHelper::runInstruction($instance, $context, $target, $params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(Context $context, ?Throwable $previous = null) {
$context,
sprintf(
'The `%s` is not a directive (in `%s`).',
$context->target,
$context->node->getDestination(),
$context->root->getRelativePath($context->file),
),
$previous,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
use GraphQL\Language\Parser;
use LastDragon_ru\LaraASP\Core\Path\DirectoryPath;
use LastDragon_ru\LaraASP\Core\Path\FilePath;
use LastDragon_ru\LaraASP\Documentator\Markdown\Document;
use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Nop;
use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Reference\Block;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File;
use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Context;
Expand Down Expand Up @@ -52,7 +54,7 @@ public function testInvoke(): void {
$file = Mockery::mock(File::class);
$params = new Parameters('...');
$target = '@test';
$context = new Context($root, $file, $target, '{...}', new Nop());
$context = new Context($root, $file, new Document(''), new Block(), new Nop());
$instance = $this->app()->make(Instruction::class);
$actual = ProcessorHelper::runInstruction($instance, $context, $target, $params);

Expand All @@ -79,7 +81,7 @@ public function testInvokeNoPrinter(): void {
$file = new File((new FilePath(__FILE__))->getNormalizedPath(), false);
$params = new Parameters('...');
$target = '@test';
$context = new Context($root, $file, $target, '{...}', new Nop());
$context = new Context($root, $file, new Document(''), new Block(), new Nop());
$instance = $this->app()->make(Instruction::class);

self::expectExceptionObject(
Expand Down Expand Up @@ -107,7 +109,7 @@ public function testInvokeNoDirective(): void {
$file = new File((new FilePath(__FILE__))->getNormalizedPath(), false);
$params = new Parameters('...');
$target = '@test';
$context = new Context($root, $file, $target, '{...}', new Nop());
$context = new Context($root, $file, new Document(''), new Block(), new Nop());
$instance = $this->app()->make(Instruction::class);

self::expectExceptionObject(
Expand All @@ -126,7 +128,7 @@ public function testInvokeNoDirectiveResolver(): void {
$file = new File((new FilePath(__FILE__))->getNormalizedPath(), false);
$params = new Parameters('...');
$target = '@test';
$context = new Context($root, $file, $target, '{...}', new Nop());
$context = new Context($root, $file, new Document(''), new Block(), new Nop());
$instance = $this->app()->make(Instruction::class);

self::expectExceptionObject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Instructions\IncludePackageList;

use LastDragon_ru\LaraASP\Core\Path\FilePath;
use LastDragon_ru\LaraASP\Documentator\Markdown\Document;
use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Nop;
use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Reference\Block;
use LastDragon_ru\LaraASP\Documentator\Processor\Dependencies\FileReference;
use LastDragon_ru\LaraASP\Documentator\Processor\Exceptions\DependencyNotFound;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory;
Expand Down Expand Up @@ -31,7 +33,7 @@ public function testInvoke(string $expected, string $template, SortOrder $order)
$file = new File($path, false);
$target = $root->getDirectoryPath('packages');
$params = new Parameters('...', template: $template, order: $order);
$context = new Context($root, $file, (string) $target, '{...}', new Nop());
$context = new Context($root, $file, new Document(''), new Block(), new Nop());
$instance = $this->app()->make(Instruction::class);
$actual = ProcessorHelper::runInstruction($instance, $context, $target, $params);

Expand All @@ -52,7 +54,7 @@ public function testInvokeNoReadme(): void {
$file = new File($path, false);
$target = $root->getDirectoryPath('no readme');
$params = new Parameters('...');
$context = new Context($root, $file, (string) $target, '{...}', new Nop());
$context = new Context($root, $file, new Document(''), new Block(), new Nop());
$instance = $this->app()->make(Instruction::class);
$package = $fs->getDirectory(new Directory($target, false), 'package');

Expand All @@ -71,7 +73,7 @@ public function testInvokeEmptyReadme(): void {
$file = new File($path, false);
$target = $root->getDirectoryPath('empty readme');
$params = new Parameters('...');
$context = new Context($root, $file, (string) $target, '{...}', new Nop());
$context = new Context($root, $file, new Document(''), new Block(), new Nop());
$instance = $this->app()->make(Instruction::class);
$package = $fs->getDirectory(new Directory($target, false), 'package');
$expected = $fs->getFile($root, 'empty readme/package/README.md');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use LastDragon_ru\LaraASP\Core\Path\FilePath;
use LastDragon_ru\LaraASP\Documentator\Markdown\Document;
use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Nop;
use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Reference\Block;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File;
use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Context;
Expand Down Expand Up @@ -37,7 +38,7 @@ public function testInvoke(string $expected, string $source, array $data): void
$file = new File((new FilePath(__FILE__))->getNormalizedPath(), false);
$params = new Parameters('...', $data);
$target = self::getTestData()->path($source);
$context = new Context($root, $file, $target, '{...}', new Nop());
$context = new Context($root, $file, new Document(''), new Block(), new Nop());
$instance = $this->app()->make(Instruction::class);
$expected = self::getTestData()->content($expected);
$actual = ProcessorHelper::runInstruction($instance, $context, $target, $params);
Expand All @@ -56,7 +57,7 @@ public function testInvokeNoData(): void {
$file = new File((new FilePath(__FILE__))->getNormalizedPath(), false);
$params = new Parameters('...', []);
$target = $file->getPath();
$context = new Context($root, $file, (string) $target, '{...}', new Nop());
$context = new Context($root, $file, new Document(''), new Block(), new Nop());
$instance = $this->app()->make(Instruction::class);

self::expectExceptionObject(
Expand All @@ -77,7 +78,7 @@ public function testInvokeVariablesUnused(): void {
'd' => 'D',
]);
$target = $file->getPath();
$context = new Context($root, $file, (string) $target, '{...}', new Nop());
$context = new Context($root, $file, new Document(''), new Block(), new Nop());
$instance = $this->app()->make(Instruction::class);

self::expectExceptionObject(
Expand All @@ -95,7 +96,7 @@ public function testInvokeVariablesMissed(): void {
'a' => 'A',
]);
$target = $file->getPath();
$context = new Context($root, $file, (string) $target, '{...}', new Nop());
$context = new Context($root, $file, new Document(''), new Block(), new Nop());
$instance = $this->app()->make(Instruction::class);

self::expectExceptionObject(
Expand Down
Loading

0 comments on commit 8d4d60a

Please sign in to comment.