protected function executeRoleCommand(UserManipulator $manipulator, OutputInterface $output, $username, $super, $role) { if ($super) { $manipulator->demote($username); $output->writeln(sprintf('User "%s" has been demoted as a simple user.', $username)); } else { if ($manipulator->removeRole($username, $role)) { $output->writeln(sprintf('Role "%s" has been removed from user "%s".', $role, $username)); } else { $output->writeln(sprintf('User "%s" didn\'t have "%s" role.', $username, $role)); } } }
/** * @expectedException \InvalidArgumentException */ public function testDemoteWithInvalidUsername() { $userManagerMock = $this->createMock('FOS\\UserBundle\\Model\\UserManagerInterface'); $invalidusername = '******'; $userManagerMock->expects($this->once())->method('findUserByUsername')->will($this->returnValue(null))->with($this->equalTo($invalidusername)); $userManagerMock->expects($this->never())->method('updateUser'); $manipulator = new UserManipulator($userManagerMock); $manipulator->demote($invalidusername); }