/** * Create a ReferencingCase with pre populated ProspectiveLandlord object. * * @return ReferencingCase */ private function getPrePopulatedCase() { // First, get the DirectLandlord object from IRIS and instantiate an empty ProspectiveLandlord. $directLandlord = $this->irisEntityManager->find(new DirectLandlord()); $prospectiveLandlord = new ProspectiveLandlord(); // Now map the DirectLandlord into a new ProspectiveLandlord: // foreach property in the DirectLandlord, if the ProspectiveLandlord contains a setter method, set it using the corresponding get method. // TODO getter and setter discovery can be handled more effectively $directLandlordReflect = new \ReflectionClass($directLandlord); $properties = $directLandlordReflect->getProperties(); foreach ($properties as $property) { $setMethod = sprintf('set%s', ucfirst($property->getName())); $getMethod = sprintf('get%s', ucfirst($property->getName())); if (method_exists($prospectiveLandlord, $setMethod) && method_exists($directLandlord, $getMethod)) { $prospectiveLandlord->{$setMethod}($directLandlord->{$getMethod}()); } } // Add the newly formed ProspectiveLandlord to the case. $case = new ReferencingCase(); $case->setProspectiveLandlord($prospectiveLandlord); return $case; }