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