1414use InvalidArgumentException ;
1515use PHPUnit \Framework \MockObject \MockObject ;
1616use React \Promise \PromiseInterface ;
17+ use RuntimeException ;
1718
1819/**
1920 * @covers \Blesta\Composer\Installer\InstallerPlugin
@@ -67,8 +68,7 @@ public function testGetInstallPath(): void
6768 }
6869
6970 /**
70- * @covers ::getInstallPath
71- * @covers ::supportedType
71+ * Test getInstallPath throws exception for invalid types
7272 */
7373 public function testGetInstallPathException (): void
7474 {
@@ -84,9 +84,7 @@ public function testGetInstallPathException(): void
8484 }
8585
8686 /**
87- * @covers ::uninstall
88- * @covers ::getInstallPath
89- * @covers ::supportedType
87+ * Test uninstall functionality
9088 */
9189 public function testUninstall (): void
9290 {
@@ -118,7 +116,7 @@ public function testUninstall(): void
118116 }
119117
120118 /**
121- * @covers :: uninstall
119+ * Test uninstall throws exception when package not found
122120 */
123121 public function testUninstallException (): void
124122 {
@@ -197,5 +195,98 @@ public function testSupportedType(): void
197195 // Test invalid types
198196 $ this ->assertFalse ($ method ->invoke ($ installer , 'invalid ' ));
199197 $ this ->assertFalse ($ method ->invoke ($ installer , 'blesta ' )); // No hyphen
198+ $ this ->assertFalse ($ method ->invoke ($ installer , 'unknown-type ' )); // Unknown base type with hyphen
199+ }
200+
201+ /**
202+ * Test getInstallPath with a custom type that doesn't have an installer class
203+ */
204+ public function testGetInstallPathWithMissingInstallerClass (): void
205+ {
206+ // Override the supportedTypes array to have a non-existent installer class
207+ $ installer = new class ($ this ->io , $ this ->composer ) extends InstallerPlugin {
208+ protected array $ supportedTypes = [
209+ 'custom ' => 'NonExistentInstaller '
210+ ];
211+
212+ protected function supportedType (string $ type ): string |false
213+ {
214+ if ($ type === 'test-invalid-type ' ) {
215+ return 'custom ' ;
216+ }
217+ return false ;
218+ }
219+ };
220+
221+ $ package = $ this ->createMock (PackageInterface::class);
222+ $ package ->expects ($ this ->once ())
223+ ->method ('getType ' )
224+ ->willReturn ('test-invalid-type ' );
225+
226+ $ this ->expectException (RuntimeException::class);
227+ $ this ->expectExceptionMessage ('Failed to create installer for package type "test-invalid-type": ' );
228+
229+ $ installer ->getInstallPath ($ package );
230+ }
231+
232+ /**
233+ * Test uninstall with exception during getInstallPath
234+ */
235+ public function testUninstallWithGetInstallPathException (): void
236+ {
237+ $ package = $ this ->createMock (PackageInterface::class);
238+ $ package ->expects ($ this ->once ())
239+ ->method ('getType ' )
240+ ->willReturn ('invalid-type ' );
241+ $ package ->expects ($ this ->once ())
242+ ->method ('getName ' )
243+ ->willReturn ('test/package ' );
244+
245+ $ repo = $ this ->createMock (InstalledRepositoryInterface::class);
246+ $ repo ->expects ($ this ->once ())
247+ ->method ('hasPackage ' )
248+ ->willReturn (true );
249+ $ repo ->expects ($ this ->once ())
250+ ->method ('removePackage ' )
251+ ->with ($ package );
252+
253+ $ installer = new InstallerPlugin ($ this ->io , $ this ->composer );
254+
255+ // Expect error to be written
256+ $ this ->io ->expects ($ this ->once ())
257+ ->method ('writeError ' )
258+ ->with ($ this ->stringContains ('Error during uninstall of test/package: ' ));
259+
260+ $ result = $ installer ->uninstall ($ repo , $ package );
261+ $ this ->assertNull ($ result );
262+ }
263+
264+ /**
265+ * Test supports method with exception during installer creation
266+ */
267+ public function testSupportsWithException (): void
268+ {
269+ // Create a custom installer that will throw an exception
270+ $ installer = new class ($ this ->io , $ this ->composer ) extends InstallerPlugin {
271+ protected array $ supportedTypes = [
272+ 'custom ' => 'NonExistentInstaller '
273+ ];
274+
275+ protected function supportedType (string $ type ): string |false
276+ {
277+ if ($ type === 'test-invalid-type ' ) {
278+ return 'custom ' ;
279+ }
280+ return false ;
281+ }
282+ };
283+
284+ // Expect error to be written
285+ $ this ->io ->expects ($ this ->once ())
286+ ->method ('writeError ' )
287+ ->with ($ this ->stringContains ('Error checking support for package type "test-invalid-type": ' ));
288+
289+ $ result = $ installer ->supports ('test-invalid-type ' );
290+ $ this ->assertFalse ($ result );
200291 }
201292}
0 commit comments