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

Commit

Permalink
Enhancement: Assert register() updates existing module
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Feb 15, 2015
1 parent 7bb4568 commit d81c777
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions module/ZfModule/test/ZfModuleTest/Service/ModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,72 @@ public function providerIsModuleReturnsTrueIfResultCountIsGreaterThanZero()
];
}

public function testRegisterUpdatesExistingModule()
{
$repository = $this->repository();

$module = $this->getMockBuilder(Entity\Module::class)->getMock();

$module
->expects($this->once())
->method('setName')
->with($this->equalTo($repository->name))
;

$module
->expects($this->once())
->method('setDescription')
->with($this->equalTo($repository->description))
;

$module
->expects($this->once())
->method('setUrl')
->with($this->equalTo($repository->html_url))
;

$module
->expects($this->once())
->method('setOwner')
->with($this->equalTo($repository->owner->login))
;
$module
->expects($this->once())
->method('setPhotoUrl')
->with($this->equalTo($repository->owner->avatar_url))
;

$moduleMapper = $this->getMockBuilder(Mapper\Module::class)->getMock();

$moduleMapper
->expects($this->once())
->method('findByUrl')
->with($this->equalTo($repository->html_url))
->willReturn($module)
;

$moduleMapper
->expects($this->once())
->method('update')
->with($this->equalTo($module))
;

$githubClient = $this->getMockBuilder(Client::class)
->disableOriginalConstructor()
->getMock()
;

$service = new Service\Module(
$moduleMapper,
$githubClient
);

$this->assertSame(
$module,
$service->register($repository)
);
}

/**
* @return stdClass
*/
Expand All @@ -391,9 +457,17 @@ private function repository()
$repository = new stdClass();

$repository->name = 'foo';
$repository->description = 'blah blah';
$repository->fork = false;
$repository->created_at = '1970-01-01 00:00:00';
$repository->html_url = 'http://www.example.org';

$repository->owner = new stdClass();
$repository->owner->login = 'suzie';
$repository->owner->avatar_url = 'http://www.example.org/img/suzie.gif';

$repository->permissions = new stdClass();
$repository->permissions->push = true;

return $repository;
}
Expand Down

0 comments on commit d81c777

Please sign in to comment.