1<?php
2
3namespace dokuwiki\test\Remote\OpenApiDoc;
4
5use dokuwiki\Remote\OpenApiDoc\DocBlockMethod;
6use dokuwiki\Remote\OpenApiDoc\Type;
7
8class DocBlockMethodTest extends \DokuWikiTest {
9
10
11    /**
12     * This is a test
13     *
14     * With more information
15     * in several lines
16     * @param string $foo First variable
17     * @param int $bar
18     * @param string[] $baz
19     * @something else
20     * @something other
21     * @another tag
22     * @return string  The return
23     */
24    public function dummyMethod1($foo, $bar, $baz=['a default'])
25    {
26        return 'dummy';
27    }
28
29    public function testMethod()
30    {
31        $reflect = new \ReflectionMethod($this, 'dummyMethod1');
32        $doc = new DocBlockMethod($reflect);
33
34        $this->assertEquals('This is a test', $doc->getSummary());
35        $this->assertEquals("With more information\nin several lines", $doc->getDescription());
36
37        $this->assertEquals(
38            [
39                'foo' => [
40                    'type' => 'string',
41                    'description' => 'First variable',
42                    'optional' => false,
43                ],
44                'bar' => [
45                    'type' => 'int',
46                    'description' => '',
47                    'optional' => false,
48                ],
49                'baz' => [
50                    'type' => 'string[]',
51                    'description' => '',
52                    'optional' => true,
53                    'default' => ['a default'],
54                ],
55            ],
56            $doc->getTag('param')
57        );
58
59        $params = $doc->getParameters();
60        $this->assertInstanceOf(Type::class, $params['foo']['type']);
61        $this->assertInstanceOf(Type::class, $params['bar']['type']);
62        $this->assertInstanceOf(Type::class, $params['baz']['type']);
63
64        $this->assertEquals(
65            [
66                'type' => 'string',
67                'description' => 'The return'
68            ],
69            $doc->getTag('return')
70        );
71
72        $return = $doc->getReturn();
73        $this->assertInstanceOf(Type::class, $return['type']);
74
75        $this->assertEquals(
76            [
77                'else',
78                'other',
79            ],
80            $doc->getTag('something')
81        );
82
83        $this->assertEquals(
84            [
85                'tag',
86            ],
87            $doc->getTag('another')
88        );
89
90
91    }
92}
93