Fix build service test - mock environment store
This commit is contained in:
parent
5da247afc7
commit
1cef8260e9
|
@ -771,6 +771,16 @@ class Project extends Model
|
|||
return $icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EnvironmentStore
|
||||
*/
|
||||
protected function getEnvironmentStore()
|
||||
{
|
||||
/** @var EnvironmentStore $store */
|
||||
$store = Factory::getStore('Environment', 'PHPCensor');
|
||||
return $store;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Environments
|
||||
*
|
||||
|
@ -788,8 +798,7 @@ class Project extends Model
|
|||
$rtn = $this->cache->get($cacheKey, null);
|
||||
|
||||
if (empty($rtn)) {
|
||||
/** @var EnvironmentStore $store */
|
||||
$store = Factory::getStore('Environment', 'PHPCensor');
|
||||
$store = $this->getEnvironmentStore();
|
||||
$rtn = $store->getByProjectId($key);
|
||||
$this->cache->set($cacheKey, $rtn);
|
||||
}
|
||||
|
@ -843,7 +852,7 @@ class Project extends Model
|
|||
$environments_names = !empty($environments_config) ? array_keys($environments_config) : [];
|
||||
|
||||
$current_environments = $this->getEnvironmentsObjects();
|
||||
$store = Factory::getStore('Environment', 'PHPCensor');
|
||||
$store = $this->getEnvironmentStore();
|
||||
foreach ($current_environments['items'] as $environment) {
|
||||
/** @var Environment $environment */
|
||||
$key = array_search($environment->getName(), $environments_names);
|
||||
|
|
|
@ -24,6 +24,11 @@ class BuildServiceTest extends \PHPUnit_Framework_TestCase
|
|||
*/
|
||||
protected $mockBuildStore;
|
||||
|
||||
/**
|
||||
* @var \ $mockEnvironmentStore
|
||||
*/
|
||||
protected $mockEnvironmentStore;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->mockBuildStore = $this->getMockBuilder('PHPCensor\Store\BuildStore')->getMock();
|
||||
|
@ -31,12 +36,25 @@ class BuildServiceTest extends \PHPUnit_Framework_TestCase
|
|||
->method('save')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$this->mockEnvironmentStore = $this->getMockBuilder('PHPCensor\Store\EnvironmentStore')->getMock();
|
||||
$this->mockEnvironmentStore->expects($this->any())
|
||||
->method('getByProjectId')
|
||||
->will($this->returnValue(['items' => [], 'count' => 0]));
|
||||
|
||||
$this->testedService = new BuildService($this->mockBuildStore);
|
||||
}
|
||||
|
||||
public function testExecute_CreateBasicBuild()
|
||||
{
|
||||
$project = new Project();
|
||||
$project = $this
|
||||
->getMockBuilder('PHPCensor\Model\Project')
|
||||
->setMethods(['getEnvironmentStore'])
|
||||
->getMock();
|
||||
|
||||
$project->expects($this->any())
|
||||
->method('getEnvironmentStore')
|
||||
->will($this->returnValue($this->mockEnvironmentStore));
|
||||
|
||||
$project->setType('github');
|
||||
$project->setId(101);
|
||||
|
||||
|
@ -57,7 +75,15 @@ class BuildServiceTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testExecute_CreateBuildWithOptions()
|
||||
{
|
||||
$project = new Project();
|
||||
$project = $this
|
||||
->getMockBuilder('PHPCensor\Model\Project')
|
||||
->setMethods(['getEnvironmentStore'])
|
||||
->getMock();
|
||||
|
||||
$project->expects($this->any())
|
||||
->method('getEnvironmentStore')
|
||||
->will($this->returnValue($this->mockEnvironmentStore));
|
||||
|
||||
$project->setType('hg');
|
||||
$project->setId(101);
|
||||
|
||||
|
@ -71,7 +97,15 @@ class BuildServiceTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testExecute_CreateBuildWithExtra()
|
||||
{
|
||||
$project = new Project();
|
||||
$project = $this
|
||||
->getMockBuilder('PHPCensor\Model\Project')
|
||||
->setMethods(['getEnvironmentStore'])
|
||||
->getMock();
|
||||
|
||||
$project->expects($this->any())
|
||||
->method('getEnvironmentStore')
|
||||
->will($this->returnValue($this->mockEnvironmentStore));
|
||||
|
||||
$project->setType('bitbucket');
|
||||
$project->setId(101);
|
||||
|
||||
|
|
Loading…
Reference in a new issue