getMockBuilder(TestableOrganizationMappingBuilder::class) ->setMethodsExcept([$methodName]) ->getMock(); } public function testMapInformations(): void { $organizationMappingBuilder = $this ->getMockBuilder(TestableOrganizationMappingBuilder::class) ->setMethodsExcept(['mapInformations']) ->getMock(); $organization = $this->createMock(Organization::class); $freemiumOrganization = $this->createMock(FreemiumOrganization::class); $contactPoint = $this->createMock(ContactPoint::class); $addressPostal = $this->createMock(AddressPostal::class); // Verify that methods are called in the correct order $organizationMappingBuilder ->expects($this->once()) ->method('mapOrganizationInformations') ->with($organization, $freemiumOrganization); $organizationMappingBuilder ->expects($this->once()) ->method('updateOrganizationTypeOfPractices') ->with($organization, $freemiumOrganization); $organizationMappingBuilder ->expects($this->once()) ->method('getPrincipalContactPointOrCreateNewOne') ->with($organization) ->willReturn($contactPoint); $organizationMappingBuilder ->expects($this->once()) ->method('mapContactPointInformations') ->with($contactPoint, $freemiumOrganization); $organizationMappingBuilder ->expects($this->once()) ->method('getPrincipalAddressPostalOrCreateNewOne') ->with($organization) ->willReturn($addressPostal); $organizationMappingBuilder ->expects($this->once()) ->method('mapAddressPostalInformations') ->with($addressPostal, $freemiumOrganization); $organizationMappingBuilder->mapInformations($organization, $freemiumOrganization); } public function testMapOrganizationInformations(): void { $organizationMappingBuilder = $this->getOrganizationMappingBuilderMockForMethod('mapOrganizationInformations'); $organization = $this->createMock(Organization::class); $logo = $this->createMock(File::class); $freemiumOrganization = new FreemiumOrganization(); $freemiumOrganization->name = 'Test Organization'; $freemiumOrganization->description = 'Test Description'; $freemiumOrganization->facebook = 'https://facebook.com/test'; $freemiumOrganization->youtube = 'https://youtube.com/test'; $freemiumOrganization->instagram = 'https://instagram.com/test'; $freemiumOrganization->twitter = 'https://twitter.com/test'; $freemiumOrganization->portailVisibility = true; $freemiumOrganization->logo = $logo; // Verify setter calls $organization->expects($this->once())->method('setName')->with('Test Organization'); $organization->expects($this->once())->method('setDescription')->with('Test Description'); $organization->expects($this->once())->method('setFacebook')->with('https://facebook.com/test'); $organization->expects($this->once())->method('setYoutube')->with('https://youtube.com/test'); $organization->expects($this->once())->method('setInstagram')->with('https://instagram.com/test'); $organization->expects($this->once())->method('setTwitter')->with('https://twitter.com/test'); $organization->expects($this->once())->method('setPortailVisibility')->with(true); $organization->expects($this->once())->method('setLogo')->with($logo); $organizationMappingBuilder->mapOrganizationInformations($organization, $freemiumOrganization); } public function testMapContactPointInformations(): void { $organizationMappingBuilder = $this->getOrganizationMappingBuilderMockForMethod('mapContactPointInformations'); $contactPoint = $this->createMock(ContactPoint::class); $tel = $this->createMock(PhoneNumber::class); $freemiumOrganization = new FreemiumOrganization(); $freemiumOrganization->tel = $tel; $freemiumOrganization->email = 'test@example.com'; $contactPoint->expects($this->once())->method('setTelphone')->with($tel); $contactPoint->expects($this->once())->method('setEmail')->with('test@example.com'); $organizationMappingBuilder->mapContactPointInformations($contactPoint, $freemiumOrganization); } public function testMapAddressPostalInformations(): void { $organizationMappingBuilder = $this->getOrganizationMappingBuilderMockForMethod('mapAddressPostalInformations'); $address = $this->createMock(AddressPostal::class); $country = $this->createMock(Country::class); $freemiumOrganization = new FreemiumOrganization(); $freemiumOrganization->streetAddress = '123 Test Street'; $freemiumOrganization->streetAddressSecond = 'Apt 1'; $freemiumOrganization->streetAddressThird = 'Floor 2'; $freemiumOrganization->postalCode = '12345'; $freemiumOrganization->addressCity = 'Test City'; $freemiumOrganization->addressCountry = $country; $freemiumOrganization->longitude = 2.3522; $freemiumOrganization->latitude = 48.8566; $address->expects($this->once())->method('setStreetAddress')->with('123 Test Street'); $address->expects($this->once())->method('setStreetAddressSecond')->with('Apt 1'); $address->expects($this->once())->method('setStreetAddressThird')->with('Floor 2'); $address->expects($this->once())->method('setPostalCode')->with('12345'); $address->expects($this->once())->method('setAddressCity')->with('Test City'); $address->expects($this->once())->method('setAddressCountry')->with($country); $address->expects($this->once())->method('setLongitude')->with(2.3522); $address->expects($this->once())->method('setLatitude')->with(48.8566); $organizationMappingBuilder->mapAddressPostalInformations($address, $freemiumOrganization); } public function testGetPrincipalContactPointOrCreateNewOneWithExisting(): void { $organizationMappingBuilder = $this->getOrganizationMappingBuilderMockForMethod('getPrincipalContactPointOrCreateNewOne'); $organization = $this->createMock(Organization::class); $existingContactPoint = $this->createMock(ContactPoint::class); $organization->expects($this->once()) ->method('getPrincipalContactPoint') ->willReturn($existingContactPoint); $result = $organizationMappingBuilder->getPrincipalContactPointOrCreateNewOne($organization); $this->assertSame($existingContactPoint, $result); } public function testGetPrincipalContactPointOrCreateNewOneCreatesNew(): void { $organizationMappingBuilder = $this->getOrganizationMappingBuilderMockForMethod('getPrincipalContactPointOrCreateNewOne'); $organization = $this->createMock(Organization::class); $organization->expects($this->once()) ->method('getPrincipalContactPoint') ->willReturn(null); $organization->expects($this->once()) ->method('addContactPoint') ->with($this->isInstanceOf(ContactPoint::class)); $result = $organizationMappingBuilder->getPrincipalContactPointOrCreateNewOne($organization); $this->assertSame(ContactPointTypeEnum::PRINCIPAL, $result->getContactType()); } public function testGetPrincipalAddressPostalOrCreateNewOneWithExisting(): void { $organizationMappingBuilder = $this->getOrganizationMappingBuilderMockForMethod('getPrincipalAddressPostalOrCreateNewOne'); $organization = $this->createMock(Organization::class); $existingAddressPostal = $this->createMock(AddressPostal::class); $existingOrganizationAddressPostal = $this->createMock(OrganizationAddressPostal::class); $existingOrganizationAddressPostal->expects($this->once()) ->method('getAddressPostal') ->willReturn($existingAddressPostal); $organization->expects($this->once()) ->method('getPrincipalAddressPostal') ->willReturn($existingOrganizationAddressPostal); $result = $organizationMappingBuilder->getPrincipalAddressPostalOrCreateNewOne($organization); $this->assertSame($existingAddressPostal, $result); } public function testGetPrincipalAddressPostalOrCreateNewOneCreatesNew(): void { $organizationMappingBuilder = $this->getOrganizationMappingBuilderMockForMethod('getPrincipalAddressPostalOrCreateNewOne'); $organization = $this->createMock(Organization::class); $organization->expects($this->once()) ->method('getPrincipalAddressPostal') ->willReturn(null); $organization->expects($this->once()) ->method('addOrganizationAddressPostal') ->with($this->isInstanceOf(OrganizationAddressPostal::class)); $result = $organizationMappingBuilder->getPrincipalAddressPostalOrCreateNewOne($organization); } }