<commit_before><?php

namespace Ray\Aop;

use Doctrine\Common\Annotations\AnnotationReader;
use Ray\Aop\Interceptor\DoubleInterceptor;
use Ray\Aop\Mock\Num;
use PHPParser_Lexer;
use PHPParser_Parser;
use PHPParser_PrettyPrinter_Default;
use PHPParser_BuilderFactory;

class BuilderTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var Bind
     */
    private $bind;

    /**
     * @var Compiler
     */
    private $compiler;

    protected function setUp()
    {
        parent::setUp();
        $this->compiler = new Compiler(
            __DIR__ . '/Weaved',
            new PHPParser_PrettyPrinter_Default,
            new PHPParser_Parser(new PHPParser_Lexer),
            new PHPParser_BuilderFactory
        );
        $this->bind = new Bind;
        $matcher = new Matcher(new AnnotationReader);
        $pointcut = new Pointcut($matcher->any(), $matcher->startWith('return'), [new DoubleInterceptor]);
        $this->bind->bind('Ray\Aop\Mock\Weaved', [$pointcut]);
    }

    public function testNew()
    {
        $this->assertInstanceOf('\Ray\Aop\Compiler', $this->compiler);
    }

    public function testBuildClass()
    {
        $class = $this->compiler->compile('\Ray\Aop\Mock\Mock', $this->bind);
        $this->assertTrue(class_exists($class));

        return $class;
    }

    public function testBuildClassTwice()
    {
        $class1 = $this->compiler->compile('\Ray\Aop\Mock\Mock', $this->bind);
        $class2 = $this->compiler->compile('\Ray\Aop\Mock\Mock', $this->bind);
        $this->assertTrue(class_exists($class1));
        $this->assertSame($class1, $class2);
    }

    /**
     * @depends testBuildClass
     */
    public function testBuild($class)
    {
        $parentClass = (new \ReflectionClass($class))->getParentClass()->name;
        $this->assertSame($parentClass, 'Ray\Aop\Mock\Mock');
    }

    /**
     * @depends testBuildClass
     */
    public function testBuildClassWeaved($class)
    {
        $weaved = new $class;
        $weaved->rayAopBind = $this->bind;
        $result = $weaved->returnSame(1);
        $this->assertSame(2, $result);
    }

    public function testNewInstance()
    {
        $weaved = $this->compiler->newInstance('Ray\Aop\Mock\Mock', [], $this->bind);
        $parent = (new \ReflectionClass($weaved))->getParentClass()->name;
        $this->assertSame($parent, 'Ray\Aop\Mock\Mock');

        return $weaved;
    }

    /**
     * @depends testNewInstance
     */
    public function testWeavedInterceptorWorks($weaved)
    {
        $result = $weaved->returnSame(1);
        $this->assertSame(2, $result);
        $result = $weaved->returnSame(1);
        $this->assertSame(2, $result);
    }


    /**
     * @depends testNewInstance
     */
    public function testMethodReturnValue($weaved)
    {
        $num = new Num;
        $num->value = 1;
        $result = $weaved->returnSame(1);
        $this->assertSame(2, $result);
    }

    public function testGetPrivateVal()
    {
        $weaved = $this->compiler->newInstance('Ray\Aop\Mock\Mock', [], $this->bind);
        /* @var $weaved \Ray\Aop\Mock\Mock */
        $val = $weaved->getPrivateVal();
        $this->assertSame($val, 1);
    }

    public function testClassDocComment()
    {
        $weaved = $this->compiler->newInstance('Ray\Aop\Mock\Mock', [], $this->bind);
        /* @var $weaved \Ray\Aop\Mock\Mock */
        $docComment = (new \ReflectionClass($weaved))->getDocComment();
        $expected = (new \ReflectionClass('Ray\Aop\Mock\Mock'))->getDocComment();
        $this->assertContains('/**', $docComment);
        $this->assertSame($expected, $docComment);
    }

    public function testMethodDocComment()
    {
        $weaved = $this->compiler->newInstance('Ray\Aop\Mock\Mock', [], $this->bind);
        /* @var $weaved \Ray\Aop\Mock\Mock */
        $docComment = (new \ReflectionClass($weaved))->getMethods()[0]->getDocComment();
        $expected = (new \ReflectionClass('Ray\Aop\Mock\Mock'))->getMethods()[0]->getDocComment();

        $this->assertContains('/**', $docComment);
        $this->assertSame($expected, $docComment);
    }

    public function testNoDocComment()
    {
        $weaved = $this->compiler->newInstance('Ray\Aop\Mock\MockNoDOc', [], $this->bind);
        /* @var $weaved \Ray\Aop\Mock\Mock */
        $classDocComment = (new \ReflectionClass($weaved))->getDocComment();
        $methodDocComment = (new \ReflectionClass($weaved))->getMethods()[0]->getDocComment();

        $this->assertFalse($classDocComment);
        $this->assertFalse($methodDocComment);
    }

}
<commit_msg>case typo<commit_after><?php

namespace Ray\Aop;

use Doctrine\Common\Annotations\AnnotationReader;
use Ray\Aop\Interceptor\DoubleInterceptor;
use Ray\Aop\Mock\Num;
use PHPParser_Lexer;
use PHPParser_Parser;
use PHPParser_PrettyPrinter_Default;
use PHPParser_BuilderFactory;

class BuilderTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var Bind
     */
    private $bind;

    /**
     * @var Compiler
     */
    private $compiler;

    protected function setUp()
    {
        parent::setUp();
        $this->compiler = new Compiler(
            __DIR__ . '/Weaved',
            new PHPParser_PrettyPrinter_Default,
            new PHPParser_Parser(new PHPParser_Lexer),
            new PHPParser_BuilderFactory
        );
        $this->bind = new Bind;
        $matcher = new Matcher(new AnnotationReader);
        $pointcut = new Pointcut($matcher->any(), $matcher->startWith('return'), [new DoubleInterceptor]);
        $this->bind->bind('Ray\Aop\Mock\Weaved', [$pointcut]);
    }

    public function testNew()
    {
        $this->assertInstanceOf('\Ray\Aop\Compiler', $this->compiler);
    }

    public function testBuildClass()
    {
        $class = $this->compiler->compile('\Ray\Aop\Mock\Mock', $this->bind);
        $this->assertTrue(class_exists($class));

        return $class;
    }

    public function testBuildClassTwice()
    {
        $class1 = $this->compiler->compile('\Ray\Aop\Mock\Mock', $this->bind);
        $class2 = $this->compiler->compile('\Ray\Aop\Mock\Mock', $this->bind);
        $this->assertTrue(class_exists($class1));
        $this->assertSame($class1, $class2);
    }

    /**
     * @depends testBuildClass
     */
    public function testBuild($class)
    {
        $parentClass = (new \ReflectionClass($class))->getParentClass()->name;
        $this->assertSame($parentClass, 'Ray\Aop\Mock\Mock');
    }

    /**
     * @depends testBuildClass
     */
    public function testBuildClassWeaved($class)
    {
        $weaved = new $class;
        $weaved->rayAopBind = $this->bind;
        $result = $weaved->returnSame(1);
        $this->assertSame(2, $result);
    }

    public function testNewInstance()
    {
        $weaved = $this->compiler->newInstance('Ray\Aop\Mock\Mock', [], $this->bind);
        $parent = (new \ReflectionClass($weaved))->getParentClass()->name;
        $this->assertSame($parent, 'Ray\Aop\Mock\Mock');

        return $weaved;
    }

    /**
     * @depends testNewInstance
     */
    public function testWeavedInterceptorWorks($weaved)
    {
        $result = $weaved->returnSame(1);
        $this->assertSame(2, $result);
        $result = $weaved->returnSame(1);
        $this->assertSame(2, $result);
    }


    /**
     * @depends testNewInstance
     */
    public function testMethodReturnValue($weaved)
    {
        $num = new Num;
        $num->value = 1;
        $result = $weaved->returnSame(1);
        $this->assertSame(2, $result);
    }

    public function testGetPrivateVal()
    {
        $weaved = $this->compiler->newInstance('Ray\Aop\Mock\Mock', [], $this->bind);
        /* @var $weaved \Ray\Aop\Mock\Mock */
        $val = $weaved->getPrivateVal();
        $this->assertSame($val, 1);
    }

    public function testClassDocComment()
    {
        $weaved = $this->compiler->newInstance('Ray\Aop\Mock\Mock', [], $this->bind);
        /* @var $weaved \Ray\Aop\Mock\Mock */
        $docComment = (new \ReflectionClass($weaved))->getDocComment();
        $expected = (new \ReflectionClass('Ray\Aop\Mock\Mock'))->getDocComment();
        $this->assertContains('/**', $docComment);
        $this->assertSame($expected, $docComment);
    }

    public function testMethodDocComment()
    {
        $weaved = $this->compiler->newInstance('Ray\Aop\Mock\Mock', [], $this->bind);
        /* @var $weaved \Ray\Aop\Mock\Mock */
        $docComment = (new \ReflectionClass($weaved))->getMethods()[0]->getDocComment();
        $expected = (new \ReflectionClass('Ray\Aop\Mock\Mock'))->getMethods()[0]->getDocComment();

        $this->assertContains('/**', $docComment);
        $this->assertSame($expected, $docComment);
    }

    public function testNoDocComment()
    {
        $weaved = $this->compiler->newInstance('Ray\Aop\Mock\MockNoDoc', [], $this->bind);
        /* @var $weaved \Ray\Aop\Mock\Mock */
        $classDocComment = (new \ReflectionClass($weaved))->getDocComment();
        $methodDocComment = (new \ReflectionClass($weaved))->getMethods()[0]->getDocComment();

        $this->assertFalse($classDocComment);
        $this->assertFalse($methodDocComment);
    }

}

{'fraction_non_alphanumeric': 0.16819371727748691, 'fraction_numerical': 0.003926701570680628, 'mean_word_length': 2.6941982272361, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 141, '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': '2989713', 'n_tokens_mistral': 2886, 'n_tokens_neox': 2861, 'n_words': 437}