@@ -55,6 +55,50 @@ public function testConfigureDirectory()
5555 }
5656 }
5757
58+ /**
59+ * @dataProvider providerTestConfigureDirectoryWithExistingFiles
60+ */
61+ public function testConfigureDirectoryWithExistingFiles (bool $ force , string $ sourceFileContent , string $ existingTargetFileContent , string $ expectedFinalTargetFileContent )
62+ {
63+ if (!is_dir ($ this ->sourceDirectory )) {
64+ mkdir ($ this ->sourceDirectory , 0777 , true );
65+ }
66+ foreach ($ this ->sourceFiles as $ sourceFile ) {
67+ if (!file_exists ($ sourceFile )) {
68+ file_put_contents ($ sourceFile , $ sourceFileContent );
69+ }
70+ }
71+
72+ if (!is_dir ($ this ->targetDirectory )) {
73+ mkdir ($ this ->targetDirectory , 0777 , true );
74+ }
75+
76+ foreach ($ this ->targetFiles as $ targetFile ) {
77+ file_put_contents ($ targetFile , $ existingTargetFileContent );
78+ }
79+
80+ $ this ->createConfigurator ()->configure (
81+ $ this ->recipe ,
82+ [$ this ->sourceFileRelativePath => $ this ->targetFileRelativePath ],
83+ $ this ->getMockBuilder (Lock::class)->disableOriginalConstructor ()->getMock (),
84+ ['force ' => $ force ]
85+ );
86+
87+ foreach ($ this ->targetFiles as $ targetFile ) {
88+ $ this ->assertFileExists ($ targetFile );
89+ $ content = file_get_contents ($ targetFile );
90+ $ this ->assertEquals ($ expectedFinalTargetFileContent , $ content );
91+ }
92+ }
93+
94+ public function providerTestConfigureDirectoryWithExistingFiles (): array
95+ {
96+ return [
97+ [true , 'NEW_CONTENT ' , 'OLD_CONTENT ' , 'NEW_CONTENT ' ],
98+ [false , 'NEW_CONTENT ' , 'OLD_CONTENT ' , 'OLD_CONTENT ' ],
99+ ];
100+ }
101+
58102 protected function setUp (): void
59103 {
60104 parent ::setUp ();
@@ -74,6 +118,7 @@ protected function setUp(): void
74118 ];
75119
76120 $ this ->io = $ this ->getMockBuilder (IOInterface::class)->getMock ();
121+ $ this ->io ->method ('askConfirmation ' )->willReturn (true );
77122
78123 $ package = $ this ->getMockBuilder (PackageInterface::class)->getMock ();
79124 $ this ->recipe = $ this ->getMockBuilder (Recipe::class)->disableOriginalConstructor ()->getMock ();
@@ -106,7 +151,7 @@ protected function tearDown(): void
106151
107152 private function createConfigurator (): CopyFromPackageConfigurator
108153 {
109- return new CopyFromPackageConfigurator ($ this ->composer , $ this ->io , new Options (['root-dir ' => FLEX_TEST_DIR ]));
154+ return new CopyFromPackageConfigurator ($ this ->composer , $ this ->io , new Options (['root-dir ' => FLEX_TEST_DIR ], $ this -> io ));
110155 }
111156
112157 private function cleanUpTargetFiles ()
0 commit comments