88use PHPUnit \Framework \Attributes \CoversClass ;
99use PHPUnit \Framework \Attributes \DataProvider ;
1010use PHPUnit \Framework \MockObject \MockObject ;
11+ use PHPUnit \Framework \MockObject \Stub ;
1112use PHPUnit \Framework \TestCase ;
1213use Psl \Env ;
1314use Psl \Exception \InvariantViolationException ;
4243final class AssertBackwardsCompatibleTest extends TestCase
4344{
4445 private CheckedOutRepository $ sourceRepository ;
45- /** @var InputInterface&MockObject */
46+ /** @var InputInterface&Stub */
4647 private InputInterface $ input ;
4748 /** @var ConsoleOutputInterface&MockObject */
4849 private ConsoleOutputInterface $ output ;
@@ -71,7 +72,7 @@ public function setUp(): void
7172
7273 Env \set_current_dir ($ this ->sourceRepository ->__toString ());
7374
74- $ this ->input = $ this ->createMock (InputInterface::class);
75+ $ this ->input = $ this ->createStub (InputInterface::class);
7576 $ this ->output = $ this ->createMock (ConsoleOutputInterface::class);
7677 $ this ->stdErr = $ this ->createMock (OutputInterface::class);
7778 $ this ->performCheckout = new PerformCheckoutOfRevisionForTests ();
@@ -99,6 +100,36 @@ public function setUp(): void
99100
100101 public function testDefinition (): void
101102 {
103+ $ this ->parseRevision
104+ ->expects (self ::never ())
105+ ->method ('fromStringForRepository ' );
106+
107+ $ this ->locateDependencies
108+ ->expects (self ::never ())
109+ ->method ('__invoke ' );
110+
111+ $ this ->compareApi
112+ ->expects (self ::never ())
113+ ->method ('__invoke ' );
114+
115+ $ this ->stdErr
116+ ->expects (self ::never ())
117+ ->method ('writeln ' );
118+
119+ $ this ->output
120+ ->expects (self ::never ())
121+ ->method ('writeln ' );
122+
123+ $ this
124+ ->getVersions
125+ ->expects (self ::never ())
126+ ->method ('fromRepository ' );
127+
128+ $ this
129+ ->pickVersion
130+ ->expects (self ::never ())
131+ ->method ('forVersions ' );
132+
102133 self ::assertSame (
103134 'roave-backwards-compatibility-check:assert-backwards-compatible ' ,
104135 $ this ->compare ->getName (),
@@ -144,12 +175,31 @@ public function testExecuteWhenRevisionsAreProvidedAsOptions(): void
144175
145176 $ this
146177 ->locateDependencies
178+ ->expects (self ::atLeastOnce ())
147179 ->method ('__invoke ' )
148180 ->with ((string ) $ this ->sourceRepository , false )
149181 ->willReturn ($ this ->dependencies );
150182
151183 $ this ->compareApi ->expects (self ::once ())->method ('__invoke ' )->willReturn (Changes::empty ());
152184
185+ $ this ->stdErr
186+ ->expects (self ::atLeastOnce ())
187+ ->method ('writeln ' );
188+
189+ $ this ->output
190+ ->expects (self ::never ())
191+ ->method ('writeln ' );
192+
193+ $ this
194+ ->getVersions
195+ ->expects (self ::never ())
196+ ->method ('fromRepository ' );
197+
198+ $ this
199+ ->pickVersion
200+ ->expects (self ::never ())
201+ ->method ('forVersions ' );
202+
153203 self ::assertSame (0 , $ this ->compare ->execute ($ this ->input , $ this ->output ));
154204 self ::assertSame (0 , $ this ->performCheckout ->nonRemovedRepositoryCount ());
155205 }
@@ -174,12 +224,31 @@ public function testExecuteWhenDevelopmentDependenciesAreRequested(): void
174224
175225 $ this
176226 ->locateDependencies
227+ ->expects (self ::atLeastOnce ())
177228 ->method ('__invoke ' )
178229 ->with ((string ) $ this ->sourceRepository , true )
179230 ->willReturn ($ this ->dependencies );
180231
181232 $ this ->compareApi ->expects (self ::once ())->method ('__invoke ' )->willReturn (Changes::empty ());
182233
234+ $ this ->stdErr
235+ ->expects (self ::atLeastOnce ())
236+ ->method ('writeln ' );
237+
238+ $ this ->output
239+ ->expects (self ::never ())
240+ ->method ('writeln ' );
241+
242+ $ this
243+ ->getVersions
244+ ->expects (self ::never ())
245+ ->method ('fromRepository ' );
246+
247+ $ this
248+ ->pickVersion
249+ ->expects (self ::never ())
250+ ->method ('forVersions ' );
251+
183252 self ::assertSame (0 , $ this ->compare ->execute ($ this ->input , $ this ->output ));
184253 self ::assertSame (0 , $ this ->performCheckout ->nonRemovedRepositoryCount ());
185254 }
@@ -205,6 +274,7 @@ public function testExecuteReturnsNonZeroExitCodeWhenChangesAreDetected(): void
205274
206275 $ this
207276 ->locateDependencies
277+ ->expects (self ::atLeastOnce ())
208278 ->method ('__invoke ' )
209279 ->with ((string ) $ this ->sourceRepository , false )
210280 ->willReturn ($ this ->dependencies );
@@ -223,6 +293,20 @@ public function testExecuteReturnsNonZeroExitCodeWhenChangesAreDetected(): void
223293 self ::matches ('<error>1 backwards-incompatible changes detected</error> ' ),
224294 ));
225295
296+ $ this ->output
297+ ->expects (self ::never ())
298+ ->method ('writeln ' );
299+
300+ $ this
301+ ->getVersions
302+ ->expects (self ::never ())
303+ ->method ('fromRepository ' );
304+
305+ $ this
306+ ->pickVersion
307+ ->expects (self ::never ())
308+ ->method ('forVersions ' );
309+
226310 self ::assertSame (3 , $ this ->compare ->execute ($ this ->input , $ this ->output ));
227311 self ::assertSame (0 , $ this ->performCheckout ->nonRemovedRepositoryCount ());
228312 }
@@ -248,6 +332,7 @@ public function testProvidingMarkdownOptionWritesMarkdownOutput(): void
248332
249333 $ this
250334 ->locateDependencies
335+ ->expects (self ::atLeastOnce ())
251336 ->method ('__invoke ' )
252337 ->with ((string ) $ this ->sourceRepository , false )
253338 ->willReturn ($ this ->dependencies );
@@ -264,6 +349,20 @@ public function testProvidingMarkdownOptionWritesMarkdownOutput(): void
264349 self ::assertStringContainsString (' [BC] ' . $ changeToExpect , $ output );
265350 });
266351
352+ $ this ->stdErr
353+ ->expects (self ::atLeastOnce ())
354+ ->method ('writeln ' );
355+
356+ $ this
357+ ->getVersions
358+ ->expects (self ::never ())
359+ ->method ('fromRepository ' );
360+
361+ $ this
362+ ->pickVersion
363+ ->expects (self ::never ())
364+ ->method ('forVersions ' );
365+
267366 $ this ->compare ->execute ($ this ->input , $ this ->output );
268367 self ::assertSame (0 , $ this ->performCheckout ->nonRemovedRepositoryCount ());
269368 }
@@ -288,15 +387,29 @@ public function testExecuteWithDefaultRevisionsNotProvidedAndNoDetectedTags(): v
288387 ->expects (self ::once ())
289388 ->method ('fromRepository ' )
290389 ->willReturn (new VersionCollection ());
390+
291391 $ this
292392 ->pickVersion
293393 ->expects (self ::never ())
294394 ->method ('forVersions ' );
395+
295396 $ this
296397 ->compareApi
297398 ->expects (self ::never ())
298399 ->method ('__invoke ' );
299400
401+ $ this ->output
402+ ->expects (self ::never ())
403+ ->method ('writeln ' );
404+
405+ $ this ->stdErr
406+ ->expects (self ::never ())
407+ ->method ('writeln ' );
408+
409+ $ this ->locateDependencies
410+ ->expects (self ::never ())
411+ ->method ('__invoke ' );
412+
300413 $ this ->expectException (InvariantViolationException::class);
301414
302415 $ this ->compare ->execute ($ this ->input , $ this ->output );
@@ -327,18 +440,29 @@ public function testExecuteWithDefaultRevisionsNotProvided(VersionCollection $ve
327440 default => throw new LogicException (),
328441 });
329442
330- $ this ->getVersions ->expects (self ::once ())
443+ $ this ->getVersions
444+ ->expects (self ::once ())
331445 ->method ('fromRepository ' )
332446 ->with (self ::callback (function (CheckedOutRepository $ checkedOutRepository ): bool {
333447 self ::assertEquals ($ this ->sourceRepository , $ checkedOutRepository );
334448
335449 return true ;
336450 }))
337451 ->willReturn ($ versions );
338- $ this ->pickVersion ->expects (self ::once ())
452+
453+ $ this ->pickVersion
454+ ->expects (self ::once ())
339455 ->method ('forVersions ' )
340456 ->with ($ versions )
341457 ->willReturn ($ pickedVersion );
458+
459+ $ this ->output
460+ ->expects (self ::never ())
461+ ->method ('writeln ' );
462+
463+ $ this ->locateDependencies
464+ ->expects (self ::atLeastOnce ())
465+ ->method ('__invoke ' );
342466
343467 $ this
344468 ->stdErr
0 commit comments