@@ -31,14 +31,15 @@ class CopyFromPackageConfiguratorTest extends TestCase
3131 private $ targetDirectory ;
3232 private $ io ;
3333 private $ recipe ;
34+ private $ composer ;
3435
3536 public function testNoFilesCopied ()
3637 {
3738 if (!file_exists ($ this ->targetDirectory )) {
3839 mkdir ($ this ->targetDirectory );
3940 }
4041 file_put_contents ($ this ->targetFile , '' );
41- $ this ->io ->expects ($ this ->exactly ( 1 ))->method ('writeError ' )->with ([' Copying files from package ' ]);
42+ $ this ->io ->expects ($ this ->once ( ))->method ('writeError ' )->with ([' Copying files from package ' ]);
4243 $ lock = $ this ->getMockBuilder (Lock::class)->disableOriginalConstructor ()->getMock ();
4344 $ this ->createConfigurator ()->configure ($ this ->recipe , [$ this ->sourceFileRelativePath => $ this ->targetFileRelativePath ], $ lock );
4445 }
@@ -55,8 +56,13 @@ public function testConfigureAndOverwriteFiles()
5556 file_put_contents ($ this ->targetFile , '- ' );
5657 $ lock = $ this ->getMockBuilder (Lock::class)->disableOriginalConstructor ()->getMock ();
5758
58- $ this ->io ->expects ($ this ->at (0 ))->method ('writeError ' )->with ([' Copying files from package ' ]);
59- $ this ->io ->expects ($ this ->at (2 ))->method ('writeError ' )->with ([' Created <fg=green>"./public/file"</> ' ]);
59+ $ expectedMessages = [
60+ ' Copying files from package ' ,
61+ ' Created <fg=green>"./public/file"</> ' ,
62+ ];
63+ $ this ->io ->expects ($ this ->exactly (2 ))->method ('writeError ' )->willReturnCallback (function ($ message ) use (&$ expectedMessages ) {
64+ $ this ->assertSame ([array_shift ($ expectedMessages )], $ message );
65+ });
6066 $ this ->io ->method ('askConfirmation ' )->with ('File "build/public/file" has uncommitted changes, overwrite? [y/N] ' )->willReturn (true );
6167
6268 $ this ->assertFileExists ($ this ->targetFile );
@@ -88,9 +94,14 @@ public function testConfigure()
8894 file_put_contents ($ this ->sourceFile , '' );
8995 }
9096
91- $ this ->io ->expects ($ this ->at (0 ))->method ('writeError ' )->with ([' Copying files from package ' ]);
92- $ this ->io ->expects ($ this ->at (1 ))->method ('writeError ' )->with ([' Created <fg=green>"./public/"</> ' ]);
93- $ this ->io ->expects ($ this ->at (2 ))->method ('writeError ' )->with ([' Created <fg=green>"./public/file"</> ' ]);
97+ $ expectedMessages = [
98+ ' Copying files from package ' ,
99+ ' Created <fg=green>"./public/"</> ' ,
100+ ' Created <fg=green>"./public/file"</> ' ,
101+ ];
102+ $ this ->io ->expects ($ this ->exactly (3 ))->method ('writeError ' )->willReturnCallback (function ($ message ) use (&$ expectedMessages ) {
103+ $ this ->assertSame ([array_shift ($ expectedMessages )], $ message );
104+ });
94105
95106 $ this ->assertFileDoesNotExist ($ this ->targetFile );
96107 $ lock = $ this ->getMockBuilder (Lock::class)->disableOriginalConstructor ()->getMock ();
@@ -100,8 +111,13 @@ public function testConfigure()
100111
101112 public function testUnconfigure ()
102113 {
103- $ this ->io ->expects ($ this ->at (0 ))->method ('writeError ' )->with ([' Removing files from package ' ]);
104- $ this ->io ->expects ($ this ->at (1 ))->method ('writeError ' )->with ([' Removed <fg=green>"./public/file"</> ' ]);
114+ $ expectedMessages = [
115+ ' Removing files from package ' ,
116+ ' Removed <fg=green>"./public/file"</> ' ,
117+ ];
118+ $ this ->io ->expects ($ this ->exactly (2 ))->method ('writeError ' )->willReturnCallback (function ($ message ) use (&$ expectedMessages ) {
119+ $ this ->assertSame ([array_shift ($ expectedMessages )], $ message );
120+ });
105121
106122 if (!file_exists ($ this ->targetDirectory )) {
107123 mkdir ($ this ->targetDirectory );
0 commit comments