parent
77ba61c8bc
commit
9261f24d25
85
PHPCI/Command/CreateBuildCommand.php
Normal file
85
PHPCI/Command/CreateBuildCommand.php
Normal file
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCI\Command;
|
||||
|
||||
use PHPCI\Helper\Lang;
|
||||
use PHPCI\Service\BuildService;
|
||||
use PHPCI\Store\ProjectStore;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* Create build command - creates a build for a project
|
||||
* @author Jérémy DECOOL (@jdecool)
|
||||
* @package PHPCI
|
||||
* @subpackage Console
|
||||
*/
|
||||
class CreateBuildCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var ProjectStore
|
||||
*/
|
||||
protected $projectStore;
|
||||
|
||||
/**
|
||||
* @var BuildService
|
||||
*/
|
||||
protected $buildService;
|
||||
|
||||
/**
|
||||
* @param ProjectStore $projectStore
|
||||
*/
|
||||
public function __construct(ProjectStore $projectStore, BuildService $buildService)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->projectStore = $projectStore;
|
||||
$this->buildService = $buildService;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('phpci:create-build')
|
||||
->setDescription(Lang::get('create_build_project'))
|
||||
->addArgument('projectId', InputArgument::REQUIRED, Lang::get('project_id_argument'))
|
||||
->addOption('commit', null, InputOption::VALUE_OPTIONAL, Lang::get('commit_id_option'))
|
||||
->addOption('branch', null, InputOption::VALUE_OPTIONAL, Lang::get('branch_name_option'));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$projectId = $input->getArgument('projectId');
|
||||
$commitId = $input->getOption('commit');
|
||||
$branch = $input->getOption('branch');
|
||||
|
||||
$project = $this->projectStore->getById($projectId);
|
||||
if (empty($project)) {
|
||||
throw new \InvalidArgumentException('Project does not exist: ' . $projectId);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->buildService->createBuild($project, $commitId, $branch);
|
||||
$output->writeln(Lang::get('build_created'));
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln(sprintf('<error>%s</error>', Lang::get('failed')));
|
||||
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -338,6 +338,12 @@ Kontrollér venligst nedenstående fejl før du fortsætter.',
|
|||
'create_admin_user' => 'Tilføj en administrator',
|
||||
'incorrect_format' => 'Forkert format',
|
||||
|
||||
// Create Build Command
|
||||
'create_build_project' => 'Create a build for a project',
|
||||
'project_id_argument' => 'A project ID',
|
||||
'commit_id_option' => 'Commit ID to build',
|
||||
'branch_name_option' => 'Branch to build',
|
||||
|
||||
// Run Command
|
||||
'run_all_pending' => 'Kør alle PHPCI builds i køen.',
|
||||
'finding_builds' => 'Finder builds der skal køres',
|
||||
|
|
|
@ -336,6 +336,12 @@ generiert. Um es zu verwenden, fügen Sie einfach den folgenden Public Key im Ab
|
|||
'create_admin_user' => 'Administratorenbenutzer erstellen',
|
||||
'incorrect_format' => 'Falsches Format',
|
||||
|
||||
// Create Build Command
|
||||
'create_build_project' => 'Create a build for a project',
|
||||
'project_id_argument' => 'A project ID',
|
||||
'commit_id_option' => 'Commit ID to build',
|
||||
'branch_name_option' => 'Branch to build',
|
||||
|
||||
// Run Command
|
||||
'run_all_pending' => 'Führe alle ausstehenden PHPCI Builds aus.',
|
||||
'finding_builds' => 'Suche verarbeitbare Builds',
|
||||
|
|
|
@ -339,6 +339,12 @@ Services</a> του Bitbucket αποθετηρίου σας.',
|
|||
'create_admin_user' => 'Δημιουργήστε ένα χρήστη διαχειριστή',
|
||||
'incorrect_format' => 'Λανθασμένη μορφοποίηση',
|
||||
|
||||
// Create Build Command
|
||||
'create_build_project' => 'Create a build for a project',
|
||||
'project_id_argument' => 'A project ID',
|
||||
'commit_id_option' => 'Commit ID to build',
|
||||
'branch_name_option' => 'Branch to build',
|
||||
|
||||
// Run Command
|
||||
'run_all_pending' => 'Εκτελέστε όλες τις εκκρεμείς PHPCI κατασκευές.',
|
||||
'finding_builds' => 'Αναζήτηση κατασκευών για επεξεργασία',
|
||||
|
|
|
@ -343,6 +343,12 @@ PHPCI',
|
|||
'create_admin_user' => 'Create an admin user',
|
||||
'incorrect_format' => 'Incorrect format',
|
||||
|
||||
// Create Build Command
|
||||
'create_build_project' => 'Create a build for a project',
|
||||
'project_id_argument' => 'A project ID',
|
||||
'commit_id_option' => 'Commit ID to build',
|
||||
'branch_name_option' => 'Branch to build',
|
||||
|
||||
// Run Command
|
||||
'run_all_pending' => 'Run all pending PHPCI builds.',
|
||||
'finding_builds' => 'Finding builds to process',
|
||||
|
|
|
@ -340,6 +340,12 @@ PHPCI',
|
|||
'create_admin_user' => 'Créer un utilisateur admin',
|
||||
'incorrect_format' => 'Format incorrect',
|
||||
|
||||
// Create Build Command
|
||||
'create_build_project' => 'Créer un build projet',
|
||||
'project_id_argument' => 'ID du projet',
|
||||
'commit_id_option' => 'ID du commit',
|
||||
'branch_name_option' => 'Branche',
|
||||
|
||||
// Run Command
|
||||
'run_all_pending' => 'Démarrage de tout les builds PHPCI en attente.',
|
||||
'finding_builds' => 'Découverte des builds à traiter',
|
||||
|
|
|
@ -342,6 +342,12 @@ PHPCI',
|
|||
'create_admin_user' => 'Crea un nuovo utente amministrarore',
|
||||
'incorrect_format' => 'Formato errato',
|
||||
|
||||
// Create Build Command
|
||||
'create_build_project' => 'Create a build for a project',
|
||||
'project_id_argument' => 'A project ID',
|
||||
'commit_id_option' => 'Commit ID to build',
|
||||
'branch_name_option' => 'Branch to build',
|
||||
|
||||
// Run Command
|
||||
'run_all_pending' => 'Esegui tutte le build in attesa su PHPCI.',
|
||||
'finding_builds' => 'Ricerca delel build da processare',
|
||||
|
|
|
@ -340,6 +340,12 @@ Gelieve de fouten na te kijken vooraleer verder te gaan.',
|
|||
'create_admin_user' => 'Administrator-gebruiker aanmaken',
|
||||
'incorrect_format' => 'Incorrect formaat',
|
||||
|
||||
// Create Build Command
|
||||
'create_build_project' => 'Create a build for a project',
|
||||
'project_id_argument' => 'A project ID',
|
||||
'commit_id_option' => 'Commit ID to build',
|
||||
'branch_name_option' => 'Branch to build',
|
||||
|
||||
// Run Command
|
||||
'run_all_pending' => 'Voer alle wachtende PHPCI builds uit.',
|
||||
'finding_builds' => 'Zoekt builds om te verwerken',
|
||||
|
|
|
@ -341,6 +341,12 @@ Przejrzyj powyższą listę błędów przed kontynuowaniem.',
|
|||
'create_admin_user' => 'Utwórz admina',
|
||||
'incorrect_format' => 'Niepoprawny format',
|
||||
|
||||
// Create Build Command
|
||||
'create_build_project' => 'Create a build for a project',
|
||||
'project_id_argument' => 'A project ID',
|
||||
'commit_id_option' => 'Commit ID to build',
|
||||
'branch_name_option' => 'Branch to build',
|
||||
|
||||
// Run Command
|
||||
'run_all_pending' => 'Uruchom wszystkie oczekujące budowy w PHPCI',
|
||||
'finding_builds' => 'Szukam budów do przetwarzania.',
|
||||
|
|
|
@ -336,6 +336,12 @@ PHPCI',
|
|||
'create_admin_user' => 'Добавить аккаунт администратора',
|
||||
'incorrect_format' => 'Неверный формат',
|
||||
|
||||
// Create Build Command
|
||||
'create_build_project' => 'Create a build for a project',
|
||||
'project_id_argument' => 'A project ID',
|
||||
'commit_id_option' => 'Commit ID to build',
|
||||
'branch_name_option' => 'Branch to build',
|
||||
|
||||
// Run Command
|
||||
'run_all_pending' => 'Запустить все ожидающие PHPCI сборки.',
|
||||
'finding_builds' => 'Поиск сборок для запуска',
|
||||
|
|
|
@ -340,6 +340,12 @@ PHPCI',
|
|||
'create_admin_user' => 'Створити аккаунт адміністратора',
|
||||
'incorrect_format' => 'Невірний формат',
|
||||
|
||||
// Create Build Command
|
||||
'create_build_project' => 'Create a build for a project',
|
||||
'project_id_argument' => 'A project ID',
|
||||
'commit_id_option' => 'Commit ID to build',
|
||||
'branch_name_option' => 'Branch to build',
|
||||
|
||||
// Run Command
|
||||
'run_all_pending' => 'Запустити всі PHPCI збірки, які очікують.',
|
||||
'finding_builds' => 'Пошук збірок для обробки',
|
||||
|
|
86
Tests/PHPCI/Command/CreateBuildCommandTest.php
Normal file
86
Tests/PHPCI/Command/CreateBuildCommandTest.php
Normal file
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link http://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace Tests\PHPCI\Command;
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class CreateBuildCommandTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \PHPCI\Command\CreateAdminCommand|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $command;
|
||||
|
||||
/**
|
||||
* @var \Symfony\Component\Console\Application|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $application;
|
||||
|
||||
public function setup()
|
||||
{
|
||||
parent::setup();
|
||||
|
||||
$projectMock = $this->getMock('PHPCI\\Model\\Project');
|
||||
|
||||
$projectStoreMock = $this->getMockBuilder('PHPCI\\Store\\ProjectStore')
|
||||
->getMock();
|
||||
$projectStoreMock->method('getById')
|
||||
->will($this->returnValueMap(array(
|
||||
array(1, 'read', $projectMock),
|
||||
array(2, 'read', null),
|
||||
)));
|
||||
|
||||
$buildServiceMock = $this->getMockBuilder('PHPCI\\Service\\BuildService')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$buildServiceMock->method('createBuild')
|
||||
->withConsecutive(
|
||||
array($projectMock, null, null, null, null, null),
|
||||
array($projectMock, '92c8c6e', null, null, null, null),
|
||||
array($projectMock, null, 'master', null, null, null)
|
||||
);
|
||||
|
||||
$this->command = $this->getMockBuilder('PHPCI\\Command\\CreateBuildCommand')
|
||||
->setConstructorArgs(array($projectStoreMock, $buildServiceMock))
|
||||
->setMethods(array('reloadConfig'))
|
||||
->getMock();
|
||||
|
||||
$this->application = new Application();
|
||||
}
|
||||
|
||||
protected function getCommandTester()
|
||||
{
|
||||
$this->application->add($this->command);
|
||||
|
||||
$command = $this->application->find('phpci:create-build');
|
||||
$commandTester = new CommandTester($command);
|
||||
|
||||
return $commandTester;
|
||||
}
|
||||
|
||||
public function testExecute()
|
||||
{
|
||||
$commandTester = $this->getCommandTester();
|
||||
|
||||
$commandTester->execute(array('projectId' => 1));
|
||||
$commandTester->execute(array('projectId' => 1, '--commit' => '92c8c6e'));
|
||||
$commandTester->execute(array('projectId' => 1, '--branch' => 'master'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testExecuteWithUnknowProjectId()
|
||||
{
|
||||
$commandTester = $this->getCommandTester();
|
||||
$commandTester->execute(array('projectId' => 2));
|
||||
}
|
||||
}
|
3
console
3
console
|
@ -20,6 +20,8 @@ use PHPCI\Command\InstallCommand;
|
|||
use PHPCI\Command\DaemonCommand;
|
||||
use PHPCI\Command\PollCommand;
|
||||
use PHPCI\Command\CreateAdminCommand;
|
||||
use PHPCI\Command\CreateBuildCommand;
|
||||
use PHPCI\Service\BuildService;
|
||||
use Symfony\Component\Console\Application;
|
||||
use b8\Store\Factory;
|
||||
|
||||
|
@ -33,5 +35,6 @@ $application->add(new GenerateCommand);
|
|||
$application->add(new DaemonCommand($loggerConfig->getFor('DaemonCommand')));
|
||||
$application->add(new PollCommand($loggerConfig->getFor('PollCommand')));
|
||||
$application->add(new CreateAdminCommand(Factory::getStore('User')));
|
||||
$application->add(new CreateBuildCommand(Factory::getStore('Project'), new BuildService(Factory::getStore('Build'))));
|
||||
|
||||
$application->run();
|
||||
|
|
Loading…
Reference in a new issue