From 37d1d5790048597dc3015b4c3e59f9b800c8eb5c Mon Sep 17 00:00:00 2001 From: Dennis Enderink Date: Tue, 24 Jul 2018 16:40:31 +0200 Subject: [PATCH] Added unit tests --- .../Tests/DbalTypes/CustomIdObjectType.php | 4 +- .../CustomIdObjectTypeChild.php | 15 ++++++ .../CustomIdObjectTypeParent.php | 39 ++++++++++++++ ...TableInheritanceCustomIdObjectTypeTest.php | 51 +++++++++++++++++++ .../ORM/Functional/CustomIdObjectTypeTest.php | 2 +- .../Doctrine/Tests/OrmFunctionalTestCase.php | 9 ++++ 6 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 tests/Doctrine/Tests/Models/ClassTableInheritanceCustomType/CustomIdObjectTypeChild.php create mode 100644 tests/Doctrine/Tests/Models/ClassTableInheritanceCustomType/CustomIdObjectTypeParent.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceCustomIdObjectTypeTest.php diff --git a/tests/Doctrine/Tests/DbalTypes/CustomIdObjectType.php b/tests/Doctrine/Tests/DbalTypes/CustomIdObjectType.php index 0ebae5dff0e..154f5778641 100644 --- a/tests/Doctrine/Tests/DbalTypes/CustomIdObjectType.php +++ b/tests/Doctrine/Tests/DbalTypes/CustomIdObjectType.php @@ -14,7 +14,7 @@ class CustomIdObjectType extends Type */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - return $value->id; + return $value->id . '_test'; } /** @@ -22,7 +22,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) */ public function convertToPHPValue($value, AbstractPlatform $platform) { - $idObject = new CustomIdObject($value); + $idObject = new CustomIdObject(str_replace('_test', '', $value)); return $idObject; } diff --git a/tests/Doctrine/Tests/Models/ClassTableInheritanceCustomType/CustomIdObjectTypeChild.php b/tests/Doctrine/Tests/Models/ClassTableInheritanceCustomType/CustomIdObjectTypeChild.php new file mode 100644 index 00000000000..99b433f4a67 --- /dev/null +++ b/tests/Doctrine/Tests/Models/ClassTableInheritanceCustomType/CustomIdObjectTypeChild.php @@ -0,0 +1,15 @@ +id = $id; + $this->type = $type; + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceCustomIdObjectTypeTest.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceCustomIdObjectTypeTest.php new file mode 100644 index 00000000000..2768c02aab9 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceCustomIdObjectTypeTest.php @@ -0,0 +1,51 @@ +useModelSet('class_table_inheritance_custom_id_object_type'); + + parent::setUp(); + } + + public function testDelete() + { + $object = new CustomIdObjectTypeChild(new CustomIdObject('foo')); + $object->name = 'Test'; + + // persist parent + $this->_em->persist($object); + $this->_em->flush(); + + // save id for later use + $id = $object->id; + + // get child + $object2 = $this->_em->find(CustomIdObjectTypeChild::class, $id); + + // remove child + $this->_em->remove($object2); + $this->_em->flush(); + + $this->assertNull($this->_em->find(CustomIdObjectTypeChild::class, $id)); + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/CustomIdObjectTypeTest.php b/tests/Doctrine/Tests/ORM/Functional/CustomIdObjectTypeTest.php index 08d89fa8ec2..75ffd05be93 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CustomIdObjectTypeTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CustomIdObjectTypeTest.php @@ -84,7 +84,7 @@ public function testFetchJoinWhereCustomIdObject() . ' parent LEFT JOIN parent.children children ' . 'WHERE children.id = ?1' ) - ->setParameter(1, $parent->children->first()->id) + ->setParameter(1, $parent->children->first()->id, CustomIdObjectType::NAME) ->getResult(); $this->assertCount(1, $result); diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index d45ebac6387..569e1a55f82 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -97,6 +97,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase * @var array */ protected static $_modelSets = [ + 'class_table_inheritance_custom_id_object_type' => [ + Models\ClassTableInheritanceCustomType\CustomIdObjectTypeParent::class, + Models\ClassTableInheritanceCustomType\CustomIdObjectTypeChild::class, + ], 'cms' => [ Models\CMS\CmsUser::class, Models\CMS\CmsPhonenumber::class, @@ -343,6 +347,11 @@ protected function tearDown() $this->_sqlLoggerStack->enabled = false; + if (isset($this->_usedModelSets['class_table_inheritance_custom_id_object_type'])) { + $conn->executeUpdate('DELETE FROM class_table_inheritance_custom_id_type_child'); + $conn->executeUpdate('DELETE FROM class_table_inheritance_custom_id_type_parent'); + } + if (isset($this->_usedModelSets['cms'])) { $conn->executeUpdate('DELETE FROM cms_users_groups'); $conn->executeUpdate('DELETE FROM cms_groups');