@@ -109,22 +109,43 @@ public function testExtractsReleaseTextViaChangelogFile(): void
109
109
### Added
110
110
111
111
- Everything.
112
+ END, $ date );
113
+
114
+ self ::assertStringContainsString (
115
+ $ expected ,
116
+ (new CreateReleaseTextViaKeepAChangelog (new ChangelogExistsViaConsole (), $ this ->clock ))
117
+ ->__invoke (
118
+ $ this ->createMockMilestone (),
119
+ RepositoryName::fromFullName ('example/repo ' ),
120
+ SemVerVersion::fromMilestoneName ('1.0.0 ' ),
121
+ BranchName::fromName ('1.0.x ' ),
122
+ $ workingPath
123
+ )
124
+ ->contents ()
125
+ );
126
+ }
127
+
128
+ public function testExtractsNonEmptySectionsForVersionViaChangelogFile (): void
129
+ {
130
+ $ date = $ this ->clock ->now ()->format ('Y-m-d ' );
131
+ $ changelogContents = sprintf (self ::CHANGELOG_MULTI_SECTION , $ date );
132
+ $ repositoryPath = $ this ->createMockRepositoryWithChangelog (
133
+ $ changelogContents ,
134
+ 'CHANGELOG.md ' ,
135
+ '2.3.x '
136
+ );
137
+ $ workingPath = $ this ->checkoutMockRepositoryWithChangelog ($ repositoryPath );
138
+
139
+ $ expected = sprintf (<<< 'END'
140
+ ## 2.3.12 - %s
112
141
113
- ### Changed
114
-
115
- - Nothing.
116
-
117
- ### Deprecated
118
-
119
- - Nothing.
120
-
121
- ### Removed
122
-
123
- - Nothing.
142
+ ### Added
124
143
144
+ - Something.
145
+
125
146
### Fixed
126
-
127
- - Nothing.
147
+
148
+ - Several things
128
149
END, $ date );
129
150
130
151
self ::assertStringContainsString (
@@ -133,8 +154,8 @@ public function testExtractsReleaseTextViaChangelogFile(): void
133
154
->__invoke (
134
155
$ this ->createMockMilestone (),
135
156
RepositoryName::fromFullName ('example/repo ' ),
136
- SemVerVersion::fromMilestoneName ('1.0.0 ' ),
137
- BranchName::fromName ('1.0 .x ' ),
157
+ SemVerVersion::fromMilestoneName ('2.3.12 ' ),
158
+ BranchName::fromName ('2.3 .x ' ),
138
159
$ workingPath
139
160
)
140
161
->contents ()
@@ -163,7 +184,8 @@ private function createMockMilestone(): Milestone
163
184
*/
164
185
private function createMockRepositoryWithChangelog (
165
186
string $ template ,
166
- string $ filename = 'CHANGELOG.md '
187
+ string $ filename = 'CHANGELOG.md ' ,
188
+ string $ initialBranch = '1.0.x '
167
189
): string {
168
190
$ repo = tempnam (sys_get_temp_dir (), 'CreateReleaseTextViaKeepAChangelog ' );
169
191
Assert::notEmpty ($ repo );
@@ -181,7 +203,7 @@ private function createMockRepositoryWithChangelog(
181
203
(
new Process ([
'git ' ,
'config ' ,
'user.email ' ,
'[email protected] ' ],
$ repo))->
mustRun ();
182
204
(new Process (['git ' , 'config ' , 'user.name ' , 'Just Me ' ], $ repo ))->mustRun ();
183
205
(new Process (['git ' , 'commit ' , '-m ' , 'Initial import ' ], $ repo ))->mustRun ();
184
- (new Process (['git ' , 'switch ' , '-c ' , ' 1.0.x ' ], $ repo ))->mustRun ();
206
+ (new Process (['git ' , 'switch ' , '-c ' , $ initialBranch ], $ repo ))->mustRun ();
185
207
186
208
return $ repo ;
187
209
}
@@ -261,5 +283,56 @@ private function checkoutMockRepositoryWithChangelog(string $origin): string
261
283
262
284
- Nothing.
263
285
286
+ END;
287
+
288
+ private const CHANGELOG_MULTI_SECTION = <<< 'END'
289
+ # Changelog
290
+
291
+ All notable changes to this project will be documented in this file, in reverse chronological order by release.
292
+
293
+ ## 2.3.12 - %s
294
+
295
+ ### Added
296
+
297
+ - Something.
298
+
299
+ ### Changed
300
+
301
+ - Nothing.
302
+
303
+ ### Deprecated
304
+
305
+ - Nothing.
306
+
307
+ ### Removed
308
+
309
+ - Nothing.
310
+
311
+ ### Fixed
312
+
313
+ - Several things
314
+
315
+ ## 0.1.0 - 2019-01-01
316
+
317
+ ### Added
318
+
319
+ - Everything.
320
+
321
+ ### Changed
322
+
323
+ - Nothing.
324
+
325
+ ### Deprecated
326
+
327
+ - Nothing.
328
+
329
+ ### Removed
330
+
331
+ - Nothing.
332
+
333
+ ### Fixed
334
+
335
+ - Nothing.
336
+
264
337
END;
265
338
}
0 commit comments