Пример #1
0
 public function apply($code, MockConfiguration $config)
 {
     $target = $config->getTargetClass();
     if (!$target) {
         return $code;
     }
     if ($target->isFinal()) {
         return $code;
     }
     $className = ltrim($target->getName(), "\\");
     if (!class_exists($className)) {
         $targetCode = '<?php ';
         if ($target->inNamespace()) {
             $targetCode .= 'namespace ' . $target->getNamespaceName() . '; ';
         }
         $targetCode .= 'class ' . $target->getShortName() . ' {} ';
         /*
          * We could eval here, but it doesn't play well with the way
          * PHPUnit tries to backup global state and the require definition
          * loader
          */
         $tmpfname = tempnam(sys_get_temp_dir(), "Mockery");
         file_put_contents($tmpfname, $targetCode);
         require $tmpfname;
         \Mockery::registerFileForCleanUp($tmpfname);
     }
     $code = str_replace("implements MockInterface", "extends \\" . $className . " implements MockInterface", $code);
     return $code;
 }
Пример #2
0
 /**
  * Apply implementation.
  *
  * @param $code
  * @param MockConfiguration $config
  * @return string
  */
 public function apply($code, MockConfiguration $config)
 {
     $magicMethods = $this->getMagicMethods($config->getTargetClass());
     foreach ($magicMethods as $method) {
         $code = $this->applyMagicTypeHints($code, $method);
     }
     return $code;
 }
Пример #3
0
 public function apply($code, MockConfiguration $config)
 {
     $target = $config->getTargetClass();
     if (!$target) {
         return $code;
     }
     if (!$config->isMockOriginalDestructor()) {
         $code = preg_replace('/public function __destruct\\(\\)\\s+\\{.*?\\}/sm', '', $code);
     }
     return $code;
 }
 public function apply($code, MockConfiguration $config)
 {
     $target = $config->getTargetClass();
     if (!$target) {
         return $code;
     }
     if (!$target->hasInternalAncestor() || !$target->implementsInterface("Serializable")) {
         return $code;
     }
     $code = $this->appendToClass($code, self::DUMMY_METHOD_DEFINITION);
     return $code;
 }
 public function apply($code, MockConfiguration $config)
 {
     $target = $config->getTargetClass();
     if (!$target) {
         return $code;
     }
     foreach ($target->getMethods() as $method) {
         if ($method->isFinal() && isset($this->methods[$method->getName()])) {
             $code = preg_replace($this->methods[$method->getName()], '', $code);
         }
     }
     return $code;
 }