From 8c2c8a8cb32576bcdd6a5e61254eac82a4dc8b4d Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 9 Jan 2020 20:14:50 -0500 Subject: [PATCH] Add unit test for Civi\Api4\Utils\ReflectionUtils::parseDocBlock --- .../api/v4/Utils/ReflectionUtilsTest.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/phpunit/api/v4/Utils/ReflectionUtilsTest.php b/tests/phpunit/api/v4/Utils/ReflectionUtilsTest.php index 437c1ab356..8323318041 100644 --- a/tests/phpunit/api/v4/Utils/ReflectionUtilsTest.php +++ b/tests/phpunit/api/v4/Utils/ReflectionUtilsTest.php @@ -62,4 +62,52 @@ This is the base class.'; $this->assertEquals("In the child class, foo has been barred.\n\nIn general, you can do nothing with it.", $doc['comment']); } + public function docBlockExamples() { + return [ + [ + "/** + * This is a function. + * + * Comment. + * IDK + * @param int|string \$foo + * Nothing interesting. + * @see 0 + * @throws tantrums + * @param \$bar: - Has a title + * @return nothing + */ + ", + [ + 'description' => 'This is a function.', + 'comment' => "Comment.\nIDK", + 'params' => [ + '$foo' => [ + 'type' => ['int', 'string'], + 'description' => '', + 'comment' => "Nothing interesting.\n", + ], + '$bar' => [ + 'type' => NULL, + 'description' => 'Has a title', + 'comment' => '', + ], + ], + 'see' => '0', + 'throws' => ['tantrums'], + 'return' => 'nothing', + ], + ], + ]; + } + + /** + * @dataProvider docBlockExamples + * @param $input + * @param $expected + */ + public function testParseDocBlock($input, $expected) { + $this->assertEquals($expected, ReflectionUtils::parseDocBlock($input)); + } + } -- 2.25.1