/** * @testdox createService() returns select element with value options if organization is associated to the user. */ public function testCreateServiceWithAssociation() { /* @var $org \PHPUnit_Framework_MockObject_MockObject */ $org = $this->user->getOrganization(); $org->expects($this->once())->method('hasAssociation')->willReturn(true); $orgs = new ArrayCollection(); $org0 = $this->generateOrganizationEntity('testOrg0', 'testOrg0.name', 'org0.testCity', 'org0.testStreet', 'org0.1234'); $org1 = $this->generateOrganizationEntity('testOrg1', 'testOrg1.name', 'org1.city', 'org1.street', 'org1.number'); $orgs->add($org1); $org->expects($this->once())->method('getHiringOrganizations')->willReturn($orgs); $org->expects($this->once())->method('getOrganization')->willReturn($org0); $expect = array('testOrg0' => 'testOrg0.name|org0.testCity|org0.testStreet|org0.1234|', 'testOrg1' => 'testOrg1.name|org1.city|org1.street|org1.number|'); $select = $this->target->createService($this->formElements); $actual = $select->getValueOptions(); $this->assertEquals($expect, $actual); }
/** * post load hook must inject organization reference to UserInterface instances! */ public function testPostLoadHookInjectsOrganizationReferenceIfDocumentIsUserInterface() { $target = new InjectOrganizationReferenceListener(); $dm = $this->getMockBuilder('\\Doctrine\\ODM\\MongoDB\\DocumentManager')->disableOriginalConstructor()->getMock(); $doc = new User(); $rep = $this->getMockBuilder('\\Organizations\\Repository\\Organization')->disableOriginalConstructor()->getMock(); $dm->expects($this->once())->method('getRepository')->with('Organizations\\Entity\\Organization')->willReturn($rep); $doc->setId('test1234'); $args = new LifecycleEventArgs($doc, $dm); $result = $target->postLoad($args); $this->assertNull($result); $ref = $doc->getOrganization(); $this->assertInstanceOf('\\Organizations\\Entity\\OrganizationReference', $ref); $this->assertAttributeSame($rep, '_repository', $ref); $this->assertAttributeEquals($doc->getId(), '_userId', $ref); }