groupManager = $this->createMock(IGroupManager::class); $this->command = new Add($this->groupManager); $this->input = $this->createMock(InputInterface::class); $this->input->method('getArgument') ->willReturnCallback(function ($arg) { if ($arg === 'groupid') { return 'myGroup'; } throw new \Exception(); }); $this->output = $this->createMock(OutputInterface::class); } public function testGroupExists(): void { $gid = 'myGroup'; $group = $this->createMock(IGroup::class); $this->groupManager->method('get') ->with($gid) ->willReturn($group); $this->groupManager->expects($this->never()) ->method('createGroup'); $this->output->expects($this->once()) ->method('writeln') ->with($this->equalTo('Group "' . $gid . '" already exists.')); $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); } public function testAdd(): void { $gid = 'myGroup'; $group = $this->createMock(IGroup::class); $group->method('getGID') ->willReturn($gid); $this->groupManager->method('createGroup') ->willReturn($group); $this->groupManager->expects($this->once()) ->method('createGroup') ->with($this->equalTo($gid)); $this->output->expects($this->once()) ->method('writeln') ->with($this->equalTo('Created group "' . $group->getGID() . '"')); $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); } }