123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- use Luticate\Utils\Business\LuDocParser;
-
- /**
- * Created by PhpStorm.
- * User: robin
- * Date: 5/29/16
- * Time: 7:52 PM
- */
- class LuDocParserTest extends \PHPUnit_Framework_TestCase
- {
- public function testSimpleSummary()
- {
- $doc = new LuDocParser("/**
- * Get all data
- */");
- $doc->parse();
- $this->assertSame("Get all data\n", $doc->getSummary());
- }
-
- public function testSimpleSummaryMultiLine()
- {
- $doc = new LuDocParser("/**
- * Get all data
- * Using the database
- */");
- $doc->parse();
- $this->assertSame("Get all data\nUsing the database\n", $doc->getSummary());
- }
-
- public function testSimpleParam()
- {
- $doc = new LuDocParser('/**
- * Get all data
- * @param $myvar MyType some doc
- * @param MyType $myvar2 some other doc
- */');
- $doc->parse();
- $this->assertSame("Get all data\n", $doc->getSummary());
-
- $params = [];
- foreach ($doc->getParams() as $param) {
- $params[] = $param->jsonSerialize();
- }
-
- $expectedParams = [
- ["Name" => 'myvar', "Type" => "MyType", "Summary" => "some doc\n",
- "Constraints" => []],
- ["Name" => 'myvar2', "Type" => "MyType", "Summary" => "some other doc\n",
- "Constraints" => []]
- ];
-
- $this->assertSame($expectedParams, $params);
- }
-
- public function testSimpleParamMultiLine()
- {
- $doc = new LuDocParser('/**
- * Get all data
- * @param $myvar MyType some doc
- * @param MyType $myvar2 some other doc
- * on another line
- */');
- $doc->parse();
- $this->assertSame("Get all data\n", $doc->getSummary());
-
- $params = [];
- foreach ($doc->getParams() as $name => $param) {
- $params[$name] = $param->jsonSerialize();
- }
-
- $expectedParams = [
- 'myvar' => ["Name" => 'myvar', "Type" => "MyType", "Summary" => "some doc\n",
- "Constraints" => []],
- 'myvar2' => ["Name" => 'myvar2', "Type" => "MyType", "Summary" => "some other doc\non another line\n",
- "Constraints" => []]
- ];
-
- $this->assertSame($expectedParams, $params);
- }
-
- public function testAll()
- {
- $doc = new LuDocParser('/**
- * Get all data
- * On another line
- * @param $myvar MyType some doc
- * Too much doc
- * @param MyType $myvar2 some other doc
- * on another line
- * @min 42
- * @max 42
- * @between 0 42
- * @another 1 2 42.42 true false "a string" \'string\'
- * and another
- * @return AnotherType
- */');
- $doc->parse();
- $this->assertSame("Get all data\nOn another line\n", $doc->getSummary());
- $this->assertSame("AnotherType", $doc->getReturnType());
-
- $params = [];
- foreach ($doc->getParams() as $name => $param) {
- $params[$name] = $param->jsonSerialize();
- }
-
- $expectedParams = [
- 'myvar' => ["Name" => 'myvar', "Type" => "MyType", "Summary" => "some doc\nToo much doc\n",
- "Constraints" => []],
- 'myvar2' => ["Name" => 'myvar2', "Type" => "MyType", "Summary" => "some other doc\non another line\nand another\n",
- "Constraints" => [
- ["Method" => "min", "Arguments" => ["42"]],
- ["Method" => "max", "Arguments" => ["42"]],
- ["Method" => "between", "Arguments" => ["0", "42"]],
- ["Method" => "another", "Arguments" => ["1", "2", "42.42", "true", "false", "a string", "string"]]
- ]
- ]
- ];
-
- $this->assertSame($expectedParams, $params);
- }
- }
|