Add unit test for Civi\Api4\Utils\ReflectionUtils::parseDocBlock
authorColeman Watts <coleman@civicrm.org>
Fri, 10 Jan 2020 01:14:50 +0000 (20:14 -0500)
committerColeman Watts <coleman@civicrm.org>
Fri, 10 Jan 2020 01:14:50 +0000 (20:14 -0500)
tests/phpunit/api/v4/Utils/ReflectionUtilsTest.php

index 437c1ab3565e409a1c12fa5ce7a03c90ac971ac2..8323318041038c37fab89c9cfea3a88f00269728 100644 (file)
@@ -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));
+  }
+
 }