More work on ProjectService and its tests
This commit is contained in:
parent
af4cdd90b6
commit
0a0c911356
|
@ -119,7 +119,7 @@ class ProjectController extends \PHPCI\Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$project = $this->projectStore->getById($projectId);
|
$project = $this->projectStore->getById($projectId);
|
||||||
$this->projectStore->delete($project);
|
$this->projectService->delete($project);
|
||||||
|
|
||||||
header('Location: '.PHPCI_URL);
|
header('Location: '.PHPCI_URL);
|
||||||
exit;
|
exit;
|
||||||
|
@ -197,7 +197,7 @@ class ProjectController extends \PHPCI\Controller
|
||||||
'allow_public_status' => $this->getParam('allow_public_status', 0),
|
'allow_public_status' => $this->getParam('allow_public_status', 0),
|
||||||
);
|
);
|
||||||
|
|
||||||
$project = $this->projectService->createProject($title, $reference, $type, $options);
|
$project = $this->projectService->createProject($title, $type, $reference, $options);
|
||||||
header('Location: '.PHPCI_URL.'project/view/' . $project->getId());
|
header('Location: '.PHPCI_URL.'project/view/' . $project->getId());
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
|
@ -247,21 +247,18 @@ class ProjectController extends \PHPCI\Controller
|
||||||
return $view->render();
|
return $view->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
$values = $form->getValues();
|
$title = $this->getParam('title', 'New Project');
|
||||||
$values['ssh_private_key'] = $values['key'];
|
$reference = $this->getParam('reference', null);
|
||||||
$values['ssh_public_key'] = $values['pubkey'];
|
$type = $this->getParam('type', null);
|
||||||
|
|
||||||
if ($values['type'] == "gitlab") {
|
$options = array(
|
||||||
preg_match('`^(.*)@(.*):(.*)/(.*)\.git`', $values['reference'], $matches);
|
'ssh_private_key' => $this->getParam('key', null),
|
||||||
$info = array();
|
'ssh_public_key' => $this->getParam('pubkey', null),
|
||||||
$info["user"] = $matches[1];
|
'build_config' => $this->getParam('build_config', null),
|
||||||
$info["domain"] = $matches[2];
|
'allow_public_status' => $this->getParam('allow_public_status', 0),
|
||||||
$values['access_information'] = serialize($info);
|
);
|
||||||
$values['reference'] = $matches[3] . "/" . $matches[4];
|
|
||||||
}
|
|
||||||
|
|
||||||
$project->setValues($values);
|
$project = $this->projectService->updateProject($project, $title, $type, $reference, $options);
|
||||||
$project = $this->projectStore->save($project);
|
|
||||||
|
|
||||||
header('Location: '.PHPCI_URL.'project/view/' . $project->getId());
|
header('Location: '.PHPCI_URL.'project/view/' . $project->getId());
|
||||||
die;
|
die;
|
||||||
|
@ -332,7 +329,7 @@ class ProjectController extends \PHPCI\Controller
|
||||||
$field = Form\Element\Checkbox::create('allow_public_status', $label, false);
|
$field = Form\Element\Checkbox::create('allow_public_status', $label, false);
|
||||||
$field->setContainerClass('form-group');
|
$field->setContainerClass('form-group');
|
||||||
$field->setCheckedValue(1);
|
$field->setCheckedValue(1);
|
||||||
$field->setValue(1);
|
$field->setValue(0);
|
||||||
$form->addField($field);
|
$form->addField($field);
|
||||||
|
|
||||||
$field = new Form\Element\Submit();
|
$field = new Form\Element\Submit();
|
||||||
|
|
|
@ -57,6 +57,7 @@ class ProjectService
|
||||||
$project->setTitle($title);
|
$project->setTitle($title);
|
||||||
$project->setType($type);
|
$project->setType($type);
|
||||||
$project->setReference($reference);
|
$project->setReference($reference);
|
||||||
|
$project->setAllowPublicStatus(0);
|
||||||
|
|
||||||
// Handle extra project options:
|
// Handle extra project options:
|
||||||
if (array_key_exists('ssh_private_key', $options)) {
|
if (array_key_exists('ssh_private_key', $options)) {
|
||||||
|
@ -82,6 +83,16 @@ class ProjectService
|
||||||
return $this->projectStore->save($project);
|
return $this->projectStore->save($project);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a given project.
|
||||||
|
* @param Project $project
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function deleteProject(Project $project)
|
||||||
|
{
|
||||||
|
return $this->projectStore->delete($project);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In circumstances where it is necessary, populate access information based on other project properties.
|
* In circumstances where it is necessary, populate access information based on other project properties.
|
||||||
* @see ProjectService::createProject()
|
* @see ProjectService::createProject()
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\PHPCI\Service;
|
|
||||||
|
|
||||||
use b8\Model;
|
|
||||||
use PHPCI\Store\ProjectStore;
|
|
||||||
|
|
||||||
class MockProjectStore extends ProjectStore
|
|
||||||
{
|
|
||||||
public function save(Model $project)
|
|
||||||
{
|
|
||||||
$project->setId(1);
|
|
||||||
return $project;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -11,7 +11,6 @@ namespace PHPCI\Service\Tests;
|
||||||
|
|
||||||
use PHPCI\Model\Project;
|
use PHPCI\Model\Project;
|
||||||
use PHPCI\Service\ProjectService;
|
use PHPCI\Service\ProjectService;
|
||||||
use Tests\PHPCI\Service\MockProjectStore;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the ProjectService class.
|
* Unit tests for the ProjectService class.
|
||||||
|
@ -32,7 +31,11 @@ class ProjectServiceTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->mockProjectStore = new MockProjectStore();
|
$this->mockProjectStore = $this->getMock('PHPCI\Store\ProjectStore');
|
||||||
|
$this->mockProjectStore->expects($this->any())
|
||||||
|
->method('save')
|
||||||
|
->will($this->returnArgument(0));
|
||||||
|
|
||||||
$this->testedService = new ProjectService($this->mockProjectStore);
|
$this->testedService = new ProjectService($this->mockProjectStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,4 +101,39 @@ class ProjectServiceTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->assertEquals('After Reference', $returnValue->getReference());
|
$this->assertEquals('After Reference', $returnValue->getReference());
|
||||||
$this->assertEquals('bitbucket', $returnValue->getType());
|
$this->assertEquals('bitbucket', $returnValue->getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers PHPUnit::execute
|
||||||
|
*/
|
||||||
|
public function testExecute_EmptyPublicStatus()
|
||||||
|
{
|
||||||
|
$project = new Project();
|
||||||
|
$project->setAllowPublicStatus(1);
|
||||||
|
|
||||||
|
$options = array(
|
||||||
|
'ssh_private_key' => 'private',
|
||||||
|
'ssh_public_key' => 'public',
|
||||||
|
'build_config' => 'config',
|
||||||
|
);
|
||||||
|
|
||||||
|
$returnValue = $this->testedService->updateProject($project, 'Test Project', 'github', 'block8/phpci', $options);
|
||||||
|
|
||||||
|
$this->assertEquals(0, $returnValue->getAllowPublicStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers PHPUnit::execute
|
||||||
|
*/
|
||||||
|
public function testExecute_DeleteProject()
|
||||||
|
{
|
||||||
|
$store = $this->getMock('PHPCI\Store\ProjectStore');
|
||||||
|
$store->expects($this->once())
|
||||||
|
->method('delete')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
|
$service = new ProjectService($store);
|
||||||
|
$project = new Project();
|
||||||
|
|
||||||
|
$this->assertEquals(true, $service->deleteProject($project));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue