Skip to content
This repository has been archived by the owner on May 1, 2019. It is now read-only.

Commit

Permalink
Enhancement: Simplify mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Feb 6, 2015
1 parent 611bef7 commit a760788
Showing 1 changed file with 20 additions and 54 deletions.
74 changes: 20 additions & 54 deletions module/ZfModule/test/ZfModuleTest/Service/ModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit a760788

Please sign in to comment.