@@ -144,7 +144,7 @@ protected function setUp(): void
144144 ->getMock ();
145145
146146 $ this ->eventMock = $ this ->getMockBuilder (PackageEvent::class)
147- ->onlyMethods (['getOperation ' , 'getComposer ' , 'getRequest ' ])
147+ ->onlyMethods (['getOperation ' , 'getComposer ' , 'getRequest ' , ' getIO ' ])
148148 ->disableOriginalConstructor ()
149149 ->getMock ();
150150
@@ -161,7 +161,7 @@ protected function setUp(): void
161161 ->getMock ();
162162
163163 $ this ->eventMock = $ this ->getMockBuilder (PackageEvent::class)
164- ->onlyMethods (['getOperation ' , 'getComposer ' ])
164+ ->onlyMethods (['getOperation ' , 'getComposer ' , ' getIO ' ])
165165 ->disableOriginalConstructor ()
166166 ->getMock ();
167167
@@ -236,7 +236,7 @@ protected function setUp(): void
236236 ->method ('getName ' )
237237 ->willReturn (self ::PACKAGE_NAME );
238238
239- $ this ->plugin = new Plugin ($ this ->versionSelectorMock , $ this -> ioMock );
239+ $ this ->plugin = new Plugin ($ this ->versionSelectorMock );
240240 $ this ->repositoryManager ->addRepository ($ this ->repositoryMock1 );
241241 $ this ->repositoryManager ->addRepository ($ this ->repositoryMock2 );
242242 parent ::setUp ();
@@ -263,21 +263,22 @@ public function testValidPackageUpdate(): void
263263 ->method ('getFullPrettyVersion ' )
264264 ->willReturnOnConsecutiveCalls ('1.0.1 ' , '1.0.10 ' );
265265
266+ $ constraintMock = $ this ->getMockBuilder (Constraint::class)
267+ ->onlyMethods (['getPrettyString ' ])
268+ ->disableOriginalConstructor ()
269+ ->getMock ();
270+
271+ $ constraintMock ->expects ($ this ->any ())
272+ ->method ('getPrettyString ' )
273+ ->willReturn ("1.0.5 " );
274+
266275 if ((int )explode ('. ' , Composer::VERSION )[0 ] === 1 ) {
267276 $ this ->requestMock ->expects ($ this ->any ())
268277 ->method ('getJobs ' )
269278 ->willReturn ([
270- ['packageName ' => self ::PACKAGE_NAME , 'cmd ' => 'install ' , 'fixed ' => true ]
279+ ['packageName ' => self ::PACKAGE_NAME , 'cmd ' => 'install ' , 'fixed ' => true , ' constraint ' => $ constraintMock ]
271280 ]);
272281 } else {
273- $ constraintMock = $ this ->getMockBuilder (Constraint::class)
274- ->onlyMethods (['getPrettyString ' ])
275- ->disableOriginalConstructor ()
276- ->getMock ();
277-
278- $ constraintMock ->expects ($ this ->any ())
279- ->method ('getPrettyString ' )
280- ->willReturn ("1.0.5 " );
281282
282283 $ this ->requestMock ->expects ($ this ->any ())
283284 ->method ('getRequires ' )
@@ -320,6 +321,15 @@ public function testInvalidPackageUpdateWithWarning(): void
320321 ->method ('getFullPrettyVersion ' )
321322 ->willReturnOnConsecutiveCalls ($ publicRepoVersion , $ privateRepoVersion );
322323
324+ $ constraintMock = $ this ->getMockBuilder (Constraint::class)
325+ ->onlyMethods (['getPrettyString ' ])
326+ ->disableOriginalConstructor ()
327+ ->getMock ();
328+
329+ $ constraintMock ->expects ($ this ->any ())
330+ ->method ('getPrettyString ' )
331+ ->willReturn ("1.0.5 " );
332+
323333 $ packageName = self ::PACKAGE_NAME ;
324334 $ exceptionMessage = "<warning>Higher matching version {$ publicRepoVersion } of {$ packageName } was found in public repository packagist.org
325335 than {$ privateRepoVersion } in private {$ privateRepoUrl }. Public package might've been taken over by a malicious entity,
@@ -329,17 +339,9 @@ public function testInvalidPackageUpdateWithWarning(): void
329339 $ this ->requestMock ->expects ($ this ->any ())
330340 ->method ('getJobs ' )
331341 ->willReturn ([
332- ['packageName ' => self ::PACKAGE_NAME , 'cmd ' => 'install ' , 'fixed ' => true ]
342+ ['packageName ' => self ::PACKAGE_NAME , 'cmd ' => 'install ' , 'fixed ' => true , ' constraint ' => $ constraintMock ]
333343 ]);
334344 } else {
335- $ constraintMock = $ this ->getMockBuilder (Constraint::class)
336- ->onlyMethods (['getPrettyString ' ])
337- ->disableOriginalConstructor ()
338- ->getMock ();
339-
340- $ constraintMock ->expects ($ this ->any ())
341- ->method ('getPrettyString ' )
342- ->willReturn ("1.0.5 " );
343345
344346 $ this ->requestMock ->expects ($ this ->any ())
345347 ->method ('getRequires ' )
@@ -358,6 +360,10 @@ public function testInvalidPackageUpdateWithWarning(): void
358360 ->method ('writeError ' )
359361 ->with ($ this ->stringContains ($ exceptionMessage ));
360362
363+ $ this ->eventMock ->expects ($ this ->once ())
364+ ->method ('getIO ' )
365+ ->willReturn ($ this ->ioMock );
366+
361367 $ this ->plugin ->packageUpdate ($ this ->eventMock );
362368 }
363369
@@ -386,21 +392,22 @@ public function testInvalidPackageUpdateWithException(): void
386392 ->method ('getFullPrettyVersion ' )
387393 ->willReturnOnConsecutiveCalls ($ publicRepoVersion , $ privateRepoVersion );
388394
395+ $ constraintMock = $ this ->getMockBuilder (Constraint::class)
396+ ->onlyMethods (['getPrettyString ' ])
397+ ->disableOriginalConstructor ()
398+ ->getMock ();
399+
400+ $ constraintMock ->expects ($ this ->any ())
401+ ->method ('getPrettyString ' )
402+ ->willReturn ("1.0.* " );
403+
389404 if ((int )explode ('. ' , Composer::VERSION )[0 ] === 1 ) {
390405 $ this ->requestMock ->expects ($ this ->any ())
391406 ->method ('getJobs ' )
392407 ->willReturn ([
393- ['packageName ' => self ::PACKAGE_NAME , 'cmd ' => 'install ' , 'fixed ' => false ]
408+ ['packageName ' => self ::PACKAGE_NAME , 'cmd ' => 'install ' , 'fixed ' => false , ' constraint ' => $ constraintMock ]
394409 ]);
395410 } else {
396- $ constraintMock = $ this ->getMockBuilder (Constraint::class)
397- ->onlyMethods (['getPrettyString ' ])
398- ->disableOriginalConstructor ()
399- ->getMock ();
400-
401- $ constraintMock ->expects ($ this ->any ())
402- ->method ('getPrettyString ' )
403- ->willReturn ("1.0.* " );
404411
405412 $ this ->requestMock ->expects ($ this ->any ())
406413 ->method ('getRequires ' )
0 commit comments