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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -77,7 +78,8 @@ protected function configure()
This will remove "ApiPlatform\Core\Annotation\ApiResource" annotation/attribute and use the "ApiPlatform\Metadata\ApiResource" attribute instead.')
->addOption('dry-run', '-d', InputOption::VALUE_OPTIONAL, 'Dry mode outputs a diff instead of writing files.', true)
->addOption('silent', '-s', InputOption::VALUE_NONE, 'Silent output.')
->addOption('force', '-f', InputOption::VALUE_NONE, 'Writes the files in place and skips PHP version check.');
->addOption('force', '-f', InputOption::VALUE_NONE, 'Writes the files in place and skips PHP version check.')
->addArgument('class', InputArgument::OPTIONAL, 'A fully qualified class name.');
}

/**
Expand All @@ -101,6 +103,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$prettyPrinter = new Standard();
foreach ($this->resourceNameCollectionFactory->create() as $resourceClass) {
if ($input->getArgument('class') && $input->getArgument('class') !== $resourceClass) {
continue;
}

try {
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
} catch (ResourceClassNotFoundException $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,32 @@ public function testDebugResource(string $entityClass, array $subresourceOperati
$this->assertStringNotContainsString('+private function nothingToDo() : void', $display);
}

/**
* @requires PHP 8.1
*
* @dataProvider debugResourceProvider
*/
public function testTargetSingleResource(string $entityClass, array $subresourceOperationFactoryReturn, array $expectedStrings): void
{
$resourceNameCollectionFactoryProphecy = $this->prophesize(ResourceNameCollectionFactoryInterface::class);
$resourceNameCollectionFactoryProphecy->create()->willReturn(new ResourceNameCollection([$entityClass]));
$resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataFactoryInterface::class);
$resourceMetadataFactoryProphecy->create($entityClass)->willReturn(new ResourceMetadata());
$subresourceOperationFactoryProphecy = $this->prophesize(SubresourceOperationFactoryInterface::class);
$subresourceOperationFactoryProphecy->create($entityClass)->willReturn($subresourceOperationFactoryReturn);

$commandTester = $this->getCommandTester($resourceNameCollectionFactoryProphecy->reveal(), $resourceMetadataFactoryProphecy->reveal(), $subresourceOperationFactoryProphecy->reveal());
$commandTester->execute(['class' => 'ApiPlatform\\Tests\\Fixtures\\TestBundle\\Entity\\DummyToUpgradeWithOnlyAttribute']);

$display = $commandTester->getDisplay();

if ($entityClass !== DummyToUpgradeWithOnlyAttribute::class) {
$this->assertEmpty($display);
} else {
$this->assertStringContainsString('begin diff', $display);
}
}

public function debugResourceProvider(): array
{
$entityClasses = [
Expand Down