You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.9 KiB

  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2018, Denis Mosolov <denismosolov@gmail.com>
  5. *
  6. * @author Denis Mosolov <denismosolov@gmail.com>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Afferoq General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\Talk\Tests\php\Command\Signaling;
  25. use OCA\Talk\Command\Signaling\ListCommand;
  26. use OCP\IConfig;
  27. use PHPUnit\Framework\MockObject\MockObject;
  28. use Symfony\Component\Console\Input\InputInterface;
  29. use Symfony\Component\Console\Output\OutputInterface;
  30. use Test\TestCase;
  31. class ListCommandTest extends TestCase {
  32. protected IConfig&MockObject $config;
  33. protected InputInterface&MockObject $input;
  34. protected OutputInterface&MockObject $output;
  35. protected ListCommand&MockObject $command;
  36. public function setUp(): void {
  37. parent::setUp();
  38. $this->config = $this->createMock(IConfig::class);
  39. $this->command = $this->getMockBuilder(ListCommand::class)
  40. ->setConstructorArgs([$this->config])
  41. ->onlyMethods(['writeMixedInOutputFormat'])
  42. ->getMock();
  43. $this->input = $this->createMock(InputInterface::class);
  44. $this->output = $this->createMock(OutputInterface::class);
  45. }
  46. public function testEmptyAppConfig(): void {
  47. $this->config->expects($this->once())
  48. ->method('getAppValue')
  49. ->with('spreed', 'signaling_servers')
  50. ->willReturn(json_encode([]));
  51. $this->command->expects($this->once())
  52. ->method('writeMixedInOutputFormat')
  53. ->with(
  54. $this->equalTo($this->input),
  55. $this->equalTo($this->output),
  56. $this->equalTo([])
  57. );
  58. self::invokePrivate($this->command, 'execute', [$this->input, $this->output]);
  59. }
  60. public function testAppConfigDataChanges(): void {
  61. $this->config->expects($this->once())
  62. ->method('getAppValue')
  63. ->with('spreed', 'signaling_servers')
  64. ->willReturn(json_encode([
  65. 'servers' => [
  66. [
  67. 'server' => 'wss://signaling.example.com',
  68. 'verify' => true
  69. ]
  70. ],
  71. 'secret' => 'my-test-secret'
  72. ]));
  73. $this->command->expects($this->once())
  74. ->method('writeMixedInOutputFormat')
  75. ->with(
  76. $this->equalTo($this->input),
  77. $this->equalTo($this->output),
  78. $this->equalTo([
  79. 'servers' => [
  80. [
  81. 'server' => 'wss://signaling.example.com',
  82. 'verify' => true
  83. ]
  84. ],
  85. 'secret' => 'my-test-secret'
  86. ])
  87. );
  88. self::invokePrivate($this->command, 'execute', [$this->input, $this->output]);
  89. }
  90. }