44
55use Inhere \Console \Annotate \DocblockRules ;
66use Inhere \ConsoleTest \BaseTestCase ;
7+ use ReflectionException ;
78use ReflectionMethod ;
9+ use function vdump ;
810
911/**
1012 * class DocblockRulesTest
1113 */
1214class DocblockRulesTest extends BaseTestCase
1315{
1416 /**
15- * @throws \ ReflectionException
17+ * @throws ReflectionException
1618 */
1719 public function testParse_byReflect (): void
1820 {
@@ -53,7 +55,7 @@ public function testParse_byDocComment(): void
5355 *
5456 */
5557DOC
56- );
58+ );
5759 $ dr ->parse ();
5860
5961 $ this ->assertNotEmpty ($ dr ->getTagValue ('desc ' ));
@@ -66,4 +68,69 @@ public function testParse_byDocComment(): void
6668 $ this ->assertArrayHasKey ('--main ' , $ opts );
6769 $ this ->assertArrayHasKey ('repoPath ' , $ args );
6870 }
71+
72+ public function testParse_byDocComment_complex (): void
73+ {
74+ $ dr = DocblockRules::new ();
75+ $ dr ->setDocTagsByDocblock (<<<DOC
76+ /**
77+ * collect git change log information by `git log`
78+ *
79+ * @arguments
80+ * oldVersion string;The old version. eg: v1.0.2
81+ * - keywords `last/latest` will auto use latest tag.
82+ * - keywords `prev/previous` will auto use previous tag.;required
83+ * newVersion string;The new version. eg: v1.2.3
84+ * - keywords `head` will use `Head` commit.;required
85+ *
86+ * @options
87+ * --exclude Exclude contains given sub-string. multi by comma split.
88+ * --fetch-tags bool;Update repo tags list by `git fetch --tags`
89+ * --file Export changelog message to file
90+ * --filters Apply built in log filters. multi by `|` split
91+ * allow:
92+ * kw keyword filter. eg: `kw:tom`
93+ * kws keywords filter.
94+ * ml msg length filter.
95+ * wl word length filter.
96+ * --format The git log option `--pretty` value.
97+ * can be one of oneline, short, medium, full, fuller, reference, email, raw, format:<string> and tformat:<string>.
98+ * --style The style for generate for changelog.
99+ * allow: markdown(<cyan>default</cyan>), simple, gh-release
100+ * --repo-url The git repo URL address. eg: https://github.com/inhere/kite
101+ * default will auto use current git origin remote url
102+ * --no-merges bool;No contains merge request logs
103+ * --unshallow bool;Convert to a complete warehouse, useful on GitHub Action.
104+ * --with-author bool;Display commit author name
105+ *
106+ * @example
107+ * {binWithCmd} last head
108+ * {binWithCmd} last head --style gh-release --no-merges
109+ * {binWithCmd} v2.0.9 v2.0.10 --no-merges --style gh-release --exclude "cs-fixer,format codes"
110+ */
111+ DOC
112+ );
113+
114+ $ dr ->parse ();
115+
116+ $ this ->assertNotEmpty ($ dr ->getTagValue ('desc ' ));
117+ $ this ->assertNotEmpty ($ dr ->getTagValue ('example ' ));
118+
119+ $ this ->assertNotEmpty ($ opts = $ dr ->getOptRules ());
120+ $ this ->assertArrayHasKey ('--exclude ' , $ opts );
121+ $ this ->assertArrayHasKey ('--with-author ' , $ opts );
122+ $ this ->assertArrayHasKey ('--format ' , $ opts );
123+ $ this ->assertArrayHasKey ('--style ' , $ opts );
124+ $ this ->assertArrayHasKey ('--filters ' , $ opts );
125+
126+ $ this ->assertStringContainsString ('can be one of oneline, short ' , $ opts ['--format ' ]);
127+ $ this ->assertStringContainsString ('kw keyword filter ' , $ opts ['--filters ' ]);
128+ $ this ->assertStringContainsString ('wl word length filter ' , $ opts ['--filters ' ]);
129+ vdump ($ opts );
130+
131+ $ this ->assertNotEmpty ($ args = $ dr ->getArgRules ());
132+ $ this ->assertCount (2 , $ args );
133+ $ this ->assertArrayHasKey ('oldVersion ' , $ args );
134+ $ this ->assertArrayHasKey ('newVersion ' , $ args );
135+ }
69136}
0 commit comments