ModuleTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App\Test\Service\Security;
  3. use App\Entity\Organization\Organization;
  4. use App\Entity\Organization\Settings;
  5. use App\Service\Utils\Parser;
  6. use App\Service\Utils\Reflection;
  7. use PHPUnit\Framework\TestCase;
  8. use App\Service\Security\Module;
  9. class ModuleTest extends TestCase
  10. {
  11. const OPENTALENT_CONFIG = __DIR__.'/../../../config/opentalent';
  12. private Reflection $reflectionMock;
  13. private Parser $parser;
  14. public function setUp():void
  15. {
  16. $this->reflectionMock = $this->getMockBuilder(Reflection::class)->disableOriginalConstructor()->getMock();
  17. $this->parser= new Parser();
  18. }
  19. /**
  20. * @see Module::getModuleBySettings()
  21. */
  22. public function testGetModuleBySettings(){
  23. $settingsMock = $this->getMockBuilder(Settings::class)->getMock();
  24. $settingsMock
  25. ->expects($this->once())
  26. ->method('getModules')
  27. ->willReturn(["Sms" => true]);
  28. $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
  29. $organizationMock
  30. ->expects($this->once())
  31. ->method('getSettings')
  32. ->willReturn($settingsMock);
  33. $module = new Module($this->reflectionMock, $this->parser, self::OPENTALENT_CONFIG);
  34. $value = "Sms";
  35. // assert function to test whether 'value' is a value of array
  36. $this->assertContains($value, $module->getModuleBySettings($organizationMock)) ;
  37. }
  38. /**
  39. * @see Module::getModulesByConditions()
  40. */
  41. public function testGetModulesByConditions()
  42. {
  43. $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
  44. $this->reflectionMock
  45. ->method('dynamicInvokeServiceWithArgsAndMethod')
  46. ->withConsecutive(
  47. ['App\\Service\\Cotisation\\Utils', 'isLastParentAndCMF', array($organizationMock)]
  48. )
  49. ->willReturnOnConsecutiveCalls(
  50. [true]
  51. )
  52. ;
  53. $module = new Module($this->reflectionMock, $this->parser, self::OPENTALENT_CONFIG);
  54. $value = "CotisationCall";
  55. // assert function to test whether 'value' is a value of array
  56. $this->assertContains($value, $module->getModulesByConditions($organizationMock)) ;
  57. }
  58. /**
  59. * @see Module::getModulesByProductConfiguration()
  60. */
  61. public function testGetModulesByProductConfiguration()
  62. {
  63. $module = new Module($this->reflectionMock, $this->parser, self::OPENTALENT_CONFIG);
  64. $value = "MessagesAdvanced";
  65. // assert function to test whether 'value' is a value of array
  66. $this->assertContains($value, $module->getModulesByProductConfiguration('artist-premium')) ;
  67. }
  68. }