From: Jeremy Benoist Date: Fri, 11 Sep 2015 14:13:59 +0000 (+0200) Subject: Fix tests X-Git-Tag: 2.0.0-alpha.0~4^2 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=af43bd37675954f937720f7b6fbcf78d85928bc5;p=github%2Fwallabag%2Fwallabag.git Fix tests Ensure that created use during install command will always be unique. We assume that the install command must be run to initialize a wallabag instance. NEVER to add more user. Also, use a better way to retrieve the real name of the database and not the one defined in parameters.yml (which isn't the same for test envi because the dbname isn't defined in parameters.yml but directly in config_test.yml) --- diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index 29d91109..1bd76ae3 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php @@ -273,10 +273,11 @@ class InstallCommand extends ContainerAwareCommand */ private function isDatabasePresent() { - $databaseName = $this->getContainer()->getParameter('database_name'); + $connection = $this->getContainer()->get('doctrine')->getManager()->getConnection(); + $databaseName = $connection->getDatabase(); try { - $schemaManager = $this->getContainer()->get('doctrine')->getManager()->getConnection()->getSchemaManager(); + $schemaManager = $connection->getSchemaManager(); } catch (\Exception $exception) { if (false !== strpos($exception->getMessage(), sprintf("Unknown database '%s'", $databaseName))) { return false; diff --git a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php index 3067e5a4..24910e60 100644 --- a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php +++ b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php @@ -41,7 +41,7 @@ class InstallCommandTest extends WallabagCoreTestCase ->getMock(); $dialog->expects($this->any()) ->method('ask') - ->will($this->returnValue('test')); + ->will($this->returnValue('test_'.uniqid('', true))); $dialog->expects($this->any()) ->method('askConfirmation') ->will($this->returnValue(true)); @@ -75,7 +75,7 @@ class InstallCommandTest extends WallabagCoreTestCase ->getMock(); $dialog->expects($this->any()) ->method('ask') - ->will($this->returnValue('test2')); + ->will($this->returnValue('test_'.uniqid('', true))); $dialog->expects($this->any()) ->method('askConfirmation') ->will($this->returnValue(true)); @@ -125,7 +125,7 @@ class InstallCommandTest extends WallabagCoreTestCase ->getMock(); $dialog->expects($this->any()) ->method('ask') - ->will($this->returnValue('test')); + ->will($this->returnValue('test_'.uniqid('', true))); $dialog->expects($this->any()) ->method('askConfirmation') ->will($this->returnValue(true)); @@ -259,7 +259,7 @@ class InstallCommandTest extends WallabagCoreTestCase ->getMock(); $dialog->expects($this->any()) ->method('ask') - ->will($this->returnValue('test')); + ->will($this->returnValue('test_'.uniqid('', true))); $dialog->expects($this->any()) ->method('askConfirmation') ->will($this->returnValue(true)); diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index a0966285..a92835b3 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php @@ -209,7 +209,7 @@ class EntryControllerTest extends WallabagCoreTestCase $content = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneById(1); + ->findOneByIsStarred(false); $client->request('GET', '/delete/'.$content->getId()); @@ -360,13 +360,13 @@ class EntryControllerTest extends WallabagCoreTestCase $form['entry_filter[isStarred]']->untick(); $crawler = $client->submit($form); - $this->assertCount(1, $crawler->filter('div[class=entry]')); + $this->assertCount(2, $crawler->filter('div[class=entry]')); $form = $crawler->filter('button[id=submit-filter]')->form(); $form['entry_filter[isArchived]']->untick(); $form['entry_filter[isStarred]']->tick(); $crawler = $client->submit($form); - $this->assertCount(1, $crawler->filter('div[class=entry]')); + $this->assertCount(2, $crawler->filter('div[class=entry]')); } } diff --git a/src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php index af39d6ce..d25b2db5 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php @@ -24,7 +24,7 @@ class TagControllerTest extends WallabagCoreTestCase $entry = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByIsArchived(false); + ->findOneBy(array()); $crawler = $client->request('GET', '/view/'.$entry->getId());