<commit_before><?php

namespace BetterReflectionTest\SourceLocator;

use BetterReflection\Identifier\Identifier;
use BetterReflection\Identifier\IdentifierType;
use BetterReflection\Reflection\ReflectionClass;
use BetterReflection\Reflector\ClassReflector;
use BetterReflection\SourceLocator\EvaledCodeSourceLocator;
use BetterReflection\SourceLocator\EvaledLocatedSource;

/**
 * @covers \BetterReflection\SourceLocator\EvaledCodeSourceLocator
 */
class EvaledCodeSourceLocatorTest extends \PHPUnit_Framework_TestCase
{
    public function testCanReflectEvaledClass()
    {
        $className = uniqid('foo');

        eval('class ' . $className . ' {function foo(){}}');

        $locator = new EvaledCodeSourceLocator();

        $source = $locator->__invoke(
            new Identifier($className, new IdentifierType(IdentifierType::IDENTIFIER_CLASS))
        );

        $this->assertInstanceOf(EvaledLocatedSource::class, $source);
        $this->assertStringMatchesFormat('%Aclass%A' . $className . '%A', $source->getSource());
    }

    public function testCanReflectEvaledInterface()
    {
        $interfaceName = uniqid('foo');

        eval('interface ' . $interfaceName . ' {function foo();}');

        $locator = new EvaledCodeSourceLocator();

        $source = $locator->__invoke(
            new Identifier($interfaceName, new IdentifierType(IdentifierType::IDENTIFIER_CLASS))
        );

        $this->assertInstanceOf(EvaledLocatedSource::class, $source);
        $this->assertStringMatchesFormat('%Aclass%A' . $interfaceName . '%A', $source->getSource());
    }

    public function testCanReflectEvaledTrait()
    {
        $traitName = uniqid('foo');

        eval('trait ' . $traitName . ' {function foo(){}}');

        $locator = new EvaledCodeSourceLocator();

        $source = $locator->__invoke(
            new Identifier($traitName, new IdentifierType(IdentifierType::IDENTIFIER_CLASS))
        );

        $this->assertInstanceOf(EvaledLocatedSource::class, $source);
        $this->assertStringMatchesFormat('%Aclass%A' . $traitName . '%A', $source->getSource());
    }

    public function testCanReflectEvaledLocatedSourceClass()
    {
        /* @var $class */
        $reflector = (new ClassReflector(new EvaledCodeSourceLocator()));
        $className = uniqid('foo');

        eval('class ' . $className . ' {function foo($bar = "baz") {}}');

        $class = $reflector->reflect($className);

        $this->assertInstanceOf(ReflectionClass::class, $class);
        $this->assertSame($className, $class->getName());
        $this->assertFalse($class->isInternal());
        $this->assertTrue($class->isUserDefined());
        $this->assertNull($class->getFileName());
        $this->assertCount(1, $class->getMethods());
    }

    public function testReturnsNullForNonExistentCode()
    {
        $locator = new EvaledCodeSourceLocator();
        $this->assertNull(
            $locator->__invoke(
                new Identifier(
                    'Foo\Bar',
                    new IdentifierType(IdentifierType::IDENTIFIER_CLASS)
                )
            )
        );
    }

    public function testReturnsNullForFunctions()
    {
        $locator = new EvaledCodeSourceLocator();
        $this->assertNull(
            $locator->__invoke(
                new Identifier(
                    'foo',
                    new IdentifierType(IdentifierType::IDENTIFIER_FUNCTION)
                )
            )
        );
    }
}
<commit_msg>#119 - Correcting completely broken test expectations<commit_after><?php

namespace BetterReflectionTest\SourceLocator;

use BetterReflection\Identifier\Identifier;
use BetterReflection\Identifier\IdentifierType;
use BetterReflection\Reflection\ReflectionClass;
use BetterReflection\Reflector\ClassReflector;
use BetterReflection\SourceLocator\EvaledCodeSourceLocator;
use BetterReflection\SourceLocator\EvaledLocatedSource;

/**
 * @covers \BetterReflection\SourceLocator\EvaledCodeSourceLocator
 */
class EvaledCodeSourceLocatorTest extends \PHPUnit_Framework_TestCase
{
    public function testCanReflectEvaledClass()
    {
        $className = uniqid('foo');

        eval('class ' . $className . ' {function foo(){}}');

        $locator = new EvaledCodeSourceLocator();

        $source = $locator->__invoke(
            new Identifier($className, new IdentifierType(IdentifierType::IDENTIFIER_CLASS))
        );

        $this->assertInstanceOf(EvaledLocatedSource::class, $source);
        $this->assertStringMatchesFormat('%Aclass%A' . $className . '%A', $source->getSource());
    }

    public function testCanReflectEvaledInterface()
    {
        $interfaceName = uniqid('foo');

        eval('interface ' . $interfaceName . ' {function foo();}');

        $locator = new EvaledCodeSourceLocator();

        $source = $locator->__invoke(
            new Identifier($interfaceName, new IdentifierType(IdentifierType::IDENTIFIER_CLASS))
        );

        $this->assertInstanceOf(EvaledLocatedSource::class, $source);
        $this->assertStringMatchesFormat('%Ainterface%A' . $interfaceName . '%A', $source->getSource());
    }

    public function testCanReflectEvaledTrait()
    {
        $traitName = uniqid('foo');

        eval('trait ' . $traitName . ' {function foo(){}}');

        $locator = new EvaledCodeSourceLocator();

        $source = $locator->__invoke(
            new Identifier($traitName, new IdentifierType(IdentifierType::IDENTIFIER_CLASS))
        );

        $this->assertInstanceOf(EvaledLocatedSource::class, $source);
        $this->assertStringMatchesFormat('%Atrait%A' . $traitName . '%A', $source->getSource());
    }

    public function testCanReflectEvaledLocatedSourceClass()
    {
        /* @var $class */
        $reflector = (new ClassReflector(new EvaledCodeSourceLocator()));
        $className = uniqid('foo');

        eval('class ' . $className . ' {function foo($bar = "baz") {}}');

        $class = $reflector->reflect($className);

        $this->assertInstanceOf(ReflectionClass::class, $class);
        $this->assertSame($className, $class->getName());
        $this->assertFalse($class->isInternal());
        $this->assertTrue($class->isUserDefined());
        $this->assertNull($class->getFileName());
        $this->assertCount(1, $class->getMethods());
    }

    public function testReturnsNullForNonExistentCode()
    {
        $locator = new EvaledCodeSourceLocator();
        $this->assertNull(
            $locator->__invoke(
                new Identifier(
                    'Foo\Bar',
                    new IdentifierType(IdentifierType::IDENTIFIER_CLASS)
                )
            )
        );
    }

    public function testReturnsNullForFunctions()
    {
        $locator = new EvaledCodeSourceLocator();
        $this->assertNull(
            $locator->__invoke(
                new Identifier(
                    'foo',
                    new IdentifierType(IdentifierType::IDENTIFIER_FUNCTION)
                )
            )
        );
    }
}

{'fraction_non_alphanumeric': 0.1309049516220831, 'fraction_numerical': 0.0007114399544678429, 'mean_word_length': 2.866336633663366, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, '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': '413015', 'n_tokens_mistral': 1962, 'n_tokens_neox': 1916, 'n_words': 297}