|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * Fast Forward Development Tools for PHP projects. |
| 7 | + * |
| 8 | + * This file is part of fast-forward/dev-tools project. |
| 9 | + * |
| 10 | + * @author Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 11 | + * @license https://opensource.org/licenses/MIT MIT License |
| 12 | + * |
| 13 | + * @see https://github.com/php-fast-forward/ |
| 14 | + * @see https://github.com/php-fast-forward/dev-tools |
| 15 | + * @see https://github.com/php-fast-forward/dev-tools/issues |
| 16 | + * @see https://php-fast-forward.github.io/dev-tools/ |
| 17 | + * @see https://datatracker.ietf.org/doc/html/rfc2119 |
| 18 | + */ |
| 19 | + |
| 20 | +namespace FastForward\DevTools\Tests\Reflection; |
| 21 | + |
| 22 | +use FastForward\DevTools\Console\Command\SelfUpdateCommand; |
| 23 | +use FastForward\DevTools\Reflection\ClassReflection; |
| 24 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 25 | +use PHPUnit\Framework\Attributes\Test; |
| 26 | +use PHPUnit\Framework\TestCase; |
| 27 | +use Symfony\Component\Console\Attribute\AsCommand; |
| 28 | +use Symfony\Component\Console\Command\Command; |
| 29 | + |
| 30 | +#[CoversClass(ClassReflection::class)] |
| 31 | +final class ClassReflectionTest extends TestCase |
| 32 | +{ |
| 33 | + /** |
| 34 | + * @return void |
| 35 | + */ |
| 36 | + #[Test] |
| 37 | + public function isInstantiableSubclassOfWillReturnTrueForMatchingClass(): void |
| 38 | + { |
| 39 | + self::assertTrue(ClassReflection::isInstantiableSubclassOf(SelfUpdateCommand::class, Command::class)); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * @return void |
| 44 | + */ |
| 45 | + #[Test] |
| 46 | + public function isInstantiableSubclassOfWillReturnFalseForNonMatchingClass(): void |
| 47 | + { |
| 48 | + self::assertFalse(ClassReflection::isInstantiableSubclassOf(self::class, Command::class)); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @return void |
| 53 | + */ |
| 54 | + #[Test] |
| 55 | + public function getAttributeArgumentsWillReturnArgumentsForMatchingAttribute(): void |
| 56 | + { |
| 57 | + self::assertSame([ |
| 58 | + 'name' => 'dev-tools:self-update', |
| 59 | + 'description' => 'Updates the installed fast-forward/dev-tools package.', |
| 60 | + 'aliases' => ['self-update', 'selfupdate'], |
| 61 | + 'hidden' => false, |
| 62 | + 'help' => null, |
| 63 | + 'usages' => [], |
| 64 | + ], ClassReflection::getAttributeArguments(SelfUpdateCommand::class, AsCommand::class)); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @return void |
| 69 | + */ |
| 70 | + #[Test] |
| 71 | + public function getAttributeArgumentsWillReturnNullWhenAttributeDoesNotExist(): void |
| 72 | + { |
| 73 | + self::assertNull(ClassReflection::getAttributeArguments(self::class, AsCommand::class)); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * @return void |
| 78 | + */ |
| 79 | + #[Test] |
| 80 | + public function getAttributeArgumentsWillNormalizePositionalArguments(): void |
| 81 | + { |
| 82 | + self::assertSame([ |
| 83 | + 'name' => 'fixture', |
| 84 | + 'description' => 'Fixture command.', |
| 85 | + 'aliases' => ['alias'], |
| 86 | + 'hidden' => false, |
| 87 | + 'help' => null, |
| 88 | + 'usages' => [], |
| 89 | + ], ClassReflection::getAttributeArguments(FixtureCommandWithPositionalAttribute::class, AsCommand::class)); |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +#[AsCommand('fixture', 'Fixture command.', ['alias'])] |
| 94 | +final class FixtureCommandWithPositionalAttribute extends Command {} |
0 commit comments