groupManager = $this->createMock(IGroupManager::class); $this->command = $this->getMockBuilder(Info::class) ->setConstructorArgs([$this->groupManager]) ->setMethods(['writeArrayInOutputFormat']) ->getMock(); $this->input = $this->createMock(InputInterface::class); $this->output = $this->createMock(OutputInterface::class); } public function testDoesNotExists() { $gid = 'myGroup'; $this->input->method('getArgument') ->willReturnCallback(function ($arg) use ($gid) { if ($arg === 'groupid') { return $gid; } throw new \Exception(); }); $this->groupManager->method('get') ->with($gid) ->willReturn(null); $this->output->expects($this->once()) ->method('writeln') ->with($this->equalTo('Group "' . $gid . '" does not exist.')); $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); } public function testInfo() { $gid = 'myGroup'; $this->input->method('getArgument') ->willReturnCallback(function ($arg) use ($gid) { if ($arg === 'groupid') { return $gid; } throw new \Exception(); }); $group = $this->createMock(IGroup::class); $group->method('getGID')->willReturn($gid); $group->method('getDisplayName') ->willReturn('My Group'); $group->method('getBackendNames') ->willReturn(['Database']); $this->groupManager->method('get') ->with($gid) ->willReturn($group); $this->command->expects($this->once()) ->method('writeArrayInOutputFormat') ->with( $this->equalTo($this->input), $this->equalTo($this->output), [ 'groupID' => 'myGroup', 'displayName' => 'My Group', 'backends' => ['Database'], ] ); $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); } }