Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Tools/Console/Command/MappingDescribeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Doctrine\ORM\Mapping\FieldMapping;
use Doctrine\Persistence\Mapping\MappingException;
use InvalidArgumentException;
use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -19,6 +21,7 @@
use function array_filter;
use function array_map;
use function array_merge;
use function array_values;
use function count;
use function current;
use function get_debug_type;
Expand All @@ -32,6 +35,7 @@
use function preg_quote;
use function print_r;
use function sprintf;
use function str_replace;

use const JSON_PRETTY_PRINT;
use const JSON_THROW_ON_ERROR;
Expand Down Expand Up @@ -73,6 +77,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
{
if ($input->mustSuggestArgumentValuesFor('entityName')) {
$entityManager = $this->getEntityManager($input);

$entities = array_map(
static fn (string $fqcn) => str_replace('\\', '\\\\', $fqcn),
$this->getMappedEntities($entityManager),
);

$suggestions->suggestValues(array_values($entities));
}
}

/**
* Display all the mapping information for a single Entity.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
use Doctrine\Tests\OrmFunctionalTestCase;
use InvalidArgumentException;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandCompletionTester;
use Symfony\Component\Console\Tester\CommandTester;

/**
Expand Down Expand Up @@ -77,4 +79,37 @@ public function testShowSpecificNotFound(): void
],
);
}

/**
* @param string[] $input
* @param string[] $expectedSuggestions
*/
#[DataProvider('provideCompletionSuggestions')]
public function testComplete(array $input, array $expectedSuggestions): void
{
$this->useModelSet('cache');

parent::setUp();

$completionTester = new CommandCompletionTester(new MappingDescribeCommand(new SingleManagerProvider($this->_em)));

$suggestions = $completionTester->complete($input);

foreach ($expectedSuggestions as $expected) {
self::assertContains($expected, $suggestions);
}
}

/** @return iterable<string, array{string[], string[]}> */
public static function provideCompletionSuggestions(): iterable
{
yield 'entityName' => [
[''],
[
'Doctrine\\\\Tests\\\\Models\\\\Cache\\\\Restaurant',
'Doctrine\\\\Tests\\\\Models\\\\Cache\\\\Beach',
'Doctrine\\\\Tests\\\\Models\\\\Cache\\\\Bar',
],
];
}
}