1414require_once PIWIK_INCLUDE_PATH . '/plugins/OpenApiDocs/vendor/autoload.php ' ;
1515
1616use PHPUnit \Framework \TestCase ;
17- use Piwik \EventDispatcher ;
1817use Piwik \Plugin \Manager ;
1918use Piwik \Plugins \OpenApiDocs \Generation \PluginListProvider ;
2019
@@ -92,10 +91,9 @@ public function testGetPluginsForSpecGenerationAppliesEventUpdates(): void
9291 ['HasApi ' => true , 'Login ' => true ],
9392 ['HasApi ' => true , 'Login ' => true ],
9493 ['HasApi ' => true , 'Login ' => true ],
95- static function (EventDispatcher $ eventDispatcher ): void {
96- $ eventDispatcher ->addObserver ('OpenApiDocs.updatePluginList ' , function (&$ pluginNames ): void {
97- $ pluginNames [] = 'Login ' ;
98- });
94+ static function (string $ eventName , array $ params ): void {
95+ $ pluginNames = &$ params [0 ];
96+ $ pluginNames [] = 'Login ' ;
9997 }
10098 );
10199
@@ -134,14 +132,13 @@ public function testGetPluginsForSpecGenerationDropsInvalidEventUpdatesButKeepsU
134132 'NoApi ' => false ,
135133 'ConnectAccounts ' => true ,
136134 ],
137- static function (EventDispatcher $ eventDispatcher ): void {
138- $ eventDispatcher ->addObserver ('OpenApiDocs.updatePluginList ' , function (&$ pluginNames ): void {
139- $ pluginNames [] = 'Login ' ;
140- $ pluginNames [] = 'InactivePlugin ' ;
141- $ pluginNames [] = 'NoApi ' ;
142- $ pluginNames [] = 'ConnectAccounts ' ;
143- $ pluginNames [] = 123 ;
144- });
135+ static function (string $ eventName , array $ params ): void {
136+ $ pluginNames = &$ params [0 ];
137+ $ pluginNames [] = 'Login ' ;
138+ $ pluginNames [] = 'InactivePlugin ' ;
139+ $ pluginNames [] = 'NoApi ' ;
140+ $ pluginNames [] = 'ConnectAccounts ' ;
141+ $ pluginNames [] = 123 ;
145142 }
146143 );
147144
@@ -159,7 +156,7 @@ private function makeProvider(
159156 array $ activatedByPlugin ,
160157 array $ inFilesystemByPlugin ,
161158 $ hasApiFile ,
162- ?callable $ configureEventDispatcher = null
159+ ?callable $ postEventCallback = null
163160 ): PluginListProvider {
164161 $ pluginManager = $ this ->createConfiguredMock (Manager::class, [
165162 'getInstalledPluginsName ' => $ installedPlugins ,
@@ -176,16 +173,9 @@ private function makeProvider(
176173 return $ inFilesystemByPlugin [$ pluginName ] ?? false ;
177174 });
178175
179- if ($ configureEventDispatcher ) {
180- $ eventDispatcher = new EventDispatcher ($ pluginManager , []);
181- $ configureEventDispatcher ($ eventDispatcher );
182- } else {
183- $ eventDispatcher = $ this ->createMock (EventDispatcher::class);
184- }
185-
186176 $ provider = $ this ->getMockBuilder (PluginListProvider::class)
187- ->setConstructorArgs ([$ pluginManager, $ eventDispatcher ])
188- ->onlyMethods (['pluginHasApiFile ' ])
177+ ->setConstructorArgs ([$ pluginManager ])
178+ ->onlyMethods (['pluginHasApiFile ' , ' postEvent ' ])
189179 ->getMock ();
190180
191181 $ provider ->method ('pluginHasApiFile ' )
@@ -197,6 +187,11 @@ private function makeProvider(
197187 return $ hasApiFile ;
198188 });
199189
190+ if ($ postEventCallback ) {
191+ $ provider ->method ('postEvent ' )
192+ ->willReturnCallback ($ postEventCallback );
193+ }
194+
200195 return $ provider ;
201196 }
202197}
0 commit comments