@@ -144,7 +144,7 @@ protected function setUp(): void
144
144
->getMock ();
145
145
146
146
$ this ->eventMock = $ this ->getMockBuilder (PackageEvent::class)
147
- ->onlyMethods (['getOperation ' , 'getComposer ' , 'getRequest ' ])
147
+ ->onlyMethods (['getOperation ' , 'getComposer ' , 'getRequest ' , ' getIO ' ])
148
148
->disableOriginalConstructor ()
149
149
->getMock ();
150
150
@@ -161,7 +161,7 @@ protected function setUp(): void
161
161
->getMock ();
162
162
163
163
$ this ->eventMock = $ this ->getMockBuilder (PackageEvent::class)
164
- ->onlyMethods (['getOperation ' , 'getComposer ' ])
164
+ ->onlyMethods (['getOperation ' , 'getComposer ' , ' getIO ' ])
165
165
->disableOriginalConstructor ()
166
166
->getMock ();
167
167
@@ -236,7 +236,7 @@ protected function setUp(): void
236
236
->method ('getName ' )
237
237
->willReturn (self ::PACKAGE_NAME );
238
238
239
- $ this ->plugin = new Plugin ($ this ->versionSelectorMock , $ this -> ioMock );
239
+ $ this ->plugin = new Plugin ($ this ->versionSelectorMock );
240
240
$ this ->repositoryManager ->addRepository ($ this ->repositoryMock1 );
241
241
$ this ->repositoryManager ->addRepository ($ this ->repositoryMock2 );
242
242
parent ::setUp ();
@@ -263,21 +263,22 @@ public function testValidPackageUpdate(): void
263
263
->method ('getFullPrettyVersion ' )
264
264
->willReturnOnConsecutiveCalls ('1.0.1 ' , '1.0.10 ' );
265
265
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
+
266
275
if ((int )explode ('. ' , Composer::VERSION )[0 ] === 1 ) {
267
276
$ this ->requestMock ->expects ($ this ->any ())
268
277
->method ('getJobs ' )
269
278
->willReturn ([
270
- ['packageName ' => self ::PACKAGE_NAME , 'cmd ' => 'install ' , 'fixed ' => true ]
279
+ ['packageName ' => self ::PACKAGE_NAME , 'cmd ' => 'install ' , 'fixed ' => true , ' constraint ' => $ constraintMock ]
271
280
]);
272
281
} 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 " );
281
282
282
283
$ this ->requestMock ->expects ($ this ->any ())
283
284
->method ('getRequires ' )
@@ -320,6 +321,15 @@ public function testInvalidPackageUpdateWithWarning(): void
320
321
->method ('getFullPrettyVersion ' )
321
322
->willReturnOnConsecutiveCalls ($ publicRepoVersion , $ privateRepoVersion );
322
323
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
+
323
333
$ packageName = self ::PACKAGE_NAME ;
324
334
$ exceptionMessage = "<warning>Higher matching version {$ publicRepoVersion } of {$ packageName } was found in public repository packagist.org
325
335
than {$ privateRepoVersion } in private {$ privateRepoUrl }. Public package might've been taken over by a malicious entity,
@@ -329,17 +339,9 @@ public function testInvalidPackageUpdateWithWarning(): void
329
339
$ this ->requestMock ->expects ($ this ->any ())
330
340
->method ('getJobs ' )
331
341
->willReturn ([
332
- ['packageName ' => self ::PACKAGE_NAME , 'cmd ' => 'install ' , 'fixed ' => true ]
342
+ ['packageName ' => self ::PACKAGE_NAME , 'cmd ' => 'install ' , 'fixed ' => true , ' constraint ' => $ constraintMock ]
333
343
]);
334
344
} 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 " );
343
345
344
346
$ this ->requestMock ->expects ($ this ->any ())
345
347
->method ('getRequires ' )
@@ -358,6 +360,10 @@ public function testInvalidPackageUpdateWithWarning(): void
358
360
->method ('writeError ' )
359
361
->with ($ this ->stringContains ($ exceptionMessage ));
360
362
363
+ $ this ->eventMock ->expects ($ this ->once ())
364
+ ->method ('getIO ' )
365
+ ->willReturn ($ this ->ioMock );
366
+
361
367
$ this ->plugin ->packageUpdate ($ this ->eventMock );
362
368
}
363
369
@@ -386,21 +392,22 @@ public function testInvalidPackageUpdateWithException(): void
386
392
->method ('getFullPrettyVersion ' )
387
393
->willReturnOnConsecutiveCalls ($ publicRepoVersion , $ privateRepoVersion );
388
394
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
+
389
404
if ((int )explode ('. ' , Composer::VERSION )[0 ] === 1 ) {
390
405
$ this ->requestMock ->expects ($ this ->any ())
391
406
->method ('getJobs ' )
392
407
->willReturn ([
393
- ['packageName ' => self ::PACKAGE_NAME , 'cmd ' => 'install ' , 'fixed ' => false ]
408
+ ['packageName ' => self ::PACKAGE_NAME , 'cmd ' => 'install ' , 'fixed ' => false , ' constraint ' => $ constraintMock ]
394
409
]);
395
410
} 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.* " );
404
411
405
412
$ this ->requestMock ->expects ($ this ->any ())
406
413
->method ('getRequires ' )
0 commit comments