/**
  * Test that an exception is thrown if the auth user does not match the requested user
  *
  * @expectedException \Scheduler\Exception\UserNotAuthorized
  */
 public function testInvokeWithUnauthorizedUser()
 {
     $hours = [['week_start' => '2015-01-01 00:00:00', 'week_end' => '2015-01-07 23:59:59', 'hours_count' => 2]];
     $employee = mockery::mock(User::class);
     $hoursTransformer = mockery::mock(HoursTransformer::class);
     $scope = mockery::mock(Scope::class);
     $scope->shouldReceive('toArray')->withNoArgs()->andReturn([]);
     $collection = mockery::mock(Collection::class);
     $collection->shouldReceive('setData')->once()->with($hours)->andReturnSelf();
     $collection->shouldReceive('setTransformer')->once()->with($hoursTransformer)->andReturnSelf();
     $payloadInterface = mockery::mock(PayloadInterface::class);
     $payloadInterface->shouldReceive('withStatus')->once()->with(PayloadInterface::OK)->andReturnSelf();
     $payloadInterface->shouldReceive('withOutput')->once()->with([])->andReturnSelf();
     $shiftRepository = mockery::mock(ShiftRepository::class);
     $shiftRepository->shouldReceive('getHoursCountGroupedByWeekFor')->once()->with($employee)->andReturn($hours);
     $userRepository = mockery::mock(UserRepository::class);
     $userRepository->shouldReceive('getOneByIdOrFail')->once()->with(1)->andReturn($employee);
     $fractal = mockery::mock(Manager::class);
     $fractal->shouldReceive('createData')->once()->with($collection)->andReturn($scope);
     $token = mockery::mock(Token::class);
     $token->shouldReceive('getMetadata')->once()->with('id')->andReturn(1);
     $domain = new GetUserHours($payloadInterface, $shiftRepository, $userRepository, $fractal, $hoursTransformer, $collection);
     $input = ['id' => 2, AuthHandler::TOKEN_ATTRIBUTE => $token];
     $payload = $domain->__invoke($input);
     $this->assertInstanceOf(PayloadInterface::class, $payload);
 }
예제 #2
0
 /**
  * Test that the GetUsersTest domain can take in input with an ID and auth user, and return an array
  */
 public function testInvoke()
 {
     $user = mockery::mock(Caller::class);
     $user->shouldReceive('getId')->once()->withNoArgs()->andReturn(1);
     $lockManager = mockery::mock(\BeatSwitch\Lock\Manager::class);
     $userTransformer = mockery::mock(UserTransformer::class);
     $scope = mockery::mock(Scope::class);
     $scope->shouldReceive('toArray')->withNoArgs()->andReturn([]);
     $item = mockery::mock(Item::class);
     $item->shouldReceive('setData')->once()->with($user)->andReturnSelf();
     $item->shouldReceive('setTransformer')->once()->with($userTransformer)->andReturnSelf();
     $payloadInterface = mockery::mock(PayloadInterface::class);
     $payloadInterface->shouldReceive('withStatus')->once()->with(PayloadInterface::OK)->andReturnSelf();
     $payloadInterface->shouldReceive('withOutput')->once()->with([])->andReturnSelf();
     $userRepository = mockery::mock(UserRepository::class);
     $userRepository->shouldReceive('getOneByIdOrFail')->once()->with(1)->andReturn($user);
     $fractal = mockery::mock(Manager::class);
     $fractal->shouldReceive('createData')->once()->with($item)->andReturn($scope);
     $token = mockery::mock(Token::class);
     $token->shouldReceive('getMetadata')->once()->with('entity')->andReturn($user);
     $domain = mockery::mock(GetUsers::class . '[authorizeUser]', [$payloadInterface, $userRepository, $userTransformer, $fractal, $lockManager, $item]);
     $domain->shouldReceive('authorizeUser')->once()->with($user, 'view', 'users')->andReturnNull();
     $input = ['id' => 1, AuthHandler::TOKEN_ATTRIBUTE => $token];
     $payload = $domain->__invoke($input);
     $this->assertInstanceOf(PayloadInterface::class, $payload);
 }
 /**
  * Test that an exception is thrown if the auth user does not match the requested user
  *
  * @expectedException \Scheduler\Exception\UserNotAuthorized
  */
 public function testInvokeWithUnauthorizedUser()
 {
     $shift = mockery::mock(Shift::class);
     $shifts = [$shift];
     $employee = mockery::mock(User::class);
     $shiftTransformer = mockery::mock(ShiftTransformer::class);
     $scope = mockery::mock(Scope::class);
     $scope->shouldReceive('toArray')->withNoArgs()->andReturn([]);
     $collection = mockery::mock(Collection::class);
     $collection->shouldReceive('setData')->once()->with($shifts)->andReturnSelf();
     $collection->shouldReceive('setTransformer')->once()->with($shiftTransformer)->andReturnSelf();
     $payloadInterface = mockery::mock(PayloadInterface::class);
     $payloadInterface->shouldReceive('withStatus')->once()->with(PayloadInterface::OK)->andReturnSelf();
     $payloadInterface->shouldReceive('withOutput')->once()->with([])->andReturnSelf();
     $shiftRepository = mockery::mock(ShiftRepository::class);
     $shiftRepository->shouldReceive('getByEmployee')->once()->with($employee)->andReturn($shifts);
     $userRepository = mockery::mock(UserRepository::class);
     $userRepository->shouldReceive('getOneByIdOrFail')->once()->with(1)->andReturn($employee);
     $fractal = mockery::mock(Manager::class);
     $fractal->shouldReceive('parseIncludes')->once()->with('employee,manager')->andReturnSelf();
     $fractal->shouldReceive('createData')->once()->with($collection)->andReturn($scope);
     $token = mockery::mock(Token::class);
     $token->shouldReceive('getMetadata')->once()->with('id')->andReturn(1);
     $domain = new GetUserShifts($payloadInterface, $userRepository, $shiftRepository, $fractal, $shiftTransformer, $collection);
     $input = ['id' => 2, 'include' => 'employee,manager', AuthHandler::TOKEN_ATTRIBUTE => $token];
     $payload = $domain->__invoke($input);
     $this->assertInstanceOf(PayloadInterface::class, $payload);
 }
예제 #4
0
 /**
  * @expectedException \Spark\Auth\Exception\AuthException
  */
 public function testValidateCredentials()
 {
     $credentials = mockery::mock(Credentials::class);
     $userRepository = mockery::mock(UserRepository::class);
     $injector = mockery::mock(Injector::class);
     $adapter = new Adapter($userRepository, $injector);
     $validatedToken = $adapter->validateCredentials($credentials);
 }
예제 #5
0
 public function testGetAndSetCoworkers()
 {
     $shift = new Shift();
     $this->assertNull($shift->getCoworkers());
     $user = mockery::mock(User::class);
     $shift->setCoworkers([$user]);
     $this->assertEquals([$user], $shift->getCoworkers());
 }
 /**
  * Test that coworkers can be included with the transformation
  */
 public function testIncludeCoworkers()
 {
     $user = mockery::mock(User::class);
     $shift = mockery::mock(Shift::class);
     $shift->shouldReceive('getCoworkers')->once()->withNoArgs()->andReturn([$user]);
     $transformer = new ShiftTransformer();
     $this->assertInstanceOf(Collection::class, $transformer->includeCoworkers($shift));
 }
예제 #7
0
 /**
  * Test that the command is handled correctly
  */
 public function testHandle()
 {
     $user = mockery::mock(User::class);
     $shift = mockery::mock(Shift::class);
     $shift->shouldReceive('setEmployee')->once()->with($user)->andReturnNull();
     $command = new AssignShift($shift, $user);
     $shiftRepository = mockery::mock(ShiftRepository::class);
     $shiftRepository->shouldReceive('update')->once()->with($shift)->andReturnNull();
     $this->assertInstanceOf(Shift::class, $command->handle($shiftRepository));
 }
예제 #8
0
 /**
  * Test that the handle method finds the shift and updates the time fields
  */
 public function testHandle()
 {
     $shift = mockery::mock(Shift::class);
     $command = new UpdateShift($shift, 20, date_create('now')->format('r'), date_create('+1 hour')->format('r'));
     $shift->shouldReceive('setBreak')->once()->with($command->break)->andReturnNull();
     $shift->shouldReceive('setStartTime')->once()->with($command->start_time)->andReturnNull();
     $shift->shouldReceive('setEndTime')->once()->with($command->end_time)->andReturnNull();
     $shiftRepository = mockery::mock(ShiftRepository::class);
     $shiftRepository->shouldReceive('update')->once()->with($shift)->andReturnNull();
     $this->assertInstanceOf(Shift::class, $command->handle($shiftRepository));
 }
 /**
  * Test that the transformer returns the correctly formatted array
  */
 public function testTransform()
 {
     $user = mockery::mock(User::class);
     $user->shouldReceive('getId')->twice()->withNoArgs()->andReturn(1);
     $user->shouldReceive('getName')->once()->withNoArgs()->andReturn('John Smith');
     $user->shouldReceive('getRole')->once()->withNoArgs()->andReturn(User::EMPLOYEE_ROLE);
     $user->shouldReceive('getEmail')->once()->withNoArgs()->andReturn('*****@*****.**');
     $user->shouldReceive('getPhone')->once()->withNoArgs()->andReturn('123-456-7890');
     $transformer = new UserTransformer();
     $transformedData = $transformer->transform($user);
     $this->assertEquals(['id' => 1, 'name' => 'John Smith', 'role' => User::EMPLOYEE_ROLE, 'email' => '*****@*****.**', 'phone' => '123-456-7890', 'links' => [['rel' => 'self', 'uri' => '/users/1']]], $transformedData);
 }
 public function testHandle()
 {
     $command = new AssignShift(1, 2);
     $employee = mockery::mock(User::class);
     $shift = mockery::mock(Shift::class);
     $shift->shouldReceive('setEmployee')->once()->with($employee)->andReturnNull();
     $shiftRepository = mockery::mock(ShiftRepository::class);
     $shiftRepository->shouldReceive('getOneByIdOrFail')->once()->with($command->shift_id)->andReturn($shift);
     $userRepository = mockery::mock(UserRepository::class);
     $userRepository->shouldReceive('getOneByIdOrFail')->once()->with($command->employee_id)->andReturn($employee);
     $commandHandler = new AssignShiftHandler($shiftRepository, $userRepository);
     $this->assertInstanceOf(Shift::class, $commandHandler->handle($command));
 }
예제 #11
0
 public function testGracefulDegradation()
 {
     $config = mockery::mock('Derby\\Config');
     $manager = new Manager($config);
     $manager->registerFileFactory(['*'], ['text/*'], function ($key, $adapter) {
         return new Media\LocalFile\Text($key, $adapter);
     });
     $localAdapter = new LocalFileAdapter(__DIR__ . '/../Temp/', true);
     // Build HTML File
     $file = $manager->buildFile('test-1.html', $localAdapter, 'test1');
     $this->assertTrue($file instanceof Media\LocalFile\Text);
     // Build Text File
     $file = $manager->buildFile('test-2.txt', $localAdapter, 'test2');
     $this->assertTrue($file instanceof Media\LocalFile\Text);
     // Will return Generic Local File b.c we haven't registered image media
     $file = $manager->buildFile('test-3.jpg', $localAdapter, file_get_contents(__DIR__ . '/../Data/test-236x315.jpg'));
     $this->assertFalse($file instanceof Media\LocalFile\Image);
     $this->assertTrue($file instanceof Media\LocalFile);
 }
 public function testHandle()
 {
     $command = new CreateShift(1, 2, 15, date_create('now')->format('r'), date_create('+1 hour')->format('r'));
     $manager = mockery::mock(User::class);
     $employee = mockery::mock(User::class);
     $shift = mockery::mock(Shift::class);
     $shift->shouldReceive('setBreak')->once()->with($command->break)->andReturnNull();
     $shift->shouldReceive('setEmployee')->once()->with($employee)->andReturnNull();
     $shift->shouldReceive('setManager')->once()->with($manager)->andReturnNull();
     $shift->shouldReceive('setStartTime')->once()->with($command->start_time)->andReturnNull();
     $shift->shouldReceive('setEndTime')->once()->with($command->end_time)->andReturnNull();
     $shiftRepository = mockery::mock(ShiftRepository::class);
     $shiftRepository->shouldReceive('store')->once()->with($shift)->andReturnNull();
     $userRepository = mockery::mock(UserRepository::class);
     $userRepository->shouldReceive('getOneById')->once()->with($command->employee_id)->andReturn($employee);
     $userRepository->shouldReceive('getOneById')->once()->with($command->manager_id)->andReturn($manager);
     $commandHandler = new CreateShiftHandler($userRepository, $shiftRepository, $shift);
     $this->assertInstanceOf(Shift::class, $commandHandler->handle($command));
 }
예제 #13
0
 /**
  * Test that giving invalid data (end time that occurs before start time) will throw an error
  *
  * @expectedException \Respect\Validation\Exceptions\NestedValidationException
  */
 public function testInvokeWithInvalidData()
 {
     $shift = mockery::mock(Shift::class);
     $user = mockery::mock(Caller::class);
     $lockManager = mockery::mock(\BeatSwitch\Lock\Manager::class);
     $shiftTransformer = mockery::mock(ShiftTransformer::class);
     $scope = mockery::mock(Scope::class);
     $scope->shouldReceive('toArray')->withNoArgs()->andReturn([]);
     $item = mockery::mock(Item::class);
     $item->shouldReceive('setData')->once()->with($shift)->andReturnSelf();
     $item->shouldReceive('setTransformer')->once()->with($shiftTransformer)->andReturnSelf();
     $payloadInterface = mockery::mock(PayloadInterface::class);
     $payloadInterface->shouldReceive('withStatus')->once()->with(PayloadInterface::OK)->andReturnSelf();
     $payloadInterface->shouldReceive('withOutput')->once()->with([])->andReturnSelf();
     $commandBus = mockery::mock(CommandBus::class);
     $commandBus->shouldReceive('handle')->once()->andReturn($shift);
     $fractal = mockery::mock(Manager::class);
     $fractal->shouldReceive('createData')->once()->with($item)->andReturn($scope);
     $fractal->shouldReceive('parseIncludes')->once()->with(['manager', 'employee'])->andReturnSelf();
     $token = mockery::mock(Token::class);
     $token->shouldReceive('getMetadata')->once()->with('entity')->andReturn($user);
     $storeShiftDomain = mockery::mock(StoreShift::class . '[authorizeUser]', [$payloadInterface, $commandBus, $fractal, $lockManager, $shiftTransformer, $item]);
     $storeShiftDomain->shouldReceive('authorizeUser')->once()->with($user, 'create', 'shifts')->andReturnNull();
     $input = ['manager_id' => 1, 'employee_id' => 2, 'break' => 15, 'start_time' => '2015-12-01 00:00:00', 'end_time' => '2014-12-02 00:00:00', AuthHandler::TOKEN_ATTRIBUTE => $token];
     $payload = $storeShiftDomain->__invoke($input);
     $this->assertInstanceOf(PayloadInterface::class, $payload);
 }
예제 #14
0
 /**
  * Test that giving invalid data (end time that occurs before start time) will throw an error
  *
  * @expectedException \Respect\Validation\Exceptions\NestedValidationException
  */
 public function testInvokeWithInvalidData()
 {
     $shift = mockery::mock(Shift::class);
     $shifts = [$shift];
     $user = mockery::mock(Caller::class);
     $user->shouldReceive('getId')->once()->withNoArgs()->andReturn(1);
     $lockManager = mockery::mock(\BeatSwitch\Lock\Manager::class);
     $shiftTransformer = mockery::mock(ShiftTransformer::class);
     $scope = mockery::mock(Scope::class);
     $scope->shouldReceive('toArray')->withNoArgs()->andReturn([]);
     $collection = mockery::mock(Collection::class);
     $collection->shouldReceive('setData')->once()->with($shifts)->andReturnSelf();
     $collection->shouldReceive('setTransformer')->once()->with($shiftTransformer)->andReturnSelf();
     $payloadInterface = mockery::mock(PayloadInterface::class);
     $payloadInterface->shouldReceive('withStatus')->once()->with(PayloadInterface::OK)->andReturnSelf();
     $payloadInterface->shouldReceive('withOutput')->once()->with([])->andReturnSelf();
     $shiftRepository = mockery::mock(ShiftRepository::class);
     $shiftRepository->shouldReceive('getShiftsBetween')->once()->andReturn($shifts);
     $fractal = mockery::mock(Manager::class);
     $fractal->shouldReceive('createData')->once()->with($collection)->andReturn($scope);
     $fractal->shouldReceive('parseIncludes')->once()->with(['manager', 'employee'])->andReturnSelf();
     $token = mockery::mock(Token::class);
     $token->shouldReceive('getMetadata')->once()->with('entity')->andReturn($user);
     $domain = mockery::mock(GetShifts::class . '[authorizeUser]', [$payloadInterface, $shiftRepository, $fractal, $lockManager, $shiftTransformer, $collection]);
     $domain->shouldReceive('authorizeUser')->once()->with($user, 'view', 'shifts')->andReturnNull();
     $input = [AuthHandler::TOKEN_ATTRIBUTE => $token];
     $payload = $domain->__invoke($input);
     $this->assertInstanceOf(PayloadInterface::class, $payload);
 }