-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(documentator): Fetching instruction parameters via Reflection AP…
…I/PhpDoc (#149).
- Loading branch information
Showing
14 changed files
with
325 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace LastDragon_ru\LaraASP\Documentator\Commands; | ||
|
||
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Contracts\ParameterizableInstruction; | ||
use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; | ||
use LastDragon_ru\LaraASP\Serializer\Contracts\Serializable; | ||
use Override; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[CoversClass(Preprocess::class)] | ||
final class PreprocessTest extends TestCase { | ||
public function testGetInstructionParameters(): void { | ||
$command = new class() extends Preprocess { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
#[Override] | ||
public function getInstructionParameters(string $instruction): array { | ||
return parent::getInstructionParameters($instruction); | ||
} | ||
}; | ||
|
||
self::assertEquals( | ||
[ | ||
'publicPropertyWithoutDefaultValue: int' => 'Description.', | ||
'publicPropertyWithDefaultValue: float = 123.0' => '_No description provided_.', | ||
'publicPromotedPropertyWithoutDefaultValue: int' => 'Description.', | ||
'publicPromotedPropertyWithDefaultValue: int = 321' => '_No description provided_.', | ||
], | ||
$command->getInstructionParameters( | ||
PreprocessTest__ParameterizableInstruction::class, | ||
), | ||
); | ||
} | ||
} | ||
|
||
// @phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses | ||
// @phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps | ||
|
||
/** | ||
* @internal | ||
* @noinspection PhpMultipleClassesDeclarationsInOneFile | ||
* | ||
* @implements ParameterizableInstruction<PreprocessTest__ParameterizableInstructionParameters> | ||
*/ | ||
class PreprocessTest__ParameterizableInstruction implements ParameterizableInstruction { | ||
#[Override] | ||
public static function getName(): string { | ||
return 'test:parameterizable-instruction'; | ||
} | ||
|
||
#[Override] | ||
public static function getDescription(): string { | ||
return 'Description description description description description.'; | ||
} | ||
|
||
#[Override] | ||
public static function getTargetDescription(): ?string { | ||
return 'Target target target target target.'; | ||
} | ||
|
||
#[Override] | ||
public static function getParameters(): string { | ||
return PreprocessTest__ParameterizableInstructionParameters::class; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
#[Override] | ||
public static function getParametersDescription(): array { | ||
return []; | ||
} | ||
|
||
#[Override] | ||
public function process(string $path, string $target, Serializable $parameters): string { | ||
return $path; | ||
} | ||
} | ||
|
||
/** | ||
* @internal | ||
* @noinspection PhpMultipleClassesDeclarationsInOneFile | ||
*/ | ||
class PreprocessTest__ParameterizableInstructionParameters implements Serializable { | ||
public static bool $publicStaticProperty = true; | ||
|
||
/** | ||
* Description. | ||
*/ | ||
public int $publicPropertyWithoutDefaultValue; | ||
public float $publicPropertyWithDefaultValue = 123; | ||
|
||
public function __construct( | ||
/** | ||
* Description. | ||
*/ | ||
public int $publicPromotedPropertyWithoutDefaultValue, | ||
public int $publicPromotedPropertyWithDefaultValue = 321, | ||
protected bool $protectedProperty = true, | ||
protected bool $privateProperty = true, | ||
) { | ||
$this->publicPropertyWithoutDefaultValue = 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.