xref: /dokuwiki/_test/tests/Remote/OpenApiDoc/DocBlockMethodTest.php (revision d1f06eb4f0e4febc5434c97e319fce6d0253e533)
18ddd9b69SAndreas Gohr<?php
28ddd9b69SAndreas Gohr
38ddd9b69SAndreas Gohrnamespace dokuwiki\test\Remote\OpenApiDoc;
48ddd9b69SAndreas Gohr
58ddd9b69SAndreas Gohruse dokuwiki\Remote\OpenApiDoc\DocBlockMethod;
6*d1f06eb4SAndreas Gohruse dokuwiki\Remote\OpenApiDoc\Type;
78ddd9b69SAndreas Gohr
88ddd9b69SAndreas Gohrclass DocBlockMethodTest extends \DokuWikiTest {
98ddd9b69SAndreas Gohr
108ddd9b69SAndreas Gohr
118ddd9b69SAndreas Gohr    /**
128ddd9b69SAndreas Gohr     * This is a test
138ddd9b69SAndreas Gohr     *
148ddd9b69SAndreas Gohr     * With more information
158ddd9b69SAndreas Gohr     * in several lines
168ddd9b69SAndreas Gohr     * @param string $foo First variable
178ddd9b69SAndreas Gohr     * @param int $bar
188ddd9b69SAndreas Gohr     * @param string[] $baz
198ddd9b69SAndreas Gohr     * @something else
208ddd9b69SAndreas Gohr     * @something other
218ddd9b69SAndreas Gohr     * @another tag
228ddd9b69SAndreas Gohr     * @return string  The return
238ddd9b69SAndreas Gohr     */
248ddd9b69SAndreas Gohr    public function dummyMethod1($foo, $bar, $baz=['a default'])
258ddd9b69SAndreas Gohr    {
268ddd9b69SAndreas Gohr        return 'dummy';
278ddd9b69SAndreas Gohr    }
288ddd9b69SAndreas Gohr
298ddd9b69SAndreas Gohr    public function testMethod()
308ddd9b69SAndreas Gohr    {
318ddd9b69SAndreas Gohr        $reflect = new \ReflectionMethod($this, 'dummyMethod1');
328ddd9b69SAndreas Gohr        $doc = new DocBlockMethod($reflect);
338ddd9b69SAndreas Gohr
348ddd9b69SAndreas Gohr        $this->assertEquals('This is a test', $doc->getSummary());
358ddd9b69SAndreas Gohr        $this->assertEquals("With more information\nin several lines", $doc->getDescription());
368ddd9b69SAndreas Gohr
378ddd9b69SAndreas Gohr        $this->assertEquals(
388ddd9b69SAndreas Gohr            [
398ddd9b69SAndreas Gohr                'foo' => [
408ddd9b69SAndreas Gohr                    'type' => 'string',
418ddd9b69SAndreas Gohr                    'description' => 'First variable',
428ddd9b69SAndreas Gohr                    'optional' => false,
438ddd9b69SAndreas Gohr                ],
448ddd9b69SAndreas Gohr                'bar' => [
458ddd9b69SAndreas Gohr                    'type' => 'int',
468ddd9b69SAndreas Gohr                    'description' => '',
478ddd9b69SAndreas Gohr                    'optional' => false,
488ddd9b69SAndreas Gohr                ],
498ddd9b69SAndreas Gohr                'baz' => [
508ddd9b69SAndreas Gohr                    'type' => 'string[]',
518ddd9b69SAndreas Gohr                    'description' => '',
528ddd9b69SAndreas Gohr                    'optional' => true,
538ddd9b69SAndreas Gohr                    'default' => ['a default'],
548ddd9b69SAndreas Gohr                ],
558ddd9b69SAndreas Gohr            ],
568ddd9b69SAndreas Gohr            $doc->getTag('param')
578ddd9b69SAndreas Gohr        );
588ddd9b69SAndreas Gohr
59*d1f06eb4SAndreas Gohr        $params = $doc->getParameters();
60*d1f06eb4SAndreas Gohr        $this->assertInstanceOf(Type::class, $params['foo']['type']);
61*d1f06eb4SAndreas Gohr        $this->assertInstanceOf(Type::class, $params['bar']['type']);
62*d1f06eb4SAndreas Gohr        $this->assertInstanceOf(Type::class, $params['baz']['type']);
63*d1f06eb4SAndreas Gohr
648ddd9b69SAndreas Gohr        $this->assertEquals(
658ddd9b69SAndreas Gohr            [
668ddd9b69SAndreas Gohr                'type' => 'string',
678ddd9b69SAndreas Gohr                'description' => 'The return'
688ddd9b69SAndreas Gohr            ],
698ddd9b69SAndreas Gohr            $doc->getTag('return')
708ddd9b69SAndreas Gohr        );
718ddd9b69SAndreas Gohr
72*d1f06eb4SAndreas Gohr        $return = $doc->getReturn();
73*d1f06eb4SAndreas Gohr        $this->assertInstanceOf(Type::class, $return['type']);
74*d1f06eb4SAndreas Gohr
758ddd9b69SAndreas Gohr        $this->assertEquals(
768ddd9b69SAndreas Gohr            [
778ddd9b69SAndreas Gohr                'else',
788ddd9b69SAndreas Gohr                'other',
798ddd9b69SAndreas Gohr            ],
808ddd9b69SAndreas Gohr            $doc->getTag('something')
818ddd9b69SAndreas Gohr        );
828ddd9b69SAndreas Gohr
838ddd9b69SAndreas Gohr        $this->assertEquals(
848ddd9b69SAndreas Gohr            [
858ddd9b69SAndreas Gohr                'tag',
868ddd9b69SAndreas Gohr            ],
878ddd9b69SAndreas Gohr            $doc->getTag('another')
888ddd9b69SAndreas Gohr        );
89*d1f06eb4SAndreas Gohr
90*d1f06eb4SAndreas Gohr
918ddd9b69SAndreas Gohr    }
928ddd9b69SAndreas Gohr}
93