entityManager = $this->createMock(EntityManagerInterface::class); } private function getEventMappingBuilderMockForMethod(string $methodName): TestableEventMappingBuilder|MockObject { return $this ->getMockBuilder(TestableEventMappingBuilder::class) ->setConstructorArgs([$this->entityManager]) ->setMethodsExcept([$methodName]) ->getMock(); } public function testMapInformations(): void { $eventMappingBuilder = $this->getEventMappingBuilderMockForMethod('mapInformations'); $event = $this->createMock(Event::class); $freemiumEvent = $this->createMock(FreemiumEvent::class); $eventMappingBuilder ->expects($this->once()) ->method('mapEventInformations') ->with($event, $freemiumEvent); $eventMappingBuilder ->expects($this->once()) ->method('mapEventPlaceInformations') ->with($event, $freemiumEvent); $eventMappingBuilder->mapInformations($event, $freemiumEvent); } public function testMapEventInformations(): void { $eventMappingBuilder = $this->getEventMappingBuilderMockForMethod('mapEventInformations'); $event = $this->createMock(Event::class); $organization = $this->createMock(Organization::class); $image = $this->createMock(File::class); $category1 = $this->createMock(Categories::class); $category2 = $this->createMock(Categories::class); $eventGender = $this->createMock(EventGender::class); $freemiumEvent = new FreemiumEvent(); $freemiumEvent->name = 'Test Event'; $freemiumEvent->organization = $organization; $freemiumEvent->datetimeStart = new \DateTime('2024-01-01 20:00:00'); $freemiumEvent->datetimeEnd = new \DateTime('2024-01-01 22:00:00'); $freemiumEvent->description = 'Test description'; $freemiumEvent->image = $image; $freemiumEvent->url = 'https://example.com'; $freemiumEvent->urlTicket = 'https://tickets.example.com'; $freemiumEvent->pricing = null; $freemiumEvent->priceMini = 0.0; $freemiumEvent->priceMaxi = 50.0; $freemiumEvent->gender = $eventGender; $freemiumEvent->addCategory($category1); $freemiumEvent->addCategory($category2); $event->expects($this->once())->method('setName')->with('Test Event'); $event->expects($this->once())->method('setOrganization')->with($organization); $event->expects($this->once())->method('setDatetimeStart')->with(new \DateTime('2024-01-01 20:00:00')); $event->expects($this->once())->method('setDatetimeEnd')->with(new \DateTime('2024-01-01 22:00:00')); $event->expects($this->once())->method('setDescription')->with('Test description'); $event->expects($this->once())->method('setImage')->with($image); $event->expects($this->once())->method('setUrl')->with('https://example.com'); $event->expects($this->once())->method('setUrlTicket')->with('https://tickets.example.com'); $event->expects($this->once())->method('setPricing')->with(null); $event->expects($this->once())->method('setPriceMini')->with(0.0); $event->expects($this->once())->method('setPriceMaxi')->with(50.0); $event->expects($this->once())->method('removeAllCategories'); $event->expects($this->exactly(2))->method('addCategory'); $eventMappingBuilder->mapEventInformations($event, $freemiumEvent); } public function testMapEventPlaceInformations(): void { $eventMappingBuilder = $this->getEventMappingBuilderMockForMethod('mapEventPlaceInformations'); $event = $this->createMock(Event::class); $freemiumEvent = $this->createMock(FreemiumEvent::class); $place = $this->createMock(Place::class); $eventMappingBuilder ->expects($this->once()) ->method('getPlace') ->with($freemiumEvent) ->willReturn($place); $eventMappingBuilder ->expects($this->once()) ->method('mapPlaceInformations') ->with($place, $freemiumEvent); $this->entityManager ->expects($this->once()) ->method('persist') ->with($place); $event->expects($this->once())->method('setPlace')->with($place); $eventMappingBuilder->mapEventPlaceInformations($event, $freemiumEvent); } public function testMapEventPlaceInformationsWithNullPlace(): void { $eventMappingBuilder = $this->getEventMappingBuilderMockForMethod('mapEventPlaceInformations'); $event = $this->createMock(Event::class); $freemiumEvent = $this->createMock(FreemiumEvent::class); $eventMappingBuilder ->expects($this->once()) ->method('getPlace') ->with($freemiumEvent) ->willReturn(null); $eventMappingBuilder ->expects($this->never()) ->method('mapPlaceInformations'); $this->entityManager ->expects($this->never()) ->method('persist'); $event->expects($this->once()) ->method('setPlace') ->with(null); $eventMappingBuilder->mapEventPlaceInformations($event, $freemiumEvent); } public function testMapPlaceInformations(): void { $eventMappingBuilder = $this->getEventMappingBuilderMockForMethod('mapPlaceInformations'); $place = $this->createMock(Place::class); $addressPostal = $this->createMock(AddressPostal::class); $organization = $this->createMock(Organization::class); $country = $this->createMock(Country::class); $freemiumEvent = new FreemiumEvent(); $freemiumEvent->organization = $organization; $freemiumEvent->placeName = 'Test Venue'; $freemiumEvent->streetAddress = '123 Test Street'; $freemiumEvent->streetAddressSecond = 'Apt 1'; $freemiumEvent->streetAddressThird = 'Floor 2'; $freemiumEvent->postalCode = '12345'; $freemiumEvent->addressCity = 'Test City'; $freemiumEvent->addressCountry = $country; $freemiumEvent->latitude = 48.8566; $freemiumEvent->longitude = 2.3522; $eventMappingBuilder ->expects($this->once()) ->method('getAddressPostal') ->with($place) ->willReturn($addressPostal); // Verify address postal setters $addressPostal->expects($this->once())->method('setStreetAddress')->with('123 Test Street')->willReturn($addressPostal); $addressPostal->expects($this->once())->method('setStreetAddressSecond')->with('Apt 1')->willReturn($addressPostal); $addressPostal->expects($this->once())->method('setStreetAddressThird')->with('Floor 2')->willReturn($addressPostal); $addressPostal->expects($this->once())->method('setPostalCode')->with('12345')->willReturn($addressPostal); $addressPostal->expects($this->once())->method('setAddressCity')->with('Test City')->willReturn($addressPostal); $addressPostal->expects($this->once())->method('setAddressCountry')->with($country)->willReturn($addressPostal); $addressPostal->expects($this->once())->method('setLatitude')->with(48.8566)->willReturn($addressPostal); $addressPostal->expects($this->once())->method('setLongitude')->with(2.3522)->willReturn($addressPostal); // Verify place setters $place->expects($this->once())->method('setOrganization')->with($organization)->willReturn($place); $place->expects($this->once())->method('setName')->with('Test Venue')->willReturn($place); $place->expects($this->once())->method('setAddressPostal')->with($addressPostal)->willReturn($place); $eventMappingBuilder->mapPlaceInformations($place, $freemiumEvent); } public function testGetPlaceWithExistingPlace(): void { $eventMappingBuilder = $this->getEventMappingBuilderMockForMethod('getPlace'); $existingPlace = $this->createMock(Place::class); $freemiumEvent = new FreemiumEvent(); $freemiumEvent->place = $existingPlace; $result = $eventMappingBuilder->getPlace($freemiumEvent); $this->assertSame($existingPlace, $result); } public function testGetPlaceCreatesNewPlace(): void { $eventMappingBuilder = $this->getEventMappingBuilderMockForMethod('getPlace'); $freemiumEvent = new FreemiumEvent(); $freemiumEvent->place = null; $freemiumEvent->placeName = 'Test Venue'; $result = $eventMappingBuilder->getPlace($freemiumEvent); $this->assertInstanceOf(Place::class, $result); } public function testGetPlaceReturnsNullWhenNoInformation(): void { $eventMappingBuilder = $this->getEventMappingBuilderMockForMethod('getPlace'); $freemiumEvent = new FreemiumEvent(); $freemiumEvent->place = null; $freemiumEvent->placeName = null; $freemiumEvent->streetAddress = null; $freemiumEvent->streetAddressSecond = null; $freemiumEvent->streetAddressThird = null; $freemiumEvent->postalCode = null; $freemiumEvent->addressCity = null; $result = $eventMappingBuilder->getPlace($freemiumEvent); $this->assertNull($result); } public function testGetAddressPostalWithExistingAddress(): void { $eventMappingBuilder = $this->getEventMappingBuilderMockForMethod('getAddressPostal'); $existingAddress = $this->createMock(AddressPostal::class); $place = $this->createMock(Place::class); $place->method('getAddressPostal')->willReturn($existingAddress); $result = $eventMappingBuilder->getAddressPostal($place); $this->assertSame($existingAddress, $result); } public function testGetAddressPostalCreatesNew(): void { $eventMappingBuilder = $this->getEventMappingBuilderMockForMethod('getAddressPostal'); $place = $this->createMock(Place::class); $place->method('getAddressPostal')->willReturn(null); $result = $eventMappingBuilder->getAddressPostal($place); $this->assertInstanceOf(AddressPostal::class, $result); } }