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

66 lines
1.9 KiB
PHP
Raw Normal View History

2014-12-04 12:31:21 +01:00
<?php
2018-03-04 12:04:15 +01:00
namespace Tests\PHPCensor\Command;
2014-12-04 12:31:21 +01:00
use PHPCensor\Command\CreateAdminCommand;
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
2014-12-04 12:31:21 +01:00
{
/**
* @var \PHPCensor\Command\CreateAdminCommand|\PHPUnit_Framework_MockObject_MockObject
2014-12-04 12:31:21 +01:00
*/
protected $command;
/**
* @var \Symfony\Component\Console\Application|\PHPUnit_Framework_MockObject_MockObject
*/
protected $application;
/**
* @var \Symfony\Component\Console\Helper\QuestionHelper|\PHPUnit_Framework_MockObject_MockObject
2014-12-04 12:31:21 +01:00
*/
protected $helper;
2014-12-04 12:31:21 +01:00
public function setUp()
2014-12-04 12:31:21 +01:00
{
parent::setUp();
2014-12-04 12:31:21 +01:00
2017-01-09 17:23:29 +01:00
$userStoreMock = $this->getMockBuilder('PHPCensor\\Store\\UserStore')->getMock();
2018-02-16 10:41:56 +01:00
$this->command = new CreateAdminCommand($userStoreMock);
2014-12-04 12:31:21 +01:00
$this->helper = $this
->getMockBuilder('Symfony\\Component\\Console\\Helper\\QuestionHelper')
->setMethods(['ask'])
->getMock();
2014-12-04 12:31:21 +01:00
$this->application = new Application();
}
/**
* @return CommandTester
*/
protected function getCommandTester()
{
$this->application->getHelperSet()->set($this->helper, 'question');
2014-12-04 12:31:21 +01:00
$this->application->add($this->command);
$commandTester = new CommandTester($this->command);
2014-12-04 12:31:21 +01:00
return $commandTester;
}
public function testExecute()
{
$this->helper->expects($this->at(0))->method('ask')->will($this->returnValue('test@example.com'));
$this->helper->expects($this->at(1))->method('ask')->will($this->returnValue('A name'));
$this->helper->expects($this->at(2))->method('ask')->will($this->returnValue('foobar123'));
2014-12-04 12:31:21 +01:00
$commandTester = $this->getCommandTester();
2016-04-21 06:58:09 +02:00
$commandTester->execute([]);
2014-12-04 12:31:21 +01:00
2018-02-16 10:41:56 +01:00
self::assertEquals('User account created!' . PHP_EOL, $commandTester->getDisplay());
2014-12-04 12:31:21 +01:00
}
}