diff --git a/composer.json b/composer.json index ad95c5a..7d718c4 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,6 @@ "moontoast/math": "~1.1", "ircmaxell/random-lib": "~1.0", "symfony/console": "~2.3", - "doctrine/dbal": ">=2.3", "phpunit/phpunit": "~4.5", "squizlabs/php_codesniffer": "^2.3", "jakub-onderka/php-parallel-lint": "^0.9.0", @@ -39,10 +38,10 @@ }, "bin": ["bin/uuid"], "suggest": { + "ramsey/uuid-doctrine": "Allow the use of a UUID as Doctrine field type.", "moontoast/math": "Support for converting UUID to 128-bit integer (in string form).", "ircmaxell/random-lib": "Provides RandomLib to use with the RandomLibAdapter", - "symfony/console": "Support for use of the bin/uuid command line tool.", - "doctrine/dbal": "Allow the use of a UUID as doctrine field type." + "symfony/console": "Support for use of the bin/uuid command line tool." }, "autoload": { "psr-4": {"Ramsey\\Uuid\\": "src/"} diff --git a/src/Doctrine/UuidType.php b/src/Doctrine/UuidType.php deleted file mode 100644 index 078d5b8..0000000 --- a/src/Doctrine/UuidType.php +++ /dev/null @@ -1,108 +0,0 @@ - - * @license http://opensource.org/licenses/MIT MIT - */ - -namespace Ramsey\Uuid\Doctrine; - -use InvalidArgumentException; -use Ramsey\Uuid\Uuid; -use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\Type; -use Doctrine\DBAL\Platforms\AbstractPlatform; - -/** - * Field type mapping for the Doctrine Database Abstraction Layer (DBAL). - * - * UUID fields will be stored as a string in the database and converted back to - * the Uuid value object when querying. - */ -class UuidType extends Type -{ - /** - * @var string - */ - const NAME = 'uuid'; - - /** - * {@inheritdoc} - * - * @param array $fieldDeclaration - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - */ - public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) - { - return $platform->getGuidTypeDeclarationSQL($fieldDeclaration); - } - - /** - * {@inheritdoc} - * - * @param string|null $value - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - */ - public function convertToPHPValue($value, AbstractPlatform $platform) - { - if (empty($value)) { - return null; - } - - if ($value instanceof Uuid) { - return $value; - } - - try { - $uuid = Uuid::fromString($value); - } catch (InvalidArgumentException $e) { - throw ConversionException::conversionFailed($value, self::NAME); - } - - return $uuid; - } - - /** - * {@inheritdoc} - * - * @param Uuid|null $value - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) - { - if (empty($value)) { - return null; - } - - if ($value instanceof Uuid || Uuid::isValid($value)) { - return (string) $value; - } - - throw ConversionException::conversionFailed($value, self::NAME); - } - - /** - * {@inheritdoc} - * - * @return string - */ - public function getName() - { - return self::NAME; - } - - /** - * {@inheritdoc} - * - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - * @return boolean - */ - public function requiresSQLCommentHint(AbstractPlatform $platform) - { - return true; - } -} diff --git a/tests/Doctrine/UuidTypeTest.php b/tests/Doctrine/UuidTypeTest.php deleted file mode 100644 index b014c2f..0000000 --- a/tests/Doctrine/UuidTypeTest.php +++ /dev/null @@ -1,123 +0,0 @@ -skipIfNoDoctrineDbal(); - $this->skip64BitTest(); - - $this->platform = $this->getPlatformMock(); - $this->platform->expects($this->any()) - ->method('getGuidTypeDeclarationSQL') - ->will($this->returnValue('DUMMYVARCHAR()')); - - $this->type = 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->type->convertToDatabaseValue($uuid, $this->platform); - - $this->assertEquals($expected, $actual); - } - - /** - * @covers Ramsey\Uuid\Doctrine\UuidType::convertToDatabaseValue - */ - public function testInvalidUuidConversionForDatabaseValue() - { - $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); - $this->type->convertToDatabaseValue('abcdefg', $this->platform); - } - - /** - * @covers Ramsey\Uuid\Doctrine\UuidType::convertToDatabaseValue - */ - public function testNullConversionForDatabaseValue() - { - $this->assertNull($this->type->convertToDatabaseValue(null, $this->platform)); - } - - /** - * @covers Ramsey\Uuid\Doctrine\UuidType::convertToPHPValue - */ - public function testUuidConvertsToPHPValue() - { - $uuid = $this->type->convertToPHPValue('ff6f8cb0-c57d-11e1-9b21-0800200c9a66', $this->platform); - $this->assertInstanceOf('Ramsey\Uuid\Uuid', $uuid); - $this->assertEquals('ff6f8cb0-c57d-11e1-9b21-0800200c9a66', $uuid->toString()); - } - - /** - * @covers Ramsey\Uuid\Doctrine\UuidType::convertToPHPValue - */ - public function testInvalidUuidConversionForPHPValue() - { - $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); - $this->type->convertToPHPValue('abcdefg', $this->platform); - } - - /** - * @covers Ramsey\Uuid\Doctrine\UuidType::convertToPHPValue - */ - public function testNullConversionForPHPValue() - { - $this->assertNull($this->type->convertToPHPValue(null, $this->platform)); - } - - /** - * @covers Ramsey\Uuid\Doctrine\UuidType::getName - */ - public function testGetName() - { - $this->assertEquals('uuid', $this->type->getName()); - } - - /** - * @covers Ramsey\Uuid\Doctrine\UuidType::getSqlDeclaration - */ - public function testGetGuidTypeDeclarationSQL() - { - $this->assertEquals('DUMMYVARCHAR()', $this->type->getSqlDeclaration(array('length' => 36), $this->platform)); - } - - /** - * @covers Ramsey\Uuid\Doctrine\UuidType::requiresSQLCommentHint - */ - public function testRequiresSQLCommentHint() - { - $this->assertTrue($this->type->requiresSQLCommentHint($this->platform)); - } - - /** - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function getPlatformMock() - { - return $this->getMockBuilder('Doctrine\DBAL\Platforms\AbstractPlatform') - ->setMethods(array('getGuidTypeDeclarationSQL')) - ->getMockForAbstractClass(); - } -} diff --git a/tests/TestCase.php b/tests/TestCase.php index b8e12ef..178a14f 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -30,15 +30,6 @@ class TestCase extends \PHPUnit_Framework_TestCase } } - protected function skipIfNoDoctrineDbal() - { - if (!$this->hasDoctrineDbal()) { - $this->markTestSkipped( - 'Skipping test that requires doctrine/dbal.' - ); - } - } - protected function hasMoontoastMath() { return class_exists('Moontoast\\Math\\BigNumber'); @@ -48,9 +39,4 @@ class TestCase extends \PHPUnit_Framework_TestCase { return class_exists('Symfony\\Component\\Console\\Application'); } - - protected function hasDoctrineDbal() - { - return class_exists('Doctrine\\DBAL\\Types\\Type'); - } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index b1857f4..7998a23 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,5 +1,4 @@ add("Doctrine\Tests\DBAL", __DIR__."/../vendor/doctrine/dbal/tests"); $loader->addPsr4('Ramsey\\Uuid\\', __DIR__);