Skip to content

Commit 5dd7383

Browse files
authored
[Debug] Show legacy resource metadata on debug command when specified (#979)
| Q | A | --------------- | ----- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | | License | MIT It improves the readability between the new resource metadata and the legacy ones. The legacy ones are used for the ResourceController and the new ones are used for Resource Operations. **Without passing legacy option** ![image](https://github.com/user-attachments/assets/e73383c3-553e-47e7-adb1-ded02b25965c) **Passing legacy option** ![image](https://github.com/user-attachments/assets/bf998a58-dec4-4e56-8cf2-66230def9f38)
2 parents 433b59a + f3073bd commit 5dd7383

File tree

2 files changed

+85
-64
lines changed

2 files changed

+85
-64
lines changed

src/Bundle/Command/DebugResourceCommand.php

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Symfony\Component\Console\Helper\Dumper;
2525
use Symfony\Component\Console\Input\InputArgument;
2626
use Symfony\Component\Console\Input\InputInterface;
27+
use Symfony\Component\Console\Input\InputOption;
2728
use Symfony\Component\Console\Output\OutputInterface;
2829
use Symfony\Component\Console\Style\SymfonyStyle;
2930
use Symfony\Component\PropertyAccess\PropertyAccess;
@@ -56,6 +57,7 @@ public function configure(): void
5657
);
5758
$this->addArgument('resource', InputArgument::OPTIONAL, 'Resource to debug');
5859
$this->addArgument('operation', InputArgument::OPTIONAL, 'Operation to debug');
60+
$this->addOption('legacy', null, InputOption::VALUE_NONE, 'Show legacy resource metadata.');
5961
}
6062

6163
public function execute(InputInterface $input, OutputInterface $output): int
@@ -92,6 +94,12 @@ public function execute(InputInterface $input, OutputInterface $output): int
9294
return Command::SUCCESS;
9395
}
9496

97+
if ($input->getOption('legacy')) {
98+
$this->debugLegacyResourceMetadata($metadata, $input, $io, $dumper);
99+
100+
return Command::SUCCESS;
101+
}
102+
95103
$this->debugResource($metadata, $input, $io, $dumper);
96104

97105
return Command::SUCCESS;
@@ -115,6 +123,19 @@ private function listResources(SymfonyStyle $io): void
115123

116124
private function debugResource(MetadataInterface $metadata, InputInterface $input, SymfonyStyle $io, Dumper $dumper): void
117125
{
126+
$resourceMetadataCollection = $this->getResourceMetadataCollection($metadata);
127+
128+
$this->debugResourceMetadata($resourceMetadataCollection, $io, $dumper);
129+
130+
$this->debugResourceCollectionOperation($metadata, $input, $io, $dumper);
131+
}
132+
133+
private function debugLegacyResourceMetadata(
134+
MetadataInterface $metadata,
135+
InputInterface $input,
136+
SymfonyStyle $io,
137+
Dumper $dumper,
138+
): void {
118139
$io->section('Configuration');
119140

120141
$values = $this->configurationToArray($metadata);
@@ -126,12 +147,6 @@ private function debugResource(MetadataInterface $metadata, InputInterface $inpu
126147
}
127148

128149
$io->table(['Option', 'Value'], $rows);
129-
130-
$resourceMetadataCollection = $this->getResourceMetadataCollection($metadata);
131-
132-
$this->debugNewResourceMetadata($resourceMetadataCollection, $io, $dumper);
133-
134-
$this->debugResourceCollectionOperation($metadata, $input, $io, $dumper);
135150
}
136151

137152
private function getResourceMetadataCollection(MetadataInterface $resourceConfiguration): ResourceMetadataCollection
@@ -154,12 +169,12 @@ private function debugOperation(Operation $operation, SymfonyStyle $io, Dumper $
154169
$io->table(['Option', 'Value'], $rows);
155170
}
156171

157-
private function debugNewResourceMetadata(ResourceMetadataCollection $resourceMetadataCollection, SymfonyStyle $io, Dumper $dumper): void
172+
private function debugResourceMetadata(ResourceMetadataCollection $resourceMetadataCollection, SymfonyStyle $io, Dumper $dumper): void
158173
{
159-
$io->section('New Resource Metadata');
174+
$io->section('Resource Metadata');
160175

161176
if (0 === $resourceMetadataCollection->count()) {
162-
$io->info('This resource has no new metadata.');
177+
$io->info('This resource has no metadata.');
163178

164179
return;
165180
}
@@ -179,7 +194,7 @@ private function debugNewResourceMetadata(ResourceMetadataCollection $resourceMe
179194

180195
private function debugResourceCollectionOperation(MetadataInterface $metadata, InputInterface $input, SymfonyStyle $io, Dumper $dumper): void
181196
{
182-
$io->section('New operations');
197+
$io->section('Operations');
183198

184199
$resourceMetadataCollection = $this->resourceMetadataCollectionFactory->create($metadata->getClass('model'));
185200

tests/Bundle/Command/DebugResourceCommandTest.php

Lines changed: 60 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Sylius\Bundle\ResourceBundle\Tests\Command;
1515

16+
use PHPUnit\Framework\Attributes\Test;
1617
use PHPUnit\Framework\TestCase;
1718
use Prophecy\PhpUnit\ProphecyTrait;
1819
use Prophecy\Prophecy\ObjectProphecy;
@@ -118,31 +119,8 @@ public function it_displays_the_metadata_for_given_resource_alias_with_operation
118119
$this->assertEquals(
119120
<<<TXT
120121
121-
Configuration
122-
-------------
123-
124-
----------------------- -----------------------------
125-
Option Value
126-
----------------------- -----------------------------
127-
name "one"
128-
applicationName "sylius"
129-
driver "doctrine/foobar"
130-
stateMachineComponent null
131-
templatesNamespace null
132-
classes [
133-
"model" => "App\One",
134-
"foo" => "bar",
135-
"bar" => "foo"
136-
]
137-
whatever [
138-
"something" => [
139-
"elephants" => "camels"
140-
]
141-
]
142-
----------------------- -----------------------------
143-
144-
New Resource Metadata
145-
---------------------
122+
Resource Metadata
123+
-----------------
146124
147125
------------------------ -------
148126
Option Value
@@ -164,8 +142,8 @@ class null
164142
vars null
165143
------------------------ -------
166144
167-
New operations
168-
--------------
145+
Operations
146+
----------
169147
170148
---------------- ---------------------------------------------------------------
171149
Name Details
@@ -206,31 +184,8 @@ public function it_displays_the_metadata_for_given_resource_as_fully_qualified_c
206184
$this->assertEquals(
207185
<<<TXT
208186
209-
Configuration
210-
-------------
211-
212-
----------------------- -----------------------------
213-
Option Value
214-
----------------------- -----------------------------
215-
name "one"
216-
applicationName "sylius"
217-
driver "doctrine/foobar"
218-
stateMachineComponent null
219-
templatesNamespace null
220-
classes [
221-
"model" => "App\One",
222-
"foo" => "bar",
223-
"bar" => "foo"
224-
]
225-
whatever [
226-
"something" => [
227-
"elephants" => "camels"
228-
]
229-
]
230-
----------------------- -----------------------------
231-
232-
New Resource Metadata
233-
---------------------
187+
Resource Metadata
188+
-----------------
234189
235190
------------------------ --------------
236191
Option Value
@@ -252,8 +207,8 @@ class null
252207
vars null
253208
------------------------ --------------
254209
255-
New operations
256-
--------------
210+
Operations
211+
----------
257212
258213
---------------- ---------------------------------------------------------------
259214
Name Details
@@ -362,6 +317,57 @@ public function it_displays_the_metadata_for_given_resource_operation(): void
362317
);
363318
}
364319

320+
#[Test]
321+
public function it_displays_the_legacy_resource_metadata_for_given_resource_alias(): void
322+
{
323+
$this->registry->get('metadata.one')->willReturn($this->createMetadata('one'));
324+
325+
$resourceMetadata = (new ResourceMetadata(alias: 'sylius.one'));
326+
327+
$resourceMetadataCollection = new ResourceMetadataCollection([$resourceMetadata]);
328+
329+
$this->resourceCollectionMetadataFactory->create('App\One')->willReturn($resourceMetadataCollection);
330+
331+
$this->tester->execute([
332+
'resource' => 'metadata.one',
333+
'--legacy' => true,
334+
]);
335+
336+
$display = $this->tester->getDisplay();
337+
338+
$this->assertEquals(
339+
<<<TXT
340+
341+
Configuration
342+
-------------
343+
344+
----------------------- -----------------------------
345+
Option Value
346+
----------------------- -----------------------------
347+
name "one"
348+
applicationName "sylius"
349+
driver "doctrine/foobar"
350+
stateMachineComponent null
351+
templatesNamespace null
352+
classes [
353+
"model" => "App\One",
354+
"foo" => "bar",
355+
"bar" => "foo"
356+
]
357+
whatever [
358+
"something" => [
359+
"elephants" => "camels"
360+
]
361+
]
362+
----------------------- -----------------------------
363+
364+
365+
TXT
366+
,
367+
$display,
368+
);
369+
}
370+
365371
private function createMetadata(string $suffix): MetadataInterface
366372
{
367373
return Metadata::fromAliasAndConfiguration(sprintf('sylius.%s', $suffix), [

0 commit comments

Comments
 (0)