Skip to content

Commit 349922f

Browse files
committed
Make method more generic
1 parent 70152a0 commit 349922f

4 files changed

Lines changed: 32 additions & 28 deletions

File tree

API.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ public function getAllowedPlugins(): array
3838
}
3939

4040
/**
41-
* Returns API class descriptions for the plugins used by OpenApiDocs spec generation.
41+
* Returns metadata for the plugins used by OpenApiDocs spec generation.
4242
*
43-
* @return array<string, string>
43+
* @return array<string, array{description: string}>
4444
*/
45-
public function getAllowedPluginDescriptions(): array
45+
public function getAllowedPluginMetadata(): array
4646
{
4747
Piwik::checkUserHasSomeViewAccess();
4848

49-
return $this->getPluginListProvider()->getAllowedPluginDescriptions();
49+
return $this->getPluginListProvider()->getAllowedPluginMetadata();
5050
}
5151

5252
/**

Generation/PluginListProvider.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,25 @@ public function getAllowedPlugins(): array
4545
}
4646

4747
/**
48-
* @return array<string, string>
48+
* @return array<string, array{description: string}>
4949
*/
50-
public function getAllowedPluginDescriptions(): array
50+
public function getAllowedPluginMetadata(): array
5151
{
52-
$descriptions = [];
52+
$metadata = [];
5353

5454
foreach ($this->getAllowedPlugins() as $pluginName) {
5555
try {
56-
$descriptions[$pluginName] = $this->getPluginDescription($pluginName);
56+
$description = $this->getPluginDescription($pluginName);
5757
} catch (\Throwable $e) {
58-
$descriptions[$pluginName] = '';
58+
$description = '';
5959
}
60+
61+
$metadata[$pluginName] = [
62+
'description' => $description,
63+
];
6064
}
6165

62-
return $descriptions;
66+
return $metadata;
6367
}
6468

6569
private function shouldIncludeEventProvidedPlugin(string $pluginName): bool

tests/Unit/APITest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ public function testGetAllowedPluginsReturnsProviderValues(): void
7777
$this->assertSame(['Login', 'ActivityLog'], $api->getAllowedPlugins());
7878
}
7979

80-
public function testGetAllowedPluginDescriptionsReturnsProviderValues(): void
80+
public function testGetAllowedPluginMetadataReturnsProviderValues(): void
8181
{
8282
$provider = $this->createMock(PluginListProvider::class);
8383
$provider->expects($this->once())
84-
->method('getAllowedPluginDescriptions')
84+
->method('getAllowedPluginMetadata')
8585
->willReturn([
86-
'Login' => 'Login API description',
87-
'ActivityLog' => '',
86+
'Login' => ['description' => 'Login API description'],
87+
'ActivityLog' => ['description' => ''],
8888
]);
8989

9090
$api = $this->getMockBuilder(API::class)
@@ -93,9 +93,9 @@ public function testGetAllowedPluginDescriptionsReturnsProviderValues(): void
9393
$api->method('getPluginListProvider')->willReturn($provider);
9494

9595
$this->assertSame([
96-
'Login' => 'Login API description',
97-
'ActivityLog' => '',
98-
], $api->getAllowedPluginDescriptions());
96+
'Login' => ['description' => 'Login API description'],
97+
'ActivityLog' => ['description' => ''],
98+
], $api->getAllowedPluginMetadata());
9999
}
100100

101101
public function testGetOpenApiSpecThrowsExceptionWhenFileMissing()

tests/Unit/Generation/PluginListProviderTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static function (string $eventName, array $params): void {
107107
$this->assertSame(['HasApi', 'Login', 'InactivePlugin'], $provider->getAllowedPlugins());
108108
}
109109

110-
public function testGetAllowedPluginDescriptionsReturnsDescriptionPerAllowedPlugin(): void
110+
public function testGetAllowedPluginMetadataReturnsDescriptionPerAllowedPlugin(): void
111111
{
112112
$provider = $this->getMockBuilder(PluginListProvider::class)
113113
->disableOriginalConstructor()
@@ -123,12 +123,12 @@ public function testGetAllowedPluginDescriptionsReturnsDescriptionPerAllowedPlug
123123
]);
124124

125125
$this->assertSame([
126-
'Login' => 'Login API description',
127-
'ActivityLog' => 'Activity log API description',
128-
], $provider->getAllowedPluginDescriptions());
126+
'Login' => ['description' => 'Login API description'],
127+
'ActivityLog' => ['description' => 'Activity log API description'],
128+
], $provider->getAllowedPluginMetadata());
129129
}
130130

131-
public function testGetAllowedPluginDescriptionsReturnsEmptyStringWhenDescriptionMissing(): void
131+
public function testGetAllowedPluginMetadataReturnsEmptyStringWhenDescriptionMissing(): void
132132
{
133133
$provider = $this->getMockBuilder(PluginListProvider::class)
134134
->disableOriginalConstructor()
@@ -140,10 +140,10 @@ public function testGetAllowedPluginDescriptionsReturnsEmptyStringWhenDescriptio
140140
$provider->method('getPluginDescription')
141141
->willReturn('');
142142

143-
$this->assertSame(['Login' => ''], $provider->getAllowedPluginDescriptions());
143+
$this->assertSame(['Login' => ['description' => '']], $provider->getAllowedPluginMetadata());
144144
}
145145

146-
public function testGetAllowedPluginDescriptionsContinuesWhenOnePluginDescriptionFails(): void
146+
public function testGetAllowedPluginMetadataContinuesWhenOnePluginDescriptionFails(): void
147147
{
148148
$provider = $this->getMockBuilder(PluginListProvider::class)
149149
->disableOriginalConstructor()
@@ -162,10 +162,10 @@ public function testGetAllowedPluginDescriptionsContinuesWhenOnePluginDescriptio
162162
});
163163

164164
$this->assertSame([
165-
'Login' => 'Login API description',
166-
'BrokenPlugin' => '',
167-
'ActivityLog' => 'Activity log API description',
168-
], $provider->getAllowedPluginDescriptions());
165+
'Login' => ['description' => 'Login API description'],
166+
'BrokenPlugin' => ['description' => ''],
167+
'ActivityLog' => ['description' => 'Activity log API description'],
168+
], $provider->getAllowedPluginMetadata());
169169
}
170170

171171
/**

0 commit comments

Comments
 (0)