. */ namespace App\Tests\Services\InfoProviderSystem\DTOs; use App\Doctrine\Types\BulkSearchResponseDTOType; use App\Entity\Parts\Part; use App\Services\InfoProviderSystem\DTOs\BulkSearchResponseDTO; use App\Services\InfoProviderSystem\DTOs\BulkSearchPartResultDTO; use App\Services\InfoProviderSystem\DTOs\BulkSearchPartResultsDTO; use App\Services\InfoProviderSystem\DTOs\SearchResultDTO; use Doctrine\ORM\EntityManagerInterface; use PHPUnit\Framework\TestCase; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; class BulkSearchResponseDTOTest extends KernelTestCase { private EntityManagerInterface $entityManager; private BulkSearchResponseDTO $dummyEmpty; private BulkSearchResponseDTO $dummy; protected function setUp(): void { self::bootKernel(); $this->entityManager = self::getContainer()->get(EntityManagerInterface::class); $this->dummyEmpty = new BulkSearchResponseDTO(partResults: []); $this->dummy = new BulkSearchResponseDTO(partResults: [ new BulkSearchPartResultsDTO( part: $this->entityManager->find(Part::class, 1), searchResults: [ new BulkSearchPartResultDTO( searchResult: new SearchResultDTO(provider_key: "dummy", provider_id: "1234", name: "Test Part", description: "A part for testing"), sourceField: "mpn", sourceKeyword: "1234", priority: 1 ), new BulkSearchPartResultDTO( searchResult: new SearchResultDTO(provider_key: "test", provider_id: "test", name: "Test Part2", description: "A part for testing"), sourceField: "name", sourceKeyword: "1234", localPart: $this->entityManager->find(Part::class, 2), priority: 2, ), ], errors: ['Error 1'] ) ]); } public function testSerializationBackAndForthEmpty(): void { $serialized = $this->dummyEmpty->toSerializableRepresentation(); //Ensure that it is json_encodable $json = json_encode($serialized, JSON_THROW_ON_ERROR); $this->assertJson($json); $deserialized = BulkSearchResponseDTO::fromSerializableRepresentation(json_decode($json), $this->entityManager); $this->assertEquals($this->dummyEmpty, $deserialized); } public function testSerializationBackAndForth(): void { $serialized = $this->dummy->toSerializableRepresentation(); //Ensure that it is json_encodable $this->assertJson(json_encode($serialized, JSON_THROW_ON_ERROR)); $deserialized = BulkSearchResponseDTO::fromSerializableRepresentation($serialized, $this->entityManager); $this->assertEquals($this->dummy, $deserialized); } public function testToSerializableRepresentation(): void { } public function testFromSerializableRepresentation(): void { } }