InfoTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2021, hosting.de, Johannes Leuker <developers@hosting.de>
  4. *
  5. * @author Johannes Leuker <developers@hosting.de>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Afferoq General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace Test\Core\Command\Group;
  24. use OC\Core\Command\Group\Info;
  25. use OCP\IGroup;
  26. use OCP\IGroupManager;
  27. use Symfony\Component\Console\Input\InputInterface;
  28. use Symfony\Component\Console\Output\OutputInterface;
  29. use Test\TestCase;
  30. class InfoTest extends TestCase {
  31. /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
  32. private $groupManager;
  33. /** @var Info|\PHPUnit\Framework\MockObject\MockObject */
  34. private $command;
  35. /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */
  36. private $input;
  37. /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */
  38. private $output;
  39. protected function setUp(): void {
  40. parent::setUp();
  41. $this->groupManager = $this->createMock(IGroupManager::class);
  42. $this->command = $this->getMockBuilder(Info::class)
  43. ->setConstructorArgs([$this->groupManager])
  44. ->setMethods(['writeArrayInOutputFormat'])
  45. ->getMock();
  46. $this->input = $this->createMock(InputInterface::class);
  47. $this->output = $this->createMock(OutputInterface::class);
  48. }
  49. public function testDoesNotExists() {
  50. $gid = 'myGroup';
  51. $this->input->method('getArgument')
  52. ->willReturnCallback(function ($arg) use ($gid) {
  53. if ($arg === 'groupid') {
  54. return $gid;
  55. }
  56. throw new \Exception();
  57. });
  58. $this->groupManager->method('get')
  59. ->with($gid)
  60. ->willReturn(null);
  61. $this->output->expects($this->once())
  62. ->method('writeln')
  63. ->with($this->equalTo('<error>Group "' . $gid . '" does not exist.</error>'));
  64. $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]);
  65. }
  66. public function testInfo() {
  67. $gid = 'myGroup';
  68. $this->input->method('getArgument')
  69. ->willReturnCallback(function ($arg) use ($gid) {
  70. if ($arg === 'groupid') {
  71. return $gid;
  72. }
  73. throw new \Exception();
  74. });
  75. $group = $this->createMock(IGroup::class);
  76. $group->method('getGID')->willReturn($gid);
  77. $group->method('getDisplayName')
  78. ->willReturn('My Group');
  79. $group->method('getBackendNames')
  80. ->willReturn(['Database']);
  81. $this->groupManager->method('get')
  82. ->with($gid)
  83. ->willReturn($group);
  84. $this->command->expects($this->once())
  85. ->method('writeArrayInOutputFormat')
  86. ->with(
  87. $this->equalTo($this->input),
  88. $this->equalTo($this->output),
  89. [
  90. 'groupID' => 'myGroup',
  91. 'displayName' => 'My Group',
  92. 'backends' => ['Database'],
  93. ]
  94. );
  95. $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]);
  96. }
  97. }