subdomainService = $this->getMockBuilder(SubdomainService::class)->disableOriginalConstructor()->getMock(); $this->organizationRepository = $this->getMockBuilder(OrganizationRepository::class)->disableOriginalConstructor()->getMock(); $this->countryRepository = $this->getMockBuilder(CountryRepository::class)->disableOriginalConstructor()->getMock(); $this->organizationUtils = $this->getMockBuilder(OrganizationUtils::class)->disableOriginalConstructor()->getMock(); $this->typo3Service = $this->getMockBuilder(Typo3Service::class)->disableOriginalConstructor()->getMock(); $this->dolibarrApiService = $this->getMockBuilder(DolibarrApiService::class)->disableOriginalConstructor()->getMock(); $this->entityManager = $this->getMockBuilder(EntityManagerInterface::class)->disableOriginalConstructor()->getMock(); $this->personRepository = $this->getMockBuilder(PersonRepository::class)->disableOriginalConstructor()->getMock(); $this->bindFileService = $this->getMockBuilder(BindFileService::class)->disableOriginalConstructor()->getMock(); $this->logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock(); } private function getOrganizationFactoryMockFor(string $methodName): TestableOrganizationFactory | MockObject { $organizationFactory = $this ->getMockBuilder(TestableOrganizationFactory::class) ->setConstructorArgs( [ $this->subdomainService, $this->organizationRepository, $this->countryRepository, $this->organizationUtils, $this->typo3Service, $this->dolibarrApiService, $this->entityManager, $this->personRepository, $this->bindFileService ]) ->setMethodsExcept(['setLoggerInterface', $methodName]) ->getMock(); $organizationFactory->setLoggerInterface($this->logger); return $organizationFactory; } public function testCreate(): void { $organizationFactory = $this->getOrganizationFactoryMockFor('create'); $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock(); $organizationCreationRequest->method('getName')->willReturn('foo'); $organizationCreationRequest->method('getSubdomain')->willReturn('subdomain'); $organizationCreationRequest->method('isClient')->willReturn(false); $organizationCreationRequest->method('getCreateWebsite')->willReturn(true); $this->entityManager->expects(self::once())->method('beginTransaction'); $organizationFactory->expects(self::once())->method('isExistingOrganization')->willReturn(false); $organizationFactory->expects(self::once())->method('validateSubdomain')->with('subdomain'); $organization = $this->getMockBuilder(Organization::class)->getMock(); $organizationFactory ->expects(self::once()) ->method('makeOrganizationWithRelations') ->with($organizationCreationRequest) ->willReturn($organization); $this->entityManager->expects(self::once())->method('persist')->with($organization); $this->entityManager->expects(self::once())->method('flush'); $this->entityManager->expects(self::once())->method('commit'); $this->dolibarrApiService ->expects(self::once()) ->method('createSociety') ->with($organization, false) ->willReturn(456); $this->bindFileService ->expects(self::once()) ->method('registerSubdomain') ->with('subdomain'); $organizationFactory ->expects(self::once()) ->method('createTypo3Website') ->with($organization); $this->logger ->method('info') ->withConsecutive( ["Start the creation of a new organization named 'foo'"], ["Subdomain is valid and available : 'subdomain'"], ["Organization created with all its relations"], ["New dolibarr structure created (uid : 456)"], ["Organization persisted in the DB"], ["Subdomain registered"], ); $result = $organizationFactory->create($organizationCreationRequest); $this->assertEquals( $organization, $result ); } }