2014-12-04 12:31:21 +01:00
|
|
|
<?php
|
2015-03-03 17:18:17 +01:00
|
|
|
|
2014-12-04 12:31:21 +01:00
|
|
|
/**
|
|
|
|
* PHPCI - Continuous Integration for PHP
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2014, Block 8 Limited.
|
2015-03-03 17:18:17 +01:00
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
|
|
|
* @link https://www.phptesting.org/
|
2014-12-04 12:31:21 +01:00
|
|
|
*/
|
|
|
|
|
2015-03-03 17:18:17 +01:00
|
|
|
namespace Tests\PHPCI\Plugin\Command;
|
2014-12-04 12:31:21 +01:00
|
|
|
|
|
|
|
use Symfony\Component\Console\Application;
|
|
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
|
|
|
|
|
|
|
class CreateAdminCommandTest 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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Symfony\Component\Console\Helper\DialogHelper|\PHPUnit_Framework_MockObject_MockObject
|
|
|
|
*/
|
|
|
|
protected $dialog;
|
|
|
|
|
|
|
|
public function setup()
|
|
|
|
{
|
|
|
|
parent::setup();
|
|
|
|
|
|
|
|
$this->command = $this->getMockBuilder('PHPCI\\Command\\CreateAdminCommand')
|
2015-03-03 17:18:17 +01:00
|
|
|
->setConstructorArgs(array($this->getMock('PHPCI\\Store\\UserStore')))
|
|
|
|
->setMethods(array('reloadConfig'))
|
2014-12-04 12:31:21 +01:00
|
|
|
->getMock()
|
|
|
|
;
|
|
|
|
|
|
|
|
$this->dialog = $this->getMockBuilder('Symfony\\Component\\Console\\Helper\\DialogHelper')
|
2015-03-03 17:18:17 +01:00
|
|
|
->setMethods(array(
|
2014-12-04 12:31:21 +01:00
|
|
|
'ask',
|
|
|
|
'askAndValidate',
|
|
|
|
'askHiddenResponse',
|
2015-03-03 17:18:17 +01:00
|
|
|
))
|
2014-12-04 12:31:21 +01:00
|
|
|
->getMock()
|
|
|
|
;
|
|
|
|
|
|
|
|
$this->application = new Application();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return CommandTester
|
|
|
|
*/
|
|
|
|
protected function getCommandTester()
|
|
|
|
{
|
|
|
|
$this->application->getHelperSet()->set($this->dialog, 'dialog');
|
|
|
|
$this->application->add($this->command);
|
|
|
|
$command = $this->application->find('phpci:create-admin');
|
|
|
|
$commandTester = new CommandTester($command);
|
|
|
|
|
|
|
|
return $commandTester;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExecute()
|
|
|
|
{
|
|
|
|
$this->dialog->expects($this->at(0))->method('askAndValidate')->will($this->returnValue('test@example.com'));
|
|
|
|
$this->dialog->expects($this->at(1))->method('ask')->will($this->returnValue('A name'));
|
|
|
|
$this->dialog->expects($this->at(2))->method('askHiddenResponse')->will($this->returnValue('foobar123'));
|
|
|
|
|
|
|
|
$commandTester = $this->getCommandTester();
|
2015-03-03 17:18:17 +01:00
|
|
|
$commandTester->execute(array());
|
2014-12-04 12:31:21 +01:00
|
|
|
|
|
|
|
$this->assertEquals('User account created!' . PHP_EOL, $commandTester->getDisplay());
|
|
|
|
}
|
|
|
|
}
|