/** * @param int $level * @param boolean $bubble * @dataProvider provideLevels */ public function testCreateHandler($level, $bubble) { $job = new Job(); $job->setTicket('JobTicket'); $handler = $this->subject->createHandler($job, $level, $bubble); $this->assertInstanceOf(StreamHandler::class, $handler); }
public function testClone() { $job = new Job(); $job->setTicket('ticket'); $clone = clone $job; $this->assertTrue($job !== $clone); $this->assertNotEquals($job->getTicket(), $clone->getTicket()); }
public function testAppliesConstraintsOfConstraintProviders() { $job = new Job(); $job->setType('abc.sleeper'); $job->setParameters(['foobar']); $errors = $this->validator->validate($job); $this->assertTrue($errors->has(0)); $this->assertEquals('parameters[0]', $errors->get(0)->getPropertyPath()); $this->assertEquals('This value should be a valid number.', $errors->get(0)->getMessage()); }
/** * @return JobInterface */ public function build() { $job = new Job(); $job->setType($this->type); $job->setParameters($this->parameters); foreach ($this->schedules as $schedule) { $job->addSchedule(new Schedule($schedule[0], $schedule[1])); } return $job; }
public function testDeleteByJob() { $job = new Job(); $job->setTicket('Ticket'); $log_A = $this->buildLog('ChannelA', 'LevelA', 'MessageA'); $this->subject = $this->getMockForAbstractClass(LogManager::class, [], '', null, null, null, ['delete']); $this->subject->expects($this->once())->method('findBy')->with(['jobTicket' => $job->getTicket()])->willReturn([$log_A]); $this->subject->expects($this->once())->method('delete')->with($log_A); $this->assertEquals(1, $this->subject->deleteByJob($job)); }
public function testValidateWithType() { $job = new Job(); $job->setType('foobar'); $job->setParameters(['JobParameters']); $validator = $this->createMock(ValidatorInterface::class); $contextualValidator = $this->createMock(ContextualValidatorInterface::class); $this->context->expects($this->once())->method('getValidator')->willReturn($validator); $validator->expects($this->once())->method('inContext')->with($this->context)->willReturn($contextualValidator); $contextualValidator->expects($this->once())->method('atPath')->with('parameters')->willReturn($contextualValidator); $contextualValidator->expects($this->once())->method('validate')->with(['JobParameters'], new Parameters(['type' => $job->getType()])); $this->subject->validate($job, new JobConstraint()); }
public function testWrite() { $log = new Log(); $job = new Job(); $job->setTicket('JobTicket'); $record = []; $record['extra']['job_ticket'] = $job->getTicket(); $this->manager->expects($this->once())->method('create')->willReturn($log); $this->subject->expects($this->once())->method('populateLog')->with($log, $record); $this->manager->expects($this->once())->method('save')->with($log); $this->subject->setJob($job); $this->invokeMethod($this->subject, 'write', [[]]); }
public function testOnSchedule() { $job = new Job(); $job->setType('type'); $job->setTicket('ticket'); $schedule = new Schedule(); $schedule->setJob($job); $event = new SchedulerEvent($schedule); $self = $this; $this->producer->expects($this->once())->method('produce')->willReturnCallback(function (Message $message) use($self) { $this->assertEquals('ticket', $message->getTicket()); $this->assertEquals('type', $message->getType()); }); $this->subject->onSchedule($event); }
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()); }
/** * @return Job */ public static function createJob($ticket = null, $type = null, $status = null, $processingTime = null, $parameters = null, array $schedules = array()) { $job = new Job(); $job->setTicket($ticket); $job->setType($type); $job->setParameters($parameters); $job->setProcessingTime($processingTime); foreach ($schedules as $schedule) { $job->addSchedule($schedule); } if ($status != null) { $job->setStatus($status); } return $job; }
/** * @return mixed * @throws \Exception If deserialization fails */ public function getResponse() { if ($this->responseDeserializationError) { return null; } if (is_null(parent::getResponse()) && !is_null($this->serializedResponse)) { try { parent::setResponse(static::getSerializationHelper()->deserializeReturnValue($this->getType(), $this->serializedResponse)); } catch (\Exception $e) { $this->responseDeserializationError = true; throw $e; } } return parent::getResponse(); }
public function testDoExitControllerReturnsTrue() { $this->controller->expects($this->any())->method('doStop')->willReturn(true); $this->assertTrue($this->subject->doStop()); $this->assertEquals(Status::CANCELLED(), $this->job->getStatus()); }
/** * Resolves the parameters of a job. * * @param string $type The job type * @param array $parameters The job parameters * @return array The parameters the job can be invoked with */ public function resolveParameters($type, array $parameters) { // serialize/deserialize parameters $deserializedParameters = $parameters; if (count($parameters) > 0) { $data = static::getSerializationHelper()->serializeParameters($type, $parameters); /** * @var array $deserializedParameters */ $deserializedParameters = static::getSerializationHelper()->deserializeParameters($type, $data); } // Dispatch event to let listeners register runtime parameters $job = new Job(); $job->setType($type); $job->setParameters($deserializedParameters); $event = new ExecutionEvent($job, new Context()); static::getDispatcher()->dispatch(JobEvents::JOB_PRE_EXECUTE, $event); return Invoker::resolveParameters(static::getJobType($type), $event->getContext(), $deserializedParameters); }
public function testDeleteLogWithNonExistingFile() { $job = new Job(); $job->setTicket('job-ticket'); $job->setType('job-type'); $this->subject->deleteByJob($job); }
/** * @param string $type * @param Status $status * @param array $parameters * @param SchedulerInterface $schedule * @param mixed $response * @return Job */ public function createJob($type, $status = null, $parameters = null, $schedule = null, $response = null) { $job = new Job(); $job->setType($type); $job->setParameters($parameters); $job->setResponse('JobResponse'); if ($status != null) { $job->setStatus($status); } if ($schedule !== null) { $job->addSchedule($schedule); } return $job; }
/** * @param array $parameters * @return Job */ private function buildJobFromArray($parameters) { $job = new Job(); $job->setType(isset($parameters['type']) ? $parameters['type'] : null); if (isset($parameters['parameters']) && count($parameters['parameters']) > 0) { $message = new Message($parameters['parameters'][0]['to'], $parameters['parameters'][0]['from'], $parameters['parameters'][0]['subject'], $parameters['parameters'][0]['message']); $job->setParameters([$message]); } if (isset($parameters['schedules'])) { foreach ($parameters['schedules'] as $scheduleParameters) { $schedule = new Schedule($scheduleParameters['type'], $scheduleParameters['expression']); $job->addSchedule($schedule); } } return $job; }
public function testUpdate() { $job = new Job(); $job->setTicket('JobTicket'); $existingJob = new Job(); $this->jobManager->expects($this->once())->method('findByTicket')->with($job->getTicket())->willReturn($existingJob); $this->helper->expects($this->once())->method('copyJob')->with($job, $existingJob)->willReturn($existingJob); $this->jobManager->expects($this->once())->method('save')->with($existingJob); $this->loggerFactory->expects($this->once())->method('create')->with($existingJob)->willReturn(new NullLogger()); $this->subject->update($job); }