From a7607887883bc8eee0908976489063132ae24950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Mo=CC=88ller?= Date: Sat, 7 Feb 2015 00:22:01 +0100 Subject: [PATCH] Enhancement: Simplify mocking --- .../test/ZfModuleTest/Service/ModuleTest.php | 74 +++++-------------- 1 file changed, 20 insertions(+), 54 deletions(-) diff --git a/module/ZfModule/test/ZfModuleTest/Service/ModuleTest.php b/module/ZfModule/test/ZfModuleTest/Service/ModuleTest.php index ea554946..c0cb9bd5 100644 --- a/module/ZfModule/test/ZfModuleTest/Service/ModuleTest.php +++ b/module/ZfModule/test/ZfModuleTest/Service/ModuleTest.php @@ -107,20 +107,11 @@ public function testListUserModuleListsCurrentUsersModulesFromApiFoundInDatabase $currentUserService ->expects($this->once()) ->method('repos') - ->with($this->logicalAnd( - $this->arrayHasKey('type'), - $this->arrayHasKey('per_page') - )) - ->willReturnCallback(function ($params) use ($repository) { - - $repositories = []; - - if ('all' === $params['type'] && 100 === $params['per_page']) { - array_push($repositories, $repository); - } - - return new Mock\Collection\RepositoryCollection($repositories); - }) + ->with($this->equalTo([ + 'type' => 'all', + 'per_page' => 100, + ])) + ->willReturn(new Mock\Collection\RepositoryCollection([$repository])) ; $githubClient = $this->getMockBuilder(Client::class)->getMock(); @@ -159,20 +150,11 @@ public function testListUserModulesDoesNotLookupModulesFromApiWhereUserHasNoPush $currentUserService ->expects($this->once()) ->method('repos') - ->with($this->logicalAnd( - $this->arrayHasKey('type'), - $this->arrayHasKey('per_page') - )) - ->willReturnCallback(function ($params) use ($repository) { - - $repositories = []; - - if ('all' === $params['type'] && 100 === $params['per_page']) { - array_push($repositories, $repository); - } - - return new Mock\Collection\RepositoryCollection($repositories); - }) + ->with($this->equalTo([ + 'type' => 'all', + 'per_page' => 100, + ])) + ->willReturn(new Mock\Collection\RepositoryCollection([$repository])) ; $githubClient = $this->getMockBuilder(Client::class)->getMock(); @@ -209,19 +191,11 @@ public function testListUsersModuleDoesNotLookupModulesFromApiThatAreForks() $currentUserService ->expects($this->once()) ->method('repos') - ->with($this->logicalAnd( - $this->arrayHasKey('type'), - $this->arrayHasKey('per_page') - )) - ->willReturnCallback(function ($params) use ($repository) { - $repositories = []; - - if ('all' === $params['type'] && 100 === $params['per_page']) { - array_push($repositories, $repository); - } - - return new Mock\Collection\RepositoryCollection($repositories); - }) + ->with($this->equalTo([ + 'type' => 'all', + 'per_page' => 100, + ])) + ->willReturn(new Mock\Collection\RepositoryCollection([$repository])) ; $githubClient = $this->getMockBuilder(Client::class)->getMock(); @@ -265,19 +239,11 @@ public function testListUserModulesDoesNotListModulesFromApiNotFoundInDatabase() $currentUserService ->expects($this->once()) ->method('repos') - ->with($this->logicalAnd( - $this->arrayHasKey('type'), - $this->arrayHasKey('per_page') - )) - ->willReturnCallback(function ($params) use ($repository) { - $repositories = []; - - if ('all' === $params['type'] && 100 === $params['per_page']) { - array_push($repositories, $repository); - } - - return new Mock\Collection\RepositoryCollection($repositories); - }) + ->with($this->equalTo([ + 'type' => 'all', + 'per_page' => 100, + ])) + ->willReturn(new Mock\Collection\RepositoryCollection([$repository])) ; $githubClient = $this->getMockBuilder(Client::class)->getMock();