setName('Foo') ->setGivenName('Bar') ; $today = new \DateTime(); $this->access = new Access(); $this->access ->setAdminAccess(true) ->setPerson($person) ->setOrganization(new Organization()) ->setActivityYear($today->format('Y')) ; $organizationProfileCreatorMock = $this->getMockBuilder(OrganizationProfileCreator::class)->disableOriginalConstructor()->getMock(); $organizationProfileCreatorMock ->method('createCompleteOrganizationProfile') ->with($this->access->getOrganization()) ->willReturn(new OrganizationProfile()); $this->accessRepositoryMock = $this->getMockBuilder(AccessRepository::class)->disableOriginalConstructor()->getMock(); $accessUtilsMock = $this->getMockBuilder(Utils::class)->disableOriginalConstructor()->getMock(); $this->accessProfileCreator = new AccessProfileCreator( $organizationProfileCreatorMock, $this->accessRepositoryMock, $accessUtilsMock ); } /** * @see AccessProfileCreator::getAccessProfile() */ public function testGetAccessProfileFailed(){ $this->accessRepositoryMock ->method('findAllValidAccesses') ->with($this->access) ->willReturn([]); $this->expectException(AuthenticationException::class); $this->accessProfileCreator->getAccessProfile($this->access); } /** * @see AccessProfileCreator::createCompleteAccessProfile() */ public function testCreateCompleteAccessProfile(){ $accessProfile = $this->accessProfileCreator->createCompleteAccessProfile($this->access); $this->assertInstanceOf(AccessProfile::class, $accessProfile); } /** * @see AccessProfileCreator::createLightAccessProfile() */ public function testCreateLightAccessProfile(){ $accessProfile = $this->accessProfileCreator->createLightAccessProfile($this->access); $this->assertInstanceOf(AccessProfile::class, $accessProfile); } public function testIsGuardian(){ $childrenMock = $this->getMockBuilder(Access::class)->disableOriginalConstructor()->getMock(); $this->access->addChild($childrenMock); $accessProfile = $this->accessProfileCreator->createCompleteAccessProfile($this->access); $this->assertTrue($accessProfile->getIsGuardian()); } public function testIsNotGuardian(){ $accessProfile = $this->accessProfileCreator->createCompleteAccessProfile($this->access); $this->assertFalse($accessProfile->getIsGuardian()); } public function testIsPayorWithBillingPayer(){ $accessPayerMock = $this->getMockBuilder(AccessPayer::class)->disableOriginalConstructor()->getMock(); $this->access->addBillingPayer($accessPayerMock); $accessProfile = $this->accessProfileCreator->createCompleteAccessProfile($this->access); $this->assertTrue($accessProfile->getIsPayor()); } public function testIsPayorWithAccessIntangible(){ $accessIntangibleMock = $this->getMockBuilder(AccessIntangible::class)->disableOriginalConstructor()->getMock(); $this->access->addAccessIntangible($accessIntangibleMock); $accessProfile = $this->accessProfileCreator->createCompleteAccessProfile($this->access); $this->assertTrue($accessProfile->getIsPayor()); } public function testIsNotPayor(){ $accessProfile = $this->accessProfileCreator->createCompleteAccessProfile($this->access); $this->assertFalse($accessProfile->getIsPayor()); } public function testIsNotPayorWithAccessIntangibleBecauseChildren(){ $accessIntangibleMock = $this->getMockBuilder(AccessIntangible::class)->disableOriginalConstructor()->getMock(); $this->access->addAccessIntangible($accessIntangibleMock); $childrenMock = $this->getMockBuilder(Access::class)->disableOriginalConstructor()->getMock(); $this->access->addChild($childrenMock); $accessProfile = $this->accessProfileCreator->createCompleteAccessProfile($this->access); $this->assertFalse($accessProfile->getIsPayor()); } public function testIsNotPayorWithAccessIntangibleBecauseBillingReceivers(){ $accessIntangibleMock = $this->getMockBuilder(AccessIntangible::class)->disableOriginalConstructor()->getMock(); $this->access->addAccessIntangible($accessIntangibleMock); $accessPayerMock = $this->getMockBuilder(AccessPayer::class)->disableOriginalConstructor()->getMock(); $this->access->addBillingReceiver($accessPayerMock); $accessProfile = $this->accessProfileCreator->createCompleteAccessProfile($this->access); $this->assertFalse($accessProfile->getIsPayor()); } }