|
|
@@ -9,49 +9,69 @@ use App\Enum\Core\ContactPointTypeEnum;
|
|
|
use App\Repository\Core\ContactPointRepository;
|
|
|
use App\Service\Access\Utils;
|
|
|
use App\Service\Core\ContactPointUtils;
|
|
|
+use PHPUnit\Framework\MockObject\MockObject;
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
class ContactPointUtilsTest extends TestCase
|
|
|
{
|
|
|
- private ContactPointUtils $contactPointUtils;
|
|
|
- private ContactPointRepository $contactPointRepositoryMock;
|
|
|
+ private MockObject | ContactPointRepository $contactPointRepository;
|
|
|
|
|
|
public function setUp():void
|
|
|
{
|
|
|
- $this->contactPointRepositoryMock = $this->getMockBuilder(ContactPointRepository::class)->disableOriginalConstructor()->getMock();
|
|
|
-
|
|
|
- $this->contactPointUtils = new ContactPointUtils($this->contactPointRepositoryMock);
|
|
|
+ $this->contactPointRepository = $this->getMockBuilder(ContactPointRepository::class)->disableOriginalConstructor()->getMock();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @see Utils::getPersonContactPointPrincipal()
|
|
|
*/
|
|
|
- public function testGetPersonContactPointPrincipal(){
|
|
|
- $person = new Person();
|
|
|
- $access = new Access();
|
|
|
- $access->setPerson($person);
|
|
|
+ public function testGetPersonContactPointPrincipal(): void
|
|
|
+ {
|
|
|
+ $person = $this->getMockBuilder(Person::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $access = $this->getMockBuilder(Access::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $access->method('getPerson')->willReturn($person);
|
|
|
+
|
|
|
+ $contactPoint = $this->getMockBuilder(ContactPoint::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
- $this->contactPointRepositoryMock
|
|
|
+ $this->contactPointRepository
|
|
|
->method('getByTypeAndPerson')
|
|
|
->with(ContactPointTypeEnum::PRINCIPAL()->getValue(), $access->getPerson())
|
|
|
- ->willReturn([new ContactPoint()]);
|
|
|
+ ->willReturn([$contactPoint]);
|
|
|
|
|
|
- $this->assertInstanceOf(ContactPoint::class, $this->contactPointUtils->getPersonContactPointPrincipal($access));
|
|
|
+ $contactPointUtils = $this
|
|
|
+ ->getMockBuilder(ContactPointUtils::class)
|
|
|
+ ->setConstructorArgs([$this->contactPointRepository])
|
|
|
+ ->setMethodsExcept(['getPersonContactPointPrincipal'])
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
+ $this->assertEquals(
|
|
|
+ $contactPoint,
|
|
|
+ $contactPointUtils->getPersonContactPointPrincipal($access)
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @see Utils::getPersonContactPointPrincipal()
|
|
|
*/
|
|
|
- public function testGetPersonContactPointPrincipalNotExist(){
|
|
|
- $person = new Person();
|
|
|
- $access = new Access();
|
|
|
- $access->setPerson($person);
|
|
|
+ public function testGetPersonContactPointPrincipalNotExisting(){
|
|
|
+ $person = $this->getMockBuilder(Person::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $access = $this->getMockBuilder(Access::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $access->method('getPerson')->willReturn($person);
|
|
|
+
|
|
|
+ $contactPoint = $this->getMockBuilder(ContactPoint::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
- $this->contactPointRepositoryMock
|
|
|
+ $this->contactPointRepository
|
|
|
->method('getByTypeAndPerson')
|
|
|
->with(ContactPointTypeEnum::PRINCIPAL()->getValue(), $access->getPerson())
|
|
|
->willReturn([]);
|
|
|
|
|
|
- $this->assertNull($this->contactPointUtils->getPersonContactPointPrincipal($access));
|
|
|
+ $contactPointUtils = $this
|
|
|
+ ->getMockBuilder(ContactPointUtils::class)
|
|
|
+ ->setConstructorArgs([$this->contactPointRepository])
|
|
|
+ ->setMethodsExcept(['getPersonContactPointPrincipal'])
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
+ $this->assertNull(
|
|
|
+ $contactPointUtils->getPersonContactPointPrincipal($access)
|
|
|
+ );
|
|
|
}
|
|
|
-}
|
|
|
+}
|