Skip to content
Snippets Groups Projects
Unverified Commit f574a9d4 authored by Joas Schilling's avatar Joas Schilling
Browse files

Make sure the exception is catched

parent 01899b8c
No related branches found
No related tags found
No related merge requests found
...@@ -37,9 +37,6 @@ class SettingTest extends TestCase { ...@@ -37,9 +37,6 @@ class SettingTest extends TestCase {
/** @var \Symfony\Component\Console\Output\OutputInterface|\PHPUnit_Framework_MockObject_MockObject */ /** @var \Symfony\Component\Console\Output\OutputInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $consoleOutput; protected $consoleOutput;
/** @var \Symfony\Component\Console\Command\Command */
protected $command;
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
...@@ -58,8 +55,23 @@ class SettingTest extends TestCase { ...@@ -58,8 +55,23 @@ class SettingTest extends TestCase {
$this->consoleOutput = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface') $this->consoleOutput = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
}
public function getCommand(array $methods = []) {
if (empty($methods)) {
return new Setting($this->userManager, $this->config, $this->connection);
} else {
$mock = $this->getMockBuilder('OC\Core\Command\User\Setting')
->setConstructorArgs([
$this->userManager,
$this->config,
$this->connection,
])
->setMethods($methods)
->getMock();
return $mock;
}
$this->command = new Setting($this->userManager, $this->config, $this->connection);
} }
public function dataCheckInput() { public function dataCheckInput() {
...@@ -201,11 +213,25 @@ class SettingTest extends TestCase { ...@@ -201,11 +213,25 @@ class SettingTest extends TestCase {
->willReturn($user); ->willReturn($user);
} }
$command = $this->getCommand();
try { try {
$this->invokePrivate($this->command, 'checkInput', [$this->consoleInput]); $this->invokePrivate($command, 'checkInput', [$this->consoleInput]);
$this->assertFalse($expectedException); $this->assertFalse($expectedException);
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {
$this->assertEquals($expectedException, $e->getMessage()); $this->assertEquals($expectedException, $e->getMessage());
} }
} }
public function testCheckInputExceptionCatch() {
$command = $this->getCommand(['checkInput']);
$command->expects($this->once())
->method('checkInput')
->willThrowException(new \InvalidArgumentException('test'));
$this->consoleOutput->expects($this->once())
->method('writeln')
->with('<error>test</error>');
$this->assertEquals(1, $this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput]));
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment