From 28d1169714e2ff5e36ca794dabe8da16fd64f708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20H=C3=A9lias?= Date: Mon, 5 Oct 2020 18:19:36 +0200 Subject: [PATCH] [DoctrineBridge] fix and replace namespace to Uid --- .../{Id => IdGenerator}/UlidGenerator.php | 2 +- .../{Id => IdGenerator}/UuidV1Generator.php | 2 +- .../{Id => IdGenerator}/UuidV4Generator.php | 2 +- .../{Id => IdGenerator}/UuidV6Generator.php | 2 +- .../Tests/IdGenerator/EntityManager.php | 21 ++++++++++++ .../Tests/IdGenerator/UlidGeneratorTest.php | 32 ++++++++++++++++++ .../Tests/IdGenerator/UuidV1GeneratorTest.php | 33 +++++++++++++++++++ .../Tests/IdGenerator/UuidV4GeneratorTest.php | 33 +++++++++++++++++++ .../Tests/IdGenerator/UuidV6GeneratorTest.php | 33 +++++++++++++++++++ 9 files changed, 156 insertions(+), 4 deletions(-) rename src/Symfony/Bridge/Doctrine/{Id => IdGenerator}/UlidGenerator.php (91%) rename src/Symfony/Bridge/Doctrine/{Id => IdGenerator}/UuidV1Generator.php (91%) rename src/Symfony/Bridge/Doctrine/{Id => IdGenerator}/UuidV4Generator.php (91%) rename src/Symfony/Bridge/Doctrine/{Id => IdGenerator}/UuidV6Generator.php (91%) create mode 100644 src/Symfony/Bridge/Doctrine/Tests/IdGenerator/EntityManager.php create mode 100644 src/Symfony/Bridge/Doctrine/Tests/IdGenerator/UlidGeneratorTest.php create mode 100644 src/Symfony/Bridge/Doctrine/Tests/IdGenerator/UuidV1GeneratorTest.php create mode 100644 src/Symfony/Bridge/Doctrine/Tests/IdGenerator/UuidV4GeneratorTest.php create mode 100644 src/Symfony/Bridge/Doctrine/Tests/IdGenerator/UuidV6GeneratorTest.php diff --git a/src/Symfony/Bridge/Doctrine/Id/UlidGenerator.php b/src/Symfony/Bridge/Doctrine/IdGenerator/UlidGenerator.php similarity index 91% rename from src/Symfony/Bridge/Doctrine/Id/UlidGenerator.php rename to src/Symfony/Bridge/Doctrine/IdGenerator/UlidGenerator.php index 61494b5f30811..8953038860fb8 100644 --- a/src/Symfony/Bridge/Doctrine/Id/UlidGenerator.php +++ b/src/Symfony/Bridge/Doctrine/IdGenerator/UlidGenerator.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Bridge\Doctrine\Types; +namespace Symfony\Bridge\Doctrine\IdGenerator; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Id\AbstractIdGenerator; diff --git a/src/Symfony/Bridge/Doctrine/Id/UuidV1Generator.php b/src/Symfony/Bridge/Doctrine/IdGenerator/UuidV1Generator.php similarity index 91% rename from src/Symfony/Bridge/Doctrine/Id/UuidV1Generator.php rename to src/Symfony/Bridge/Doctrine/IdGenerator/UuidV1Generator.php index 739a10afd691b..21d2fd6c19314 100644 --- a/src/Symfony/Bridge/Doctrine/Id/UuidV1Generator.php +++ b/src/Symfony/Bridge/Doctrine/IdGenerator/UuidV1Generator.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Bridge\Doctrine\Types; +namespace Symfony\Bridge\Doctrine\IdGenerator; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Id\AbstractIdGenerator; diff --git a/src/Symfony/Bridge/Doctrine/Id/UuidV4Generator.php b/src/Symfony/Bridge/Doctrine/IdGenerator/UuidV4Generator.php similarity index 91% rename from src/Symfony/Bridge/Doctrine/Id/UuidV4Generator.php rename to src/Symfony/Bridge/Doctrine/IdGenerator/UuidV4Generator.php index 10eef5db64169..35b94a7cd0196 100644 --- a/src/Symfony/Bridge/Doctrine/Id/UuidV4Generator.php +++ b/src/Symfony/Bridge/Doctrine/IdGenerator/UuidV4Generator.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Bridge\Doctrine\Types; +namespace Symfony\Bridge\Doctrine\IdGenerator; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Id\AbstractIdGenerator; diff --git a/src/Symfony/Bridge/Doctrine/Id/UuidV6Generator.php b/src/Symfony/Bridge/Doctrine/IdGenerator/UuidV6Generator.php similarity index 91% rename from src/Symfony/Bridge/Doctrine/Id/UuidV6Generator.php rename to src/Symfony/Bridge/Doctrine/IdGenerator/UuidV6Generator.php index 66ea8d728cb97..3677af1c2de70 100644 --- a/src/Symfony/Bridge/Doctrine/Id/UuidV6Generator.php +++ b/src/Symfony/Bridge/Doctrine/IdGenerator/UuidV6Generator.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Bridge\Doctrine\Types; +namespace Symfony\Bridge\Doctrine\IdGenerator; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Id\AbstractIdGenerator; diff --git a/src/Symfony/Bridge/Doctrine/Tests/IdGenerator/EntityManager.php b/src/Symfony/Bridge/Doctrine/Tests/IdGenerator/EntityManager.php new file mode 100644 index 0000000000000..22667a6daad4d --- /dev/null +++ b/src/Symfony/Bridge/Doctrine/Tests/IdGenerator/EntityManager.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\Doctrine\Tests\IdGenerator; + +use Doctrine\ORM\EntityManager as DoctrineEntityManager; + +class EntityManager extends DoctrineEntityManager +{ + public function __construct() + { + } +} diff --git a/src/Symfony/Bridge/Doctrine/Tests/IdGenerator/UlidGeneratorTest.php b/src/Symfony/Bridge/Doctrine/Tests/IdGenerator/UlidGeneratorTest.php new file mode 100644 index 0000000000000..c4373554e2b6b --- /dev/null +++ b/src/Symfony/Bridge/Doctrine/Tests/IdGenerator/UlidGeneratorTest.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\Doctrine\Tests\IdGenerator; + +use Doctrine\ORM\Mapping\Entity; +use PHPUnit\Framework\TestCase; +use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator; +use Symfony\Component\Uid\AbstractUid; +use Symfony\Component\Uid\Ulid; + +class UlidGeneratorTest extends TestCase +{ + public function testUlidCanBeGenerated() + { + $em = new EntityManager(); + $generator = new UlidGenerator(); + $ulid = $generator->generate($em, new Entity()); + + $this->assertInstanceOf(AbstractUid::class, $ulid); + $this->assertInstanceOf(Ulid::class, $ulid); + $this->assertTrue(Ulid::isValid($ulid)); + } +} diff --git a/src/Symfony/Bridge/Doctrine/Tests/IdGenerator/UuidV1GeneratorTest.php b/src/Symfony/Bridge/Doctrine/Tests/IdGenerator/UuidV1GeneratorTest.php new file mode 100644 index 0000000000000..b9010afe417ef --- /dev/null +++ b/src/Symfony/Bridge/Doctrine/Tests/IdGenerator/UuidV1GeneratorTest.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\Doctrine\Tests\IdGenerator; + +use Doctrine\ORM\Mapping\Entity; +use PHPUnit\Framework\TestCase; +use Symfony\Bridge\Doctrine\IdGenerator\UuidV1Generator; +use Symfony\Component\Uid\AbstractUid; +use Symfony\Component\Uid\UuidV1; + +class UuidV1GeneratorTest extends TestCase +{ + public function testUuidv1CanBeGenerated() + { + $em = new EntityManager(); + $generator = new UuidV1Generator(); + + $uuid = $generator->generate($em, new Entity()); + + $this->assertInstanceOf(AbstractUid::class, $uuid); + $this->assertInstanceOf(UuidV1::class, $uuid); + $this->assertTrue(UuidV1::isValid($uuid)); + } +} diff --git a/src/Symfony/Bridge/Doctrine/Tests/IdGenerator/UuidV4GeneratorTest.php b/src/Symfony/Bridge/Doctrine/Tests/IdGenerator/UuidV4GeneratorTest.php new file mode 100644 index 0000000000000..cc87f74428d84 --- /dev/null +++ b/src/Symfony/Bridge/Doctrine/Tests/IdGenerator/UuidV4GeneratorTest.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\Doctrine\Tests\IdGenerator; + +use Doctrine\ORM\Mapping\Entity; +use PHPUnit\Framework\TestCase; +use Symfony\Bridge\Doctrine\IdGenerator\UuidV4Generator; +use Symfony\Component\Uid\AbstractUid; +use Symfony\Component\Uid\UuidV4; + +class UuidV4GeneratorTest extends TestCase +{ + public function testUuidv4CanBeGenerated() + { + $em = new EntityManager(); + $generator = new UuidV4Generator(); + + $uuid = $generator->generate($em, new Entity()); + + $this->assertInstanceOf(AbstractUid::class, $uuid); + $this->assertInstanceOf(UuidV4::class, $uuid); + $this->assertTrue(UuidV4::isValid($uuid)); + } +} diff --git a/src/Symfony/Bridge/Doctrine/Tests/IdGenerator/UuidV6GeneratorTest.php b/src/Symfony/Bridge/Doctrine/Tests/IdGenerator/UuidV6GeneratorTest.php new file mode 100644 index 0000000000000..f0697b272c981 --- /dev/null +++ b/src/Symfony/Bridge/Doctrine/Tests/IdGenerator/UuidV6GeneratorTest.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\Doctrine\Tests\IdGenerator; + +use Doctrine\ORM\Mapping\Entity; +use PHPUnit\Framework\TestCase; +use Symfony\Bridge\Doctrine\IdGenerator\UuidV6Generator; +use Symfony\Component\Uid\AbstractUid; +use Symfony\Component\Uid\UuidV6; + +class UuidV6GeneratorTest extends TestCase +{ + public function testUuidv6CanBeGenerated() + { + $em = new EntityManager(); + $generator = new UuidV6Generator(); + + $uuid = $generator->generate($em, new Entity()); + + $this->assertInstanceOf(AbstractUid::class, $uuid); + $this->assertInstanceOf(UuidV6::class, $uuid); + $this->assertTrue(UuidV6::isValid($uuid)); + } +}