/** * {@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); }
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(); }
/** * @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(); }
/** * @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); }
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); }