From b7f20c0f36dd6e0ed65ca93fcec44aa23f2fa203 Mon Sep 17 00:00:00 2001 From: Daniel Schaal Date: Tue, 6 Jun 2017 18:20:20 +0200 Subject: Fix travis build (#178) * Use stable12 branch for travis * Shorten db indices to max 27 characters to satisfy app:check-code * Use precise container, downgrade to psql 9.4 * Create psql role * Fix ContentController test * Fix PageController and StatusService tests * Use OCP\IDBConnection, OCP\IDb was removed * Extend IntegrationTest from \Test\Testcase, use loginAsUser to login * Require phpunit 5, nextcloud tests not compatible with phpunit 6 Change tests to use phpunit from vendor directory --- tests/Integration/IntegrationTest.php | 11 +++++------ tests/Unit/Controller/PageControllerTest.php | 8 ++++---- tests/Unit/Service/StatusServiceTest.php | 7 +++++-- 3 files changed, 14 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/Integration/IntegrationTest.php b/tests/Integration/IntegrationTest.php index fb39dfd7a..c14d3007a 100644 --- a/tests/Integration/IntegrationTest.php +++ b/tests/Integration/IntegrationTest.php @@ -19,7 +19,7 @@ use OCA\News\Db\Item; use OCP\AppFramework\Db\Entity; use OCP\AppFramework\IAppContainer; -use OCP\IDb; +use OCP\IDBConnection; use OCP\IUserSession; use OCP\IUserManager; @@ -32,7 +32,7 @@ use OCA\News\Db\ItemMapper; use OCA\News\Db\FolderMapper; -abstract class IntegrationTest extends PHPUnit_Framework_TestCase { +abstract class IntegrationTest extends \Test\TestCase { protected $user = 'test'; protected $userPassword = 'test'; @@ -162,8 +162,7 @@ abstract class IntegrationTest extends PHPUnit_Framework_TestCase { $userManager = $this->container->query(IUserManager::class); $userManager->createUser($user, $password); - $session = $this->container->query(IUserSession::class); - $session->login($user, $password); + $this->loginAsUser($user); } /** @@ -192,9 +191,9 @@ abstract class IntegrationTest extends PHPUnit_Framework_TestCase { 'DELETE FROM `*PREFIX*news_folders` WHERE `user_id` = ?' ]; - $db = $this->container->query(IDb::class); + $db = $this->container->query(IDBConnection::class); foreach ($sql as $query) { - $db->prepareQuery($query)->execute([$user]); + $db->prepare($query)->execute([$user]); } } diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php index 5cfba947e..9923befb4 100644 --- a/tests/Unit/Controller/PageControllerTest.php +++ b/tests/Unit/Controller/PageControllerTest.php @@ -80,8 +80,8 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase { ->disableOriginalConstructor() ->getMock(); $this->controller = new PageController($this->appName, $this->request, - $this->settings, $this->urlGenerator, $this->appConfig, - $this->config, $this->l10n, $this->recommended, $this->status, + $this->settings, $this->urlGenerator, $this->config, + $this->l10n, $this->recommended, $this->status, $this->user); } @@ -97,7 +97,7 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->controller->index(); $this->assertEquals('index', $response->getTemplateName()); - $this->assertSame(false, $response->getParams()['cronWarning']); + $this->assertSame(false, $response->getParams()['warnings']['improperlyConfiguredCron']); } @@ -112,7 +112,7 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->controller->index(); - $this->assertEquals(true, $response->getParams()['cronWarning']); + $this->assertEquals(true, $response->getParams()['warnings']['improperlyConfiguredCron']); } diff --git a/tests/Unit/Service/StatusServiceTest.php b/tests/Unit/Service/StatusServiceTest.php index dcd331b99..095bf6247 100644 --- a/tests/Unit/Service/StatusServiceTest.php +++ b/tests/Unit/Service/StatusServiceTest.php @@ -33,8 +33,11 @@ class StatusServiceTest extends \PHPUnit_Framework_TestCase { '\OCA\News\Config\Config') ->disableOriginalConstructor() ->getMock(); - $this->service = new StatusService($this->settings, $this->config, - $this->appName); + $this->db = $this->getMockBuilder("\OCP\IDBConnection") + ->disableOriginalConstructor() + ->getMock(); + $this->service = new StatusService($this->settings, $this->db, + $this->config, $this->appName); } private function beforeStatus($cronMode='cron', $cronEnabled=true, -- cgit v1.2.3