summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2015-12-03 21:40:46 +0100
committerBernhard Posselt <dev@bernhard-posselt.com>2016-01-17 18:18:39 +0100
commit570c75db776a79294d97a05cd8ac63ac4ab39685 (patch)
treedeedd28a10628a06b9d0b53400a2719b7a659562
parente5d606d3ee7dc046e7db9eb1f94b6cc6e542ecbe (diff)
fix several integration test issues
-rw-r--r--tests/integration/db/ItemMapperTest.php12
-rw-r--r--tests/integration/fixtures/feedfixture.php3
-rw-r--r--tests/integration/fixtures/fixture.php3
-rw-r--r--tests/integration/fixtures/folderfixture.php2
-rw-r--r--tests/integration/fixtures/itemfixture.php10
-rw-r--r--tests/integration/integrationtest.php26
6 files changed, 34 insertions, 22 deletions
diff --git a/tests/integration/db/ItemMapperTest.php b/tests/integration/db/ItemMapperTest.php
index 948b843de..0f5f15318 100644
--- a/tests/integration/db/ItemMapperTest.php
+++ b/tests/integration/db/ItemMapperTest.php
@@ -11,16 +11,21 @@
namespace OCA\News\Db;
+use OCA\News\Tests\Integration\Fixtures\FeedFixture;
use OCA\News\Tests\Integration\Fixtures\ItemFixture;
use OCA\News\Tests\Integration\IntegrationTest;
class ItemMapperTest extends IntegrationTest {
public function testFind() {
- $item = new ItemFixture();
+ $feed = new FeedFixture();
+ $feed = $this->feedMapper->insert($feed);
- $created = $this->itemMapper->insert($item);
- $fetched = $this->itemMapper->find($created->getId(), $this->user);
+ $item = new ItemFixture(['feedId' => $feed->getId()]);
+
+ $item = $this->itemMapper->insert($item);
+
+ $fetched = $this->itemMapper->find($item->getId(), $this->user);
$this->assertEquals($item->getTitle(), $fetched->getTitle());
}
@@ -51,6 +56,7 @@ class ItemMapperTest extends IntegrationTest {
public function testFindNotFoundWhenDeletedFolder() {
$this->loadFixtures('default');
+
$id = $this->whereTitleId('not found folder');
$this->itemMapper->find($id, $this->user);
}
diff --git a/tests/integration/fixtures/feedfixture.php b/tests/integration/fixtures/feedfixture.php
index 8c87a8efd..5394ebf6b 100644
--- a/tests/integration/fixtures/feedfixture.php
+++ b/tests/integration/fixtures/feedfixture.php
@@ -21,7 +21,7 @@ class FeedFixture extends Feed {
public function __construct(array $defaults=[]) {
parent::__construct();
- $defaults = array_combine([
+ $defaults = array_merge([
'userId' => 'test',
'urlHash' => 'urlHash',
'url' => 'http://the.url.com',
@@ -29,7 +29,6 @@ class FeedFixture extends Feed {
'faviconLink' => 'http://the.faviconLink.com',
'added' => 9,
'folderId' => 0,
- 'unreadCount' => 0,
'link' => 'http://thelink.com',
'preventUpdate' => false,
'deletedAt' => 0,
diff --git a/tests/integration/fixtures/fixture.php b/tests/integration/fixtures/fixture.php
index 52015ebc2..a5bceda17 100644
--- a/tests/integration/fixtures/fixture.php
+++ b/tests/integration/fixtures/fixture.php
@@ -15,12 +15,11 @@ namespace OCA\News\Tests\Integration\Fixtures;
trait Fixture {
- public function fillDefaults(array $defaults=[]) {
+ protected function fillDefaults(array $defaults=[]) {
foreach ($defaults as $key => $value) {
$method = 'set' . ucfirst($key);
$this->$method($value);
}
- $this->resetUpdatedFields();
}
} \ No newline at end of file
diff --git a/tests/integration/fixtures/folderfixture.php b/tests/integration/fixtures/folderfixture.php
index 872ee33b8..2c884c6ed 100644
--- a/tests/integration/fixtures/folderfixture.php
+++ b/tests/integration/fixtures/folderfixture.php
@@ -20,7 +20,7 @@ class FolderFixture extends Folder {
public function __construct(array $defaults=[]) {
parent::__construct();
- $defaults = array_combine([
+ $defaults = array_merge([
'parentId' => 0,
'name' => 'folder',
'userId' => 'test',
diff --git a/tests/integration/fixtures/itemfixture.php b/tests/integration/fixtures/itemfixture.php
index ac9191c4d..8914773dc 100644
--- a/tests/integration/fixtures/itemfixture.php
+++ b/tests/integration/fixtures/itemfixture.php
@@ -20,8 +20,7 @@ class ItemFixture extends Item {
public function __construct(array $defaults=[]) {
parent::__construct();
- $defaults = array_combine([
- 'guid' => 'guid',
+ $defaults = array_merge([
'url' => 'http://google.de',
'title' => 'title',
'author' => 'author',
@@ -34,17 +33,18 @@ class ItemFixture extends Item {
'lastModified' => 113,
'rtl' => false,
], $defaults);
- $this->fillDefaults($defaults);
if (!array_key_exists('guid', $defaults)) {
- $this->setGuid($this->getTitle());
+ $defaults['guid'] = $defaults['title'];
}
if (!array_key_exists('guidHash', $defaults)) {
- $this->setGuidHash($this->getGuid());
+ $defaults['guidHash'] = $defaults['guid'];
}
$this->generateSearchIndex();
+
+ $this->fillDefaults($defaults);
}
}
diff --git a/tests/integration/integrationtest.php b/tests/integration/integrationtest.php
index 08f146fdd..50c172705 100644
--- a/tests/integration/integrationtest.php
+++ b/tests/integration/integrationtest.php
@@ -64,18 +64,24 @@ abstract class IntegrationTest extends PHPUnit_Framework_TestCase {
protected function findItemByTitle($title) {
// db logic in app code, negligible since its a test
- $items = $this->itemMapper->where();
+ $items = $this->itemMapper->where(['title' => $title]);
$feeds = $this->feedMapper->where(['userId' => $this->user]);
- $feedIds = array_map(function (Feed $feed) {
- return $feed->getId();
- }, $feeds);
+ $feedIds = [];
+ foreach ($feeds as $feed) {
+ $feedIds[$feed->getId()] = true;
+ }
+
+ $result = array_filter($items,
+ function (Item $item) use ($feedIds) {
+ return array_key_exists($item->getFeedId(), $feedIds);
+ });
- return array_filter($items, function (Item $item) use ($title, $feedIds) {
- return $item->getTitle() === $title &&
- in_array($item->getFeedId(), $feedIds);
+ // ok so this is funny: array_filter preserves indices, meaning that
+ // you can't use 0 as key for the first element return from it :D
+ $result = array_values($result)[0];
- })[0];
+ return $result;
}
protected function findFolderByName($name) {
@@ -96,7 +102,7 @@ abstract class IntegrationTest extends PHPUnit_Framework_TestCase {
* @param string $name loads fixtures from a given file
*/
protected function loadFixtures($name) {
- $fixtures = include __DIR__ . '/data/' . $name . '.php';
+ $fixtures = include __DIR__ . '/fixtures/data/' . $name . '.php';
if (array_key_exists('folders', $fixtures)) {
$this->loadFolderFixtures($fixtures['folders']);
}
@@ -116,6 +122,7 @@ abstract class IntegrationTest extends PHPUnit_Framework_TestCase {
protected function loadFeedFixtures(array $feedFixtures=[], $folderId=0) {
foreach ($feedFixtures as $feedFixture) {
$feed = new FeedFixture($feedFixture);
+ $feed->setFolderId($folderId);
$feedId = $this->loadFixture($feed);
$this->loadItemFixtures($feedFixture['items'], $feedId);
}
@@ -124,6 +131,7 @@ abstract class IntegrationTest extends PHPUnit_Framework_TestCase {
protected function loadItemFixtures(array $itemFixtures=[], $feedId) {
foreach ($itemFixtures as $itemFixture) {
$item = new ItemFixture($itemFixture);
+ $item->setFeedId($feedId);
$this->loadFixture($item);
}
}