@@ -9,13 +9,25 @@ class ReleaseCommandTest extends GitHub_TestCase {
99 const REPO = 'repos/wp-cli/block-command ' ;
1010
1111 /**
12- * Sets up a repository whose latest tag is v1.0.0, with the given open
13- * milestones, each holding the recorded merged pull requests #18 and #19.
12+ * Sets up a repository whose latest tag is the first of the given tags,
13+ * with the given open milestones, each holding the recorded merged pull
14+ * requests #18 and #19.
1415 *
1516 * @param array<int, string> $milestones Milestone number => title.
16- * @param string[] $tags Tag names.
17+ * @param string[] $tags Tag names, latest first.
18+ * @param array<int, string> $on_branch Pull requests merged into the
19+ * default branch since the latest
20+ * tag: number => milestone title.
21+ * Defaults to #18 and #19 on the
22+ * first milestone.
23+ * @param array<int, int> $open_items Milestone number => open items.
1724 */
18- private function repository ( array $ milestones , array $ tags = [ 'v1.0.0 ' ] ) {
25+ private function repository ( array $ milestones , array $ tags = [ 'v1.0.0 ' ], $ on_branch = null , array $ open_items = [] ) {
26+ $ comparison = $ this ->fixture ( 'comparison ' );
27+ if ( null === $ on_branch ) {
28+ $ on_branch = array_fill_keys ( [ 18 , 19 ], reset ( $ milestones ) );
29+ }
30+
1931 $ this ->respond ( 'GET ' , self ::REPO . '/releases ' , [] );
2032 $ this ->respond (
2133 'GET ' ,
@@ -27,24 +39,45 @@ function ( $tag ) {
2739 $ tags
2840 )
2941 );
42+ $ this ->respond ( 'GET ' , self ::REPO . "/compare/ {$ tags [0 ]}...main " , $ comparison );
43+
44+ $ pull_requests = [];
45+ $ index = 0 ;
46+ foreach ( $ on_branch as $ number => $ milestone ) {
47+ $ pull_requests [] = $ this ->fixture_object (
48+ 'pull-requests ' ,
49+ 0 ,
50+ [
51+ 'number ' => $ number ,
52+ 'updated_at ' => '2026-09-01T00:00:00Z ' ,
53+ 'merged_at ' => '2026-09-01T00:00:00Z ' ,
54+ 'merge_commit_sha ' => $ comparison ->commits [ $ index ++ ]->sha ,
55+ 'milestone ' => [ 'title ' => $ milestone ],
56+ ]
57+ );
58+ }
59+ $ this ->respond ( 'GET ' , self ::REPO . '/pulls ' , $ pull_requests );
3060
3161 $ open = [];
3262 foreach ( $ milestones as $ number => $ title ) {
63+ $ count = isset ( $ open_items [ $ number ] ) ? $ open_items [ $ number ] : 0 ;
3364 $ open [] = $ this ->fixture_object (
3465 'milestone ' ,
3566 null ,
3667 [
3768 'number ' => $ number ,
3869 'title ' => $ title ,
3970 'state ' => 'open ' ,
40- 'open_issues ' => 0 ,
71+ 'open_issues ' => $ count ,
4172 ]
4273 );
43- $ this ->respond ( 'GET ' , self ::REPO . "/issues?milestone= {$ number }&state=open " , [] );
74+ $ this ->respond ( 'GET ' , self ::REPO . "/issues?milestone= {$ number }&state=open " , array_slice ( $ this -> fixture ( ' issues ' ), 0 , $ count ) );
4475 $ this ->respond ( 'GET ' , self ::REPO . "/issues?milestone= {$ number }&state=all " , $ this ->fixture ( 'issues ' ) );
4576 $ this ->respond ( 'PATCH ' , self ::REPO . "/milestones/ {$ number }" , $ this ->fixture ( 'milestone ' ) );
4677 }
4778
79+ // The plan asks for all milestones, `generate` for the open ones.
80+ $ this ->respond ( 'GET ' , self ::REPO . '/milestones?state=all ' , $ open );
4881 $ this ->respond ( 'GET ' , self ::REPO . '/milestones ' , $ open );
4982 $ this ->respond ( 'GET ' , self ::REPO , $ this ->fixture ( 'repository ' ) );
5083 $ this ->respond ( 'POST ' , self ::REPO . '/releases ' , $ this ->fixture ( 'release ' ) );
@@ -127,6 +160,37 @@ public function test_generate_needs_a_choice_between_several_milestones(): void
127160 $ this ->assertStringContainsString ( 'several milestones could be released: 1.0.1, 1.1.0 ' , $ this ->logger ->stderr );
128161 }
129162
163+ public function test_generate_refuses_when_changes_of_another_milestone_would_ship (): void {
164+ $ this ->repository (
165+ [
166+ 4 => '1.0.1 ' ,
167+ 5 => '1.1.0 ' ,
168+ ],
169+ [ 'v1.0.0 ' ],
170+ [
171+ 18 => '1.0.1 ' ,
172+ 19 => '1.0.1 ' ,
173+ 30 => '1.1.0 ' ,
174+ ],
175+ [ 5 => 1 ]
176+ );
177+
178+ ( new Release_Command () )->generate ( [ 'block-command ' ], [ 'yes ' => true ] );
179+
180+ $ this ->assertSame ( [], $ this ->writes () );
181+ $ this ->assertStringContainsString ( "Skipping milestone '1.0.1' as wp-cli/block-command needs a maintainer's decision first " , $ this ->logger ->stderr );
182+ $ this ->assertStringContainsString ( 'spread over the milestones 1.0.1, 1.1.0 ' , $ this ->logger ->stdout );
183+ }
184+
185+ public function test_generate_refuses_notes_for_pull_requests_missing_from_the_branch (): void {
186+ $ this ->repository ( [ 4 => '1.0.1 ' ], [ 'v1.0.0 ' ], [ 18 => '1.0.1 ' ] );
187+
188+ ( new Release_Command () )->generate ( [ 'block-command ' ], [ 'yes ' => true ] );
189+
190+ $ this ->assertSame ( [], $ this ->writes () );
191+ $ this ->assertStringContainsString ( "Skipping milestone '1.0.1' as #19 was not merged into the default branch since v1.0.0 " , $ this ->logger ->stderr );
192+ }
193+
130194 public function test_plan_reports_a_ready_milestone (): void {
131195 $ comparison = $ this ->fixture ( 'comparison ' );
132196
0 commit comments