@@ -1095,4 +1095,63 @@ public function testGetStackStateCountsOnlyCreatedContainers(): void
10951095 $ this ->assertSame (2 , $ state ['running ' ]);
10961096 $ this ->assertSame ('partial (2/3) ' , $ state ['label ' ]);
10971097 }
1098+ /**
1099+ * Bug #95: When importing an indirect project that already has docker-compose.yml,
1100+ * compose manager should NOT create a new compose.yaml and should resolve the
1101+ * override name based on the existing file.
1102+ */
1103+ public function testCreateNewIndirectExistingDockerComposeYml (): void
1104+ {
1105+ $ indirectDir = $ this ->tempRoot . '/falco ' ;
1106+ mkdir ($ indirectDir , 0755 , true );
1107+ file_put_contents ("$ indirectDir/docker-compose.yml " , "services: \n falco: \n image: falco \n" );
1108+
1109+ $ stack = \StackInfo::createNew ($ this ->tempRoot , 'Falco ' , '' , $ indirectDir );
1110+
1111+ $ this ->assertTrue ($ stack ->isIndirect );
1112+ // Should NOT create compose.yaml when docker-compose.yml already exists
1113+ $ this ->assertFileDoesNotExist ("$ indirectDir/compose.yaml " ,
1114+ "compose.yaml should not be created when docker-compose.yml already exists " );
1115+ // Should NOT overwrite existing compose file
1116+ $ this ->assertSame ("services: \n falco: \n image: falco \n" ,
1117+ file_get_contents ("$ indirectDir/docker-compose.yml " ));
1118+ // The resolved compose file should be the existing docker-compose.yml
1119+ $ this ->assertSame ("$ indirectDir/docker-compose.yml " , $ stack ->composeFilePath );
1120+ // The override should be named to match docker-compose.yml, not compose.yaml
1121+ $ this ->assertSame ('docker-compose.override.yml ' , $ stack ->overrideInfo ->computedName );
1122+ }
1123+
1124+ /**
1125+ * Bug #95 variant: Same issue with docker-compose.yaml
1126+ */
1127+ public function testCreateNewIndirectExistingDockerComposeYaml (): void
1128+ {
1129+ $ indirectDir = $ this ->tempRoot . '/test-yaml ' ;
1130+ mkdir ($ indirectDir , 0755 , true );
1131+ file_put_contents ("$ indirectDir/docker-compose.yaml " , "services: \n app: \n image: app \n" );
1132+
1133+ $ stack = \StackInfo::createNew ($ this ->tempRoot , 'TestYaml ' , '' , $ indirectDir );
1134+
1135+ $ this ->assertTrue ($ stack ->isIndirect );
1136+ $ this ->assertFileDoesNotExist ("$ indirectDir/compose.yaml " );
1137+ $ this ->assertSame ("$ indirectDir/docker-compose.yaml " , $ stack ->composeFilePath );
1138+ $ this ->assertSame ('docker-compose.override.yaml ' , $ stack ->overrideInfo ->computedName );
1139+ }
1140+
1141+ /**
1142+ * Bug #95 variant: Same issue with compose.yml
1143+ */
1144+ public function testCreateNewIndirectExistingComposeYml (): void
1145+ {
1146+ $ indirectDir = $ this ->tempRoot . '/test-yml ' ;
1147+ mkdir ($ indirectDir , 0755 , true );
1148+ file_put_contents ("$ indirectDir/compose.yml " , "services: \n svc: \n image: svc \n" );
1149+
1150+ $ stack = \StackInfo::createNew ($ this ->tempRoot , 'TestYml ' , '' , $ indirectDir );
1151+
1152+ $ this ->assertTrue ($ stack ->isIndirect );
1153+ $ this ->assertFileDoesNotExist ("$ indirectDir/compose.yaml " );
1154+ $ this ->assertSame ("$ indirectDir/compose.yml " , $ stack ->composeFilePath );
1155+ $ this ->assertSame ('compose.override.yml ' , $ stack ->overrideInfo ->computedName );
1156+ }
10981157}
0 commit comments