config = $this->createMock(IConfig::class); $this->command = new Add($this->config); $this->input = $this->createMock(InputInterface::class); $this->output = $this->createMock(OutputInterface::class); } public function testMalformedServerString(): void { $this->input->method('getArgument') ->with('server') ->willReturn('stun.test.com'); $this->output->expects($this->once()) ->method('writeln') ->with($this->equalTo('Incorrect value. Must be stunserver:port.')); $this->config->expects($this->never()) ->method('setAppValue'); self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } public function testAddServerToEmptyList(): void { $this->input->method('getArgument') ->with('server') ->willReturn('stun.test.com:443'); $this->config->method('getAppValue') ->with('spreed', 'stun_servers') ->willReturn(json_encode([])); $this->config->expects($this->once()) ->method('setAppValue') ->with( $this->equalTo('spreed'), $this->equalTo('stun_servers'), $this->equalTo(json_encode(['stun.test.com:443'])) ); $this->output->expects($this->once()) ->method('writeln') ->with($this->equalTo('Added stun.test.com:443.')); self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } public function testAddServerToNonEmptyList(): void { $this->input->method('getArgument') ->with('server') ->willReturn('stun2.test.com:443'); $this->config->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', 'stun2.test.com:443'])) ); $this->output->expects($this->once()) ->method('writeln') ->with($this->equalTo('Added stun2.test.com:443.')); self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } public function testAddDuplicateServer(): void { $this->input->method('getArgument') ->with('server') ->willReturn('stun.test.com:443'); $this->config->method('getAppValue') ->with('spreed', 'stun_servers') ->willReturn(json_encode(['stun.test.com:443'])); $this->config->expects($this->never()) ->method('setAppValue'); $this->output->expects($this->once()) ->method('writeln') ->with($this->equalTo('Server already exists.')); $this->assertSame(1, self::invokePrivate($this->command, 'execute', [$this->input, $this->output])); } }