public function testCreateReturnsChainedController() { /** * @var ControllerInterface|\PHPUnit_Framework_MockObject_MockObject */ $otherController = $this->createMock(ControllerInterface::class); $this->subject->addController($otherController); $controller = $this->subject->create($this->job); $this->assertInstanceOf(JobController::class, $controller); $this->assertAttributeInstanceOf(ChainController::class, 'controller', $controller); // assert that default controller is in the chain $this->manager->expects($this->once())->method('refresh')->with($this->job); // assert that additional controllers are in the chain $otherController->expects($this->once())->method('doStop'); $controller->doStop(); }
/** * Invokes the job. * * @param JobInterface $job * @param ContextInterface $context * @return mixed * @throws JobTypeNotFoundException */ public function invoke(JobInterface $job, ContextInterface $context) { $jobType = $this->registry->get($job->getType()); $callableArray = $jobType->getCallable(); $parameters = static::resolveParameters($jobType, $context, $job->getParameters()); if (is_array($callableArray) && ($callable = $callableArray[0])) { if ($callable instanceof JobAwareInterface) { $callable->setJob($job); } if ($callable instanceof ManagerAwareInterface) { $callable->setManager($this->manager); } if ($callable instanceof ControllerAwareInterface) { $callable->setController($this->controllerFactory->create($job)); } if ($callable instanceof LoggerAwareInterface && $context->has('abc.logger')) { $callable->setLogger($context->get('abc.logger')); } } return call_user_func_array($callableArray, $parameters); }
public function testInvokeHandlesControllerAwareJobs() { $serviceId = 'serviceId'; $type = 'callable-type'; $callable = new ControllerAwareJob(); $jobType = new JobType($serviceId, $type, array($callable, 'execute')); $controller = $this->createMock(ControllerInterface::class); $job = new Job($type); $this->registry->register($jobType); $this->controllerFactory->expects($this->once())->method('create')->with($job)->willReturn($controller); $this->assertEquals('foobar', $this->subject->invoke($job, new Context())); $this->assertEquals($controller, $callable->getController()); }