Skip to content

Commit 70152a0

Browse files
committed
Handle getPluginDescription errors
1 parent 6ea130c commit 70152a0

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

Generation/PluginListProvider.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ public function getAllowedPluginDescriptions(): array
5252
$descriptions = [];
5353

5454
foreach ($this->getAllowedPlugins() as $pluginName) {
55-
$descriptions[$pluginName] = $this->getPluginDescription($pluginName);
55+
try {
56+
$descriptions[$pluginName] = $this->getPluginDescription($pluginName);
57+
} catch (\Throwable $e) {
58+
$descriptions[$pluginName] = '';
59+
}
5660
}
5761

5862
return $descriptions;

tests/Unit/Generation/PluginListProviderTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,31 @@ public function testGetAllowedPluginDescriptionsReturnsEmptyStringWhenDescriptio
143143
$this->assertSame(['Login' => ''], $provider->getAllowedPluginDescriptions());
144144
}
145145

146+
public function testGetAllowedPluginDescriptionsContinuesWhenOnePluginDescriptionFails(): void
147+
{
148+
$provider = $this->getMockBuilder(PluginListProvider::class)
149+
->disableOriginalConstructor()
150+
->onlyMethods(['getAllowedPlugins', 'getPluginDescription'])
151+
->getMock();
152+
153+
$provider->method('getAllowedPlugins')
154+
->willReturn(['Login', 'BrokenPlugin', 'ActivityLog']);
155+
$provider->method('getPluginDescription')
156+
->willReturnCallback(static function (string $pluginName): string {
157+
if ($pluginName === 'BrokenPlugin') {
158+
throw new \RuntimeException('Could not register API class');
159+
}
160+
161+
return $pluginName === 'Login' ? 'Login API description' : 'Activity log API description';
162+
});
163+
164+
$this->assertSame([
165+
'Login' => 'Login API description',
166+
'BrokenPlugin' => '',
167+
'ActivityLog' => 'Activity log API description',
168+
], $provider->getAllowedPluginDescriptions());
169+
}
170+
146171
/**
147172
* @param string[] $activatedPlugins
148173
* @param array<string, bool> $inFilesystemByPlugin

0 commit comments

Comments
 (0)