public function testUpdateByNonAdmin($isAdmin = false) { $data = ['id' => 1, 'email' => 'foo', 'firstName' => 'bob', 'lastName' => 'dude', 'groups' => ['mod']]; $returnedUser = Mockery::mock('Cartalyst\\Sentry\\Users\\UserInterface')->makePartial(); $returnedUser->first_name = ''; $returnedUser->last_name = ''; $sentryMock = \Sentry::shouldReceive('findUserById')->once()->andReturn($returnedUser)->getMock(); $sentryMock->shouldReceive('getUser')->once()->andReturn($returnedUser); $returnedUser->shouldReceive('hasAccess')->once()->andReturn($isAdmin); $returnedUser->shouldReceive('save')->once()->andReturn(true); if ($isAdmin) { $group = new \stdClass(); $group->id = 'mod'; $groups = [$group]; $groupMock = Mockery::mock('Cartalyst\\Sentry\\Groups\\GroupInterface')->makePartial(); $sentryMock->shouldReceive('getGroupProvider')->once()->andReturn($groupMock); $groupMock->shouldReceive('findAll')->once()->andReturn($groupMock); } $userRepository = new SentryUser($sentryMock); $expectedResult = ['success' => true, 'message' => trans('users.updated')]; $this->assertEquals($expectedResult, $userRepository->update($data)); $this->assertEquals('bob', $returnedUser->first_name); }