Esempio n. 1
0
 /**
  * @test
  */
 public function the_ServiceDefinition_resolves_an_ImplementingType_that_has_been_build_with_the_isTheSame_method()
 {
     // given
     $Target = new ServiceDefinition('/my/path', 42, IdentifyingType::is(Type::fromName('tueena\\spec\\core\\stubs\\MyService')), ImplementingType::isTheSame());
     // when
     $Result = $Target->getImplementingType();
     // then
     $this->assertEquals('tueena\\spec\\core\\stubs\\MyService', $Result->getName());
 }
 /**
  * @param ServiceDefinition $ServiceDefinition
  */
 private static function validateImplementingTypeIsInstanceOfIdentifyingType(ServiceDefinition $ServiceDefinition)
 {
     $IdentifyingType = $ServiceDefinition->getIdentifyingType();
     $ImplementingType = $ServiceDefinition->getImplementingType();
     // The only case, the implementing is NULL is, when a factory function is
     // defined. We cannot validate, if the the factory function retuns a valid
     // type without building the service, so we validate that in the
     // ServiceFactory when the service is build.
     if (is_null($ImplementingType)) {
         return;
     }
     if ($ImplementingType === $IdentifyingType) {
         return;
     }
     if (!$ImplementingType->isInstanceOf($IdentifyingType)) {
         $message = $ImplementingType->getName() . ' does not implement ' . $IdentifyingType->getName() . '. ';
         $message .= 'The implementing type of a service must be an instance of the identifying type.';
         throw new InvalidServiceDefinition($ServiceDefinition, $message);
     }
 }