@@ -145,6 +145,146 @@ public function testWillSwitchToExistingNewestDefaultBranch(): void
145145 self ::assertSame (0 , $ this ->command ->run (new ArrayInput ([]), new NullOutput ()));
146146 }
147147
148+ public function testWillSwitchToExistingNewestDefaultBranchEvenWithNewMajorBranchExist (): void
149+ {
150+ $ event = MilestoneClosedEvent::fromEventJson (
151+ <<<'JSON'
152+ {
153+ "milestone": {
154+ "title": "1.3.0",
155+ "number": 123
156+ },
157+ "repository": {
158+ "full_name": "foo/bar"
159+ },
160+ "action": "closed"
161+ }
162+ JSON,
163+ );
164+
165+ $ workspace = Filesystem \create_temporary_file (Env \temp_dir (), 'workspace ' );
166+
167+ Filesystem \delete_file ($ workspace );
168+ Filesystem \create_directory ($ workspace );
169+ Filesystem \create_directory ($ workspace . '/.git ' );
170+
171+ $ this ->variables ->method ('githubWorkspacePath ' )
172+ ->willReturn ($ workspace );
173+
174+ $ this ->loadEvent ->method ('__invoke ' )
175+ ->willReturn ($ event );
176+
177+ $ this ->fetch ->expects (self ::once ())
178+ ->method ('__invoke ' )
179+ ->with (
180+ 'https://github.com/foo/bar.git ' ,
181+ 'https://github-auth-token:x-oauth-basic@github.com/foo/bar.git ' ,
182+ $ workspace ,
183+ );
184+
185+ $ this ->getMergeTargets ->method ('__invoke ' )
186+ ->with ($ workspace )
187+ ->willReturn (MergeTargetCandidateBranches::fromAllBranches (
188+ BranchName::fromName ('1.1.x ' ),
189+ BranchName::fromName ('1.2.x ' ),
190+ BranchName::fromName ('1.3.x ' ),
191+ BranchName::fromName ('2.0.x ' ),
192+ BranchName::fromName ('master ' ),
193+ ));
194+
195+ $ this ->push ->expects (self ::once ())
196+ ->method ('__invoke ' )
197+ ->with ($ workspace , '1.3.x ' , '1.4.x ' );
198+
199+ $ this ->bumpChangelogVersion ->expects (self ::once ())
200+ ->method ('__invoke ' )
201+ ->with (
202+ BumpAndCommitChangelogVersion::BUMP_MINOR ,
203+ $ workspace ,
204+ SemVerVersion::fromMilestoneName ('1.3.0 ' ),
205+ BranchName::fromName ('1.4.x ' ),
206+ );
207+
208+ $ this ->setDefaultBranch ->expects (self ::once ())
209+ ->method ('__invoke ' )
210+ ->with (
211+ self ::equalTo (RepositoryName::fromFullName ('foo/bar ' )),
212+ self ::equalTo (BranchName::fromName ('1.4.x ' )),
213+ );
214+
215+ self ::assertSame (0 , $ this ->command ->run (new ArrayInput ([]), new NullOutput ()));
216+ }
217+
218+ public function testWillNotSwitchToBranchWhenTargetBranchNotFound (): void
219+ {
220+ $ event = MilestoneClosedEvent::fromEventJson (
221+ <<<'JSON'
222+ {
223+ "milestone": {
224+ "title": "1.4.0",
225+ "number": 123
226+ },
227+ "repository": {
228+ "full_name": "foo/bar"
229+ },
230+ "action": "closed"
231+ }
232+ JSON,
233+ );
234+
235+ $ workspace = Filesystem \create_temporary_file (Env \temp_dir (), 'workspace ' );
236+
237+ Filesystem \delete_file ($ workspace );
238+ Filesystem \create_directory ($ workspace );
239+ Filesystem \create_directory ($ workspace . '/.git ' );
240+
241+ $ this ->variables ->method ('githubWorkspacePath ' )
242+ ->willReturn ($ workspace );
243+
244+ $ this ->loadEvent ->method ('__invoke ' )
245+ ->willReturn ($ event );
246+
247+ $ this ->fetch ->expects (self ::once ())
248+ ->method ('__invoke ' )
249+ ->with (
250+ 'https://github.com/foo/bar.git ' ,
251+ 'https://github-auth-token:x-oauth-basic@github.com/foo/bar.git ' ,
252+ $ workspace ,
253+ );
254+
255+ $ this ->getMergeTargets ->method ('__invoke ' )
256+ ->with ($ workspace )
257+ ->willReturn (MergeTargetCandidateBranches::fromAllBranches (
258+ BranchName::fromName ('1.1.x ' ),
259+ BranchName::fromName ('1.2.x ' ),
260+ BranchName::fromName ('1.3.x ' ),
261+ BranchName::fromName ('2.0.x ' ),
262+ BranchName::fromName ('master ' ),
263+ ));
264+
265+ $ this ->push ->expects (self ::never ())
266+ ->method ('__invoke ' );
267+
268+ $ this ->bumpChangelogVersion ->expects (self ::never ())
269+ ->method ('__invoke ' );
270+
271+ $ this ->setDefaultBranch ->expects (self ::never ())
272+ ->method ('__invoke ' );
273+
274+ $ output = new BufferedOutput ();
275+
276+ self ::assertSame (1 , $ this ->command ->run (new ArrayInput ([]), $ output ));
277+
278+ self ::assertSame (
279+ <<<'OUTPUT'
280+ Target branch for release [1.4.0] was not found. Expected [1.4.x] to exist.
281+
282+ OUTPUT
283+ ,
284+ $ output ->fetch (),
285+ );
286+ }
287+
148288 public function testWillSwitchToNewlyCreatedDefaultBranchWhenNoNewerReleaseBranchExists (): void
149289 {
150290 $ workspace = Filesystem \create_temporary_file (Env \temp_dir (), 'workspace ' );
0 commit comments