groupManager = $this->createMock(IGroupManager::class);
$this->command = new Delete($this->groupManager);
$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('groupExists')
->with($gid)
->willReturn(false);
$this->groupManager->expects($this->never())
->method('get');
$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 testDeleteAdmin() {
$gid = 'admin';
$this->input->method('getArgument')
->willReturnCallback(function ($arg) use ($gid) {
if ($arg === 'groupid') {
return $gid;
}
throw new \Exception();
});
$this->groupManager->expects($this->never())
->method($this->anything());
$this->output->expects($this->once())
->method('writeln')
->with($this->equalTo('Group "' . $gid . '" could not be deleted.'));
$this->invokePrivate($this->command, 'execute', [$this->input, $this->output]);
}
public function testDeleteFailed() {
$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('delete')
->willReturn(false);
$this->groupManager->method('groupExists')
->with($gid)
->willReturn(true);
$this->groupManager->method('get')
->with($gid)
->willReturn($group);
$this->output->expects($this->once())
->method('writeln')
->with($this->equalTo('Group "' . $gid . '" could not be deleted. Please check the logs.'));
$this->invokePrivate($this->command, 'execute', [$this->input, $this->output]);
}
public function testDelete() {
$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('delete')
->willReturn(true);
$this->groupManager->method('groupExists')
->with($gid)
->willReturn(true);
$this->groupManager->method('get')
->with($gid)
->willReturn($group);
$this->output->expects($this->once())
->method('writeln')
->with($this->equalTo('Group "' . $gid . '" was removed'));
$this->invokePrivate($this->command, 'execute', [$this->input, $this->output]);
}
}