php-censor/tests/PHPCensor/Command/CreateAdminCommandTest.php

78 lines
2.3 KiB
PHP
Raw Normal View History

2014-12-04 12:31:21 +01:00
<?php
2014-12-04 12:31:21 +01:00
/**
* 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/
2014-12-04 12:31:21 +01:00
*/
2016-07-19 20:28:11 +02:00
namespace Tests\PHPCensor\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();
2016-07-19 20:28:11 +02:00
$this->command = $this->getMockBuilder('PHPCensor\\Command\\CreateAdminCommand')
->setConstructorArgs([$this->getMock('PHPCensor\\Store\\UserStore')])
2016-04-21 09:46:38 +02:00
->setMethods(['reloadConfig'])
->getMock();
2014-12-04 12:31:21 +01:00
$this->dialog = $this->getMockBuilder('Symfony\\Component\\Console\\Helper\\DialogHelper')
2016-04-21 09:46:38 +02:00
->setMethods([
2014-12-04 12:31:21 +01:00
'ask',
'askAndValidate',
'askHiddenResponse',
2016-04-21 09:46:38 +02:00
])->getMock()
2014-12-04 12:31:21 +01:00
;
$this->application = new Application();
}
/**
* @return CommandTester
*/
protected function getCommandTester()
{
$this->application->getHelperSet()->set($this->dialog, 'dialog');
$this->application->add($this->command);
2016-07-21 19:02:11 +02:00
$command = $this->application->find('php-censor:create-admin');
2014-12-04 12:31:21 +01:00
$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();
2016-04-21 06:58:09 +02:00
$commandTester->execute([]);
2014-12-04 12:31:21 +01:00
$this->assertEquals('User account created!' . PHP_EOL, $commandTester->getDisplay());
}
}