ContactPointUtilsTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Test\Service\Access;
  3. use App\Entity\Access\Access;
  4. use App\Entity\Core\ContactPoint;
  5. use App\Entity\Person\Person;
  6. use App\Enum\Core\ContactPointTypeEnum;
  7. use App\Repository\Core\ContactPointRepository;
  8. use App\Service\Access\Utils;
  9. use App\Service\Core\ContactPointUtils;
  10. use PHPUnit\Framework\TestCase;
  11. class ContactPointUtilsTest extends TestCase
  12. {
  13. private ContactPointUtils $contactPointUtils;
  14. private ContactPointRepository $contactPointRepositoryMock;
  15. public function setUp():void
  16. {
  17. $this->contactPointRepositoryMock = $this->getMockBuilder(ContactPointRepository::class)->disableOriginalConstructor()->getMock();
  18. $this->contactPointUtils = new ContactPointUtils($this->contactPointRepositoryMock);
  19. }
  20. /**
  21. * @see Utils::getPersonContactPointPrincipal()
  22. */
  23. public function testGetPersonContactPointPrincipal(){
  24. $person = new Person();
  25. $access = new Access();
  26. $access->setPerson($person);
  27. $this->contactPointRepositoryMock
  28. ->method('getByTypeAndPerson')
  29. ->with(ContactPointTypeEnum::PRINCIPAL()->getValue(), $access->getPerson())
  30. ->willReturn([new ContactPoint()]);
  31. $this->assertInstanceOf(ContactPoint::class, $this->contactPointUtils->getPersonContactPointPrincipal($access));
  32. }
  33. /**
  34. * @see Utils::getPersonContactPointPrincipal()
  35. */
  36. public function testGetPersonContactPointPrincipalNotExist(){
  37. $person = new Person();
  38. $access = new Access();
  39. $access->setPerson($person);
  40. $this->contactPointRepositoryMock
  41. ->method('getByTypeAndPerson')
  42. ->with(ContactPointTypeEnum::PRINCIPAL()->getValue(), $access->getPerson())
  43. ->willReturn([]);
  44. $this->assertNull($this->contactPointUtils->getPersonContactPointPrincipal($access));
  45. }
  46. }