Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function doStop()
 {
     $time = time();
     if (null === $this->lastCheck || $this->lastCheck + $this->interval <= $time) {
         $this->lastCheck = $time;
         $this->manager->refresh($this->job);
     }
     return $this->job->getStatus() == Status::CANCELLING() || $this->job->getStatus() == Status::CANCELLED();
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     $this->controller = $this->createMock(ControllerInterface::class);
     $this->manager = $this->createMock(JobManagerInterface::class);
     $this->job = new Job();
     $this->job->setStatus(Status::REQUESTED());
     $this->manager->expects($this->any())->method('isManagerOf')->willReturn(true);
     $this->subject = new JobController($this->controller, $this->manager, $this->job);
 }
Ejemplo n.º 3
0
 /**
  * @param ControllerInterface $controller
  * @param JobManagerInterface $jobManager
  * @param JobInterface        $job
  * @throws \InvalidArgumentException If the given manager is not a manager of the given job
  */
 public function __construct(ControllerInterface $controller, JobManagerInterface $jobManager, JobInterface $job)
 {
     if (!$jobManager->isManagerOf($job)) {
         throw new \InvalidArgumentException('The job manager is not a manager of the job');
     }
     $this->controller = $controller;
     $this->jobManager = $jobManager;
     $this->job = $job;
 }
Ejemplo n.º 4
0
 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();
 }
Ejemplo n.º 5
0
 /**
  * @param string $ticket
  * @return \Abc\Bundle\JobBundle\Model\JobInterface
  * @throws TicketNotFoundException If a job with the given ticket was not found
  */
 protected function findJob($ticket)
 {
     if ($job = $this->jobManager->findByTicket($ticket)) {
         return $job;
     }
     $this->logger->error('Job with ticket {ticket} not found', ['ticket' => $ticket]);
     throw new TicketNotFoundException($ticket);
 }
 /**
  * @param $secondsPassed
  * @dataProvider provideSecondsLessThanInterval
  */
 public function testDoStopSkipsRefreshingIfIntervalNotExceeded($secondsPassed)
 {
     $this->manager->expects($this->exactly(1))->method('refresh')->with($this->job);
     $this->job->expects($this->any())->method('getStatus')->willReturn(Status::CANCELLING());
     $this->time->expects($this->at(0))->willReturn(0);
     $this->time->expects($this->at(1))->willReturn($secondsPassed);
     // initial invocation
     $this->subject->doStop();
     // second invocation
     $this->subject->doStop();
 }
Ejemplo n.º 7
0
 /**
  * @dataProvider provideInvalidListData
  * @param array $parameters
  */
 public function testListActionWithInvalidParameters($parameters)
 {
     $url = '/api/jobs?' . http_build_query($parameters);
     $this->entityManager->expects($this->never())->method('findBy');
     $this->entityManager->expects($this->never())->method('findByCount');
     $client = static::createClient();
     $this->mockServices(['abc.job.job_manager' => $this->entityManager]);
     $client->request('GET', $url, [], [], ['CONTENT_TYPE' => 'application/json'], null, 'json');
     $this->assertEquals(400, $client->getResponse()->getStatusCode());
     $data = json_decode($client->getResponse()->getContent(), true);
 }
Ejemplo n.º 8
0
 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);
 }