. * */ namespace OCA\News\Db; require_once(__DIR__ . "/../classloader.php"); class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility { private $feedMapper; private $feeds; protected function setUp(){ $this->beforeEach(); $this->feedMapper = new FeedMapper($this->api); // create mock feeds $feed1 = new Feed(); $feed2 = new Feed(); $this->feeds = array( $feed1, $feed2 ); } public function testFind(){ $userId = 'john'; $id = 3; $rows = array( array('id' => $this->feeds[0]->getId()), ); $sql = 'SELECT * FROM `*dbprefix*news_feeds` ' . 'WHERE `id` = ? ' . 'AND `user_id` = ?'; $this->setMapperResult($sql, array($id, $userId), $rows); $result = $this->feedMapper->find($id, $userId); $this->assertEquals($this->feeds[0], $result); } public function testFindNotFound(){ $userId = 'john'; $id = 3; $sql = 'SELECT * FROM `*dbprefix*news_feeds` ' . 'WHERE `id` = ? ' . 'AND `user_id` = ?'; $this->setMapperResult($sql, array($id, $userId)); $this->setExpectedException('\OCA\AppFramework\Db\DoesNotExistException'); $result = $this->itemMapper->find($id, $userId); } public function testFindMoreThanOneResultFound(){ $userId = 'john'; $id = 3; $rows = array( array('id' => $this->items[0]->getId()), array('id' => $this->items[1]->getId()) ); $sql = 'SELECT * FROM `*dbprefix*news_feeds` ' . 'WHERE `id` = ? ' . 'AND `user_id` = ?'; $this->setMapperResult($sql, array($id, $userId), $rows); $this->setExpectedException('\OCA\AppFramework\Db\MultipleObjectsReturnedException'); $result = $this->itemMapper->find($id, $userId); } }