/**
  * @test
  * @expectedException RuntimeException
  * @expectedExceptionMessage Found service class mismatch with expected type! - name: 'SingletonTestService' type: 'PhSpring\Annotations\Autowired'
  */
 public function withQualifierAndWrongType()
 {
     Collection::add('SingletonTestService', Singleton::getInstance());
     $instance = new ClassInvokerFixture();
     $refl = new ReflectionProperty(ClassInvokerFixture::class, 'singleton5');
     $this->handler->run($refl, $instance);
 }
Example #2
0
 private static function addSingleton(ReflectionClass $reflClass)
 {
     if ($reflClass->hasMethod('getInstance')) {
         $type = $reflClass->getName();
         $service = $type::getInstance();
     } else {
         $service = ClassInvoker::getNewInstanceByRefl($reflClass);
     }
     Collection::add(self::getName($reflClass), $service);
 }
Example #3
0
 public function getInstance()
 {
     if ($this->getReflClass()->hasMethod('getInstance')) {
         $type = $this->getReflClass()->getName();
         $service = $type::getInstance();
     } else {
         $service = ClassInvoker::getNewInstanceByRefl($this->getReflClass());
     }
     Collection::add($this->getName(), $service);
     return $service;
 }