diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-06-23 09:18:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-23 09:18:18 +0200 |
commit | d37bb05c881bfdbeb1144b327edd4dcc2cbb163f (patch) | |
tree | 1b90f7e733a83af4741a8cb7f49edf3e303f8677 /tests/Wallabag/CoreBundle/Subscriber | |
parent | 891a026e31ad54ca90b70f6026f23260cfadb7fd (diff) | |
parent | 99451fe4b76051d61922a6beb7ee9e79cc6e7893 (diff) | |
download | wallabag-d37bb05c881bfdbeb1144b327edd4dcc2cbb163f.tar.gz wallabag-d37bb05c881bfdbeb1144b327edd4dcc2cbb163f.tar.zst wallabag-d37bb05c881bfdbeb1144b327edd4dcc2cbb163f.zip |
Merge pull request #2132 from wallabag/sf3.1
Jump to Symfony 3.1
Diffstat (limited to 'tests/Wallabag/CoreBundle/Subscriber')
-rw-r--r-- | tests/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriberTest.php | 114 |
1 files changed, 114 insertions, 0 deletions
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 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Subscriber; | ||
4 | |||
5 | use Doctrine\Common\EventManager; | ||
6 | use Doctrine\ORM\Event\LoadClassMetadataEventArgs; | ||
7 | use Doctrine\ORM\Mapping\ClassMetadata; | ||
8 | use Wallabag\CoreBundle\Subscriber\TablePrefixSubscriber; | ||
9 | |||
10 | class TablePrefixSubscriberTest extends \PHPUnit_Framework_TestCase | ||
11 | { | ||
12 | public function dataForPrefix() | ||
13 | { | ||
14 | return [ | ||
15 | ['wallabag_', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'wallabag_user', '"wallabag_user"', new \Doctrine\DBAL\Platforms\PostgreSqlPlatform()], | ||
16 | ['wallabag_', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'wallabag_user', '`wallabag_user`', new \Doctrine\DBAL\Platforms\MySqlPlatform()], | ||
17 | ['wallabag_', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'wallabag_user', '"wallabag_user"', new \Doctrine\DBAL\Platforms\SqlitePlatform()], | ||
18 | |||
19 | ['wallabag_', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'wallabag_user', 'wallabag_user', new \Doctrine\DBAL\Platforms\PostgreSqlPlatform()], | ||
20 | ['wallabag_', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'wallabag_user', 'wallabag_user', new \Doctrine\DBAL\Platforms\MySqlPlatform()], | ||
21 | ['wallabag_', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'wallabag_user', 'wallabag_user', new \Doctrine\DBAL\Platforms\SqlitePlatform()], | ||
22 | |||
23 | ['', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'user', '"user"', new \Doctrine\DBAL\Platforms\PostgreSqlPlatform()], | ||
24 | ['', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'user', '`user`', new \Doctrine\DBAL\Platforms\MySqlPlatform()], | ||
25 | ['', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'user', '"user"', new \Doctrine\DBAL\Platforms\SqlitePlatform()], | ||
26 | |||
27 | ['', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'user', 'user', new \Doctrine\DBAL\Platforms\PostgreSqlPlatform()], | ||
28 | ['', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'user', 'user', new \Doctrine\DBAL\Platforms\MySqlPlatform()], | ||
29 | ['', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'user', 'user', new \Doctrine\DBAL\Platforms\SqlitePlatform()], | ||
30 | ]; | ||
31 | } | ||
32 | |||
33 | /** | ||
34 | * @dataProvider dataForPrefix | ||
35 | */ | ||
36 | public function testPrefix($prefix, $entityName, $tableName, $tableNameExpected, $finalTableName, $finalTableNameQuoted, $platform) | ||
37 | { | ||
38 | $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') | ||
39 | ->disableOriginalConstructor() | ||
40 | ->getMock(); | ||
41 | |||
42 | $subscriber = new TablePrefixSubscriber($prefix); | ||
43 | |||
44 | $metaClass = new ClassMetadata($entityName); | ||
45 | $metaClass->setPrimaryTable(['name' => $tableName]); | ||
46 | |||
47 | $metaDataEvent = new LoadClassMetadataEventArgs($metaClass, $em); | ||
48 | |||
49 | $this->assertEquals($tableNameExpected, $metaDataEvent->getClassMetadata()->getTableName()); | ||
50 | |||
51 | $subscriber->loadClassMetadata($metaDataEvent); | ||
52 | |||
53 | $this->assertEquals($finalTableName, $metaDataEvent->getClassMetadata()->getTableName()); | ||
54 | $this->assertEquals($finalTableNameQuoted, $metaDataEvent->getClassMetadata()->getQuotedTableName($platform)); | ||
55 | } | ||
56 | |||
57 | /** | ||
58 | * @dataProvider dataForPrefix | ||
59 | */ | ||
60 | public function testSubscribedEvents($prefix, $entityName, $tableName, $tableNameExpected, $finalTableName, $finalTableNameQuoted, $platform) | ||
61 | { | ||
62 | $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') | ||
63 | ->disableOriginalConstructor() | ||
64 | ->getMock(); | ||
65 | |||
66 | $metaClass = new ClassMetadata($entityName); | ||
67 | $metaClass->setPrimaryTable(['name' => $tableName]); | ||
68 | |||
69 | $metaDataEvent = new LoadClassMetadataEventArgs($metaClass, $em); | ||
70 | |||
71 | $subscriber = new TablePrefixSubscriber($prefix); | ||
72 | |||
73 | $evm = new EventManager(); | ||
74 | $evm->addEventSubscriber($subscriber); | ||
75 | |||
76 | $evm->dispatchEvent('loadClassMetadata', $metaDataEvent); | ||
77 | |||
78 | $this->assertEquals($finalTableName, $metaDataEvent->getClassMetadata()->getTableName()); | ||
79 | $this->assertEquals($finalTableNameQuoted, $metaDataEvent->getClassMetadata()->getQuotedTableName($platform)); | ||
80 | } | ||
81 | |||
82 | public function testPrefixManyToMany() | ||
83 | { | ||
84 | $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') | ||
85 | ->disableOriginalConstructor() | ||
86 | ->getMock(); | ||
87 | |||
88 | $subscriber = new TablePrefixSubscriber('yo_'); | ||
89 | |||
90 | $metaClass = new ClassMetadata('Wallabag\UserBundle\Entity\Entry'); | ||
91 | $metaClass->setPrimaryTable(['name' => 'entry']); | ||
92 | $metaClass->mapManyToMany([ | ||
93 | 'fieldName' => 'tags', | ||
94 | 'joinTable' => ['name' => null, 'schema' => null], | ||
95 | 'targetEntity' => 'Tag', | ||
96 | 'mappedBy' => null, | ||
97 | 'inversedBy' => 'entries', | ||
98 | 'cascade' => ['persist'], | ||
99 | 'indexBy' => null, | ||
100 | 'orphanRemoval' => false, | ||
101 | 'fetch' => 2, | ||
102 | ]); | ||
103 | |||
104 | $metaDataEvent = new LoadClassMetadataEventArgs($metaClass, $em); | ||
105 | |||
106 | $this->assertEquals('entry', $metaDataEvent->getClassMetadata()->getTableName()); | ||
107 | |||
108 | $subscriber->loadClassMetadata($metaDataEvent); | ||
109 | |||
110 | $this->assertEquals('yo_entry', $metaDataEvent->getClassMetadata()->getTableName()); | ||
111 | $this->assertEquals('yo_entry_tag', $metaDataEvent->getClassMetadata()->associationMappings['tags']['joinTable']['name']); | ||
112 | $this->assertEquals('yo_entry', $metaDataEvent->getClassMetadata()->getQuotedTableName(new \Doctrine\DBAL\Platforms\MySqlPlatform())); | ||
113 | } | ||
114 | } | ||