From 23634d5d842dabcf5d7475e2becb7e127824239e Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 1 Jun 2016 21:27:35 +0200 Subject: Jump to Symfony 3.1 --- .../Subscriber/TablePrefixSubscriberTest.php | 114 +++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 tests/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriberTest.php (limited to 'tests/Wallabag/CoreBundle/Subscriber') diff --git a/tests/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriberTest.php b/tests/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriberTest.php new file mode 100644 index 00000000..4ae76703 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriberTest.php @@ -0,0 +1,114 @@ +getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $subscriber = new TablePrefixSubscriber($prefix); + + $metaClass = new ClassMetadata($entityName); + $metaClass->setPrimaryTable(['name' => $tableName]); + + $metaDataEvent = new LoadClassMetadataEventArgs($metaClass, $em); + + $this->assertEquals($tableNameExpected, $metaDataEvent->getClassMetadata()->getTableName()); + + $subscriber->loadClassMetadata($metaDataEvent); + + $this->assertEquals($finalTableName, $metaDataEvent->getClassMetadata()->getTableName()); + $this->assertEquals($finalTableNameQuoted, $metaDataEvent->getClassMetadata()->getQuotedTableName($platform)); + } + + /** + * @dataProvider dataForPrefix + */ + public function testSubscribedEvents($prefix, $entityName, $tableName, $tableNameExpected, $finalTableName, $finalTableNameQuoted, $platform) + { + $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $metaClass = new ClassMetadata($entityName); + $metaClass->setPrimaryTable(['name' => $tableName]); + + $metaDataEvent = new LoadClassMetadataEventArgs($metaClass, $em); + + $subscriber = new TablePrefixSubscriber($prefix); + + $evm = new EventManager(); + $evm->addEventSubscriber($subscriber); + + $evm->dispatchEvent('loadClassMetadata', $metaDataEvent); + + $this->assertEquals($finalTableName, $metaDataEvent->getClassMetadata()->getTableName()); + $this->assertEquals($finalTableNameQuoted, $metaDataEvent->getClassMetadata()->getQuotedTableName($platform)); + } + + public function testPrefixManyToMany() + { + $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $subscriber = new TablePrefixSubscriber('yo_'); + + $metaClass = new ClassMetadata('Wallabag\UserBundle\Entity\Entry'); + $metaClass->setPrimaryTable(['name' => 'entry']); + $metaClass->mapManyToMany([ + 'fieldName' => 'tags', + 'joinTable' => ['name' => null, 'schema' => null], + 'targetEntity' => 'Tag', + 'mappedBy' => null, + 'inversedBy' => 'entries', + 'cascade' => ['persist'], + 'indexBy' => null, + 'orphanRemoval' => false, + 'fetch' => 2, + ]); + + $metaDataEvent = new LoadClassMetadataEventArgs($metaClass, $em); + + $this->assertEquals('entry', $metaDataEvent->getClassMetadata()->getTableName()); + + $subscriber->loadClassMetadata($metaDataEvent); + + $this->assertEquals('yo_entry', $metaDataEvent->getClassMetadata()->getTableName()); + $this->assertEquals('yo_entry_tag', $metaDataEvent->getClassMetadata()->associationMappings['tags']['joinTable']['name']); + $this->assertEquals('yo_entry', $metaDataEvent->getClassMetadata()->getQuotedTableName(new \Doctrine\DBAL\Platforms\MySqlPlatform())); + } +} -- cgit v1.2.3