1717use CaptainHook \App \Exception \ActionFailed ;
1818use CaptainHook \App \Mockery as CHMockery ;
1919use CaptainHook \App \RepoMock ;
20- use SebastianFeldmann \Git \CommitMessage ;
2120use PHPUnit \Framework \TestCase ;
21+ use SebastianFeldmann \Git \CommitMessage ;
2222
2323class InjectIssueKeyFromBranchTest extends TestCase
2424{
@@ -44,7 +44,7 @@ public function testConstraint(): void
4444 public function testPrependSubject (): void
4545 {
4646 $ repo = new RepoMock ();
47- $ info = $ this ->createGitInfoOperator ('5.0.0 ' , 'freature /ABCD-12345-foo-bar-baz ' );
47+ $ info = $ this ->createGitInfoOperator ('5.0.0 ' , 'feature /ABCD-12345-foo-bar-baz ' );
4848
4949 $ repo ->setCommitMsg (new CommitMessage ('foo ' . PHP_EOL . PHP_EOL . 'bar ' ));
5050 $ repo ->setInfoOperator ($ info );
@@ -71,7 +71,7 @@ public function testPrependSubject(): void
7171 public function testAppendSubject (): void
7272 {
7373 $ repo = new RepoMock ();
74- $ info = $ this ->createGitInfoOperator ('5.0.0 ' , 'freature /ABCD-12345-foo-bar-baz ' );
74+ $ info = $ this ->createGitInfoOperator ('5.0.0 ' , 'feature /ABCD-12345-foo-bar-baz ' );
7575
7676 $ repo ->setCommitMsg (new CommitMessage ('foo ' . PHP_EOL . PHP_EOL . 'bar ' ));
7777 $ repo ->setInfoOperator ($ info );
@@ -98,7 +98,7 @@ public function testAppendSubject(): void
9898 public function testAppendBodyWithPrefix (): void
9999 {
100100 $ repo = new RepoMock ();
101- $ info = $ this ->createGitInfoOperator ('5.0.0 ' , 'freature /ABCD-12345-foo-bar-baz ' );
101+ $ info = $ this ->createGitInfoOperator ('5.0.0 ' , 'feature /ABCD-12345-foo-bar-baz ' );
102102
103103 $ repo ->setCommitMsg (new CommitMessage ('foo ' . PHP_EOL . PHP_EOL . 'bar ' ));
104104 $ repo ->setInfoOperator ($ info );
@@ -130,7 +130,7 @@ public function testAppendBodyWithPrefix(): void
130130 public function testAppendBodyWithPrefixWithComments (): void
131131 {
132132 $ repo = new RepoMock ();
133- $ info = $ this ->createGitInfoOperator ('5.0.0 ' , 'freature /ABCD-12345-foo-bar-baz ' );
133+ $ info = $ this ->createGitInfoOperator ('5.0.0 ' , 'feature /ABCD-12345-foo-bar-baz ' );
134134
135135 $ repo ->setCommitMsg (
136136 new CommitMessage (
@@ -221,7 +221,7 @@ public function testFailIssueKeyNotFound(): void
221221 public function testIssueKeyAlreadyInMSG (): void
222222 {
223223 $ repo = new RepoMock ();
224- $ info = $ this ->createGitInfoOperator ('5.0.0 ' , 'freature /ABCD-12345-foo-bar-baz ' );
224+ $ info = $ this ->createGitInfoOperator ('5.0.0 ' , 'feature /ABCD-12345-foo-bar-baz ' );
225225
226226 $ repo ->setCommitMsg (new CommitMessage ('ABCD-12345 foo ' . PHP_EOL . PHP_EOL . 'bar ' ));
227227 $ repo ->setInfoOperator ($ info );
@@ -238,4 +238,60 @@ public function testIssueKeyAlreadyInMSG(): void
238238
239239 $ this ->assertEquals ('ABCD-12345 foo ' , $ repo ->getCommitMsg ()->getSubject ());
240240 }
241+
242+ /**
243+ * Tests InjectIssueKeyFromBranch::execute
244+ *
245+ * @throws \Exception
246+ */
247+ public function testSubjectWithPattern (): void
248+ {
249+ $ repo = new RepoMock ();
250+ $ info = $ this ->createGitInfoOperator ('5.0.0 ' , 'feature/ABCD-12345-foo-bar-baz ' );
251+
252+ $ repo ->setCommitMsg (new CommitMessage ('foo ' . PHP_EOL . PHP_EOL . 'bar ' ));
253+ $ repo ->setInfoOperator ($ info );
254+
255+ $ io = $ this ->createIOMock ();
256+ $ config = $ this ->createConfigMock ();
257+ $ action = $ this ->createActionConfigMock ();
258+ $ action ->method ('getOptions ' )->willReturn (new Options ([
259+ 'into ' => 'subject ' ,
260+ 'pattern ' => '$1: ' ,
261+ 'mode ' => 'prepend ' ,
262+ ]));
263+
264+ $ hook = new InjectIssueKeyFromBranch ();
265+ $ hook ->execute ($ config , $ io , $ repo , $ action );
266+
267+ $ this ->assertEquals ('ABCD-12345: foo ' , $ repo ->getCommitMsg ()->getSubject ());
268+ }
269+
270+ /**
271+ * Tests InjectIssueKeyFromBranch::execute
272+ *
273+ * @throws \Exception
274+ */
275+ public function testSubjectWithEmptyPattern (): void
276+ {
277+ $ repo = new RepoMock ();
278+ $ info = $ this ->createGitInfoOperator ('5.0.0 ' , 'feature/ABCD-12345-foo-bar-baz ' );
279+
280+ $ repo ->setCommitMsg (new CommitMessage ('foo ' . PHP_EOL . PHP_EOL . 'bar ' ));
281+ $ repo ->setInfoOperator ($ info );
282+
283+ $ io = $ this ->createIOMock ();
284+ $ config = $ this ->createConfigMock ();
285+ $ action = $ this ->createActionConfigMock ();
286+ $ action ->method ('getOptions ' )->willReturn (new Options ([
287+ 'into ' => 'subject ' ,
288+ 'pattern ' => '' ,
289+ 'mode ' => 'prepend ' ,
290+ ]));
291+
292+ $ hook = new InjectIssueKeyFromBranch ();
293+ $ hook ->execute ($ config , $ io , $ repo , $ action );
294+
295+ $ this ->assertEquals ('ABCD-12345 foo ' , $ repo ->getCommitMsg ()->getSubject ());
296+ }
241297}
0 commit comments