config = $this->createMock(IConfig::class); $this->command = new Delete($this->config); $this->input = $this->createMock(InputInterface::class); $this->output = $this->createMock(OutputInterface::class); } public function testAddDefaultServerIfEmpty(): void { $this->input->method('getArgument') ->with('server') ->willReturn('stun1.test.com:443'); $this->config->expects($this->once()) ->method('getAppValue') ->with('spreed', 'stun_servers') ->willReturn(''); $this->config->expects($this->once()) ->method('setAppValue') ->with( $this->equalTo('spreed'), $this->equalTo('stun_servers'), $this->equalTo(json_encode(['stun.nextcloud.com:443'])) ); $this->output->expects($this->once()) ->method('writeln') ->with($this->equalTo('You deleted all STUN servers. A default STUN server was added.')); self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } public function testDelete(): void { $this->input->method('getArgument') ->with('server') ->willReturn('stun1.test.com:443'); $this->config->expects($this->once()) ->method('getAppValue') ->with('spreed', 'stun_servers') ->willReturn(json_encode(['stun1.test.com:443', 'stun2.test.com:443'])); $this->config->expects($this->once()) ->method('setAppValue') ->with( $this->equalTo('spreed'), $this->equalTo('stun_servers'), $this->equalTo(json_encode(['stun2.test.com:443'])) ); $this->output->expects($this->once()) ->method('writeln') ->with($this->equalTo('Deleted stun1.test.com:443.')); self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } public function testNothingToDelete(): void { $this->input->method('getArgument') ->with('server') ->willReturn('stun3.test.com:443'); $this->config->expects($this->once()) ->method('getAppValue') ->with('spreed', 'stun_servers') ->willReturn(json_encode(['stun1.test.com:443'])); $this->config->expects($this->once()) ->method('setAppValue') ->with( $this->equalTo('spreed'), $this->equalTo('stun_servers'), $this->equalTo(json_encode(['stun1.test.com:443'])) ); $this->output->expects($this->once()) ->method('writeln') ->with($this->equalTo('There is nothing to delete.')); self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } }