summaryrefslogtreecommitdiffstats
path: root/tests/Core/Command
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2016-06-13 16:16:16 +0200
committerJoas Schilling <coding@schilljs.com>2016-07-13 18:43:53 +0200
commitf574a9d44f28b9d2279adbc63ae4a3a98ec19b10 (patch)
tree3065299c5fc9f50b80c987729c41551af2bb0775 /tests/Core/Command
parent01899b8cf1f8b00aae72798cdb02ad71b1972288 (diff)
downloadnextcloud-server-f574a9d44f28b9d2279adbc63ae4a3a98ec19b10.tar.gz
nextcloud-server-f574a9d44f28b9d2279adbc63ae4a3a98ec19b10.zip
Make sure the exception is catched
Diffstat (limited to 'tests/Core/Command')
-rw-r--r--tests/Core/Command/User/SettingTest.php36
1 files changed, 31 insertions, 5 deletions
diff --git a/tests/Core/Command/User/SettingTest.php b/tests/Core/Command/User/SettingTest.php
index 1ed275d6673..a40aeb748e8 100644
--- a/tests/Core/Command/User/SettingTest.php
+++ b/tests/Core/Command/User/SettingTest.php
@@ -37,9 +37,6 @@ class SettingTest extends TestCase {
/** @var \Symfony\Component\Console\Output\OutputInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $consoleOutput;
- /** @var \Symfony\Component\Console\Command\Command */
- protected $command;
-
protected function setUp() {
parent::setUp();
@@ -58,8 +55,23 @@ class SettingTest extends TestCase {
$this->consoleOutput = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')
->disableOriginalConstructor()
->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() {
@@ -201,11 +213,25 @@ class SettingTest extends TestCase {
->willReturn($user);
}
+ $command = $this->getCommand();
try {
- $this->invokePrivate($this->command, 'checkInput', [$this->consoleInput]);
+ $this->invokePrivate($command, 'checkInput', [$this->consoleInput]);
$this->assertFalse($expectedException);
} catch (\InvalidArgumentException $e) {
$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]));
+ }
}