Example #1
0
 /**
  * Puts it into a plan, then serializes the plan and deserializes it in order
  * to build a new object from which the value is read. 
  * 
  * @param ValueSource $source
  * @return mixed rebuilt value
  */
 protected function getRebuiltResultOf(ValueSource $source)
 {
     $plan = (new NewInstanceBuildPlan())->setClassSource(new ExactClassPath(TestClass::class))->addMethodCall((new MethodCall(ConstructorSelector::getInstance()))->assignParamValue(new AssignedParamValue(new ParamByExactName("passedToConstructor"), $source)));
     /* @var $rebuiltObject TestClass */
     $rebuiltObject = $this->getRebuiltObjectBy($plan);
     return $rebuiltObject->passedToConstructor;
 }
 public function testAddingExtension()
 {
     $valueSource = new NewValueSource();
     $extension = $this->getExtension($valueSource, "abc");
     $builder = $this->buildExtendedBuilder($extension);
     $plan = new NewInstanceBuildPlan();
     $plan->setClassSource(new ExactClassPath(TestClass::class));
     $plan->addMethodCall((new MethodCall(ConstructorSelector::getInstance()))->assignParamValue(new AssignedParamValue(new ParamByPosition(0), $valueSource)));
     $serializedPlan = $builder->serializeBuildPlan($plan);
     $deserializedPlan = $builder->deserializeBuildPlan($serializedPlan);
     /* @var $rebuiltObject TestClass */
     $rebuiltObject = $builder->buildObjectBasedOn($deserializedPlan);
     $this->assertEquals("abc", $rebuiltObject->passedToConstructor);
 }
 public function testConstructorSelector()
 {
     $this->checkMethodSelector(ConstructorSelector::getInstance());
 }
 /**
  * Gets a build plan of TestClass instance with 
  * a value resolved from the container (with key equals $containerKey)
  * passed as the constructor parameter.
  * 
  * @param String $containerKey
  * @return BuildPlan 
  */
 private function getBuildPlanOfObjectUsing($containerKey)
 {
     return (new NewInstanceBuildPlan())->setClassSource(new ExactClassPath(TestClass::class))->addMethodCall((new MethodCall(ConstructorSelector::getInstance()))->assignParamValue(new AssignedParamValue(new ParamByPosition(0), new InjectedValue($containerKey))));
 }
 public function mapToObject(array $previouslyMappedObject)
 {
     return ConstructorSelector::getInstance();
 }