Skip to content

Commit 1b7410d

Browse files
committed
feat: enhance compatibility check with verbose output and add isHyvaAware determination logic
1 parent c29779c commit 1b7410d

3 files changed

Lines changed: 61 additions & 2 deletions

File tree

src/Console/Command/Hyva/CompatibilityCheckCommand.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ private function runInteractiveMode(InputInterface $input, OutputInterface $outp
135135
{
136136
$this->io->title('Hyvä Theme Compatibility Check');
137137

138+
if ($this->isVerbose($output)) {
139+
$this->io->info('Running in interactive mode');
140+
}
141+
138142
// Set environment variables for Laravel Prompts
139143
$this->setPromptEnvironment();
140144

@@ -230,6 +234,17 @@ private function runDirectMode(InputInterface $input, OutputInterface $output):
230234

231235
$this->io->title('Hyvä Theme Compatibility Check');
232236

237+
if ($this->isVerbose($output)) {
238+
$this->io->info(sprintf(
239+
'Direct mode: showAll=%s, thirdPartyOnly=%s, includeCore=%s, excludeVendor=%s, detailed=%s',
240+
$showAll ? 'true' : 'false',
241+
$thirdPartyOnly ? 'true' : 'false',
242+
$includeCore ? 'true' : 'false',
243+
$excludeVendor ? 'true' : 'false',
244+
$detailed ? 'true' : 'false',
245+
));
246+
}
247+
233248
return $this->runScan($showAll, $thirdPartyOnly, $includeCore, $excludeVendor, $detailed, false);
234249
}
235250

src/Service/Hyva/ModuleScanner.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,32 @@ public function getModuleInfo(string $modulePath): array
174174
return [
175175
'name' => is_string($composerData['name'] ?? null) ? $composerData['name'] : 'Unknown',
176176
'version' => is_string($composerData['version'] ?? null) ? $composerData['version'] : 'Unknown',
177-
'isHyvaAware' => $this->isHyvaCompatibilityPackage($composerData),
177+
'isHyvaAware' => $this->isHyvaAware($modulePath, $composerData),
178178
];
179179
} catch (\Throwable $e) {
180180
return ['name' => 'Unknown', 'version' => 'Unknown', 'isHyvaAware' => false];
181181
}
182182
}
183183

184+
/**
185+
* Determine whether a module is Hyvä-aware.
186+
*
187+
* A module is considered Hyvä-aware when it either declares a Hyvä dependency,
188+
* is a Hyvä compatibility package, or ships a hyva-themes.json config.
189+
*
190+
* @param string $modulePath
191+
* @param array<string, mixed> $composerData
192+
* @return bool
193+
*/
194+
private function isHyvaAware(string $modulePath, array $composerData): bool
195+
{
196+
if ($this->isHyvaCompatibilityPackage($composerData)) {
197+
return true;
198+
}
199+
200+
return $this->fileDriver->isExists($modulePath . '/hyva-themes.json');
201+
}
202+
184203
/**
185204
* Get basename without using basename().
186205
*

tests/Unit/Service/Hyva/ModuleScannerTest.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ private function givenDirectories(array $directories): void
226226
*/
227227
private function givenComposerJson(array $composerData): void
228228
{
229-
$this->fileDriver->method('isExists')->with('/module/composer.json')->willReturn(true);
229+
$this->fileDriver->method('isExists')->willReturnCallback(
230+
static fn(string $path): bool => $path === '/module/composer.json',
231+
);
230232
$this->fileDriver->method('fileGetContents')->willReturn(json_encode($composerData));
231233
}
232234

@@ -239,4 +241,27 @@ public function testNonHyvaRequirementsAreNotHyvaAware(): void
239241

240242
$this->assertFalse($this->scanner->getModuleInfo('/module')['isHyvaAware']);
241243
}
244+
245+
public function testHyvaThemesJsonMakesModuleHyvaAware(): void
246+
{
247+
$this->fileDriver->method('isExists')->willReturnMap([
248+
['/module/composer.json', true],
249+
['/module/hyva-themes.json', true],
250+
]);
251+
$this->fileDriver->method('fileGetContents')->with('/module/composer.json')->willReturn(
252+
json_encode(['name' => 'vendor/module']),
253+
);
254+
255+
$this->assertTrue($this->scanner->getModuleInfo('/module')['isHyvaAware']);
256+
}
257+
258+
public function testComposerHyvaDependencyTakesPrecedenceOverMissingHyvaThemesJson(): void
259+
{
260+
$this->givenComposerJson([
261+
'name' => 'vendor/module',
262+
'require' => ['hyva-themes/magento2-default-theme' => '*'],
263+
]);
264+
265+
$this->assertTrue($this->scanner->getModuleInfo('/module')['isHyvaAware']);
266+
}
242267
}

0 commit comments

Comments
 (0)