ListPointDTOMapperTest.php 1.7 KB

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