From 735068d1814a4b7a688e1d19cd17b13e8c5da3eb Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 25 Oct 2015 15:55:19 +0100 Subject: Add tests on TablePrefixSubscriber --- .../Tests/Subscriber/TablePrefixSubscriberTest.php | 115 +++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/Wallabag/CoreBundle/Tests/Subscriber/TablePrefixSubscriberTest.php (limited to 'src/Wallabag/CoreBundle/Tests') diff --git a/src/Wallabag/CoreBundle/Tests/Subscriber/TablePrefixSubscriberTest.php b/src/Wallabag/CoreBundle/Tests/Subscriber/TablePrefixSubscriberTest.php new file mode 100644 index 00000000..4c138610 --- /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())); + } +} -- cgit v1.2.3 From 8a493541fa4911233fe9186e88371d17cb9fd7db Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 1 Nov 2015 23:42:52 +0100 Subject: 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. --- src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php | 6 ++++++ src/Wallabag/CoreBundle/Tests/EventListener/LocaleListenerTest.php | 3 +-- .../Tests/EventListener/RegistrationConfirmedListenerTest.php | 3 +-- .../CoreBundle/Tests/EventListener/UserLocaleListenerTest.php | 3 +-- src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php | 3 +-- .../Tests/ParamConverter/UsernameRssTokenConverterTest.php | 3 +-- .../CoreBundle/Tests/Subscriber/TablePrefixSubscriberTest.php | 3 +-- 7 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/Wallabag/CoreBundle/Tests') diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index 5ac39d12..0bd7d4fe 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 356a411e..d89bee04 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 df94fad2..31283399 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 e8a65fbf..80ddb457 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 1d0d4062..4bce4708 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 e28dc4ba..1c9a4ad7 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 4c138610..a26ff436 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() { -- cgit v1.2.3 From d502762598db68ec822078642df8f6a8214202f7 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 6 Nov 2015 22:08:51 +0100 Subject: 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 ..) --- .../Tests/Command/InstallCommandTest.php | 69 +++++++++++++--------- .../CoreBundle/Tests/WallabagCoreTestCase.php | 2 + 2 files changed, 42 insertions(+), 29 deletions(-) (limited to 'src/Wallabag/CoreBundle/Tests') diff --git a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php index e98dd202..e3ff47c0 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(); - - $application = new Application(static::$kernel); - $application->add(new InstallCommand()); + 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($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(); - - $application = new Application(static::$kernel); + 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($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 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 public function setUp() { + parent::setUp(); + $this->client = static::createClient(); } -- cgit v1.2.3 From 75c48e3ae0e7b23a246216b98f9b1368b9cdd69b Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 6 Nov 2015 22:15:20 +0100 Subject: CS --- src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php | 8 ++++---- src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/Wallabag/CoreBundle/Tests') diff --git a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php index e3ff47c0..0bb8be57 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 0bd7d4fe..56b4c9e4 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() { -- cgit v1.2.3 From 970e0e994f62d59e25ba42de4502714ab0ab08a1 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 7 Nov 2015 14:18:38 +0100 Subject: Remove duplicate comments --- src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'src/Wallabag/CoreBundle/Tests') diff --git a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php index 0bb8be57..c9346040 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.'); } -- cgit v1.2.3