ArticleDTOMapperTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Tests;
  4. use App\Components\Balticrest\Service\Mapper\ArticleDTOMapper;
  5. use App\Entity\Article;
  6. use App\Entity\ArticleLangData;
  7. use App\Entity\Language;
  8. use Codeception\Module\Symfony;
  9. use Codeception\Test\Unit;
  10. use Doctrine\ORM\EntityManagerInterface;
  11. class ArticleDTOMapperTest extends Unit
  12. {
  13. /** @var string */
  14. private const TEST_TITLE = 'Тестовая статья';
  15. /** @var string */
  16. private const TEST_TEXT = 'Текст тестовой статьи';
  17. private ArticleDTOMapper $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(ArticleDTOMapper::class);
  25. }
  26. public function testMapper()
  27. {
  28. $articleRuData = (new ArticleLangData())
  29. ->setTitle(self::TEST_TITLE)
  30. ->setText(self::TEST_TEXT)
  31. ->setLanguage($this->entityManager->getRepository(Language::class)->findOneByCode('ru'))
  32. ->setMetaKeywords('')
  33. ->setMetaDescription('');
  34. $article = (new Article())
  35. ->setIsActive(true)
  36. ->setUrl('testurl')
  37. ->addArticleLangData($articleRuData);
  38. $dto = $this->mapper->fill($article);
  39. $this->assertEquals($dto->getTitle(), self::TEST_TITLE);
  40. $this->assertEquals($dto->getText(), self::TEST_TEXT);
  41. }
  42. }