<commit_before><?php

namespace Ramsey\Uuid\Doctrine;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use Mockery;
use Mockery\MockInterface;
use PHPUnit\Framework\TestCase;
use Ramsey\Uuid\Uuid;

class UuidTypeTest extends TestCase
{
    public function __construct()
    {
        parent::__construct();

        if (class_exists('Doctrine\DBAL\Types\Type') && !Type::hasType('uuid')) {
            Type::addType('uuid', 'Ramsey\Uuid\Doctrine\UuidType');
        }
    }

    protected function getPlatform()
    {
        $platform = $this->getPlatformMock();
        $platform->shouldAllowMockingProtectedMethods();
        $platform
            ->shouldReceive('getGuidTypeDeclarationSQL')
            ->andReturn('DUMMYVARCHAR()');

        return $platform;
    }

    protected function getType()
    {
        return Type::getType('uuid');
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::convertToDatabaseValue
     */
    public function testUuidConvertsToDatabaseValue()
    {
        $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');

        $expected = $uuid->toString();
        $actual = $this->getType()->convertToDatabaseValue($uuid, $this->getPlatform());

        $this->assertEquals($expected, $actual);
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::convertToDatabaseValue
     */
    public function testUuidInterfaceConvertsToDatabaseValue()
    {
        $uuid = \Mockery::mock('Ramsey\\Uuid\\Uuid');

        $uuid
            ->shouldReceive('__toString')
            ->once()
            ->andReturn('foo');

        $actual = $this->getType()->convertToDatabaseValue($uuid, $this->getPlatform());

        $this->assertEquals('foo', $actual);
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::convertToDatabaseValue
     */
    public function testUuidStringConvertsToDatabaseValue()
    {
        $uuid = 'ff6f8cb0-c57d-11e1-9b21-0800200c9a66';

        $actual = $this->getType()->convertToDatabaseValue($uuid, $this->getPlatform());

        $this->assertEquals($uuid, $actual);
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::convertToDatabaseValue
     */
    public function testInvalidUuidConversionForDatabaseValue()
    {
        if (!method_exists($this, 'expectException')) {
            $this->markTestSkipped('This version of PHPUnit does not have expectException()');
        }

        $this->expectException('Doctrine\\DBAL\\Types\\ConversionException');

        $this->getType()->convertToDatabaseValue('abcdefg', $this->getPlatform());
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::convertToDatabaseValue
     */
    public function testNullConversionForDatabaseValue()
    {
        $this->assertNull($this->getType()->convertToDatabaseValue(null, $this->getPlatform()));
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::convertToPHPValue
     */
    public function testUuidInterfaceConvertsToPHPValue()
    {
        $uuid = \Mockery::mock('Ramsey\\Uuid\\Uuid');

        $actual = $this->getType()->convertToPHPValue($uuid, $this->getPlatform());

        $this->assertSame($uuid, $actual);
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::convertToPHPValue
     */
    public function testUuidConvertsToPHPValue()
    {
        $uuid = $this->getType()->convertToPHPValue('ff6f8cb0-c57d-11e1-9b21-0800200c9a66', $this->getPlatform());
        $this->assertInstanceOf('Ramsey\Uuid\UuidInterface', $uuid);
        $this->assertEquals('ff6f8cb0-c57d-11e1-9b21-0800200c9a66', $uuid->toString());
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::convertToPHPValue
     */
    public function testInvalidUuidConversionForPHPValue()
    {
        if (!method_exists($this, 'expectException')) {
            $this->markTestSkipped('This version of PHPUnit does not have expectException()');
        }

        $this->expectException('Doctrine\\DBAL\\Types\\ConversionException');

        $this->getType()->convertToPHPValue('abcdefg', $this->getPlatform());
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::convertToPHPValue
     */
    public function testNullConversionForPHPValue()
    {
        $this->assertNull($this->getType()->convertToPHPValue(null, $this->getPlatform()));
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::convertToPHPValue
     */
    public function testReturnValueIfUuidForPHPValue()
    {
        $uuid = Uuid::uuid4();
        $this->assertSame($uuid, $this->getType()->convertToPHPValue($uuid, $this->getPlatform()));
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::getName
     */
    public function testGetName()
    {
        $this->assertEquals('uuid', $this->getType()->getName());
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::getSqlDeclaration
     */
    public function testGetGuidTypeDeclarationSQL()
    {
        $this->assertEquals(
            'DUMMYVARCHAR()',
            $this->getType()->getSqlDeclaration(['length' => 36], $this->getPlatform())
        );
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::requiresSQLCommentHint
     */
    public function testRequiresSQLCommentHint()
    {
        $this->assertTrue($this->getType()->requiresSQLCommentHint($this->getPlatform()));
    }

    /**
     * @return AbstractPlatform & MockInterface
     */
    private function getPlatformMock()
    {
        return Mockery::mock('Doctrine\DBAL\Platforms\AbstractPlatform')->makePartial();<commit_msg>Add test for full coverage of UuidType<commit_after><?php

namespace Ramsey\Uuid\Doctrine;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use Mockery;
use Mockery\MockInterface;
use PHPUnit\Framework\TestCase;
use Ramsey\Uuid\Uuid;

class UuidTypeTest extends TestCase
{
    public function __construct()
    {
        parent::__construct();

        if (class_exists('Doctrine\DBAL\Types\Type') && !Type::hasType('uuid')) {
            Type::addType('uuid', 'Ramsey\Uuid\Doctrine\UuidType');
        }
    }

    protected function getPlatform()
    {
        $platform = $this->getPlatformMock();
        $platform->shouldAllowMockingProtectedMethods();
        $platform
            ->shouldReceive('getGuidTypeDeclarationSQL')
            ->andReturn('DUMMYVARCHAR()');

        return $platform;
    }

    protected function getType()
    {
        return Type::getType('uuid');
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::convertToDatabaseValue
     */
    public function testUuidConvertsToDatabaseValue()
    {
        $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');

        $expected = $uuid->toString();
        $actual = $this->getType()->convertToDatabaseValue($uuid, $this->getPlatform());

        $this->assertEquals($expected, $actual);
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::convertToDatabaseValue
     */
    public function testUuidInterfaceConvertsToDatabaseValue()
    {
        $uuid = \Mockery::mock('Ramsey\\Uuid\\Uuid');

        $uuid
            ->shouldReceive('__toString')
            ->once()
            ->andReturn('foo');

        $actual = $this->getType()->convertToDatabaseValue($uuid, $this->getPlatform());

        $this->assertEquals('foo', $actual);
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::convertToDatabaseValue
     */
    public function testUuidStringConvertsToDatabaseValue()
    {
        $uuid = 'ff6f8cb0-c57d-11e1-9b21-0800200c9a66';

        $actual = $this->getType()->convertToDatabaseValue($uuid, $this->getPlatform());

        $this->assertEquals($uuid, $actual);
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::convertToDatabaseValue
     */
    public function testInvalidUuidConversionForDatabaseValue()
    {
        if (!method_exists($this, 'expectException')) {
            $this->markTestSkipped('This version of PHPUnit does not have expectException()');
        }

        $this->expectException('Doctrine\\DBAL\\Types\\ConversionException');

        $this->getType()->convertToDatabaseValue('abcdefg', $this->getPlatform());
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::convertToDatabaseValue
     */
    public function testNullConversionForDatabaseValue()
    {
        $this->assertNull($this->getType()->convertToDatabaseValue(null, $this->getPlatform()));
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::convertToPHPValue
     */
    public function testUuidInterfaceConvertsToPHPValue()
    {
        $uuid = \Mockery::mock('Ramsey\\Uuid\\Uuid');

        $actual = $this->getType()->convertToPHPValue($uuid, $this->getPlatform());

        $this->assertSame($uuid, $actual);
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::convertToPHPValue
     */
    public function testUuidConvertsToPHPValue()
    {
        $uuid = $this->getType()->convertToPHPValue('ff6f8cb0-c57d-11e1-9b21-0800200c9a66', $this->getPlatform());
        $this->assertInstanceOf('Ramsey\Uuid\UuidInterface', $uuid);
        $this->assertEquals('ff6f8cb0-c57d-11e1-9b21-0800200c9a66', $uuid->toString());
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::convertToPHPValue
     */
    public function testInvalidUuidConversionForPHPValue()
    {
        if (!method_exists($this, 'expectException')) {
            $this->markTestSkipped('This version of PHPUnit does not have expectException()');
        }

        $this->expectException('Doctrine\\DBAL\\Types\\ConversionException');

        $this->getType()->convertToPHPValue('abcdefg', $this->getPlatform());
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::convertToPHPValue
     */
    public function testNullConversionForPHPValue()
    {
        $this->assertNull($this->getType()->convertToPHPValue(null, $this->getPlatform()));
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::convertToPHPValue
     */
    public function testReturnValueIfUuidForPHPValue()
    {
        $uuid = Uuid::uuid4();
        $this->assertSame($uuid, $this->getType()->convertToPHPValue($uuid, $this->getPlatform()));
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::getName
     */
    public function testGetName()
    {
        $this->assertEquals('uuid', $this->getType()->getName());
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::getSqlDeclaration
     */
    public function testGetGuidTypeDeclarationSQL()
    {
        $this->assertEquals(
            'DUMMYVARCHAR()',
            $this->getType()->getSqlDeclaration(['length' => 36], $this->getPlatform())
        );
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::requiresSQLCommentHint
     */
    public function testRequiresSQLCommentHint()
    {
        $this->assertTrue($this->getType()->requiresSQLCommentHint($this->getPlatform()));
    }

    /**
     * @covers \Ramsey\Uuid\Doctrine\UuidType::getMappedDatabaseTypes
     */
    public function testGetMappedDatabaseTypes()
    {
        $this->assertSame(['uuid'], $this->getType()->getMappedDatabaseTypes($this->getPlatformMock()));
    }

    /**
     * @return AbstractPlatform & MockInterface
     */
    private function getPlatformMock()
    {
        return Mockery::mock('Doctrine\DBAL\Platforms\AbstractPlatform')->makePartial();
{'fraction_non_alphanumeric': 0.15444424810037108, 'fraction_numerical': 0.015373740943629616, 'mean_word_length': 2.97436797752809, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 137, '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': '734384', 'n_tokens_mistral': 3596, 'n_tokens_neox': 3454, 'n_words': 418}