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/Unit/Controller | |
parent | eb382ded61f608a4bb8d52a7a71478e461ca5be7 (diff) |
Fix usage of at() in unittests
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'tests/Unit/Controller')
-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 |
4 files changed, 71 insertions, 169 deletions
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') |