public function testValidateWithTypeRegistered()
 {
     $value = 'foobar';
     $this->registry->expects($this->once())->method('has')->with($value)->willReturn(true);
     $this->context->expects($this->never())->method('buildViolation');
     $this->subject->validate($value, new JobType());
 }
 public function testProduce()
 {
     $type = 'JobType';
     $ticket = 'JobTicket';
     $queue = 'QueueName';
     $message = new Message($type, $ticket);
     $jobType = $this->createMock(JobTypeInterface::class);
     $jobType->expects($this->once())->method('getQueue')->willReturn($queue);
     $producerMessage = new DefaultMessage('ConsumeJob', ['type' => $type, 'ticket' => $ticket]);
     $this->registry->expects($this->once())->method('get')->with($message->getType())->willReturn($jobType);
     $this->producer->expects($this->once())->method('produce')->with($producerMessage, $queue);
     $this->subject->produce($message);
 }
 /**
  * @dataProvider provideValuesWithConstraints
  * @param array $parameters
  * @param array $constraints
  */
 public function testValidateWithValue(array $parameters, array $constraints)
 {
     $validator = $this->createMock(ValidatorInterface::class);
     $contextualValidator = $this->createMock(ContextualValidatorInterface::class);
     $provider = $this->createMock(ConstraintProviderInterface::class);
     $this->subject->register($provider);
     $this->registry->expects($this->once())->method('getTypeChoices')->willReturn(['foobar']);
     $provider->expects($this->any())->method('getConstraints')->with('foobar')->willReturn($constraints);
     $this->context->expects($this->once())->method('getValidator')->willReturn($validator);
     $validator->expects($this->once())->method('inContext')->with($this->context)->willReturn($contextualValidator);
     $contextualValidator->expects($this->exactly(count($constraints)))->method('atPath')->willReturn($contextualValidator);
     $contextualValidator->expects($this->exactly(count($constraints)))->method('validate');
     $this->subject->validate($parameters, new ParametersConstraint(['type' => 'foobar']));
 }
Beispiel #4
0
 /**
  * @expectedException \Exception
  */
 public function testAddRethrowsBackendExceptions()
 {
     $job = new Job();
     $job->setTicket('ticket');
     $this->jobManager->expects($this->once())->method('isManagerOf')->with($job)->willReturn(true);
     $this->registry->expects($this->any())->method('has')->willReturn(true);
     $this->producer->expects($this->once())->method('produce')->willThrowException(new \Exception());
     $this->subject->add($job);
 }
 /**
  * @expectedException \Exception
  */
 public function testProduceThrowsExceptionsThrownByBackend()
 {
     $queue = 'foobar';
     $message = new Message('type', 'ticket', 'callback');
     $backend = $this->createMock(BackendInterface::class);
     $jobType = $this->createMock(JobTypeInterface::class);
     $jobType->expects($this->any())->method('getQueue')->willReturn($queue);
     $this->registry->expects($this->any())->method('get')->with('type')->willReturn($jobType);
     $this->backendProvider->expects($this->once())->method('getBackend')->with($queue)->willReturn($backend);
     $backend->expects($this->once())->method('createAndPublish')->willThrowException(new \Exception());
     $this->subject->produce($message);
 }
 public function testDeserializeReturnValue()
 {
     $jobType = $this->createMock(JobTypeInterface::class);
     $this->registry->expects($this->once())->method('get')->with('JobType')->willReturn($jobType);
     $jobType->expects($this->once())->method('getReturnType')->willReturn('ReturnType');
     $jobType->expects($this->once())->method('getReturnTypeOptions')->willReturn(['groups' => ['group1', 'group2'], 'version' => '12345']);
     $expectedContext = new DeserializationContext();
     $expectedContext->setGroups(['group1', 'group2']);
     $expectedContext->setVersion('12345');
     $this->serializer->expects($this->once())->method('deserialize')->with('ReturnValue', 'ReturnType', 'json', $expectedContext);
     $this->subject->deserializeReturnValue('JobType', 'ReturnValue');
 }
 public function testCreatesLoggerWithAddedHandlers()
 {
     $job = new Job();
     $job->setType('JobType');
     $handler = $this->createMock(HandlerInterface::class);
     $extraHandler = $this->createMock(HandlerInterface::class);
     $factory = $this->getMockBuilder(BaseHandlerFactory::class)->disableOriginalConstructor()->getMock();
     $jobType = $this->createMock(JobTypeInterface::class);
     $this->handlerFactory->register($factory);
     $jobType->expects($this->any())->method('getLogLevel')->willReturn(Logger::CRITICAL);
     $this->registry->expects($this->once())->method('get')->with($job->getType())->willReturn($jobType);
     $factory->expects($this->once())->method('createHandler')->willReturn($handler);
     $this->subject->addHandler($extraHandler);
     $logger = $this->subject->create($job);
     $this->assertContains($handler, $logger->getHandlers());
     $this->assertContains($extraHandler, $logger->getHandlers());
 }
 /**
  * @param JobTypeInterface $jobType
  */
 private function setUpRegistry(JobTypeInterface $jobType)
 {
     $this->registry->expects($this->any())->method('get')->with($jobType->getName())->willReturn($jobType);
 }