PointDTOMapperTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Tests;
  4. use App\Components\Admin\Service\DTO\PointDTO;
  5. use App\Components\Admin\Service\Mapper\PointDTOMapper;
  6. use App\Entity\City;
  7. use App\Entity\Language;
  8. use App\Entity\Point;
  9. use App\Entity\PointLangData;
  10. use App\Entity\PointType;
  11. use Codeception\Module\Symfony;
  12. use Codeception\Test\Unit;
  13. use Doctrine\ORM\EntityManagerInterface;
  14. class PointDTOMapperTest extends Unit
  15. {
  16. /** @var string */
  17. private const TEST_TITLE = 'Тестовый объект';
  18. private PointDTOMapper $mapper;
  19. private EntityManagerInterface $entityManager;
  20. protected function _before()
  21. {
  22. /** @var Symfony $symfony */
  23. $symfony = $this->getModule('Symfony');
  24. $this->entityManager = $symfony->grabService(EntityManagerInterface::class);
  25. $this->mapper = $symfony->grabService(PointDTOMapper::class);
  26. }
  27. public function testMapper()
  28. {
  29. $pointRuData = (new PointLangData())
  30. ->setTitle(self::TEST_TITLE)
  31. ->setLanguage($this->entityManager->getRepository(Language::class)->findOneByCode('ru'));
  32. $point = (new Point())
  33. ->setIsActive(true)
  34. ->setUrl('testurl')
  35. ->setType($this->entityManager->getRepository(PointType::class)->findOneByCode('hotels'))
  36. ->setCity($this->entityManager->getRepository(City::class)->findOneByCode('svetlogorsk'))
  37. ->addPointLangData($pointRuData);
  38. $dto = $this->mapper->fill($point, new PointDTO());
  39. $this->assertEquals($dto->getTitle(), self::TEST_TITLE);
  40. $this->assertEquals($dto->getCity(), 'svetlogorsk');
  41. $this->assertEquals($dto->getType(), 'hotels');
  42. $this->assertEquals($dto->getIsActive(), '1');
  43. }
  44. }