@@ -507,6 +507,75 @@ public function testInsertCodeToMethodNotClassTraitEnum(): void
507507 ->save ();
508508 }
509509
510+ public function testRemoveImportsUnused (): void
511+ {
512+ $ this ->mockNativeFunction (
513+ 'RonasIT\Larabuilder\Builders ' ,
514+ $ this ->callFileGetContent ('some_file_path.php ' , 'remove_imports_from_class.php ' ),
515+ $ this ->callFilePutContent ('some_file_path.php ' , 'remove_unused_import.php ' ),
516+ );
517+
518+ new PHPFileBuilder ('some_file_path.php ' )
519+ ->removeImports ([
520+ 'App\Service\UserService ' ,
521+ 'App\Support\Traits\SecondTrait ' ,
522+ ])
523+ ->save ();
524+ }
525+
526+ public function testRemoveImportsUsedSkipped (): void
527+ {
528+ $ this ->mockNativeFunction (
529+ 'RonasIT\Larabuilder\Builders ' ,
530+ $ this ->callFileGetContent ('some_file_path.php ' , 'remove_imports_from_class.php ' ),
531+ $ this ->callFilePutContent ('some_file_path.php ' , 'remove_imports_from_class_unchanged.php ' ),
532+ );
533+
534+ new PHPFileBuilder ('some_file_path.php ' )
535+ ->removeImports ([
536+ 'App\SomeClass ' ,
537+ 'App\Models\User ' ,
538+ 'RonasIT\Support\Traits\SecondTrait ' ,
539+ ])
540+ ->save ();
541+ }
542+
543+ public function testRemoveImportsForce (): void
544+ {
545+ $ this ->mockNativeFunction (
546+ 'RonasIT\Larabuilder\Builders ' ,
547+ $ this ->callFileGetContent ('some_file_path.php ' , 'remove_imports_from_class.php ' ),
548+ $ this ->callFilePutContent ('some_file_path.php ' , 'remove_imports_force.php ' ),
549+ );
550+
551+ new PHPFileBuilder ('some_file_path.php ' )
552+ ->removeImports ([
553+ 'App\SomeClass ' ,
554+ 'App\Models\User ' ,
555+ 'App\Support\Traits\SecondTrait ' ,
556+ 'App\Service\UserService ' ,
557+ 'App\Support\Classname ' ,
558+ ], force: true )
559+ ->save ();
560+ }
561+
562+ public function testRemoveImportsAfterChanges (): void
563+ {
564+ $ this ->mockNativeFunction (
565+ 'RonasIT\Larabuilder\Builders ' ,
566+ $ this ->callFileGetContent ('some_file_path.php ' , 'remove_imports_from_class.php ' ),
567+ $ this ->callFilePutContent ('some_file_path.php ' , 'remove_imports_after_changes.php ' ),
568+ );
569+
570+ new PHPFileBuilder ('some_file_path.php ' )
571+ ->insertCodeToMethod ('someMethod ' , 'app(UserService::class)->doSomething(); ' )
572+ ->removeImports ([
573+ 'App\Service\UserService ' ,
574+ 'App\Support\Classname ' ,
575+ ])
576+ ->save ();
577+ }
578+
510579 public function testInsertCodeToMethodWhenMethodNotExist (): void
511580 {
512581 $ this ->mockNativeFunction (
0 commit comments