public function getTargetInterfaces()
 {
     if (!empty($this->targetInterfaces)) {
         return $this->targetInterfaces;
     }
     foreach ($this->targetInterfaceNames as $targetInterface) {
         if (!interface_exists($targetInterface)) {
             $this->targetInterfaces[] = new UndefinedTargetClass($targetInterface);
             return;
         }
         $dtc = DefinedTargetClass::factory($targetInterface);
         $extendedInterfaces = array_keys($dtc->getInterfaces());
         $extendedInterfaces[] = $targetInterface;
         $traversableFound = false;
         $iteratorShiftedToFront = false;
         foreach ($extendedInterfaces as $interface) {
             if (!$traversableFound && preg_match("/^\\?Iterator(|Aggregate)\$/i", $interface)) {
                 break;
             }
             if (preg_match("/^\\\\?IteratorAggregate\$/i", $interface)) {
                 $this->targetInterfaces[] = DefinedTargetClass::factory("\\IteratorAggregate");
                 $iteratorShiftedToFront = true;
             } else {
                 if (preg_match("/^\\\\?Iterator\$/i", $interface)) {
                     $this->targetInterfaces[] = DefinedTargetClass::factory("\\Iterator");
                     $iteratorShiftedToFront = true;
                 } else {
                     if (preg_match("/^\\\\?Traversable\$/i", $interface)) {
                         $traversableFound = true;
                     }
                 }
             }
         }
         if ($traversableFound && !$iteratorShiftedToFront) {
             $this->targetInterfaces[] = DefinedTargetClass::factory("\\IteratorAggregate");
         }
         /**
          * We never straight up implement Traversable
          */
         if (!preg_match("/^\\\\?Traversable\$/i", $targetInterface)) {
             $this->targetInterfaces[] = $dtc;
         }
     }
     $this->targetInterfaces = array_unique($this->targetInterfaces);
     // just in case
     return $this->targetInterfaces;
 }
Exemplo n.º 2
0
 public function getTargetClass()
 {
     if ($this->targetClass) {
         return $this->targetClass;
     }
     if (!$this->targetClassName) {
         return null;
     }
     if (class_exists($this->targetClassName)) {
         $dtc = DefinedTargetClass::factory($this->targetClassName);
         if ($this->getTargetObject() == false && $dtc->isFinal()) {
             throw new \Mockery\Exception('The class ' . $this->targetClassName . ' is marked final and its methods' . ' cannot be replaced. Classes marked final can be passed in' . ' to \\Mockery::mock() as instantiated objects to create a' . ' partial mock, but only if the mock is not subject to type' . ' hinting checks.');
         }
         $this->targetClass = $dtc;
     } else {
         $this->targetClass = new UndefinedTargetClass($this->targetClassName);
     }
     return $this->targetClass;
 }