2525use FastForward \DevTools \Funding \FundingProfile ;
2626use FastForward \DevTools \Funding \FundingProfileMerger ;
2727use FastForward \DevTools \Funding \FundingYamlCodec ;
28+ use FastForward \DevTools \Process \ProcessBuilderInterface ;
29+ use FastForward \DevTools \Process \ProcessQueueInterface ;
2830use FastForward \DevTools \Resource \FileDiff ;
2931use FastForward \DevTools \Resource \FileDiffer ;
3032use PHPUnit \Framework \Attributes \CoversClass ;
3739use ReflectionMethod ;
3840use Symfony \Component \Console \Input \InputInterface ;
3941use Symfony \Component \Console \Output \OutputInterface ;
42+ use Symfony \Component \Process \Process ;
4043use Symfony \Component \Yaml \Yaml ;
4144
4245use function Safe \json_decode ;
@@ -59,6 +62,12 @@ final class FundingCommandTest extends TestCase
5962
6063 private ObjectProphecy $ fileDiffer ;
6164
65+ private ObjectProphecy $ processBuilder ;
66+
67+ private ObjectProphecy $ processQueue ;
68+
69+ private ObjectProphecy $ normalizeProcess ;
70+
6271 private FundingCommand $ command ;
6372
6473 protected function setUp (): void
@@ -67,6 +76,9 @@ protected function setUp(): void
6776 $ this ->input = $ this ->prophesize (InputInterface::class);
6877 $ this ->output = $ this ->prophesize (OutputInterface::class);
6978 $ this ->fileDiffer = $ this ->prophesize (FileDiffer::class);
79+ $ this ->processBuilder = $ this ->prophesize (ProcessBuilderInterface::class);
80+ $ this ->processQueue = $ this ->prophesize (ProcessQueueInterface::class);
81+ $ this ->normalizeProcess = $ this ->prophesize (Process::class);
7082 $ this ->output ->isDecorated ()->willReturn (false );
7183 $ this ->output ->writeln (Argument::any ());
7284 $ this ->fileDiffer ->formatForConsole (Argument::cetera ())->willReturn (null );
@@ -76,13 +88,20 @@ protected function setUp(): void
7688 $ this ->input ->getOption ('check ' )->willReturn (false );
7789 $ this ->input ->getOption ('interactive ' )->willReturn (false );
7890 $ this ->filesystem ->dirname ('.github/FUNDING.yml ' )->willReturn ('.github ' );
91+ $ this ->filesystem ->dirname ('composer.json ' )->willReturn ('. ' );
92+ $ this ->filesystem ->basename ('composer.json ' )->willReturn ('composer.json ' );
93+ $ this ->processBuilder ->withArgument (Argument::any ())->willReturn ($ this ->processBuilder ->reveal ());
94+ $ this ->processBuilder ->withArgument (Argument::any (), Argument::any ())->willReturn ($ this ->processBuilder ->reveal ());
95+ $ this ->processBuilder ->build ('composer normalize ' )->willReturn ($ this ->normalizeProcess ->reveal ());
7996
8097 $ this ->command = new FundingCommand (
8198 $ this ->filesystem ->reveal (),
8299 new ComposerFundingCodec (),
83100 new FundingYamlCodec (),
84101 new FundingProfileMerger (),
85102 $ this ->fileDiffer ->reveal (),
103+ $ this ->processBuilder ->reveal (),
104+ $ this ->processQueue ->reveal (),
86105 );
87106 }
88107
@@ -117,6 +136,8 @@ public function executeWillCreateComposerFundingFromFundingYaml(): void
117136 $ fundingYaml ,
118137 'Updating managed file .github/FUNDING.yml from generated funding metadata synchronization. ' ,
119138 )->willReturn (new FileDiff (FileDiff::STATUS_UNCHANGED , 'Funding unchanged ' ))->shouldBeCalledOnce ();
139+ $ this ->processQueue ->add ($ this ->normalizeProcess ->reveal ())->shouldBeCalledOnce ();
140+ $ this ->processQueue ->run ($ this ->output ->reveal ())->willReturn (ProcessQueueInterface::SUCCESS )->shouldBeCalledOnce ();
120141 $ this ->filesystem ->dumpFile (
121142 'composer.json ' ,
122143 Argument::that (static fn (string $ contents ): bool => str_contains ($ contents , '"funding" ' )),
@@ -149,7 +170,7 @@ public function executeWillCreateFundingYamlFromComposerFunding(): void
149170 $ decoded = Yaml::parse ($ contents );
150171
151172 return 'foo ' === $ decoded ['github ' ]
152- && 'https://example.com/support ' === $ decoded ['custom ' ];
173+ && [ 'https://example.com/support ' ] === $ decoded ['custom ' ];
153174 }),
154175 null ,
155176 'Managed file .github/FUNDING.yml will be created from generated funding metadata synchronization. ' ,
@@ -193,11 +214,13 @@ public function executeWillMergeBothSourcesWithoutDuplicatingEntries(): void
193214 $ decoded = Yaml::parse ($ contents );
194215
195216 return 'foo ' === $ decoded ['github ' ]
196- && 'https://example.com/support ' === $ decoded ['custom ' ];
217+ && [ 'https://example.com/support ' ] === $ decoded ['custom ' ];
197218 }),
198219 $ fundingYaml ,
199220 'Updating managed file .github/FUNDING.yml from generated funding metadata synchronization. ' ,
200221 )->willReturn (new FileDiff (FileDiff::STATUS_CHANGED , 'Funding changed ' ))->shouldBeCalledOnce ();
222+ $ this ->processQueue ->add ($ this ->normalizeProcess ->reveal ())->shouldBeCalledOnce ();
223+ $ this ->processQueue ->run ($ this ->output ->reveal ())->willReturn (ProcessQueueInterface::SUCCESS )->shouldBeCalledOnce ();
201224 $ this ->filesystem ->dumpFile ('composer.json ' , Argument::type ('string ' ))->shouldBeCalledOnce ();
202225 $ this ->filesystem ->mkdir ('.github ' )->shouldBeCalledOnce ();
203226 $ this ->filesystem ->dumpFile ('.github/FUNDING.yml ' , Argument::type ('string ' ))->shouldBeCalledOnce ();
@@ -232,6 +255,7 @@ public function executeWillBeIdempotentWhenFundingMetadataAlreadyMatches(): void
232255 'Updating managed file .github/FUNDING.yml from generated funding metadata synchronization. ' ,
233256 )->willReturn (new FileDiff (FileDiff::STATUS_UNCHANGED , 'Funding unchanged ' ))->shouldBeCalledOnce ();
234257 $ this ->filesystem ->dumpFile (Argument::cetera ())->shouldNotBeCalled ();
258+ $ this ->processQueue ->add (Argument::cetera ())->shouldNotBeCalled ();
235259
236260 self ::assertSame (FundingCommand::SUCCESS , $ this ->executeCommand ());
237261 }
0 commit comments