reflectionMock = $this->getMockBuilder(Reflection::class)->disableOriginalConstructor()->getMock(); $this->parser = new Parser(); } public function testGetOrganizationModules() { $module = $this->getMockBuilder(Module::class) ->onlyMethods(['getModuleBySettings', 'getModulesByConditions', 'getModulesByProductConfiguration']) ->disableOriginalConstructor() ->getMock(); $module->expects(self::once())->method('getModuleBySettings')->willReturn(['Sms']); $module->expects(self::once())->method('getModulesByConditions')->willReturn(['CotisationCall']); $settings = $this->getMockBuilder(Settings::class)->disableOriginalConstructor()->getMock(); $settings->expects(self::once())->method('getProduct')->willReturn('school'); $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock(); $organization->expects(self::once())->method('getSettings')->willReturn($settings); $module->expects(self::once())->method('getModulesByProductConfiguration')->willReturn(['Notification']); $this->assertEqualsCanonicalizing( ['Sms', 'CotisationCall', 'Notification'], $module->getOrganizationModules($organization) ); } /** * @see Module::getModuleBySettings() */ public function testGetModuleBySettings(){ $settingsMock = $this->getMockBuilder(Settings::class)->getMock(); $settingsMock ->expects($this->once()) ->method('getModules') ->willReturn(["Sms" => true]); $organizationMock = $this->getMockBuilder(Organization::class)->getMock(); $organizationMock ->expects($this->once()) ->method('getSettings') ->willReturn($settingsMock); $module = new Module($this->reflectionMock, $this->parser, self::OPENTALENT_CONFIG); $value = "Sms"; // assert function to test whether 'value' is a value of array $this->assertContains($value, $module->getModuleBySettings($organizationMock)) ; } /** * @see Module::getModulesByConditions() */ public function testGetModulesByConditions() { $organizationMock = $this->getMockBuilder(Organization::class)->getMock(); $this->reflectionMock ->method('dynamicInvokeServiceWithArgsAndMethod') ->withConsecutive( ['App\\Service\\Cotisation\\Utils', 'isLastParentAndCMF', array($organizationMock)] ) ->willReturnOnConsecutiveCalls( [true] ) ; $module = new Module($this->reflectionMock, $this->parser, self::OPENTALENT_CONFIG); $value = "CotisationCall"; // assert function to test whether 'value' is a value of array $this->assertContains($value, $module->getModulesByConditions($organizationMock)) ; } /** * @see Module::getModulesByProductConfiguration() */ public function testGetModulesByProductConfiguration() { $module = new Module($this->reflectionMock, $this->parser, self::OPENTALENT_CONFIG); $value = "MessagesAdvanced"; // assert function to test whether 'value' is a value of array $this->assertContains($value, $module->getModulesByProductConfiguration('artist-premium')) ; } }