<commit_before><?php
/**
 * Created by PhpStorm.
 * User: daniel
 * Date: 27/07/15
 * Time: 08:23
 */

namespace AyeAye\Api\Tests;


use AyeAye\Api\Documentor;
use AyeAye\Api\Tests\TestData\DocumentedController;

/**
 * Class DocumentorTest
 * @package AyeAye\Api\Tests
 * @coversDefaultClass \AyeAye\Api\Documentor
 */
class DocumentorTest extends TestCase
{

    /**
     * @test
     * @covers ::getMethodComment
     */
    public function testGetMethodComment()
    {
        $controller = new DocumentedController();
        $documentor = new Documentor();

        $expected = [
            'Test Summary',
            'on two lines.',
            'Test Description',
            'on',
            'three lines.',
            '@param        $incomplete',
            '@param int    $integer    Test integer',
            '@param string $string     Test string',
            'Second line',
            '@return string'
        ];

        $getMethodComment = $this->getObjectMethod($documentor, 'getMethodComment');
        $reflectionMethod = new \ReflectionMethod($controller, 'getDocumentedEndpoint');

        $this->assertSame(
            $expected,
            $getMethodComment($reflectionMethod)
        );
    }

    /**
     * @test
     * @covers ::getSummary
     * @uses \AyeAye\Api\Documentor::getMethodComment
     */
    public function testgetSummary()
    {
        $controller = new DocumentedController();
        $documentor = new Documentor();

        $getMethodComment = $this->getObjectMethod($documentor, 'getMethodComment');
        $getSummary = $this->getObjectMethod($documentor, 'getSummary');

        $reflectionMethod = new \ReflectionMethod($controller, 'getDocumentedEndpoint');

        $comment = $getMethodComment($reflectionMethod);
        $this->assertSame(
            "Test Summary\non two lines.",
            $getSummary($comment)
        );

        $reflectionMethod = new \ReflectionMethod($controller, 'selfReferenceController');

        $comment = $getMethodComment($reflectionMethod);
        $this->assertSame(
            "This is a\nthree line summary\nwith a break",
            $getSummary($comment)
        );

        $reflectionMethod = new \ReflectionMethod($controller, 'getNullEndpoint');

        $comment = $getMethodComment($reflectionMethod);
        $this->assertSame(
            "This is a summary. There is no description",
            $getSummary($comment)
        );
    }

    /**
     * @test
     * @covers ::getDescription
     * @uses \AyeAye\Api\Documentor::getMethodComment
     */
    public function testGetDescription()
    {
        $controller = new DocumentedController();
        $documentor = new Documentor();

        $getMethodComment = $this->getObjectMethod($documentor, 'getMethodComment');
        $getDescription = $this->getObjectMethod($documentor, 'getDescription');

        $reflectionMethod = new \ReflectionMethod($controller, 'getDocumentedEndpoint');

        $comment = $getMethodComment($reflectionMethod);
        $this->assertSame(
            "Test Description\non\nthree lines.",
            $getDescription($comment)
        );

        $reflectionMethod = new \ReflectionMethod($controller, 'selfReferenceController');

        $comment = $getMethodComment($reflectionMethod);
        $this->assertSame(
            "This is a one line description",
            $getDescription($comment)
        );

        $reflectionMethod = new \ReflectionMethod($controller, 'getNullEndpoint');

        $comment = $getMethodComment($reflectionMethod);
        $this->assertSame(
            "",
            $getDescription($comment)
        );
    }

    /**
     * @test
     * @covers ::getParameters
     * @uses \AyeAye\Api\Documentor::getMethodComment
     */
    public function testGetParameters()
    {
        $controller = new DocumentedController();
        $documentor = new Documentor();

        $getMethodComment = $this->getObjectMethod($documentor, 'getMethodComment');
        $getParameters = $this->getObjectMethod($documentor, 'getParameters');

        $reflectionMethod = new \ReflectionMethod($controller, 'getDocumentedEndpoint');

        $expected = [
            'incomplete' => [
                'type' => '',
                'description' => '',
            ],
            'integer' => [
                'type' => 'int',
                'description' => 'Test integer',
            ],
            'string' => [
                'type' => 'string',
                'description' => "Test string\nSecond line",
            ],
        ];

        $comment = $getMethodComment($reflectionMethod);
        $this->assertSame(
            $expected,
            $getParameters($comment)
        );
    }

    /**
     * @test
     * @covers ::getReturnType()
     * @uses \AyeAye\Api\Documentor::getMethodComment
     */
    public function testGetReturnType()
    {
        $controller = new DocumentedController();
        $documentor = new Documentor();

        $getMethodComment = $this->getObjectMethod($documentor, 'getMethodComment');
        $getReturnType = $this->getObjectMethod($documentor, 'getReturnType');

        $reflectionMethod = new \ReflectionMethod($controller, 'getDocumentedEndpoint');
        $comment = $getMethodComment($reflectionMethod);

        $this->assertSame(
            ['string'],
            $getReturnType($comment, $reflectionMethod->getDeclaringClass())
        );

        $reflectionMethod = new \ReflectionMethod($controller, 'selfReferenceController');
        $comment = $getMethodComment($reflectionMethod);
        $this->assertSame(
            ['self'],<commit_msg>Tests cleaned up and made more unifrom<commit_after><?php
/**
 * Created by PhpStorm.
 * User: daniel
 * Date: 27/07/15
 * Time: 08:23
 */

namespace AyeAye\Api\Tests;


use AyeAye\Api\Documentor;
use AyeAye\Api\Tests\TestData\DocumentedController;

/**
 * Class DocumentorTest
 * @package AyeAye\Api\Tests
 * @coversDefaultClass \AyeAye\Api\Documentor
 */
class DocumentorTest extends TestCase
{

    /**
     * @test
     * @covers ::getMethodComment
     */
    public function testGetMethodComment()
    {
        $controller = new DocumentedController();
        $documentor = new Documentor();
        $getMethodComment = $this->getObjectMethod($documentor, 'getMethodComment');

        $reflectionMethod = new \ReflectionMethod($controller, 'getDocumentedEndpoint');
        $expected = [
            'Test Summary',
            'on two lines.',
            'Test Description',
            'on',
            'three lines.',
            '@param        $incomplete',
            '@param int    $integer    Test integer',
            '@param string $string     Test string',
            'Second line',
            '@return string'
        ];
        $this->assertSame(
            $expected,
            $getMethodComment($reflectionMethod)
        );

        $reflectionMethod = new \ReflectionMethod($controller, 'selfReferenceController');
        $expected = [
            '',
            'This is a',
            'three line summary',
            'with a break',
            '',
            'This is a one line description',
            '@return $this'
        ];
        $this->assertSame(
            $expected,
            $getMethodComment($reflectionMethod)
        );

        $reflectionMethod = new \ReflectionMethod($controller, 'getNullEndpoint');
        $expected = [
            'This is a summary. There is no description',
            '@return null|mixed',
        ];
        $this->assertSame(
            $expected,
            $getMethodComment($reflectionMethod)
        );

        $reflectionMethod = new \ReflectionMethod($controller, 'noDocumentation');
        $expected = [];
        $this->assertSame(
            $expected,
            $getMethodComment($reflectionMethod)
        );
    }

    /**
     * @test
     * @covers ::getSummary
     * @uses \AyeAye\Api\Documentor::getMethodComment
     */
    public function testgetSummary()
    {
        $controller = new DocumentedController();
        $documentor = new Documentor();

        $getMethodComment = $this->getObjectMethod($documentor, 'getMethodComment');
        $getSummary = $this->getObjectMethod($documentor, 'getSummary');

        $reflectionMethod = new \ReflectionMethod($controller, 'getDocumentedEndpoint');
        $comment = $getMethodComment($reflectionMethod);
        $this->assertSame(
            "Test Summary\non two lines.",
            $getSummary($comment)
        );

        $reflectionMethod = new \ReflectionMethod($controller, 'selfReferenceController');
        $comment = $getMethodComment($reflectionMethod);
        $this->assertSame(
            "This is a\nthree line summary\nwith a break",
            $getSummary($comment)
        );

        $reflectionMethod = new \ReflectionMethod($controller, 'getNullEndpoint');
        $comment = $getMethodComment($reflectionMethod);
        $this->assertSame(
            'This is a summary. There is no description',
            $getSummary($comment)
        );

        $reflectionMethod = new \ReflectionMethod($controller, 'noDocumentation');
        $comment = $getMethodComment($reflectionMethod);
        $this->assertSame(
            '',
            $getSummary($comment)
        );
    }

    /**
     * @test
     * @covers ::getDescription
     * @uses \AyeAye\Api\Documentor::getMethodComment
     */
    public function testGetDescription()
    {
        $controller = new DocumentedController();
        $documentor = new Documentor();

        $getMethodComment = $this->getObjectMethod($documentor, 'getMethodComment');
        $getDescription = $this->getObjectMethod($documentor, 'getDescription');

        $reflectionMethod = new \ReflectionMethod($controller, 'getDocumentedEndpoint');

        $comment = $getMethodComment($reflectionMethod);
        $this->assertSame(
            "Test Description\non\nthree lines.",
            $getDescription($comment)
        );

        $reflectionMethod = new \ReflectionMethod($controller, 'selfReferenceController');
        $comment = $getMethodComment($reflectionMethod);
        $this->assertSame(
            'This is a one line description',
            $getDescription($comment)
        );

        $reflectionMethod = new \ReflectionMethod($controller, 'getNullEndpoint');
        $comment = $getMethodComment($reflectionMethod);
        $this->assertSame(
            '',
            $getDescription($comment)
        );

        $reflectionMethod = new \ReflectionMethod($controller, 'noDocumentation');
        $comment = $getMethodComment($reflectionMethod);
        $this->assertSame(
            '',
            $getDescription($comment)
        );
    }

    /**
     * @test
     * @covers ::getParameters
     * @uses \AyeAye\Api\Documentor::getMethodComment
     */
    public function testGetParameters()
    {
        $controller = new DocumentedController();
        $documentor = new Documentor();

        $getMethodComment = $this->getObjectMethod($documentor, 'getMethodComment');
        $getParameters = $this->getObjectMethod($documentor, 'getParameters');

        $reflectionMethod = new \ReflectionMethod($controller, 'getDocumentedEndpoint');
        $expected = [
            'incomplete' => [
                'type' => '',
                'description' => '',
            ],
            'integer' => [
                'type' => 'int',
                'description' => 'Test integer',
            ],
            'string' => [
                'type' => 'string',
                'description' => "Test string\nSecond line",
            ],
        ];
        $comment = $getMethodComment($reflectionMethod);
        $this->assertSame(
            $expected,
            $getParameters($comment)
        );

        $reflectionMethod = new \ReflectionMethod($controller, 'selfReferenceController');
        $comment = $getMethodComment($reflectionMethod);
        $this->assertSame(
            [],
            $getParameters($comment)
        );

        $reflectionMethod = new \ReflectionMethod($controller, 'getNullEndpoint');
        $comment = $getMethodComment($reflectionMethod);
        $this->assertSame(
            [],
            $getParameters($comment)
        );

        $reflectionMethod = new \ReflectionMethod($controller, 'noDocumentation');
        $comment = $getMethodComment($reflectionMethod);
        $this->assertSame(
            [],
            $getParameters($comment)
        );
    }

    /**
     * @test
     * @covers ::getReturnType()
     * @uses \AyeAye\Api\Documentor::getMethodComment
     */
    public function testGetReturnType()
    {
        $controller = new DocumentedController();
        $documentor = new Documentor();

        $getMethodComment = $this->getObjectMethod($documentor, 'getMethodComment');
        $getReturnType = $this->getObjectMethod($documentor, 'getReturnType');

        $reflectionMethod = new \ReflectionMethod($controller, 'getDocumentedEndpoint');
        $comment = $getMethodComment($reflectionMethod);

        $this->assertSame(
            ['string'],
            $getReturnType($comment, $reflectionMethod->getDeclaringClass())
        );

        $reflectionMethod = new \ReflectionMethod($controller, 'selfReferenceController');
        $comment = $getMethodComment($reflectionMethod);
        $this->assertSame(
            ['self'],
{'fraction_non_alphanumeric': 0.12731464267122777, 'fraction_numerical': 0.0014873205919535956, 'mean_word_length': 2.249879168680522, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3916750', 'n_tokens_mistral': 3509, 'n_tokens_neox': 3424, 'n_words': 646}