ContactPointUtilsTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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\MockObject\MockObject;
  11. use PHPUnit\Framework\TestCase;
  12. class ContactPointUtilsTest extends TestCase
  13. {
  14. private MockObject | ContactPointRepository $contactPointRepository;
  15. public function setUp():void
  16. {
  17. $this->contactPointRepository = $this->getMockBuilder(ContactPointRepository::class)->disableOriginalConstructor()->getMock();
  18. }
  19. /**
  20. * @see Utils::getPersonContactPointPrincipal()
  21. */
  22. public function testGetPersonContactPointPrincipal(): void
  23. {
  24. $person = $this->getMockBuilder(Person::class)->disableOriginalConstructor()->getMock();
  25. $access = $this->getMockBuilder(Access::class)->disableOriginalConstructor()->getMock();
  26. $access->method('getPerson')->willReturn($person);
  27. $contactPoint = $this->getMockBuilder(ContactPoint::class)->disableOriginalConstructor()->getMock();
  28. $this->contactPointRepository
  29. ->method('getByTypeAndPerson')
  30. ->with(ContactPointTypeEnum::PRINCIPAL()->getValue(), $access->getPerson())
  31. ->willReturn([$contactPoint]);
  32. $contactPointUtils = $this
  33. ->getMockBuilder(ContactPointUtils::class)
  34. ->setConstructorArgs([$this->contactPointRepository])
  35. ->setMethodsExcept(['getPersonContactPointPrincipal'])
  36. ->getMock();
  37. $this->assertEquals(
  38. $contactPoint,
  39. $contactPointUtils->getPersonContactPointPrincipal($access)
  40. );
  41. }
  42. /**
  43. * @see Utils::getPersonContactPointPrincipal()
  44. */
  45. public function testGetPersonContactPointPrincipalNotExisting(){
  46. $person = $this->getMockBuilder(Person::class)->disableOriginalConstructor()->getMock();
  47. $access = $this->getMockBuilder(Access::class)->disableOriginalConstructor()->getMock();
  48. $access->method('getPerson')->willReturn($person);
  49. $this->contactPointRepository
  50. ->method('getByTypeAndPerson')
  51. ->with(ContactPointTypeEnum::PRINCIPAL()->getValue(), $access->getPerson())
  52. ->willReturn([]);
  53. $contactPointUtils = $this
  54. ->getMockBuilder(ContactPointUtils::class)
  55. ->setConstructorArgs([$this->contactPointRepository])
  56. ->setMethodsExcept(['getPersonContactPointPrincipal'])
  57. ->getMock();
  58. $this->assertNull(
  59. $contactPointUtils->getPersonContactPointPrincipal($access)
  60. );
  61. }
  62. }