From 54a2241e136ccf90c659b5699af4489b6e4d2da1 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 24 Oct 2015 15:27:34 +0200 Subject: [PATCH 1/8] Fix database already exist detection This is not the same message exception from MySQL & SQLite with Postgres. --- src/Wallabag/CoreBundle/Command/InstallCommand.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index 808baaf68..865a73e1d 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php @@ -283,10 +283,16 @@ class InstallCommand extends ContainerAwareCommand try { $schemaManager = $connection->getSchemaManager(); } catch (\Exception $exception) { + // mysql & sqlite if (false !== strpos($exception->getMessage(), sprintf("Unknown database '%s'", $databaseName))) { return false; } + // pgsql + if (false !== strpos($exception->getMessage(), sprintf('database "%s" does not exist', $databaseName))) { + return false; + } + throw $exception; } From bd0f3d32c9ccb8f7a1409edb960b909a5e6a096d Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 24 Oct 2015 15:28:02 +0200 Subject: [PATCH 2/8] Quoted entity to avoid reserved keyword Should fix #1498 --- app/config/config.yml | 1 - .../Mapping/PrefixedNamingStrategy.php | 83 ------------------- src/Wallabag/CoreBundle/Entity/Config.php | 2 +- src/Wallabag/CoreBundle/Entity/Entry.php | 2 +- src/Wallabag/CoreBundle/Entity/Tag.php | 2 +- .../CoreBundle/Resources/config/services.yml | 6 +- .../Subscriber/TablePrefixSubscriber.php | 47 +++++++++++ src/Wallabag/UserBundle/Entity/User.php | 2 +- 8 files changed, 55 insertions(+), 90 deletions(-) delete mode 100644 src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php create mode 100644 src/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriber.php diff --git a/app/config/config.yml b/app/config/config.yml index 0655fed58..285fbd7cf 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -88,7 +88,6 @@ doctrine: auto_generate_proxy_classes: "%kernel.debug%" entity_managers: default: - naming_strategy: wallabag_core.doctrine.prefixed_naming_strategy auto_mapping: true # Swiftmailer Configuration diff --git a/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php b/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php deleted file mode 100644 index 509348db5..000000000 --- a/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php +++ /dev/null @@ -1,83 +0,0 @@ -prefix = (string) $prefix; - } - - /** - * {@inheritdoc} - */ - public function classToTableName($className) - { - return strtolower($this->prefix.substr($className, strrpos($className, '\\') + 1)); - } - - /** - * {@inheritdoc} - */ - public function propertyToColumnName($propertyName, $className = null) - { - return $propertyName; - } - - /** - * {@inheritdoc} - */ - public function referenceColumnName() - { - return 'id'; - } - - /** - * {@inheritdoc} - */ - public function joinColumnName($propertyName) - { - return $propertyName.'_'.$this->referenceColumnName(); - } - - /** - * {@inheritdoc} - */ - public function joinTableName($sourceEntity, $targetEntity, $propertyName = null) - { - // for join table we don't want to have both table concatenated AND prefixed - // we just want the whole table to prefixed once - // ie: not "wallabag_entry_wallabag_tag" but "wallabag_entry_tag" - $target = substr($targetEntity, strrpos($targetEntity, '\\') + 1); - - return strtolower($this->classToTableName($sourceEntity).'_'.$target); - } - - /** - * {@inheritdoc} - */ - public function joinKeyColumnName($entityName, $referencedColumnName = null) - { - return strtolower($this->classToTableName($entityName).'_'.($referencedColumnName ?: $this->referenceColumnName())); - } - - /** - * {@inheritdoc} - */ - public function embeddedFieldToColumnName($propertyName, $embeddedColumnName, $className = null, $embeddedClassName = null) - { - return $propertyName.'_'.$embeddedColumnName; - } -} diff --git a/src/Wallabag/CoreBundle/Entity/Config.php b/src/Wallabag/CoreBundle/Entity/Config.php index f4edcfa9f..b2a1915a4 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; * Config. * * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\ConfigRepository") - * @ORM\Table + * @ORM\Table(name="`config`") * @ORM\Entity */ class Config diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 4fd74001b..9e5446a64 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -14,7 +14,7 @@ use Wallabag\UserBundle\Entity\User; * * @XmlRoot("entry") * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository") - * @ORM\Table + * @ORM\Table(name="`entry`") * @ORM\HasLifecycleCallbacks() * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())") */ diff --git a/src/Wallabag/CoreBundle/Entity/Tag.php b/src/Wallabag/CoreBundle/Entity/Tag.php index 5b571823f..7cc452fd7 100644 --- a/src/Wallabag/CoreBundle/Entity/Tag.php +++ b/src/Wallabag/CoreBundle/Entity/Tag.php @@ -12,7 +12,7 @@ use Doctrine\Common\Collections\ArrayCollection; * Tag. * * @XmlRoot("tag") - * @ORM\Table + * @ORM\Table(name="`tag`") * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TagRepository") * @ExclusionPolicy("all") */ diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index debbf39e0..65c2c8d85 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml @@ -33,10 +33,12 @@ services: arguments: - @doctrine - wallabag_core.doctrine.prefixed_naming_strategy: - class: Wallabag\CoreBundle\Doctrine\Mapping\PrefixedNamingStrategy + wallabag_core.table_prefix_subscriber: + class: Wallabag\CoreBundle\Subscriber\TablePrefixSubscriber arguments: - %database_table_prefix% + tags: + - { name: doctrine.event_subscriber } wallabag_core.graby: class: Graby\Graby diff --git a/src/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriber.php b/src/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriber.php new file mode 100644 index 000000000..8ec85e643 --- /dev/null +++ b/src/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriber.php @@ -0,0 +1,47 @@ +prefix = (string) $prefix; + } + + public function getSubscribedEvents() + { + return array('loadClassMetadata'); + } + + public function loadClassMetadata(LoadClassMetadataEventArgs $args) + { + $classMetadata = $args->getClassMetadata(); + // if we are in an inheritance hierarchy, only apply this once + if ($classMetadata->isInheritanceTypeSingleTable() && !$classMetadata->isRootEntity()) { + return; + } + + $classMetadata->setTableName($this->prefix . $classMetadata->getTableName()); + + foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) { + if ($mapping['type'] === ClassMetadataInfo::MANY_TO_MANY && isset($classMetadata->associationMappings[$fieldName]['joinTable']['name'])) { + $mappedTableName = $classMetadata->associationMappings[$fieldName]['joinTable']['name']; + $classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $this->prefix . $mappedTableName; + } + } + } +} diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php index d2efd2008..e3b9a519c 100644 --- a/src/Wallabag/UserBundle/Entity/User.php +++ b/src/Wallabag/UserBundle/Entity/User.php @@ -19,7 +19,7 @@ use Wallabag\CoreBundle\Entity\Tag; * User. * * @ORM\Entity(repositoryClass="Wallabag\UserBundle\Repository\UserRepository") - * @ORM\Table + * @ORM\Table(name="`user`") * @ORM\HasLifecycleCallbacks() * @ExclusionPolicy("all") * From 735068d1814a4b7a688e1d19cd17b13e8c5da3eb Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 25 Oct 2015 15:55:19 +0100 Subject: [PATCH 3/8] Add tests on TablePrefixSubscriber --- .../Subscriber/TablePrefixSubscriber.php | 8 +- .../Subscriber/TablePrefixSubscriberTest.php | 115 ++++++++++++++++++ 2 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 src/Wallabag/CoreBundle/Tests/Subscriber/TablePrefixSubscriberTest.php diff --git a/src/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriber.php b/src/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriber.php index 8ec85e643..0019eead2 100644 --- a/src/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriber.php +++ b/src/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriber.php @@ -8,6 +8,9 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; /** * Puts a prefix to each table. + * This way were used instead of using the built-in strategy from Doctrine, using `naming_strategy` + * Because it conflicts with the DefaultQuoteStrategy (that espace table name, like user for Postgres) + * see #1498 for more detail. * * Solution from : * - http://stackoverflow.com/a/23860613/569101 @@ -30,17 +33,18 @@ class TablePrefixSubscriber implements EventSubscriber public function loadClassMetadata(LoadClassMetadataEventArgs $args) { $classMetadata = $args->getClassMetadata(); + // if we are in an inheritance hierarchy, only apply this once if ($classMetadata->isInheritanceTypeSingleTable() && !$classMetadata->isRootEntity()) { return; } - $classMetadata->setTableName($this->prefix . $classMetadata->getTableName()); + $classMetadata->setTableName($this->prefix.$classMetadata->getTableName()); foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) { if ($mapping['type'] === ClassMetadataInfo::MANY_TO_MANY && isset($classMetadata->associationMappings[$fieldName]['joinTable']['name'])) { $mappedTableName = $classMetadata->associationMappings[$fieldName]['joinTable']['name']; - $classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $this->prefix . $mappedTableName; + $classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $this->prefix.$mappedTableName; } } } diff --git a/src/Wallabag/CoreBundle/Tests/Subscriber/TablePrefixSubscriberTest.php b/src/Wallabag/CoreBundle/Tests/Subscriber/TablePrefixSubscriberTest.php new file mode 100644 index 000000000..4c1386109 --- /dev/null +++ b/src/Wallabag/CoreBundle/Tests/Subscriber/TablePrefixSubscriberTest.php @@ -0,0 +1,115 @@ +getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $subscriber = new TablePrefixSubscriber($prefix); + + $metaClass = new ClassMetadata($entityName); + $metaClass->setPrimaryTable(array('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(array('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(array('name' => 'entry')); + $metaClass->mapManyToMany(array( + 'fieldName' => 'tags', + 'joinTable' => array('name' => null, 'schema' => null), + 'targetEntity' => 'Tag', + 'mappedBy' => null, + 'inversedBy' => 'entries', + 'cascade' => array('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())); + } +} From 8a493541fa4911233fe9186e88371d17cb9fd7db Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 1 Nov 2015 23:42:52 +0100 Subject: [PATCH 4/8] Re-enable test on doctrine command It will slow down the whole test suite (because it'll use doctrine command). Remove unecessary `KernelTestCase`. Also rename `AbstractControllerTest` to `WallabagApiTestCase` for consistency. --- .travis.yml | 2 +- .../Tests/Controller/WallabagRestControllerTest.php | 4 ++-- .../{AbstractControllerTest.php => WallabagApiTestCase.php} | 2 +- src/Wallabag/CoreBundle/Command/InstallCommand.php | 4 ++-- .../CoreBundle/Tests/Controller/EntryControllerTest.php | 6 ++++++ .../CoreBundle/Tests/EventListener/LocaleListenerTest.php | 3 +-- .../EventListener/RegistrationConfirmedListenerTest.php | 3 +-- .../Tests/EventListener/UserLocaleListenerTest.php | 3 +-- src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php | 3 +-- .../Tests/ParamConverter/UsernameRssTokenConverterTest.php | 3 +-- .../Tests/Subscriber/TablePrefixSubscriberTest.php | 3 +-- 11 files changed, 18 insertions(+), 18 deletions(-) rename src/Wallabag/ApiBundle/Tests/{AbstractControllerTest.php => WallabagApiTestCase.php} (96%) diff --git a/.travis.yml b/.travis.yml index df3a5c725..9a19be617 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,7 +51,7 @@ before_script: script: - ant prepare-$DB - - SYMFONY_DEPRECATIONS_HELPER=weak bin/phpunit --exclude-group command-doctrine -v + - SYMFONY_DEPRECATIONS_HELPER=weak bin/phpunit -v # after_script: # - | diff --git a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php index bc7ef4895..bdd36e0c6 100644 --- a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php @@ -2,9 +2,9 @@ namespace Wallabag\ApiBundle\Tests\Controller; -use Wallabag\ApiBundle\Tests\AbstractControllerTest; +use Wallabag\ApiBundle\Tests\WallabagApiTestCase; -class WallabagRestControllerTest extends AbstractControllerTest +class WallabagRestControllerTest extends WallabagApiTestCase { protected static $salt; diff --git a/src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php b/src/Wallabag/ApiBundle/Tests/WallabagApiTestCase.php similarity index 96% rename from src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php rename to src/Wallabag/ApiBundle/Tests/WallabagApiTestCase.php index 09cde0f60..8a57fea26 100644 --- a/src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php +++ b/src/Wallabag/ApiBundle/Tests/WallabagApiTestCase.php @@ -5,7 +5,7 @@ namespace Wallabag\ApiBundle\Tests; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Component\BrowserKit\Cookie; -abstract class AbstractControllerTest extends WebTestCase +abstract class WallabagApiTestCase extends WebTestCase { /** * @var Client diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index 865a73e1d..8b702c958 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php @@ -96,10 +96,10 @@ class InstallCommand extends ContainerAwareCommand if (!$fulfilled) { throw new \RuntimeException('Some system requirements are not fulfilled. Please check output messages and fix them.'); - } else { - $this->defaultOutput->writeln('Success! Your system can run Wallabag properly.'); } + $this->defaultOutput->writeln('Success! Your system can run Wallabag properly.'); + $this->defaultOutput->writeln(''); return $this; diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index 5ac39d121..0bd7d4fe6 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 $this->assertEquals('This value should not be blank.', $alert[0]); } + /** + * This test will require an internet connection + */ public function testPostNewOk() { $this->logInAs('admin'); @@ -119,6 +122,9 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertEquals(200, $client->getResponse()->getStatusCode()); } + /** + * @depends testPostNewOk + */ public function testView() { $this->logInAs('admin'); diff --git a/src/Wallabag/CoreBundle/Tests/EventListener/LocaleListenerTest.php b/src/Wallabag/CoreBundle/Tests/EventListener/LocaleListenerTest.php index 356a411e6..d89bee047 100644 --- a/src/Wallabag/CoreBundle/Tests/EventListener/LocaleListenerTest.php +++ b/src/Wallabag/CoreBundle/Tests/EventListener/LocaleListenerTest.php @@ -2,7 +2,6 @@ namespace Wallabag\CoreBundle\Tests\EventListener; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\KernelEvents; @@ -12,7 +11,7 @@ use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Symfony\Component\HttpFoundation\Session\Session; use Wallabag\CoreBundle\EventListener\LocaleListener; -class LocaleListenerTest extends KernelTestCase +class LocaleListenerTest extends \PHPUnit_Framework_TestCase { private function getEvent(Request $request) { diff --git a/src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php b/src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php index df94fad25..31283399d 100644 --- a/src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php +++ b/src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php @@ -2,7 +2,6 @@ namespace Wallabag\CoreBundle\Tests\EventListener; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -12,7 +11,7 @@ use Wallabag\CoreBundle\EventListener\RegistrationConfirmedListener; use Wallabag\CoreBundle\Entity\Config; use Wallabag\UserBundle\Entity\User; -class RegistrationConfirmedListenerTest extends KernelTestCase +class RegistrationConfirmedListenerTest extends \PHPUnit_Framework_TestCase { private $em; private $listener; diff --git a/src/Wallabag/CoreBundle/Tests/EventListener/UserLocaleListenerTest.php b/src/Wallabag/CoreBundle/Tests/EventListener/UserLocaleListenerTest.php index e8a65fbf1..80ddb4572 100644 --- a/src/Wallabag/CoreBundle/Tests/EventListener/UserLocaleListenerTest.php +++ b/src/Wallabag/CoreBundle/Tests/EventListener/UserLocaleListenerTest.php @@ -2,7 +2,6 @@ namespace Wallabag\CoreBundle\Tests\EventListener; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Symfony\Component\HttpFoundation\Session\Session; @@ -12,7 +11,7 @@ use Wallabag\CoreBundle\EventListener\UserLocaleListener; use Wallabag\CoreBundle\Entity\Config; use Wallabag\UserBundle\Entity\User; -class UserLocaleListenerTest extends KernelTestCase +class UserLocaleListenerTest extends \PHPUnit_Framework_TestCase { public function testWithLanguage() { diff --git a/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php b/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php index 1d0d40628..4bce4708f 100644 --- a/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php +++ b/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php @@ -2,12 +2,11 @@ namespace Wallabag\CoreBundle\Tests\Helper; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Helper\ContentProxy; -class ContentProxyTest extends KernelTestCase +class ContentProxyTest extends \PHPUnit_Framework_TestCase { public function testWithEmptyContent() { diff --git a/src/Wallabag/CoreBundle/Tests/ParamConverter/UsernameRssTokenConverterTest.php b/src/Wallabag/CoreBundle/Tests/ParamConverter/UsernameRssTokenConverterTest.php index e28dc4bae..1c9a4ad7c 100644 --- a/src/Wallabag/CoreBundle/Tests/ParamConverter/UsernameRssTokenConverterTest.php +++ b/src/Wallabag/CoreBundle/Tests/ParamConverter/UsernameRssTokenConverterTest.php @@ -2,13 +2,12 @@ namespace Wallabag\CoreBundle\Tests\Command; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Wallabag\CoreBundle\ParamConverter\UsernameRssTokenConverter; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use Symfony\Component\HttpFoundation\Request; use Wallabag\UserBundle\Entity\User; -class UsernameRssTokenConverterTest extends KernelTestCase +class UsernameRssTokenConverterTest extends \PHPUnit_Framework_TestCase { public function testSupportsWithNoRegistry() { diff --git a/src/Wallabag/CoreBundle/Tests/Subscriber/TablePrefixSubscriberTest.php b/src/Wallabag/CoreBundle/Tests/Subscriber/TablePrefixSubscriberTest.php index 4c1386109..a26ff4368 100644 --- a/src/Wallabag/CoreBundle/Tests/Subscriber/TablePrefixSubscriberTest.php +++ b/src/Wallabag/CoreBundle/Tests/Subscriber/TablePrefixSubscriberTest.php @@ -2,13 +2,12 @@ namespace Wallabag\CoreBundle\Tests\Subscriber; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Event\LoadClassMetadataEventArgs; use Doctrine\Common\EventManager; use Wallabag\CoreBundle\Subscriber\TablePrefixSubscriber; -class TablePrefixSubscriberTest extends KernelTestCase +class TablePrefixSubscriberTest extends \PHPUnit_Framework_TestCase { public function dataForPrefix() { From d502762598db68ec822078642df8f6a8214202f7 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 6 Nov 2015 22:08:51 +0100 Subject: [PATCH 5/8] Skipping PostgreSQL test that drop database For a not-clear reason, I can't properly drop the current database. Even if Doctrine made a special case for that (https://github.com/doctrine/dbal/pull/849). So instead of trying crazy things to achieve the test, better way is to skip test (too much wasted days ..) --- .../CoreBundle/Command/InstallCommand.php | 7 +- .../Tests/Command/InstallCommandTest.php | 65 +++++++++++-------- .../CoreBundle/Tests/WallabagCoreTestCase.php | 2 + 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index 8b702c958..85c4ee902 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php @@ -111,14 +111,17 @@ class InstallCommand extends ContainerAwareCommand // user want to reset everything? Don't care about what is already here if (true === $this->defaultInput->getOption('reset')) { - $this->defaultOutput->writeln('Droping database, creating database and schema'); + $this->defaultOutput->writeln('Droping database, creating database and schema, clearing the cache'); $this ->runCommand('doctrine:database:drop', array('--force' => true)) ->runCommand('doctrine:database:create') ->runCommand('doctrine:schema:create') + ->runCommand('cache:clear') ; + $this->defaultOutput->writeln(''); + return $this; } @@ -131,6 +134,8 @@ class InstallCommand extends ContainerAwareCommand ->runCommand('cache:clear') ; + $this->defaultOutput->writeln(''); + return $this; } diff --git a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php index e98dd2026..e3ff47c0e 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 public function testRunInstallCommand() { - $this->container = static::$kernel->getContainer(); - - $application = new Application(static::$kernel); + $application = new Application($this->getClient()->getKernel()); $application->add(new InstallCommandMock()); $command = $application->find('wallabag:install'); @@ -59,9 +57,7 @@ class InstallCommandTest extends WallabagCoreTestCase public function testRunInstallCommandWithReset() { - $this->container = static::$kernel->getContainer(); - - $application = new Application(static::$kernel); + $application = new Application($this->getClient()->getKernel()); $application->add(new InstallCommandMock()); $command = $application->find('wallabag:install'); @@ -89,28 +85,39 @@ class InstallCommandTest extends WallabagCoreTestCase $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay()); // we force to reset everything - $this->assertContains('Droping database, creating database and schema', $tester->getDisplay()); + $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay()); } - /** - * @group command-doctrine - */ public function testRunInstallCommandWithDatabaseRemoved() { - $this->container = static::$kernel->getContainer(); + if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceOf \Doctrine\DBAL\Driver\PDOPgSql\Driver) { + /** + * LOG: statement: CREATE DATABASE "wallabag" + * ERROR: source database "template1" is being accessed by other users + * DETAIL: There is 1 other session using the database. + * STATEMENT: CREATE DATABASE "wallabag" + * FATAL: database "wallabag" does not exist + * + * http://stackoverflow.com/a/14374832/569101 + */ + $this->markTestSkipped('PostgreSQL spotted: can find a good way to drop current database, skipping.'); + } - $application = new Application(static::$kernel); - $application->add(new InstallCommand()); + $application = new Application($this->getClient()->getKernel()); $application->add(new DropDatabaseDoctrineCommand()); // drop database first, so the install command won't ask to reset things - $command = new DropDatabaseDoctrineCommand(); - $command->setApplication($application); + $command = $application->find('doctrine:database:drop'); $command->run(new ArrayInput(array( 'command' => 'doctrine:database:drop', '--force' => true, )), new NullOutput()); + // start a new application to avoid lagging connexion to pgsql + $client = static::createClient(); + $application = new Application($client->getKernel()); + $application->add(new InstallCommand()); + $command = $application->find('wallabag:install'); // We mock the QuestionHelper @@ -140,9 +147,7 @@ class InstallCommandTest extends WallabagCoreTestCase public function testRunInstallCommandChooseResetSchema() { - $this->container = static::$kernel->getContainer(); - - $application = new Application(static::$kernel); + $application = new Application($this->getClient()->getKernel()); $application->add(new InstallCommandMock()); $command = $application->find('wallabag:install'); @@ -176,14 +181,22 @@ class InstallCommandTest extends WallabagCoreTestCase $this->assertContains('Droping schema and creating schema', $tester->getDisplay()); } - /** - * @group command-doctrine - */ public function testRunInstallCommandChooseNothing() { - $this->container = static::$kernel->getContainer(); + if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceOf \Doctrine\DBAL\Driver\PDOPgSql\Driver) { + /** + * LOG: statement: CREATE DATABASE "wallabag" + * ERROR: source database "template1" is being accessed by other users + * DETAIL: There is 1 other session using the database. + * STATEMENT: CREATE DATABASE "wallabag" + * FATAL: database "wallabag" does not exist + * + * http://stackoverflow.com/a/14374832/569101 + */ + $this->markTestSkipped('PostgreSQL spotted: can find a good way to drop current database, skipping.'); + } - $application = new Application(static::$kernel); + $application = new Application($this->getClient()->getKernel()); $application->add(new InstallCommand()); $application->add(new DropDatabaseDoctrineCommand()); $application->add(new CreateDatabaseDoctrineCommand()); @@ -196,7 +209,7 @@ class InstallCommandTest extends WallabagCoreTestCase '--force' => true, )), new NullOutput()); - $this->container->get('doctrine')->getManager()->getConnection()->close(); + $this->getClient()->getContainer()->get('doctrine')->getConnection()->close(); $command = new CreateDatabaseDoctrineCommand(); $command->setApplication($application); @@ -237,9 +250,7 @@ class InstallCommandTest extends WallabagCoreTestCase public function testRunInstallCommandNoInteraction() { - $this->container = static::$kernel->getContainer(); - - $application = new Application(static::$kernel); + $application = new Application($this->getClient()->getKernel()); $application->add(new InstallCommandMock()); $command = $application->find('wallabag:install'); diff --git a/src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php b/src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php index e5096528c..ce3cabe8d 100644 --- a/src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php +++ b/src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php @@ -15,6 +15,8 @@ abstract class WallabagCoreTestCase extends WebTestCase public function setUp() { + parent::setUp(); + $this->client = static::createClient(); } From 75c48e3ae0e7b23a246216b98f9b1368b9cdd69b Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 6 Nov 2015 22:15:20 +0100 Subject: [PATCH 6/8] CS --- .../CoreBundle/Tests/Command/InstallCommandTest.php | 8 ++++---- .../CoreBundle/Tests/Controller/EntryControllerTest.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php index e3ff47c0e..0bb8be57b 100644 --- a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php +++ b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php @@ -90,8 +90,8 @@ class InstallCommandTest extends WallabagCoreTestCase public function testRunInstallCommandWithDatabaseRemoved() { - if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceOf \Doctrine\DBAL\Driver\PDOPgSql\Driver) { - /** + if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOPgSql\Driver) { + /* * LOG: statement: CREATE DATABASE "wallabag" * ERROR: source database "template1" is being accessed by other users * DETAIL: There is 1 other session using the database. @@ -183,8 +183,8 @@ class InstallCommandTest extends WallabagCoreTestCase public function testRunInstallCommandChooseNothing() { - if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceOf \Doctrine\DBAL\Driver\PDOPgSql\Driver) { - /** + if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOPgSql\Driver) { + /* * LOG: statement: CREATE DATABASE "wallabag" * ERROR: source database "template1" is being accessed by other users * DETAIL: There is 1 other session using the database. diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index 0bd7d4fe6..56b4c9e41 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php @@ -75,7 +75,7 @@ class EntryControllerTest extends WallabagCoreTestCase } /** - * This test will require an internet connection + * This test will require an internet connection. */ public function testPostNewOk() { From 970e0e994f62d59e25ba42de4502714ab0ab08a1 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 7 Nov 2015 14:18:38 +0100 Subject: [PATCH 7/8] Remove duplicate comments --- .../CoreBundle/Tests/Command/InstallCommandTest.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php index 0bb8be57b..c93460406 100644 --- a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php +++ b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php @@ -185,13 +185,7 @@ class InstallCommandTest extends WallabagCoreTestCase { if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOPgSql\Driver) { /* - * LOG: statement: CREATE DATABASE "wallabag" - * ERROR: source database "template1" is being accessed by other users - * DETAIL: There is 1 other session using the database. - * STATEMENT: CREATE DATABASE "wallabag" - * FATAL: database "wallabag" does not exist - * - * http://stackoverflow.com/a/14374832/569101 + * @see testRunInstallCommandWithDatabaseRemoved */ $this->markTestSkipped('PostgreSQL spotted: can find a good way to drop current database, skipping.'); } From 53cf5106891fc64f3f66cb6b3316654a9620239c Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 8 Nov 2015 10:47:56 +0100 Subject: [PATCH 8/8] Lock DoctrineBundle to 1.5.2 Because of a bad change, SQLite database cannot be created anymore. :arrow_right: https://github.com/doctrine/DoctrineBundle/pull/434 --- composer.json | 2 +- composer.lock | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index b8c936f0d..a46e990ad 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "php": ">=5.3.3", "symfony/symfony": "~2.7.0", "doctrine/orm": "~2.3", - "doctrine/doctrine-bundle": "~1.2", + "doctrine/doctrine-bundle": "1.5.2", "twig/extensions": "~1.0", "symfony/assetic-bundle": "~2.3", "symfony/swiftmailer-bundle": "~2.3", diff --git a/composer.lock b/composer.lock index ee6e483a0..ec11324f5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "01e7829e7ff2b39b288871661bb05e9a", - "content-hash": "76830bc9c2cd6f600613c9eea7c0f1b1", + "hash": "6bd09434f83c7e6b5e1c75fddbd7608b", + "content-hash": "d07d54c4cc6f4f4947c652bd659af02e", "packages": [ { "name": "doctrine/annotations", @@ -357,16 +357,16 @@ }, { "name": "doctrine/doctrine-bundle", - "version": "1.6.0", + "version": "v1.5.2", "source": { "type": "git", "url": "https://github.com/doctrine/DoctrineBundle.git", - "reference": "a5b3ba908ba68f3e14e42762a7b940fde65ed7da" + "reference": "d63be7eb9a95d46720f7d6badac4e5bc2bcff2e3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/DoctrineBundle/zipball/a5b3ba908ba68f3e14e42762a7b940fde65ed7da", - "reference": "a5b3ba908ba68f3e14e42762a7b940fde65ed7da", + "url": "https://api.github.com/repos/doctrine/DoctrineBundle/zipball/d63be7eb9a95d46720f7d6badac4e5bc2bcff2e3", + "reference": "d63be7eb9a95d46720f7d6badac4e5bc2bcff2e3", "shasum": "" }, "require": { @@ -431,7 +431,7 @@ "orm", "persistence" ], - "time": "2015-11-04 21:33:02" + "time": "2015-08-31 14:47:06" }, { "name": "doctrine/doctrine-cache-bundle", @@ -2771,20 +2771,20 @@ }, { "name": "sensiolabs/security-checker", - "version": "v3.0.1", + "version": "v3.0.2", "source": { "type": "git", "url": "https://github.com/sensiolabs/security-checker.git", - "reference": "7735fd97ff7303d9df776b8dbc970f949399abc9" + "reference": "21696b0daa731064c23cfb694c60a2584a7b6e93" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sensiolabs/security-checker/zipball/7735fd97ff7303d9df776b8dbc970f949399abc9", - "reference": "7735fd97ff7303d9df776b8dbc970f949399abc9", + "url": "https://api.github.com/repos/sensiolabs/security-checker/zipball/21696b0daa731064c23cfb694c60a2584a7b6e93", + "reference": "21696b0daa731064c23cfb694c60a2584a7b6e93", "shasum": "" }, "require": { - "symfony/console": "~2.0" + "symfony/console": "~2.0|~3.0" }, "bin": [ "security-checker" @@ -2811,7 +2811,7 @@ } ], "description": "A security checker for your composer.lock", - "time": "2015-08-11 12:11:25" + "time": "2015-11-07 08:07:40" }, { "name": "simplepie/simplepie",