diff options
author | Sean Molenaar <sean@seanmolenaar.eu> | 2020-10-10 00:23:15 +0200 |
---|---|---|
committer | Benjamin Brahmer <info@b-brahmer.de> | 2020-10-10 10:26:12 +0200 |
commit | b46c6df6322e09c05a34acca69403fd4ebd238ba (patch) | |
tree | 47182b11d97869304e97f729eacc490bc420d5df /tests | |
parent | eb382ded61f608a4bb8d52a7a71478e461ca5be7 (diff) |
Fix usage of at() in unittests
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Unit/Command/ExploreGeneratorTest.php | 8 | ||||
-rw-r--r-- | tests/Unit/Controller/FeedControllerTest.php | 19 | ||||
-rw-r--r-- | tests/Unit/Controller/ItemApiControllerTest.php | 101 | ||||
-rw-r--r-- | tests/Unit/Controller/ItemControllerTest.php | 87 | ||||
-rw-r--r-- | tests/Unit/Controller/PageControllerTest.php | 33 | ||||
-rw-r--r-- | tests/Unit/Db/FolderMapperTest.php | 228 | ||||
-rw-r--r-- | tests/Unit/Db/MapperTestUtility.php | 202 | ||||
-rw-r--r-- | tests/Unit/Service/FeedServiceTest.php | 195 | ||||
-rw-r--r-- | tests/Unit/Service/FolderServiceTest.php | 14 |
9 files changed, 365 insertions, 522 deletions
diff --git a/tests/Unit/Command/ExploreGeneratorTest.php b/tests/Unit/Command/ExploreGeneratorTest.php index 213633549..4512e206c 100644 --- a/tests/Unit/Command/ExploreGeneratorTest.php +++ b/tests/Unit/Command/ExploreGeneratorTest.php @@ -136,13 +136,9 @@ class ExploreGeneratorTest extends TestCase { ->with('votes') ->willReturn(100); - $this->consoleOutput->expects($this->at(0)) + $this->consoleOutput->expects($this->exactly(2)) ->method('writeln') - ->with($this->stringContains('<error>')); - - $this->consoleOutput->expects($this->at(1)) - ->method('writeln') - ->with($this->stringContains('Failure')); + ->withConsecutive(['<error>Failed to fetch feed info:</error>'], ['Failure']); self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); } diff --git a/tests/Unit/Controller/FeedControllerTest.php b/tests/Unit/Controller/FeedControllerTest.php index 7498d0ccb..f5c51b93e 100644 --- a/tests/Unit/Controller/FeedControllerTest.php +++ b/tests/Unit/Controller/FeedControllerTest.php @@ -142,22 +142,13 @@ class FeedControllerTest extends TestCase private function activeInitMocks($id, $type) { - $this->settings->expects($this->at(0)) + $this->settings->expects($this->exactly(2)) ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('lastViewedFeedId') - ) - ->will($this->returnValue($id)); - $this->settings->expects($this->at(1)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('lastViewedFeedType') + ->withConsecutive( + [$this->user, $this->appName, 'lastViewedFeedId'], + [$this->user, $this->appName, 'lastViewedFeedType'] ) - ->will($this->returnValue($type)); + ->willReturnOnConsecutiveCalls($id, $type); } diff --git a/tests/Unit/Controller/ItemApiControllerTest.php b/tests/Unit/Controller/ItemApiControllerTest.php index d2653b92a..75fd6bbef 100644 --- a/tests/Unit/Controller/ItemApiControllerTest.php +++ b/tests/Unit/Controller/ItemApiControllerTest.php @@ -308,19 +308,11 @@ class ItemApiControllerTest extends TestCase public function testReadMultiple() { - $this->itemService->expects($this->at(0)) + $this->itemService->expects($this->exactly(2)) ->method('read') - ->with( - $this->equalTo(2), - $this->equalTo(true), - $this->equalTo($this->user->getUID()) - ); - $this->itemService->expects($this->at(1)) - ->method('read') - ->with( - $this->equalTo(4), - $this->equalTo(true), - $this->equalTo($this->user->getUID()) + ->withConsecutive( + [2, true, $this->user->getUID()], + [4, true, $this->user->getUID()] ); $this->itemAPI->readMultiple([2, 4]); } @@ -328,35 +320,24 @@ class ItemApiControllerTest extends TestCase public function testReadMultipleDoesntCareAboutException() { - $this->itemService->expects($this->at(0)) - ->method('read') - ->will($this->throwException(new ServiceNotFoundException(''))); - $this->itemService->expects($this->at(1)) + $this->itemService->expects($this->exactly(2)) ->method('read') - ->with( - $this->equalTo(4), - $this->equalTo(true), - $this->equalTo($this->user->getUID()) - ); + ->withConsecutive( + [2, true, $this->user->getUID()], + [4, true, $this->user->getUID()] + ) + ->willReturnOnConsecutiveCalls($this->throwException(new ServiceNotFoundException('')), null); $this->itemAPI->readMultiple([2, 4]); } public function testUnreadMultiple() { - $this->itemService->expects($this->at(0)) - ->method('read') - ->with( - $this->equalTo(2), - $this->equalTo(false), - $this->equalTo($this->user->getUID()) - ); - $this->itemService->expects($this->at(1)) + $this->itemService->expects($this->exactly(2)) ->method('read') - ->with( - $this->equalTo(4), - $this->equalTo(false), - $this->equalTo($this->user->getUID()) + ->withConsecutive( + [2, false, $this->user->getUID()], + [4, false, $this->user->getUID()] ); $this->itemAPI->unreadMultiple([2, 4]); } @@ -375,21 +356,11 @@ class ItemApiControllerTest extends TestCase ] ]; - $this->itemService->expects($this->at(0)) - ->method('star') - ->with( - $this->equalTo(2), - $this->equalTo('a'), - $this->equalTo(true), - $this->equalTo($this->user->getUID()) - ); - $this->itemService->expects($this->at(1)) + $this->itemService->expects($this->exactly(2)) ->method('star') - ->with( - $this->equalTo(4), - $this->equalTo('b'), - $this->equalTo(true), - $this->equalTo($this->user->getUID()) + ->withConsecutive( + [2, 'a', true, $this->user->getUID()], + [4, 'b', true, $this->user->getUID()] ); $this->itemAPI->starMultiple($ids); } @@ -408,17 +379,14 @@ class ItemApiControllerTest extends TestCase ] ]; - $this->itemService->expects($this->at(0)) - ->method('star') - ->will($this->throwException(new ServiceNotFoundException(''))); - $this->itemService->expects($this->at(1)) + $this->itemService->expects($this->exactly(2)) ->method('star') - ->with( - $this->equalTo(4), - $this->equalTo('b'), - $this->equalTo(true), - $this->equalTo($this->user->getUID()) - ); + ->withConsecutive( + [2, 'a', true, $this->user->getUID()], + [4, 'b', true, $this->user->getUID()] + ) + ->willReturnOnConsecutiveCalls($this->throwException(new ServiceNotFoundException('')), null); + $this->itemAPI->starMultiple($ids); } @@ -436,22 +404,13 @@ class ItemApiControllerTest extends TestCase ] ]; - $this->itemService->expects($this->at(0)) - ->method('star') - ->with( - $this->equalTo(2), - $this->equalTo('a'), - $this->equalTo(false), - $this->equalTo($this->user->getUID()) - ); - $this->itemService->expects($this->at(1)) + $this->itemService->expects($this->exactly(2)) ->method('star') - ->with( - $this->equalTo(4), - $this->equalTo('b'), - $this->equalTo(false), - $this->equalTo($this->user->getUID()) + ->withConsecutive( + [2, 'a', false, $this->user->getUID()], + [4, 'b', false, $this->user->getUID()] ); + $this->itemAPI->unstarMultiple($ids); } diff --git a/tests/Unit/Controller/ItemControllerTest.php b/tests/Unit/Controller/ItemControllerTest.php index c69191423..c015c33a1 100644 --- a/tests/Unit/Controller/ItemControllerTest.php +++ b/tests/Unit/Controller/ItemControllerTest.php @@ -36,6 +36,7 @@ class ItemControllerTest extends TestCase private $itemService; private $feedService; private $request; + private $user; private $controller; private $newestItemId; @@ -98,41 +99,27 @@ class ItemControllerTest extends TestCase public function testReadMultiple() { - $this->itemService->expects($this->at(0)) + $this->itemService->expects($this->exactly(2)) ->method('read') - ->with( - $this->equalTo(2), - $this->equalTo(true), - $this->equalTo($this->user) - ); - $this->itemService->expects($this->at(1)) - ->method('read') - ->with( - $this->equalTo(4), - $this->equalTo(true), - $this->equalTo($this->user) + ->withConsecutive( + [2, true, $this->user], + [4, true, $this->user] ); + $this->controller->readMultiple([2, 4]); } public function testReadMultipleDontStopOnException() { - $this->itemService->expects($this->at(0)) + + $this->itemService->expects($this->exactly(2)) ->method('read') - ->with( - $this->equalTo(2), - $this->equalTo(true), - $this->equalTo($this->user) + ->withConsecutive( + [2, true, $this->user], + [4, true, $this->user] ) - ->will($this->throwException(new ServiceNotFoundException('yo'))); - $this->itemService->expects($this->at(1)) - ->method('read') - ->with( - $this->equalTo(4), - $this->equalTo(true), - $this->equalTo($this->user) - ); + ->willReturnOnConsecutiveCalls($this->throwException(new ServiceNotFoundException('yo')), null); $this->controller->readMultiple([2, 4]); } @@ -190,39 +177,20 @@ class ItemControllerTest extends TestCase } - private function itemsApiExpects($id, $type, $oldestFirst='1') + private function itemsApiExpects($id, $type, $oldestFirst = '1') { - $this->settings->expects($this->at(0)) + $this->settings->expects($this->exactly(2)) ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('showAll') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(1)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('oldestFirst') + ->withConsecutive( + [$this->user, $this->appName, 'showAll'], + [$this->user, $this->appName, 'oldestFirst'] ) - ->will($this->returnValue($oldestFirst)); - $this->settings->expects($this->at(2)) - ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('lastViewedFeedId'), - $this->equalTo($id) - ); - $this->settings->expects($this->at(3)) + ->willReturnOnConsecutiveCalls('1', $oldestFirst); + $this->settings->expects($this->exactly(2)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('lastViewedFeedType'), - $this->equalTo($type) + ->withConsecutive( + [$this->user, $this->appName, 'lastViewedFeedId', $id], + [$this->user, $this->appName, 'lastViewedFeedType', $type] ); } @@ -256,16 +224,7 @@ class ItemControllerTest extends TestCase $this->itemService->expects($this->once()) ->method('findAllItems') - ->with( - $this->equalTo(2), - $this->equalTo(FeedType::FEED), - $this->equalTo(3), - $this->equalTo(0), - $this->equalTo(true), - $this->equalTo(false), - $this->equalTo($this->user), - $this->equalTo([]) - ) + ->with(2, FeedType::FEED, 3, 0, true, false, $this->user, []) ->will($this->returnValue($result['items'])); $response = $this->controller->index(FeedType::FEED, 2, 3); diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php index fe263f242..2afe2d590 100644 --- a/tests/Unit/Controller/PageControllerTest.php +++ b/tests/Unit/Controller/PageControllerTest.php @@ -234,21 +234,15 @@ class PageControllerTest extends TestCase */ public function testUpdateSettings() { - $this->settings->expects($this->at(0)) - ->method('setUserValue') - ->with('becka', 'news', 'showAll', '1'); - $this->settings->expects($this->at(1)) - ->method('setUserValue') - ->with('becka', 'news', 'compact', '1'); - $this->settings->expects($this->at(2)) - ->method('setUserValue') - ->with('becka', 'news', 'preventReadOnScroll', '0'); - $this->settings->expects($this->at(3)) - ->method('setUserValue') - ->with('becka', 'news', 'oldestFirst', '1'); - $this->settings->expects($this->at(4)) + $this->settings->expects($this->exactly(5)) ->method('setUserValue') - ->with('becka', 'news', 'compactExpand', '1'); + ->withConsecutive( + ['becka', 'news', 'showAll', '1'], + ['becka', 'news', 'compact', '1'], + ['becka', 'news', 'preventReadOnScroll', '0'], + ['becka', 'news', 'oldestFirst', '1'], + ['becka', 'news', 'compactExpand', '1'] + ); $this->controller->updateSettings(true, true, false, true, true); } @@ -256,13 +250,12 @@ class PageControllerTest extends TestCase public function testExplore() { $in = ['test']; - $this->settings->expects($this->at(0)) - ->method('setUserValue') - ->with('becka', 'news', 'lastViewedFeedId', 0); - - $this->settings->expects($this->at(1)) + $this->settings->expects($this->exactly(2)) ->method('setUserValue') - ->with('becka', 'news', 'lastViewedFeedType', FeedType::EXPLORE); + ->withConsecutive( + ['becka', 'news', 'lastViewedFeedId', 0], + ['becka', 'news', 'lastViewedFeedType', FeedType::EXPLORE] + ); $this->recommended->expects($this->once()) ->method('forLanguage') diff --git a/tests/Unit/Db/FolderMapperTest.php b/tests/Unit/Db/FolderMapperTest.php index deb235ff7..803c84ebe 100644 --- a/tests/Unit/Db/FolderMapperTest.php +++ b/tests/Unit/Db/FolderMapperTest.php @@ -50,21 +50,40 @@ class FolderMapperTest extends MapperTestUtility ]; } - + /** + * @covers \OCA\News\Db\FolderMapper::find + */ public function testFind() { $userId = 'john'; $id = 3; - $rows = [['id' => $this->folders[0]->getId()]]; $sql = 'SELECT * FROM `*PREFIX*news_folders` ' . 'WHERE `id` = ? ' . 'AND `user_id` = ?'; - $this->setMapperResult($sql, [$id, $userId], $rows); + $this->db->expects($this->exactly(1)) + ->method('prepare') + ->with($sql, null, null) + ->will(($this->returnValue($this->query))); + + $this->query->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls(['id' => 4], false); + + $this->query->expects($this->exactly(2)) + ->method('bindValue') + ->withConsecutive([1, 3, 1], [2, $userId, 2]); + + $this->query->expects($this->exactly(1)) + ->method('closeCursor'); + + $this->query->expects($this->once()) + ->method('execute') + ->with('') + ->will($this->returnValue([])); $result = $this->folderMapper->find($userId, $id); $this->assertEquals($this->folders[0], $result); - } @@ -76,7 +95,26 @@ class FolderMapperTest extends MapperTestUtility 'WHERE `id` = ? ' . 'AND `user_id` = ?'; - $this->setMapperResult($sql, [$id, $userId]); + $this->db->expects($this->exactly(1)) + ->method('prepare') + ->with($sql, null, null) + ->will(($this->returnValue($this->query))); + + $this->query->expects($this->exactly(1)) + ->method('fetch') + ->willReturnOnConsecutiveCalls(false); + + $this->query->expects($this->exactly(2)) + ->method('bindValue') + ->withConsecutive([1, $id, 1], [2, $userId, 2]); + + $this->query->expects($this->exactly(1)) + ->method('closeCursor'); + + $this->query->expects($this->once()) + ->method('execute') + ->with('') + ->will($this->returnValue([])); $this->expectException(DoesNotExistException::class); $this->folderMapper->find($userId, $id); @@ -87,12 +125,30 @@ class FolderMapperTest extends MapperTestUtility { $userId = 'john'; $id = 3; - $rows = $this->twoRows; $sql = 'SELECT * FROM `*PREFIX*news_folders` ' . 'WHERE `id` = ? ' . 'AND `user_id` = ?'; - $this->setMapperResult($sql, [$id, $userId], $rows); + $this->db->expects($this->exactly(1)) + ->method('prepare') + ->with($sql, null, null) + ->will(($this->returnValue($this->query))); + + $this->query->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls(['id' => 4], ['id' => 5]); + + $this->query->expects($this->exactly(2)) + ->method('bindValue') + ->withConsecutive([1, 3, 1], [2, $userId, 2]); + + $this->query->expects($this->exactly(1)) + ->method('closeCursor'); + + $this->query->expects($this->once()) + ->method('execute') + ->with('') + ->will($this->returnValue([])); $this->expectException(MultipleObjectsReturnedException::class); $this->folderMapper->find($userId, $id); @@ -103,12 +159,29 @@ class FolderMapperTest extends MapperTestUtility public function testFindAllFromUser() { $userId = 'john'; - $rows = $this->twoRows; $sql = 'SELECT * FROM `*PREFIX*news_folders` ' . 'WHERE `user_id` = ? ' . 'AND `deleted_at` = 0'; - $this->setMapperResult($sql, [$userId], $rows); + $this->db->expects($this->exactly(1)) + ->method('prepare') + ->with($sql, null, null) + ->will(($this->returnValue($this->query))); + + $this->query->expects($this->exactly(3)) + ->method('fetch') + ->willReturnOnConsecutiveCalls(['id' => 4], ['id' => 5]); + + $this->query->expects($this->exactly(1)) + ->method('bindValue') + ->withConsecutive([1, $userId, 2]); + + $this->query->expects($this->exactly(1)) + ->method('closeCursor'); + + $this->query->expects($this->once()) + ->method('execute') + ->will($this->returnValue([])); $result = $this->folderMapper->findAllFromUser($userId); $this->assertEquals($this->folders, $result); @@ -119,12 +192,29 @@ class FolderMapperTest extends MapperTestUtility { $folderName = 'heheh'; $userId = 'john'; - $rows = $this->twoRows; $sql = 'SELECT * FROM `*PREFIX*news_folders` ' . 'WHERE `name` = ? ' . 'AND `user_id` = ?'; - $this->setMapperResult($sql, [$folderName, $userId], $rows); + $this->db->expects($this->exactly(1)) + ->method('prepare') + ->with($sql, null, null) + ->will(($this->returnValue($this->query))); + + $this->query->expects($this->exactly(3)) + ->method('fetch') + ->willReturnOnConsecutiveCalls(['id' => 4], ['id' => 5]); + + $this->query->expects($this->exactly(2)) + ->method('bindValue') + ->withConsecutive([1, $folderName, 2], [2, $userId, 2]); + + $this->query->expects($this->exactly(1)) + ->method('closeCursor'); + + $this->query->expects($this->once()) + ->method('execute') + ->will($this->returnValue([])); $result = $this->folderMapper->findByName($folderName, $userId); $this->assertEquals($this->folders, $result); @@ -145,9 +235,25 @@ class FolderMapperTest extends MapperTestUtility $sql3 = 'DELETE FROM `*PREFIX*news_items` WHERE `feed_id` NOT IN '. '(SELECT `feeds`.`id` FROM `*PREFIX*news_feeds` `feeds`)'; - $this->setMapperResult($sql, $arguments, [], null, null, true); - $this->setMapperResult($sql2, $arguments2, [], null, null, true); - $this->setMapperResult($sql3, [], [], null, null, true); + $this->db->expects($this->exactly(3)) + ->method('prepare') + ->withConsecutive( + [$sql, null, null], + [$sql2, null, null], + [$sql3, null, null] + ) + ->will(($this->returnValue($this->query))); + + $this->query->expects($this->exactly(2)) + ->method('bindValue') + ->withConsecutive([1, 3, 1]); + + $this->query->expects($this->exactly(3)) + ->method('closeCursor'); + + $this->query->expects($this->exactly(3)) + ->method('execute') + ->will($this->returnValue([])); $this->folderMapper->delete($folder); } @@ -155,13 +261,32 @@ class FolderMapperTest extends MapperTestUtility public function testGetPurgeDeleted() { - $rows = $this->twoRows; - $deleteOlderThan = 110; $sql = 'SELECT * FROM `*PREFIX*news_folders` ' . 'WHERE `deleted_at` > 0 ' . 'AND `deleted_at` < ? '; - $this->setMapperResult($sql, [$deleteOlderThan], $rows); - $result = $this->folderMapper->getToDelete($deleteOlderThan); + + + $this->db->expects($this->exactly(1)) + ->method('prepare') + ->with($sql, null, null) + ->will(($this->returnValue($this->query))); + + $this->query->expects($this->exactly(3)) + ->method('fetch') + ->willReturnOnConsecutiveCalls(['id' => 4], ['id' => 5]); + + $this->query->expects($this->exactly(1)) + ->method('bindValue') + ->withConsecutive([1, 110, 1]); + + $this->query->expects($this->exactly(1)) + ->method('closeCursor'); + + $this->query->expects($this->once()) + ->method('execute') + ->will($this->returnValue([])); + + $result = $this->folderMapper->getToDelete(110); $this->assertEquals($this->folders, $result); } @@ -170,13 +295,33 @@ class FolderMapperTest extends MapperTestUtility public function testGetPurgeDeletedUser() { - $rows = $this->twoRows; $deleteOlderThan = 110; $sql = 'SELECT * FROM `*PREFIX*news_folders` ' . 'WHERE `deleted_at` > 0 ' . 'AND `deleted_at` < ? ' . 'AND `user_id` = ?'; - $this->setMapperResult($sql, [$deleteOlderThan, $this->user], $rows); + + + $this->db->expects($this->exactly(1)) + ->method('prepare') + ->with($sql, null, null) + ->will(($this->returnValue($this->query))); + + $this->query->expects($this->exactly(3)) + ->method('fetch') + ->willReturnOnConsecutiveCalls(['id' => 4], ['id' => 5]); + + $this->query->expects($this->exactly(2)) + ->method('bindValue') + ->withConsecutive([1, 110, 1], [2, 'hh', 2]); + + $this->query->expects($this->exactly(1)) + ->method('closeCursor'); + + $this->query->expects($this->once()) + ->method('execute') + ->will($this->returnValue([])); + $result = $this->folderMapper->getToDelete( $deleteOlderThan, $this->user ); @@ -187,12 +332,30 @@ class FolderMapperTest extends MapperTestUtility public function testGetAllPurgeDeletedUser() { - $rows = $this->twoRows; - $sql = 'SELECT * FROM `*PREFIX*news_folders` ' . 'WHERE `deleted_at` > 0 ' . 'AND `user_id` = ?'; - $this->setMapperResult($sql, [$this->user], $rows); + + $this->db->expects($this->exactly(1)) + ->method('prepare') + ->with($sql, null, null) + ->will(($this->returnValue($this->query))); + + $this->query->expects($this->exactly(3)) + ->method('fetch') + ->willReturnOnConsecutiveCalls(['id' => 4], ['id' => 5]); + + $this->query->expects($this->exactly(1)) + ->method('bindValue') + ->withConsecutive([1, 'hh', 2]); + + $this->query->expects($this->exactly(1)) + ->method('closeCursor'); + + $this->query->expects($this->once()) + ->method('execute') + ->will($this->returnValue([])); + $result = $this->folderMapper->getToDelete(null, $this->user); $this->assertEquals($this->folders, $result); @@ -204,7 +367,24 @@ class FolderMapperTest extends MapperTestUtility $userId = 'john'; $sql = 'DELETE FROM `*PREFIX*news_folders` WHERE `user_id` = ?'; - $this->setMapperResult($sql, [$userId]); + $this->db->expects($this->exactly(1)) + ->method('prepare') + ->with($sql, null, null) + ->will(($this->returnValue($this->query))); + + $this->query->expects($this->never()) + ->method('fetch'); + + $this->query->expects($this->exactly(1)) + ->method('bindValue') + ->withConsecutive([1, $userId, 2]); + + $this->query->expects($this->exactly(0)) + ->method('closeCursor'); + + $this->query->expects($this->once()) + ->method('execute') + ->will($this->returnValue([])); $this->folderMapper->deleteUser($userId); } diff --git a/tests/Unit/Db/MapperTestUtility.php b/tests/Unit/Db/MapperTestUtility.php index b414b43e3..695738179 100644 --- a/tests/Unit/Db/MapperTestUtility.php +++ b/tests/Unit/Db/MapperTestUtility.php @@ -23,20 +23,27 @@ namespace OCA\News\Tests\Unit\Db; +use Doctrine\DBAL\Driver\PDOStatement; use OCP\IDBConnection; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; + /** * Simple utility class for testing mappers */ abstract class MapperTestUtility extends TestCase { + + /** + * @var MockObject|IDBConnection + */ protected $db; - private $query; - private $queryAt; - private $prepareAt; - private $fetchAt; - private $iterators; + + /** + * @var MockObject|PDOStatement + */ + protected $query; /** @@ -48,187 +55,10 @@ abstract class MapperTestUtility extends TestCase parent::setUp(); $this->db = $this->getMockBuilder(IDBConnection::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->query = $this->createMock(\PDOStatement::class); - $this->queryAt = 0; - $this->prepareAt = 0; - $this->iterators = []; - $this->fetchAt = 0; - } - - /** - * Checks if an array is associative - * - * @param array $array - * @return bool true if associative - */ - private function isAssocArray(array $array) - { - return array_values($array) !== $array; - } - - /** - * Returns the correct PDO constant based on the value type - * - * @param $value - * @return PDO constant - */ - private function getPDOType($value) - { - switch (gettype($value)) { - case 'integer': - return \PDO::PARAM_INT; - case 'boolean': - return \PDO::PARAM_BOOL; - default: - return \PDO::PARAM_STR; - } - } - - /** - * Create mocks and set expected results for database queries - * - * @param string $sql the sql query that you expect to receive - * @param array $arguments the expected arguments for the prepare query - * method - * @param array $returnRows the rows that should be returned for the result - * of the database query. If not provided, it wont - * be assumed that fetch will be called on the - * result - */ - protected function setMapperResult($sql, $arguments=array(), $returnRows=array(), - $limit=null, $offset=null, $expectClose=false - ) { - if($limit === null && $offset === null) { - $this->db->expects($this->at($this->prepareAt)) - ->method('prepare') - ->with($this->equalTo($sql)) - ->will(($this->returnValue($this-& |