Ejemplo n.º 1
0
 public static function instance($class)
 {
     \Arg::_($class, 'Class name')->is_string()->assert(class_exists($class), 'Class to getMock must be defined');
     $instance = new self();
     $instance->class = $class;
     return $instance;
 }
 public static function on($times)
 {
     \Arg::_($times, 'Times')->is_int();
     $instance = new static();
     $instance->times = $times;
     return $instance;
 }
 public static function instance($class)
 {
     \Arg::_($class, 'Class name')->is_string()->assert(class_exists($class) || interface_exists($class) || trait_exists($class), 'Class must be a defined one');
     $instance = new self();
     $instance->requestClassName = $class;
     $instance->isStaticMethod = false;
     $instance->isInstanceMethod = true;
     $instance->isFunction = false;
     $instance->isMethod = true;
     $instance->methodName = '';
     return $instance;
 }
 public static function make($times)
 {
     \Arg::_($times, 'Times')->is_int()->_or()->is_string();
     if (is_numeric($times)) {
         $times = (int) $times;
         return EqualMatchingStrategy::on($times);
     }
     $matches = array();
     if (!preg_match("/(>|>=|<|<=|==|!=)*(\\d)+/uU", $times, $matches)) {
         throw new \InvalidArgumentException('If times is a string it must follow the pattern [==|!=|<=|<|>=|>]*\\d+');
     }
     $prefix = $matches[1];
     $times = (int) $matches[2];
     switch ($prefix) {
         case '>':
             $matchingStrategy = GreaterThanMatchingStrategy::on($times);
             break;
         case '>=':
             $matchingStrategy = AtLeastMatchingStrategy::on($times);
             break;
         case '==':
             $matchingStrategy = EqualMatchingStrategy::on($times);
             break;
         case '<':
             $matchingStrategy = LessThanMatchingStrategy::on($times);
             break;
         case '<=':
             $matchingStrategy = AtMostMatchingStrategy::on($times);
             break;
         case '!=':
             $matchingStrategy = NotEqualMatchingStrategy::on($times);
             break;
         default:
             $matchingStrategy = EqualMatchingStrategy::on($times);
             break;
     }
     return $matchingStrategy;
 }
Ejemplo n.º 5
0
 public static function fromName($functionName)
 {
     if (!self::$systemFunctions) {
         self::$systemFunctions = get_defined_functions()['internal'];
     }
     $condition = !in_array($functionName, self::$systemFunctions);
     \Arg::_($functionName)->assert($condition, 'Function must not be an internal one.');
     $instance = new self();
     $instance->isEvalCreated = false;
     $instance->functionName = $functionName;
     $isMethod = preg_match("/^[\\w\\d_\\\\]+::[\\w\\d_]+\$/", $functionName);
     if (!$isMethod && !function_exists($functionName)) {
         $namespace = self::hasNamespace($functionName) ? 'namespace ' . self::getNamespaceFrom($functionName) . ";" : '';
         $functionName = self::hasNamespace($functionName) ? self::getFunctionNameFrom($functionName) : $functionName;
         $code = sprintf('%sfunction %s(){return null;}', $namespace, $functionName);
         $ok = eval($code);
         if ($ok === false) {
             throw new \Exception("Could not eval code {$code} for function {$functionName}");
         }
         $instance->isEvalCreated = true;
     }
     return $instance;
 }
Ejemplo n.º 6
0
 public function setOriginalClassName($className)
 {
     \Arg::_($className, "Original class name")->is_string()->assert(class_exists($className) || interface_exists($className) || trait_exists($className), 'Original class, interface or trait must be defined');
     $this->originalClassName = $className;
 }
Ejemplo n.º 7
0
 /**
  * @test
  * it should fail if array has not all the values
  */
 public function it_should_fail_if_array_has_not_all_the_values()
 {
     $this->setExpectedException('InvalidArgumentException');
     $array = ['foo' => 23, 'format' => 11];
     Arg::_($array)->has_value(13, 23);
 }
Ejemplo n.º 8
0
 /**
  * @param string $functionName
  *
  * @return LoggerInterface
  */
 public static function make($functionName)
 {
     \Arg::_($functionName, 'Function name')->is_string();
     $invocation = new SpyCallLogger();
     return $invocation;
 }
Ejemplo n.º 9
0
 /**
  * Sets a global value restoring the state after the test ran.
  *
  * @param string $globalHandle The key the value will be associated to in the $GLOBALS array.
  * @param mixed $replacement The value that will be set in the $GLOBALS array.
  *
  * @return mixed               The object that's been set in the $GLOBALS array.
  */
 public static function setGlobal($globalHandle, $replacement = null)
 {
     \Arg::_($globalHandle, 'Global var key')->is_string();
     self::backupGlobal($globalHandle);
     $GLOBALS[$globalHandle] = $replacement;
     return $replacement;
 }
Ejemplo n.º 10
0
 public static function normalizePathFrag($path)
 {
     \Arg::_($path, 'Path')->is_string();
     return trim(trim($path), '/');
 }
Ejemplo n.º 11
0
 public static function on($mockRequest)
 {
     \Arg::_($mockRequest, 'Function or method name')->is_string();
     $type = self::getType($mockRequest);
     return self::getInstanceForTypeAndRequest($type, $mockRequest);
 }