@@ -31,14 +31,15 @@ class CopyFromPackageConfiguratorTest extends TestCase
31
31
private $ targetDirectory ;
32
32
private $ io ;
33
33
private $ recipe ;
34
+ private $ composer ;
34
35
35
36
public function testNoFilesCopied ()
36
37
{
37
38
if (!file_exists ($ this ->targetDirectory )) {
38
39
mkdir ($ this ->targetDirectory );
39
40
}
40
41
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 ' ]);
42
43
$ lock = $ this ->getMockBuilder (Lock::class)->disableOriginalConstructor ()->getMock ();
43
44
$ this ->createConfigurator ()->configure ($ this ->recipe , [$ this ->sourceFileRelativePath => $ this ->targetFileRelativePath ], $ lock );
44
45
}
@@ -55,8 +56,13 @@ public function testConfigureAndOverwriteFiles()
55
56
file_put_contents ($ this ->targetFile , '- ' );
56
57
$ lock = $ this ->getMockBuilder (Lock::class)->disableOriginalConstructor ()->getMock ();
57
58
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
+ });
60
66
$ this ->io ->method ('askConfirmation ' )->with ('File "build/public/file" has uncommitted changes, overwrite? [y/N] ' )->willReturn (true );
61
67
62
68
$ this ->assertFileExists ($ this ->targetFile );
@@ -88,9 +94,14 @@ public function testConfigure()
88
94
file_put_contents ($ this ->sourceFile , '' );
89
95
}
90
96
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
+ });
94
105
95
106
$ this ->assertFileDoesNotExist ($ this ->targetFile );
96
107
$ lock = $ this ->getMockBuilder (Lock::class)->disableOriginalConstructor ()->getMock ();
@@ -100,8 +111,13 @@ public function testConfigure()
100
111
101
112
public function testUnconfigure ()
102
113
{
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
+ });
105
121
106
122
if (!file_exists ($ this ->targetDirectory )) {
107
123
mkdir ($ this ->targetDirectory );
0 commit comments