<commit_before><?php

declare(strict_types=1);

namespace Roave\BetterReflectionTest\Reflection;

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Roave\BetterReflection\Reflection\Exception\ClassDoesNotExist;
use Roave\BetterReflection\Reflection\Exception\ReflectionTypeDoesNotPointToAClassAlikeType;
use Roave\BetterReflection\Reflection\Reflection;
use Roave\BetterReflection\Reflection\ReflectionClass;
use Roave\BetterReflection\Reflection\ReflectionType;
use Roave\BetterReflection\Reflector\Reflector;

/**
 * @covers \Roave\BetterReflection\Reflection\ReflectionType
 */
class ReflectionTypeTest extends TestCase
{
    /** @var Reflector|MockObject */
    private $reflector;

    protected function setUp(): void
    {
        parent::setUp();

        $this->reflector = $this->createMock(Reflector::class);
    }

    public function testCreateFromType(): void
    {
        $typeInfo = ReflectionType::createFromTypeAndReflector('string', false, $this->reflector);
        self::assertInstanceOf(ReflectionType::class, $typeInfo);
    }

    public function testAllowsNull(): void
    {
        $noNullType = ReflectionType::createFromTypeAndReflector('string', false, $this->reflector);
        self::assertFalse($noNullType->allowsNull());

        $allowsNullType = ReflectionType::createFromTypeAndReflector('string', true, $this->reflector);
        self::assertTrue($allowsNullType->allowsNull());
    }

    public function testIsBuiltin(): void
    {
        self::assertTrue(ReflectionType::createFromTypeAndReflector('string', false, $this->reflector)->isBuiltin());
        self::assertTrue(ReflectionType::createFromTypeAndReflector('int', false, $this->reflector)->isBuiltin());
        self::assertTrue(ReflectionType::createFromTypeAndReflector('array', false, $this->reflector)->isBuiltin());
        self::assertTrue(ReflectionType::createFromTypeAndReflector('object', false, $this->reflector)->isBuiltin());
        self::assertTrue(ReflectionType::createFromTypeAndReflector('iterable', false, $this->reflector)->isBuiltin());
        self::assertFalse(ReflectionType::createFromTypeAndReflector('foo', false, $this->reflector)->isBuiltin());
        self::assertFalse(ReflectionType::createFromTypeAndReflector('\foo', false, $this->reflector)->isBuiltin());
    }

    public function testGetName(): void
    {
        self::assertSame('int', ReflectionType::createFromTypeAndReflector('int', false, $this->reflector)->getName());
        self::assertSame('string', ReflectionType::createFromTypeAndReflector('string', false, $this->reflector)->getName());
        self::assertSame('array', ReflectionType::createFromTypeAndReflector('array', false, $this->reflector)->getName());
        self::assertSame('callable', ReflectionType::createFromTypeAndReflector('callable', false, $this->reflector)->getName());
        self::assertSame('bool', ReflectionType::createFromTypeAndReflector('bool', false, $this->reflector)->getName());
        self::assertSame('float', ReflectionType::createFromTypeAndReflector('float', false, $this->reflector)->getName());
        self::assertSame('void', ReflectionType::createFromTypeAndReflector('void', false, $this->reflector)->getName());
        self::assertSame('object', ReflectionType::createFromTypeAndReflector('object', false, $this->reflector)->getName());
        self::assertSame('iterable', ReflectionType::createFromTypeAndReflector('iterable', false, $this->reflector)->getName());

        self::assertSame('Foo\Bar\Baz', ReflectionType::createFromTypeAndReflector('Foo\Bar\Baz', false, $this->reflector)->getName());
        self::assertSame('Foo\Bar\Baz', ReflectionType::createFromTypeAndReflector('\Foo\Bar\Baz', false, $this->reflector)->getName());
    }

    public function testImplicitCastToString(): void
    {
        self::assertSame('int', (string) ReflectionType::createFromTypeAndReflector('int', false, $this->reflector));
        self::assertSame('string', (string) ReflectionType::createFromTypeAndReflector('string', false, $this->reflector));
        self::assertSame('array', (string) ReflectionType::createFromTypeAndReflector('array', false, $this->reflector));
        self::assertSame('callable', (string) ReflectionType::createFromTypeAndReflector('callable', false, $this->reflector));
        self::assertSame('bool', (string) ReflectionType::createFromTypeAndReflector('bool', false, $this->reflector));
        self::assertSame('float', (string) ReflectionType::createFromTypeAndReflector('float', false, $this->reflector));
        self::assertSame('void', (string) ReflectionType::createFromTypeAndReflector('void', false, $this->reflector));
        self::assertSame('object', (string) ReflectionType::createFromTypeAndReflector('object', false, $this->reflector));
        self::assertSame('iterable', (string) ReflectionType::createFromTypeAndReflector('iterable', false, $this->reflector));

        self::assertSame('Foo\Bar\Baz', (string) ReflectionType::createFromTypeAndReflector('Foo\Bar\Baz', false, $this->reflector));
        self::assertSame('Foo\Bar\Baz', (string) ReflectionType::createFromTypeAndReflector('\Foo\Bar\Baz', false, $this->reflector));
    }

    public function testWillDisallowFetchingTargetClassForInternalTypes(): void<commit_msg>Add tests for builtin mixed type<commit_after><?php

declare(strict_types=1);

namespace Roave\BetterReflectionTest\Reflection;

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Roave\BetterReflection\Reflection\Exception\ClassDoesNotExist;
use Roave\BetterReflection\Reflection\Exception\ReflectionTypeDoesNotPointToAClassAlikeType;
use Roave\BetterReflection\Reflection\Reflection;
use Roave\BetterReflection\Reflection\ReflectionClass;
use Roave\BetterReflection\Reflection\ReflectionType;
use Roave\BetterReflection\Reflector\Reflector;

/**
 * @covers \Roave\BetterReflection\Reflection\ReflectionType
 */
class ReflectionTypeTest extends TestCase
{
    /** @var Reflector|MockObject */
    private $reflector;

    protected function setUp(): void
    {
        parent::setUp();

        $this->reflector = $this->createMock(Reflector::class);
    }

    public function testCreateFromType(): void
    {
        $typeInfo = ReflectionType::createFromTypeAndReflector('string', false, $this->reflector);
        self::assertInstanceOf(ReflectionType::class, $typeInfo);
    }

    public function testAllowsNull(): void
    {
        $noNullType = ReflectionType::createFromTypeAndReflector('string', false, $this->reflector);
        self::assertFalse($noNullType->allowsNull());

        $allowsNullType = ReflectionType::createFromTypeAndReflector('string', true, $this->reflector);
        self::assertTrue($allowsNullType->allowsNull());
    }

    public function testIsBuiltin(): void
    {
        self::assertTrue(ReflectionType::createFromTypeAndReflector('string', false, $this->reflector)->isBuiltin());
        self::assertTrue(ReflectionType::createFromTypeAndReflector('int', false, $this->reflector)->isBuiltin());
        self::assertTrue(ReflectionType::createFromTypeAndReflector('array', false, $this->reflector)->isBuiltin());
        self::assertTrue(ReflectionType::createFromTypeAndReflector('object', false, $this->reflector)->isBuiltin());
        self::assertTrue(ReflectionType::createFromTypeAndReflector('iterable', false, $this->reflector)->isBuiltin());
        self::assertTrue(ReflectionType::createFromTypeAndReflector('mixed', false, $this->reflector)->isBuiltin());
        self::assertTrue(ReflectionType::createFromTypeAndReflector('static', false, $this->reflector)->isBuiltin());
        self::assertFalse(ReflectionType::createFromTypeAndReflector('foo', false, $this->reflector)->isBuiltin());
        self::assertFalse(ReflectionType::createFromTypeAndReflector('\foo', false, $this->reflector)->isBuiltin());
    }

    public function testGetName(): void
    {
        self::assertSame('int', ReflectionType::createFromTypeAndReflector('int', false, $this->reflector)->getName());
        self::assertSame('string', ReflectionType::createFromTypeAndReflector('string', false, $this->reflector)->getName());
        self::assertSame('array', ReflectionType::createFromTypeAndReflector('array', false, $this->reflector)->getName());
        self::assertSame('callable', ReflectionType::createFromTypeAndReflector('callable', false, $this->reflector)->getName());
        self::assertSame('bool', ReflectionType::createFromTypeAndReflector('bool', false, $this->reflector)->getName());
        self::assertSame('float', ReflectionType::createFromTypeAndReflector('float', false, $this->reflector)->getName());
        self::assertSame('void', ReflectionType::createFromTypeAndReflector('void', false, $this->reflector)->getName());
        self::assertSame('object', ReflectionType::createFromTypeAndReflector('object', false, $this->reflector)->getName());
        self::assertSame('iterable', ReflectionType::createFromTypeAndReflector('iterable', false, $this->reflector)->getName());
        self::assertSame('mixed', ReflectionType::createFromTypeAndReflector('mixed', false, $this->reflector)->getName());

        self::assertSame('Foo\Bar\Baz', ReflectionType::createFromTypeAndReflector('Foo\Bar\Baz', false, $this->reflector)->getName());
        self::assertSame('Foo\Bar\Baz', ReflectionType::createFromTypeAndReflector('\Foo\Bar\Baz', false, $this->reflector)->getName());
    }

    public function testImplicitCastToString(): void
    {
        self::assertSame('int', (string) ReflectionType::createFromTypeAndReflector('int', false, $this->reflector));
        self::assertSame('string', (string) ReflectionType::createFromTypeAndReflector('string', false, $this->reflector));
        self::assertSame('array', (string) ReflectionType::createFromTypeAndReflector('array', false, $this->reflector));
        self::assertSame('callable', (string) ReflectionType::createFromTypeAndReflector('callable', false, $this->reflector));
        self::assertSame('bool', (string) ReflectionType::createFromTypeAndReflector('bool', false, $this->reflector));
        self::assertSame('float', (string) ReflectionType::createFromTypeAndReflector('float', false, $this->reflector));
        self::assertSame('void', (string) ReflectionType::createFromTypeAndReflector('void', false, $this->reflector));
        self::assertSame('object', (string) ReflectionType::createFromTypeAndReflector('object', false, $this->reflector));
        self::assertSame('iterable', (string) ReflectionType::createFromTypeAndReflector('iterable', false, $this->reflector));
        self::assertSame('mixed', (string) ReflectionType::createFromTypeAndReflector('mixed', false, $this->reflector));

        self::assertSame('Foo\Bar\Baz', (string) ReflectionType::createFromTypeAndReflector('Foo\Bar\Baz', false, $this->reflector));
        self::assertSame('Foo\Bar\Baz', (string) ReflectionType::createFromTypeAndReflector('\Foo\Bar\Baz', false, $this->reflector));
    }

    public function testWillDisallowFetchingTargetClassForInternalTypes(): void
{'fraction_non_alphanumeric': 0.15666546891843333, 'fraction_numerical': 0.00017966223499820338, 'mean_word_length': 6.392430278884462, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 118, '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': '2879632', 'n_tokens_mistral': 3077, 'n_tokens_neox': 3107, 'n_words': 413}