public function testGetResponseWithSerializerException() { $job = new Job(); $job->setType('JobType'); $this->setProperty($job, 'serializedResponse', 'SerializedResponse'); $this->serializationHelper->expects($this->any())->method('deserializeReturnValue')->willThrowException(new \Exception('Some deserialization error')); try { $job->getResponse(); } catch (\Exception $e) { $this->assertNull($job->getResponse()); } }
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 testHandlesResponseSerialization() { $type = 'foobar'; $response = ['foo' => 'bar']; // persist object with parameters being an array $this->serializationHelper->expects($this->once())->method('serializeReturnValue')->with($type, $response)->willReturn('SerializedResponse'); $job = $this->subject->create($type); $job->setStatus(Status::REQUESTED()); $job->setResponse($response); $this->subject->save($job); $this->getEntityManager()->clear(); $this->serializationHelper->expects($this->once())->method('deserializeReturnValue')->with($type, 'SerializedResponse')->willReturn($response); $persistedJob = $this->subject->findByTicket($job->getTicket()); $this->assertEquals($response, $persistedJob->getResponse()); }