aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2015-11-09 16:31:59 +0100
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2015-11-09 16:31:59 +0100
commitf1eccfd63f214dcc730ab0d18a694a5465f425db (patch)
treee6cbd355f3a360e5619821fb1415ee26a01f11ce
parent4529d0f4b6b20cbbd1ccb5339a753aff7d35552b (diff)
parent53cf5106891fc64f3f66cb6b3316654a9620239c (diff)
downloadwallabag-f1eccfd63f214dcc730ab0d18a694a5465f425db.tar.gz
wallabag-f1eccfd63f214dcc730ab0d18a694a5465f425db.tar.zst
wallabag-f1eccfd63f214dcc730ab0d18a694a5465f425db.zip
Merge pull request #1500 from wallabag/v2-quote-pgsql
Fix quote strategy for reserved keyword in Postgres
-rw-r--r--.travis.yml2
-rw-r--r--app/config/config.yml1
-rw-r--r--composer.json2
-rw-r--r--composer.lock26
-rw-r--r--src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php4
-rw-r--r--src/Wallabag/ApiBundle/Tests/WallabagApiTestCase.php (renamed from src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php)2
-rw-r--r--src/Wallabag/CoreBundle/Command/InstallCommand.php17
-rw-r--r--src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php83
-rw-r--r--src/Wallabag/CoreBundle/Entity/Config.php2
-rw-r--r--src/Wallabag/CoreBundle/Entity/Entry.php2
-rw-r--r--src/Wallabag/CoreBundle/Entity/Tag.php2
-rw-r--r--src/Wallabag/CoreBundle/Resources/config/services.yml6
-rw-r--r--src/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriber.php51
-rw-r--r--src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php63
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php6
-rw-r--r--src/Wallabag/CoreBundle/Tests/EventListener/LocaleListenerTest.php3
-rw-r--r--src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php3
-rw-r--r--src/Wallabag/CoreBundle/Tests/EventListener/UserLocaleListenerTest.php3
-rw-r--r--src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php3
-rw-r--r--src/Wallabag/CoreBundle/Tests/ParamConverter/UsernameRssTokenConverterTest.php3
-rw-r--r--src/Wallabag/CoreBundle/Tests/Subscriber/TablePrefixSubscriberTest.php114
-rw-r--r--src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php2
-rw-r--r--src/Wallabag/UserBundle/Entity/User.php2
23 files changed, 252 insertions, 150 deletions
diff --git a/.travis.yml b/.travis.yml
index df3a5c72..9a19be61 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -51,7 +51,7 @@ before_script:
51 51
52script: 52script:
53 - ant prepare-$DB 53 - ant prepare-$DB
54 - SYMFONY_DEPRECATIONS_HELPER=weak bin/phpunit --exclude-group command-doctrine -v 54 - SYMFONY_DEPRECATIONS_HELPER=weak bin/phpunit -v
55 55
56# after_script: 56# after_script:
57 # - | 57 # - |
diff --git a/app/config/config.yml b/app/config/config.yml
index 0655fed5..285fbd7c 100644
--- a/app/config/config.yml
+++ b/app/config/config.yml
@@ -88,7 +88,6 @@ doctrine:
88 auto_generate_proxy_classes: "%kernel.debug%" 88 auto_generate_proxy_classes: "%kernel.debug%"
89 entity_managers: 89 entity_managers:
90 default: 90 default:
91 naming_strategy: wallabag_core.doctrine.prefixed_naming_strategy
92 auto_mapping: true 91 auto_mapping: true
93 92
94# Swiftmailer Configuration 93# Swiftmailer Configuration
diff --git a/composer.json b/composer.json
index b8c936f0..a46e990a 100644
--- a/composer.json
+++ b/composer.json
@@ -31,7 +31,7 @@
31 "php": ">=5.3.3", 31 "php": ">=5.3.3",
32 "symfony/symfony": "~2.7.0", 32 "symfony/symfony": "~2.7.0",
33 "doctrine/orm": "~2.3", 33 "doctrine/orm": "~2.3",
34 "doctrine/doctrine-bundle": "~1.2", 34 "doctrine/doctrine-bundle": "1.5.2",
35 "twig/extensions": "~1.0", 35 "twig/extensions": "~1.0",
36 "symfony/assetic-bundle": "~2.3", 36 "symfony/assetic-bundle": "~2.3",
37 "symfony/swiftmailer-bundle": "~2.3", 37 "symfony/swiftmailer-bundle": "~2.3",
diff --git a/composer.lock b/composer.lock
index ee6e483a..ec11324f 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,8 +4,8 @@
4 "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 4 "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
5 "This file is @generated automatically" 5 "This file is @generated automatically"
6 ], 6 ],
7 "hash": "01e7829e7ff2b39b288871661bb05e9a", 7 "hash": "6bd09434f83c7e6b5e1c75fddbd7608b",
8 "content-hash": "76830bc9c2cd6f600613c9eea7c0f1b1", 8 "content-hash": "d07d54c4cc6f4f4947c652bd659af02e",
9 "packages": [ 9 "packages": [
10 { 10 {
11 "name": "doctrine/annotations", 11 "name": "doctrine/annotations",
@@ -357,16 +357,16 @@
357 }, 357 },
358 { 358 {
359 "name": "doctrine/doctrine-bundle", 359 "name": "doctrine/doctrine-bundle",
360 "version": "1.6.0", 360 "version": "v1.5.2",
361 "source": { 361 "source": {
362 "type": "git", 362 "type": "git",
363 "url": "https://github.com/doctrine/DoctrineBundle.git", 363 "url": "https://github.com/doctrine/DoctrineBundle.git",
364 "reference": "a5b3ba908ba68f3e14e42762a7b940fde65ed7da" 364 "reference": "d63be7eb9a95d46720f7d6badac4e5bc2bcff2e3"
365 }, 365 },
366 "dist": { 366 "dist": {
367 "type": "zip", 367 "type": "zip",
368 "url": "https://api.github.com/repos/doctrine/DoctrineBundle/zipball/a5b3ba908ba68f3e14e42762a7b940fde65ed7da", 368 "url": "https://api.github.com/repos/doctrine/DoctrineBundle/zipball/d63be7eb9a95d46720f7d6badac4e5bc2bcff2e3",
369 "reference": "a5b3ba908ba68f3e14e42762a7b940fde65ed7da", 369 "reference": "d63be7eb9a95d46720f7d6badac4e5bc2bcff2e3",
370 "shasum": "" 370 "shasum": ""
371 }, 371 },
372 "require": { 372 "require": {
@@ -431,7 +431,7 @@
431 "orm", 431 "orm",
432 "persistence" 432 "persistence"
433 ], 433 ],
434 "time": "2015-11-04 21:33:02" 434 "time": "2015-08-31 14:47:06"
435 }, 435 },
436 { 436 {
437 "name": "doctrine/doctrine-cache-bundle", 437 "name": "doctrine/doctrine-cache-bundle",
@@ -2771,20 +2771,20 @@
2771 }, 2771 },
2772 { 2772 {
2773 "name": "sensiolabs/security-checker", 2773 "name": "sensiolabs/security-checker",
2774 "version": "v3.0.1", 2774 "version": "v3.0.2",
2775 "source": { 2775 "source": {
2776 "type": "git", 2776 "type": "git",
2777 "url": "https://github.com/sensiolabs/security-checker.git", 2777 "url": "https://github.com/sensiolabs/security-checker.git",
2778 "reference": "7735fd97ff7303d9df776b8dbc970f949399abc9" 2778 "reference": "21696b0daa731064c23cfb694c60a2584a7b6e93"
2779 }, 2779 },
2780 "dist": { 2780 "dist": {
2781 "type": "zip", 2781 "type": "zip",
2782 "url": "https://api.github.com/repos/sensiolabs/security-checker/zipball/7735fd97ff7303d9df776b8dbc970f949399abc9", 2782 "url": "https://api.github.com/repos/sensiolabs/security-checker/zipball/21696b0daa731064c23cfb694c60a2584a7b6e93",
2783 "reference": "7735fd97ff7303d9df776b8dbc970f949399abc9", 2783 "reference": "21696b0daa731064c23cfb694c60a2584a7b6e93",
2784 "shasum": "" 2784 "shasum": ""
2785 }, 2785 },
2786 "require": { 2786 "require": {
2787 "symfony/console": "~2.0" 2787 "symfony/console": "~2.0|~3.0"
2788 }, 2788 },
2789 "bin": [ 2789 "bin": [
2790 "security-checker" 2790 "security-checker"
@@ -2811,7 +2811,7 @@
2811 } 2811 }
2812 ], 2812 ],
2813 "description": "A security checker for your composer.lock", 2813 "description": "A security checker for your composer.lock",
2814 "time": "2015-08-11 12:11:25" 2814 "time": "2015-11-07 08:07:40"
2815 }, 2815 },
2816 { 2816 {
2817 "name": "simplepie/simplepie", 2817 "name": "simplepie/simplepie",
diff --git a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php
index bc7ef489..bdd36e0c 100644
--- a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php
+++ b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php
@@ -2,9 +2,9 @@
2 2
3namespace Wallabag\ApiBundle\Tests\Controller; 3namespace Wallabag\ApiBundle\Tests\Controller;
4 4
5use Wallabag\ApiBundle\Tests\AbstractControllerTest; 5use Wallabag\ApiBundle\Tests\WallabagApiTestCase;
6 6
7class WallabagRestControllerTest extends AbstractControllerTest 7class WallabagRestControllerTest extends WallabagApiTestCase
8{ 8{
9 protected static $salt; 9 protected static $salt;
10 10
diff --git a/src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php b/src/Wallabag/ApiBundle/Tests/WallabagApiTestCase.php
index 09cde0f6..8a57fea2 100644
--- a/src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php
+++ b/src/Wallabag/ApiBundle/Tests/WallabagApiTestCase.php
@@ -5,7 +5,7 @@ namespace Wallabag\ApiBundle\Tests;
5use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; 5use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6use Symfony\Component\BrowserKit\Cookie; 6use Symfony\Component\BrowserKit\Cookie;
7 7
8abstract class AbstractControllerTest extends WebTestCase 8abstract class WallabagApiTestCase extends WebTestCase
9{ 9{
10 /** 10 /**
11 * @var Client 11 * @var Client
diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php
index 808baaf6..85c4ee90 100644
--- a/src/Wallabag/CoreBundle/Command/InstallCommand.php
+++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php
@@ -96,10 +96,10 @@ class InstallCommand extends ContainerAwareCommand
96 96
97 if (!$fulfilled) { 97 if (!$fulfilled) {
98 throw new \RuntimeException('Some system requirements are not fulfilled. Please check output messages and fix them.'); 98 throw new \RuntimeException('Some system requirements are not fulfilled. Please check output messages and fix them.');
99 } else {
100 $this->defaultOutput->writeln('<info>Success! Your system can run Wallabag properly.</info>');
101 } 99 }
102 100
101 $this->defaultOutput->writeln('<info>Success! Your system can run Wallabag properly.</info>');
102
103 $this->defaultOutput->writeln(''); 103 $this->defaultOutput->writeln('');
104 104
105 return $this; 105 return $this;
@@ -111,14 +111,17 @@ class InstallCommand extends ContainerAwareCommand
111 111
112 // user want to reset everything? Don't care about what is already here 112 // user want to reset everything? Don't care about what is already here
113 if (true === $this->defaultInput->getOption('reset')) { 113 if (true === $this->defaultInput->getOption('reset')) {
114 $this->defaultOutput->writeln('Droping database, creating database and schema'); 114 $this->defaultOutput->writeln('Droping database, creating database and schema, clearing the cache');
115 115
116 $this 116 $this
117 ->runCommand('doctrine:database:drop', array('--force' => true)) 117 ->runCommand('doctrine:database:drop', array('--force' => true))
118 ->runCommand('doctrine:database:create') 118 ->runCommand('doctrine:database:create')
119 ->runCommand('doctrine:schema:create') 119 ->runCommand('doctrine:schema:create')
120 ->runCommand('cache:clear')
120 ; 121 ;
121 122
123 $this->defaultOutput->writeln('');
124
122 return $this; 125 return $this;
123 } 126 }
124 127
@@ -131,6 +134,8 @@ class InstallCommand extends ContainerAwareCommand
131 ->runCommand('cache:clear') 134 ->runCommand('cache:clear')
132 ; 135 ;
133 136
137 $this->defaultOutput->writeln('');
138
134 return $this; 139 return $this;
135 } 140 }
136 141
@@ -283,10 +288,16 @@ class InstallCommand extends ContainerAwareCommand
283 try { 288 try {
284 $schemaManager = $connection->getSchemaManager(); 289 $schemaManager = $connection->getSchemaManager();
285 } catch (\Exception $exception) { 290 } catch (\Exception $exception) {
291 // mysql & sqlite
286 if (false !== strpos($exception->getMessage(), sprintf("Unknown database '%s'", $databaseName))) { 292 if (false !== strpos($exception->getMessage(), sprintf("Unknown database '%s'", $databaseName))) {
287 return false; 293 return false;
288 } 294 }
289 295
296 // pgsql
297 if (false !== strpos($exception->getMessage(), sprintf('database "%s" does not exist', $databaseName))) {
298 return false;
299 }
300
290 throw $exception; 301 throw $exception;
291 } 302 }
292 303
diff --git a/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php b/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php
deleted file mode 100644
index 509348db..00000000
--- a/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php
+++ /dev/null
@@ -1,83 +0,0 @@
1<?php
2
3namespace Wallabag\CoreBundle\Doctrine\Mapping;
4
5use Doctrine\ORM\Mapping\NamingStrategy;
6
7/**
8 * Puts a prefix to each table.
9 *
10 * Solution from :
11 * - http://stackoverflow.com/a/23860613/569101
12 * - http://doctrine-orm.readthedocs.org/en/latest/reference/namingstrategy.html
13 */
14class PrefixedNamingStrategy implements NamingStrategy
15{
16 protected $prefix = '';
17
18 public function __construct($prefix)
19 {
20 $this->prefix = (string) $prefix;
21 }
22
23 /**
24 * {@inheritdoc}
25 */
26 public function classToTableName($className)
27 {
28 return strtolower($this->prefix.substr($className, strrpos($className, '\\') + 1));
29 }
30
31 /**
32 * {@inheritdoc}
33 */
34 public function propertyToColumnName($propertyName, $className = null)
35 {
36 return $propertyName;
37 }
38
39 /**
40 * {@inheritdoc}
41 */
42 public function referenceColumnName()
43 {
44 return 'id';
45 }
46
47 /**
48 * {@inheritdoc}
49 */
50 public function joinColumnName($propertyName)
51 {
52 return $propertyName.'_'.$this->referenceColumnName();
53 }
54
55 /**
56 * {@inheritdoc}
57 */
58 public function joinTableName($sourceEntity, $targetEntity, $propertyName = null)
59 {
60 // for join table we don't want to have both table concatenated AND prefixed
61 // we just want the whole table to prefixed once
62 // ie: not "wallabag_entry_wallabag_tag" but "wallabag_entry_tag"
63 $target = substr($targetEntity, strrpos($targetEntity, '\\') + 1);
64
65 return strtolower($this->classToTableName($sourceEntity).'_'.$target);
66 }
67
68 /**
69 * {@inheritdoc}
70 */
71 public function joinKeyColumnName($entityName, $referencedColumnName = null)
72 {
73 return strtolower($this->classToTableName($entityName).'_'.($referencedColumnName ?: $this->referenceColumnName()));
74 }
75
76 /**
77 * {@inheritdoc}
78 */
79 public function embeddedFieldToColumnName($propertyName, $embeddedColumnName, $className = null, $embeddedClassName = null)
80 {
81 return $propertyName.'_'.$embeddedColumnName;
82 }
83}
diff --git a/src/Wallabag/CoreBundle/Entity/Config.php b/src/Wallabag/CoreBundle/Entity/Config.php
index f4edcfa9..b2a1915a 100644
--- a/src/Wallabag/CoreBundle/Entity/Config.php
+++ b/src/Wallabag/CoreBundle/Entity/Config.php
@@ -9,7 +9,7 @@ use Symfony\Component\Validator\Constraints as Assert;
9 * Config. 9 * Config.
10 * 10 *
11 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\ConfigRepository") 11 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\ConfigRepository")
12 * @ORM\Table 12 * @ORM\Table(name="`config`")
13 * @ORM\Entity 13 * @ORM\Entity
14 */ 14 */
15class Config 15class Config
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php
index 4fd74001..9e5446a6 100644
--- a/src/Wallabag/CoreBundle/Entity/Entry.php
+++ b/src/Wallabag/CoreBundle/Entity/Entry.php
@@ -14,7 +14,7 @@ use Wallabag\UserBundle\Entity\User;
14 * 14 *
15 * @XmlRoot("entry") 15 * @XmlRoot("entry")
16 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository") 16 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository")
17 * @ORM\Table 17 * @ORM\Table(name="`entry`")
18 * @ORM\HasLifecycleCallbacks() 18 * @ORM\HasLifecycleCallbacks()
19 * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())") 19 * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
20 */ 20 */
diff --git a/src/Wallabag/CoreBundle/Entity/Tag.php b/src/Wallabag/CoreBundle/Entity/Tag.php
index 5b571823..7cc452fd 100644
--- a/src/Wallabag/CoreBundle/Entity/Tag.php
+++ b/src/Wallabag/CoreBundle/Entity/Tag.php
@@ -12,7 +12,7 @@ use Doctrine\Common\Collections\ArrayCollection;
12 * Tag. 12 * Tag.
13 * 13 *
14 * @XmlRoot("tag") 14 * @XmlRoot("tag")
15 * @ORM\Table 15 * @ORM\Table(name="`tag`")
16 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TagRepository") 16 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TagRepository")
17 * @ExclusionPolicy("all") 17 * @ExclusionPolicy("all")
18 */ 18 */
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml
index debbf39e..65c2c8d8 100644
--- a/src/Wallabag/CoreBundle/Resources/config/services.yml
+++ b/src/Wallabag/CoreBundle/Resources/config/services.yml
@@ -33,10 +33,12 @@ services:
33 arguments: 33 arguments:
34 - @doctrine 34 - @doctrine
35 35
36 wallabag_core.doctrine.prefixed_naming_strategy: 36 wallabag_core.table_prefix_subscriber:
37 class: Wallabag\CoreBundle\Doctrine\Mapping\PrefixedNamingStrategy 37 class: Wallabag\CoreBundle\Subscriber\TablePrefixSubscriber
38 arguments: 38 arguments:
39 - %database_table_prefix% 39 - %database_table_prefix%
40 tags:
41 - { name: doctrine.event_subscriber }
40 42
41 wallabag_core.graby: 43 wallabag_core.graby:
42 class: Graby\Graby 44 class: Graby\Graby
diff --git a/src/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriber.php b/src/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriber.php
new file mode 100644
index 00000000..0019eead
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriber.php
@@ -0,0 +1,51 @@
1<?php
2
3namespace Wallabag\CoreBundle\Subscriber;
4
5use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
6use Doctrine\Common\EventSubscriber;
7use Doctrine\ORM\Mapping\ClassMetadataInfo;
8
9/**
10 * Puts a prefix to each table.
11 * This way were used instead of using the built-in strategy from Doctrine, using `naming_strategy`
12 * Because it conflicts with the DefaultQuoteStrategy (that espace table name, like user for Postgres)
13 * see #1498 for more detail.
14 *
15 * Solution from :
16 * - http://stackoverflow.com/a/23860613/569101
17 * - http://doctrine-orm.readthedocs.org/en/latest/reference/namingstrategy.html
18 */
19class TablePrefixSubscriber implements EventSubscriber
20{
21 protected $prefix = '';
22
23 public function __construct($prefix)
24 {
25 $this->prefix = (string) $prefix;
26 }
27
28 public function getSubscribedEvents()
29 {
30 return array('loadClassMetadata');
31 }
32
33 public function loadClassMetadata(LoadClassMetadataEventArgs $args)
34 {
35 $classMetadata = $args->getClassMetadata();
36
37 // if we are in an inheritance hierarchy, only apply this once
38 if ($classMetadata->isInheritanceTypeSingleTable() && !$classMetadata->isRootEntity()) {
39 return;
40 }
41
42 $classMetadata->setTableName($this->prefix.$classMetadata->getTableName());
43
44 foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) {
45 if ($mapping['type'] === ClassMetadataInfo::MANY_TO_MANY && isset($classMetadata->associationMappings[$fieldName]['joinTable']['name'])) {
46 $mappedTableName = $classMetadata->associationMappings[$fieldName]['joinTable']['name'];
47 $classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $this->prefix.$mappedTableName;
48 }
49 }
50 }
51}
diff --git a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php
index e98dd202..c9346040 100644
--- a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php
@@ -28,9 +28,7 @@ class InstallCommandTest extends WallabagCoreTestCase
28 28
29 public function testRunInstallCommand() 29 public function testRunInstallCommand()
30 { 30 {
31 $this->container = static::$kernel->getContainer(); 31 $application = new Application($this->getClient()->getKernel());
32
33 $application = new Application(static::$kernel);
34 $application->add(new InstallCommandMock()); 32 $application->add(new InstallCommandMock());
35 33
36 $command = $application->find('wallabag:install'); 34 $command = $application->find('wallabag:install');
@@ -59,9 +57,7 @@ class InstallCommandTest extends WallabagCoreTestCase
59 57
60 public function testRunInstallCommandWithReset() 58 public function testRunInstallCommandWithReset()
61 { 59 {
62 $this->container = static::$kernel->getContainer(); 60 $application = new Application($this->getClient()->getKernel());
63
64 $application = new Application(static::$kernel);
65 $application->add(new InstallCommandMock()); 61 $application->add(new InstallCommandMock());
66 62
67 $command = $application->find('wallabag:install'); 63 $command = $application->find('wallabag:install');
@@ -89,28 +85,39 @@ class InstallCommandTest extends WallabagCoreTestCase
89 $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay()); 85 $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay());
90 86
91 // we force to reset everything 87 // we force to reset everything
92 $this->assertContains('Droping database, creating database and schema', $tester->getDisplay()); 88 $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay());
93 } 89 }
94 90
95 /**
96 * @group command-doctrine
97 */
98 public function testRunInstallCommandWithDatabaseRemoved() 91 public function testRunInstallCommandWithDatabaseRemoved()
99 { 92 {
100 $this->container = static::$kernel->getContainer(); 93 if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOPgSql\Driver) {
101 94 /*
102 $application = new Application(static::$kernel); 95 * LOG: statement: CREATE DATABASE "wallabag"
103 $application->add(new InstallCommand()); 96 * ERROR: source database "template1" is being accessed by other users
97 * DETAIL: There is 1 other session using the database.
98 * STATEMENT: CREATE DATABASE "wallabag"
99 * FATAL: database "wallabag" does not exist
100 *
101 * http://stackoverflow.com/a/14374832/569101
102 */
103 $this->markTestSkipped('PostgreSQL spotted: can find a good way to drop current database, skipping.');
104 }
105
106 $application = new Application($this->getClient()->getKernel());
104 $application->add(new DropDatabaseDoctrineCommand()); 107 $application->add(new DropDatabaseDoctrineCommand());
105 108
106 // drop database first, so the install command won't ask to reset things 109 // drop database first, so the install command won't ask to reset things
107 $command = new DropDatabaseDoctrineCommand(); 110 $command = $application->find('doctrine:database:drop');
108 $command->setApplication($application);
109 $command->run(new ArrayInput(array( 111 $command->run(new ArrayInput(array(
110 'command' => 'doctrine:database:drop', 112 'command' => 'doctrine:database:drop',
111 '--force' => true, 113 '--force' => true,
112 )), new NullOutput()); 114 )), new NullOutput());
113 115
116 // start a new application to avoid lagging connexion to pgsql
117 $client = static::createClient();
118 $application = new Application($client->getKernel());
119 $application->add(new InstallCommand());
120
114 $command = $application->find('wallabag:install'); 121 $command = $application->find('wallabag:install');
115 122
116 // We mock the QuestionHelper 123 // We mock the QuestionHelper
@@ -140,9 +147,7 @@ class InstallCommandTest extends WallabagCoreTestCase
140 147
141 public function testRunInstallCommandChooseResetSchema() 148 public function testRunInstallCommandChooseResetSchema()
142 { 149 {
143 $this->container = static::$kernel->getContainer(); 150 $application = new Application($this->getClient()->getKernel());
144
145 $application = new Application(static::$kernel);
146 $application->add(new InstallCommandMock()); 151 $application->add(new InstallCommandMock());
147 152
148 $command = $application->find('wallabag:install'); 153 $command = $application->find('wallabag:install');
@@ -176,14 +181,16 @@ class InstallCommandTest extends WallabagCoreTestCase
176 $this->assertContains('Droping schema and creating schema', $tester->getDisplay()); 181 $this->assertContains('Droping schema and creating schema', $tester->getDisplay());
177 } 182 }
178 183
179 /**
180 * @group command-doctrine
181 */
182 public function testRunInstallCommandChooseNothing() 184 public function testRunInstallCommandChooseNothing()
183 { 185 {
184 $this->container = static::$kernel->getContainer(); 186 if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOPgSql\Driver) {
185 187 /*
186 $application = new Application(static::$kernel); 188 * @see testRunInstallCommandWithDatabaseRemoved
189 */
190 $this->markTestSkipped('PostgreSQL spotted: can find a good way to drop current database, skipping.');
191 }
192
193 $application = new Application($this->getClient()->getKernel());
187 $application->add(new InstallCommand()); 194 $application->add(new InstallCommand());
188 $application->add(new DropDatabaseDoctrineCommand()); 195 $application->add(new DropDatabaseDoctrineCommand());
189 $application->add(new CreateDatabaseDoctrineCommand()); 196 $application->add(new CreateDatabaseDoctrineCommand());
@@ -196,7 +203,7 @@ class InstallCommandTest extends WallabagCoreTestCase
196 '--force' => true, 203 '--force' => true,
197 )), new NullOutput()); 204 )), new NullOutput());
198 205
199 $this->container->get('doctrine')->getManager()->getConnection()->close(); 206 $this->getClient()->getContainer()->get('doctrine')->getConnection()->close();
200 207
201 $command = new CreateDatabaseDoctrineCommand(); 208 $command = new CreateDatabaseDoctrineCommand();
202 $command->setApplication($application); 209 $command->setApplication($application);
@@ -237,9 +244,7 @@ class InstallCommandTest extends WallabagCoreTestCase
237 244
238 public function testRunInstallCommandNoInteraction() 245 public function testRunInstallCommandNoInteraction()
239 { 246 {
240 $this->container = static::$kernel->getContainer(); 247 $application = new Application($this->getClient()->getKernel());
241
242 $application = new Application(static::$kernel);
243 $application->add(new InstallCommandMock()); 248 $application->add(new InstallCommandMock());
244 249
245 $command = $application->find('wallabag:install'); 250 $command = $application->find('wallabag:install');
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
index 5ac39d12..56b4c9e4 100644
--- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
@@ -74,6 +74,9 @@ class EntryControllerTest extends WallabagCoreTestCase
74 $this->assertEquals('This value should not be blank.', $alert[0]); 74 $this->assertEquals('This value should not be blank.', $alert[0]);
75 } 75 }
76 76
77 /**
78 * This test will require an internet connection.
79 */
77 public function testPostNewOk() 80 public function testPostNewOk()
78 { 81 {
79 $this->logInAs('admin'); 82 $this->logInAs('admin');
@@ -119,6 +122,9 @@ class EntryControllerTest extends WallabagCoreTestCase
119 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 122 $this->assertEquals(200, $client->getResponse()->getStatusCode());
120 } 123 }
121 124
125 /**
126 * @depends testPostNewOk
127 */
122 public function testView() 128 public function testView()
123 { 129 {
124 $this->logInAs('admin'); 130 $this->logInAs('admin');
diff --git a/src/Wallabag/CoreBundle/Tests/EventListener/LocaleListenerTest.php b/src/Wallabag/CoreBundle/Tests/EventListener/LocaleListenerTest.php
index 356a411e..d89bee04 100644
--- a/src/Wallabag/CoreBundle/Tests/EventListener/LocaleListenerTest.php
+++ b/src/Wallabag/CoreBundle/Tests/EventListener/LocaleListenerTest.php
@@ -2,7 +2,6 @@
2 2
3namespace Wallabag\CoreBundle\Tests\EventListener; 3namespace Wallabag\CoreBundle\Tests\EventListener;
4 4
5use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
6use Symfony\Component\EventDispatcher\EventDispatcher; 5use Symfony\Component\EventDispatcher\EventDispatcher;
7use Symfony\Component\HttpFoundation\Request; 6use Symfony\Component\HttpFoundation\Request;
8use Symfony\Component\HttpKernel\KernelEvents; 7use Symfony\Component\HttpKernel\KernelEvents;
@@ -12,7 +11,7 @@ use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
12use Symfony\Component\HttpFoundation\Session\Session; 11use Symfony\Component\HttpFoundation\Session\Session;
13use Wallabag\CoreBundle\EventListener\LocaleListener; 12use Wallabag\CoreBundle\EventListener\LocaleListener;
14 13
15class LocaleListenerTest extends KernelTestCase 14class LocaleListenerTest extends \PHPUnit_Framework_TestCase
16{ 15{
17 private function getEvent(Request $request) 16 private function getEvent(Request $request)
18 { 17 {
diff --git a/src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php b/src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php
index df94fad2..31283399 100644
--- a/src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php
+++ b/src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php
@@ -2,7 +2,6 @@
2 2
3namespace Wallabag\CoreBundle\Tests\EventListener; 3namespace Wallabag\CoreBundle\Tests\EventListener;
4 4
5use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
6use Symfony\Component\EventDispatcher\EventDispatcher; 5use Symfony\Component\EventDispatcher\EventDispatcher;
7use Symfony\Component\HttpFoundation\Request; 6use Symfony\Component\HttpFoundation\Request;
8use Symfony\Component\HttpFoundation\Response; 7use Symfony\Component\HttpFoundation\Response;
@@ -12,7 +11,7 @@ use Wallabag\CoreBundle\EventListener\RegistrationConfirmedListener;
12use Wallabag\CoreBundle\Entity\Config; 11use Wallabag\CoreBundle\Entity\Config;
13use Wallabag\UserBundle\Entity\User; 12use Wallabag\UserBundle\Entity\User;
14 13
15class RegistrationConfirmedListenerTest extends KernelTestCase 14class RegistrationConfirmedListenerTest extends \PHPUnit_Framework_TestCase
16{ 15{
17 private $em; 16 private $em;
18 private $listener; 17 private $listener;
diff --git a/src/Wallabag/CoreBundle/Tests/EventListener/UserLocaleListenerTest.php b/src/Wallabag/CoreBundle/Tests/EventListener/UserLocaleListenerTest.php
index e8a65fbf..80ddb457 100644
--- a/src/Wallabag/CoreBundle/Tests/EventListener/UserLocaleListenerTest.php
+++ b/src/Wallabag/CoreBundle/Tests/EventListener/UserLocaleListenerTest.php
@@ -2,7 +2,6 @@
2 2
3namespace Wallabag\CoreBundle\Tests\EventListener; 3namespace Wallabag\CoreBundle\Tests\EventListener;
4 4
5use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
6use Symfony\Component\HttpFoundation\Request; 5use Symfony\Component\HttpFoundation\Request;
7use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; 6use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
8use Symfony\Component\HttpFoundation\Session\Session; 7use Symfony\Component\HttpFoundation\Session\Session;
@@ -12,7 +11,7 @@ use Wallabag\CoreBundle\EventListener\UserLocaleListener;
12use Wallabag\CoreBundle\Entity\Config; 11use Wallabag\CoreBundle\Entity\Config;
13use Wallabag\UserBundle\Entity\User; 12use Wallabag\UserBundle\Entity\User;
14 13
15class UserLocaleListenerTest extends KernelTestCase 14class UserLocaleListenerTest extends \PHPUnit_Framework_TestCase
16{ 15{
17 public function testWithLanguage() 16 public function testWithLanguage()
18 { 17 {
diff --git a/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php b/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php
index 1d0d4062..4bce4708 100644
--- a/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php
@@ -2,12 +2,11 @@
2 2
3namespace Wallabag\CoreBundle\Tests\Helper; 3namespace Wallabag\CoreBundle\Tests\Helper;
4 4
5use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
6use Wallabag\CoreBundle\Entity\Entry; 5use Wallabag\CoreBundle\Entity\Entry;
7use Wallabag\UserBundle\Entity\User; 6use Wallabag\UserBundle\Entity\User;
8use Wallabag\CoreBundle\Helper\ContentProxy; 7use Wallabag\CoreBundle\Helper\ContentProxy;
9 8
10class ContentProxyTest extends KernelTestCase 9class ContentProxyTest extends \PHPUnit_Framework_TestCase
11{ 10{
12 public function testWithEmptyContent() 11 public function testWithEmptyContent()
13 { 12 {
diff --git a/src/Wallabag/CoreBundle/Tests/ParamConverter/UsernameRssTokenConverterTest.php b/src/Wallabag/CoreBundle/Tests/ParamConverter/UsernameRssTokenConverterTest.php
index e28dc4ba..1c9a4ad7 100644
--- a/src/Wallabag/CoreBundle/Tests/ParamConverter/UsernameRssTokenConverterTest.php
+++ b/src/Wallabag/CoreBundle/Tests/ParamConverter/UsernameRssTokenConverterTest.php
@@ -2,13 +2,12 @@
2 2
3namespace Wallabag\CoreBundle\Tests\Command; 3namespace Wallabag\CoreBundle\Tests\Command;
4 4
5use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
6use Wallabag\CoreBundle\ParamConverter\UsernameRssTokenConverter; 5use Wallabag\CoreBundle\ParamConverter\UsernameRssTokenConverter;
7use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; 6use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
8use Symfony\Component\HttpFoundation\Request; 7use Symfony\Component\HttpFoundation\Request;
9use Wallabag\UserBundle\Entity\User; 8use Wallabag\UserBundle\Entity\User;
10 9
11class UsernameRssTokenConverterTest extends KernelTestCase 10class UsernameRssTokenConverterTest extends \PHPUnit_Framework_TestCase
12{ 11{
13 public function testSupportsWithNoRegistry() 12 public function testSupportsWithNoRegistry()
14 { 13 {
diff --git a/src/Wallabag/CoreBundle/Tests/Subscriber/TablePrefixSubscriberTest.php b/src/Wallabag/CoreBundle/Tests/Subscriber/TablePrefixSubscriberTest.php
new file mode 100644
index 00000000..a26ff436
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Tests/Subscriber/TablePrefixSubscriberTest.php
@@ -0,0 +1,114 @@
1<?php
2
3namespace Wallabag\CoreBundle\Tests\Subscriber;
4
5use Doctrine\ORM\Mapping\ClassMetadata;
6use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
7use Doctrine\Common\EventManager;
8use Wallabag\CoreBundle\Subscriber\TablePrefixSubscriber;
9
10class TablePrefixSubscriberTest extends \PHPUnit_Framework_TestCase
11{
12 public function dataForPrefix()
13 {
14 return array(
15 array('wallabag_', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'wallabag_user', '"wallabag_user"', new \Doctrine\DBAL\Platforms\PostgreSqlPlatform()),
16 array('wallabag_', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'wallabag_user', '`wallabag_user`', new \Doctrine\DBAL\Platforms\MySqlPlatform()),
17 array('wallabag_', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'wallabag_user', '"wallabag_user"', new \Doctrine\DBAL\Platforms\SqlitePlatform()),
18
19 array('wallabag_', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'wallabag_user', 'wallabag_user', new \Doctrine\DBAL\Platforms\PostgreSqlPlatform()),
20 array('wallabag_', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'wallabag_user', 'wallabag_user', new \Doctrine\DBAL\Platforms\MySqlPlatform()),
21 array('wallabag_', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'wallabag_user', 'wallabag_user', new \Doctrine\DBAL\Platforms\SqlitePlatform()),
22
23 array('', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'user', '"user"', new \Doctrine\DBAL\Platforms\PostgreSqlPlatform()),
24 array('', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'user', '`user`', new \Doctrine\DBAL\Platforms\MySqlPlatform()),
25 array('', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'user', '"user"', new \Doctrine\DBAL\Platforms\SqlitePlatform()),
26
27 array('', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'user', 'user', new \Doctrine\DBAL\Platforms\PostgreSqlPlatform()),
28 array('', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'user', 'user', new \Doctrine\DBAL\Platforms\MySqlPlatform()),
29 array('', '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(array('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(array('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(array('name' => 'entry'));
92 $metaClass->mapManyToMany(array(
93 'fieldName' => 'tags',
94 'joinTable' => array('name' => null, 'schema' => null),
95 'targetEntity' => 'Tag',
96 'mappedBy' => null,
97 'inversedBy' => 'entries',
98 'cascade' => array('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}
diff --git a/src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php b/src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php
index e5096528..ce3cabe8 100644
--- a/src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php
+++ b/src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php
@@ -15,6 +15,8 @@ abstract class WallabagCoreTestCase extends WebTestCase
15 15
16 public function setUp() 16 public function setUp()
17 { 17 {
18 parent::setUp();
19
18 $this->client = static::createClient(); 20 $this->client = static::createClient();
19 } 21 }
20 22
diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php
index d2efd200..e3b9a519 100644
--- a/src/Wallabag/UserBundle/Entity/User.php
+++ b/src/Wallabag/UserBundle/Entity/User.php
@@ -19,7 +19,7 @@ use Wallabag\CoreBundle\Entity\Tag;
19 * User. 19 * User.
20 * 20 *
21 * @ORM\Entity(repositoryClass="Wallabag\UserBundle\Repository\UserRepository") 21 * @ORM\Entity(repositoryClass="Wallabag\UserBundle\Repository\UserRepository")
22 * @ORM\Table 22 * @ORM\Table(name="`user`")
23 * @ORM\HasLifecycleCallbacks() 23 * @ORM\HasLifecycleCallbacks()
24 * @ExclusionPolicy("all") 24 * @ExclusionPolicy("all")
25 * 25 *