networkOrganizationRepositoryMock = $this ->getMockBuilder(NetworkOrganizationRepository::class) ->disableOriginalConstructor() ->getMock(); $this->tree = new Tree($this->networkOrganizationRepositoryMock); } /** * @see Tree::findAllParentsAndSortByType() */ public function testFindAllParentsAndSortByType():void { $organizationMock = $this->getMockBuilder(Organization::class)->getMock(); $organizationMock ->method('getId') ->willReturn(1); $this->networkOrganizationRepositoryMock ->expects($this->once()) ->method('findAllParents') ->with($organizationMock) ->willReturn([$organizationMock]); $treeMock = $this ->getMockBuilder(Tree::class) ->setConstructorArgs([$this->networkOrganizationRepositoryMock]) ->onlyMethods(['sortByType']) ->getMock(); $treeMock ->expects($this->once()) ->method('sortByType'); $treeMock->findAllParentsAndSortByType($organizationMock); } /** * @see Tree::sortByType() */ public function testSortByType():void { $organizationMock1 = $this->getMockBuilder(Organization::class)->getMock(); $organizationMock1->method('getId')->willReturn(2); $organizationMock1->method('getPrincipalType')->willReturn('REGIONAL_FEDERATION'); $organizationMock2 = $this->getMockBuilder(Organization::class)->getMock(); $organizationMock2->method('getId')->willReturn(3); $organizationMock2->method('getPrincipalType')->willReturn('NATIONAL_FEDERATION'); $organizationMock3 = $this->getMockBuilder(Organization::class)->getMock(); $organizationMock3->method('getId')->willReturn(4); $organizationMock3->method('getPrincipalType')->willReturn('DEPARTEMENTAL_FEDERATION'); $organizations = [ $organizationMock2, $organizationMock1, $organizationMock3 ]; $result = $this->tree->sortByType($organizations); $this->assertIsArray($result); $this->assertContainsOnlyInstancesOf(Organization::class, $result); $this->assertEquals(4, $result[0]->getId()); $this->assertEquals(2, $result[1]->getId()); $this->assertEquals(3, $result[2]->getId()); } }