I am working on writing tests for some existing code. The code works, but if I write a unit test that hits the same code, I get this error:
Doctrine\Common\Annotations\AnnotationException : [Semantical Error] The annotation "@JMS\Serializer\Annotation\Type" in property App\DTO\ItemDataCostValue::$available does not exist, or could not be auto-loaded.
The annotation for that property exists and I can click through to it:
use JMS\Serializer\Annotation\ as JMS;
class ItemDataCostValue
{
/**
* @var boolean
* @JMS\Type("boolean")
* @JMS\SerializedName("f")
* @JMS\SkipWhenEmpty
*/
protected $available;
It seems like this line is causing the error:
$idc = $this->serializer->deserialize($amenity->getData(), ItemDataCostValue::class, 'json');
The serializer is built in my test like this:
$accommodationAmenities = new AccommodationAmenitiesBusinessCase(
new AccommodationDataService($accommodationRepositoryMock),
new FieldsService($fieldRepositoryMock),
new ValueTypeService($valueRepositoryMock),
SerializerBuilder::create()->build(),
new CostObjectsHelpers()
);
The constructor looks like this:
public function __construct(
AccommodationDataService $dataService,
FieldsService $fieldsService,
ValueTypeService $valueTypeService,
SerializerInterface $serializer,
CostObjectsHelpers $costHelpers
) {
$this->dataService = $dataService;
$this->fieldsService = $fieldsService;
$this->valueTypeService = $valueTypeService;
$this->serializer = $serializer;
$this->costHelpers = $costHelpers;
}
Am I building the serializer wrong? Is there something I should check in my config? What could be the problem?