OrganizationProfileCreatorTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Test\Service\Organization;
  3. use App\ApiResources\Profile\OrganizationProfile;
  4. use App\Entity\Organization\Organization;
  5. use App\Entity\Organization\Parameters;
  6. use App\Entity\Organization\Settings;
  7. use App\Service\Network\Tree;
  8. use App\Service\Organization\OrganizationProfileCreator;
  9. use App\Service\Security\Module;
  10. use PHPUnit\Framework\TestCase;
  11. class OrganizationProfileCreatorTest extends TestCase
  12. {
  13. private Organization $organization;
  14. public function setUp():void
  15. {
  16. $this->organization = new Organization();
  17. $this->organization
  18. ->setParameters(new Parameters())
  19. ->setSettings(new Settings())
  20. ->setName('Foo')
  21. ;
  22. }
  23. /**
  24. * @see OrganizationProfileCreator::getOrganizationProfile()
  25. */
  26. public function testGetOrganizationProfile(){
  27. $moduleMock = $this->getMockBuilder(Module::class)->disableOriginalConstructor()->getMock();
  28. $moduleMock
  29. ->method('getOrganizationModules')
  30. ->with($this->organization)
  31. ->willReturn(["MODULE_A", "MODULE_B"]);
  32. $treeMock = $this->getMockBuilder(Tree::class)->disableOriginalConstructor()->getMock();
  33. $parent = new Organization();
  34. $parent->setParameters(new Parameters());
  35. $treeMock
  36. ->method('findAllParentsAndSortByType')
  37. ->with($this->organization)
  38. ->willReturn([$parent, $parent]);
  39. $organizationProfileCreator = new OrganizationProfileCreator($moduleMock,$treeMock);
  40. $organizationProfile = $organizationProfileCreator->getOrganizationProfile($this->organization);
  41. $this->assertInstanceOf(OrganizationProfile::class, $organizationProfile);
  42. }
  43. }