parameters() public static method

Gets the parameters array of a class method.
public static parameters ( $class, $method, $data = null ) : array
$class The class name.
$method The method name.
$data The default values.
return array The parameters array.
Beispiel #1
0
            expect(Inspector::typehint($inspector[0]))->toBe('');
            $inspector = Inspector::parameters($this->class, 'parameterByReference');
            expect(Inspector::typehint($inspector[0]))->toBe('');
        });
        it("returns parameter typehint", function () {
            $inspector = Inspector::parameters($this->class, 'exceptionTypeHint');
            $typehint = Inspector::typehint(current($inspector));
            expect($typehint)->toBeA('string');
            expect($typehint)->toBe('\\Exception');
            $inspector = Inspector::parameters($this->class, 'arrayTypeHint');
            $typehint = Inspector::typehint(current($inspector));
            expect($typehint)->toBeA('string');
            expect($typehint)->toBe('array');
            $inspector = Inspector::parameters($this->class, 'callableTypeHint');
            $typehint = Inspector::typehint(current($inspector));
            expect($typehint)->toBeA('string');
            expect($typehint)->toBe('callable');
        });
        it("returns parameter typehint for scalar type hints", function () {
            skipIf(PHP_MAJOR_VERSION < 7);
            $inspector = Inspector::parameters('Kahlan\\Spec\\Fixture\\Analysis\\ScalarTypeHintsClass', 'intTypeHint');
            $typehint = Inspector::typehint(current($inspector));
            expect($typehint)->toBeA('string');
            expect($typehint)->toBe('int');
            $inspector = Inspector::parameters('Kahlan\\Spec\\Fixture\\Analysis\\ScalarTypeHintsClass', 'boolTypeHint');
            $typehint = Inspector::typehint(current($inspector));
            expect($typehint)->toBeA('string');
            expect($typehint)->toBe('bool');
        });
    });
});
Beispiel #2
0
            expect($param4->getName())->toBe('d');
            expect($param4->getDefaultValue())->toBe(null);
        });
        it("merges defauts values with populated values when the third argument is not empty", function () {
            $inspector = Inspector::parameters($this->class, 'parametersExample', ['first', 1000, true]);
            expect($inspector)->toBe(['a' => 'first', 'b' => 1000, 'c' => true, 'd' => null]);
        });
    });
    describe("::typehint()", function () {
        it("returns an empty string when no typehint is present", function () {
            $inspector = Inspector::parameters($this->class, 'parametersExample');
            expect(Inspector::typehint($inspector[0]))->toBe('');
            $inspector = Inspector::parameters($this->class, 'parameterByReference');
            expect(Inspector::typehint($inspector[0]))->toBe('');
        });
        it("returns parameter typehint", function () {
            $inspector = Inspector::parameters($this->class, 'exceptionTypeHint');
            $typehint = Inspector::typehint(current($inspector));
            expect($typehint)->toBeA('string');
            expect($typehint)->toBe('\\Exception');
            $inspector = Inspector::parameters($this->class, 'arrayTypeHint');
            $typehint = Inspector::typehint(current($inspector));
            expect($typehint)->toBeA('string');
            expect($typehint)->toBe('array');
            $inspector = Inspector::parameters($this->class, 'callableTypeHint');
            $typehint = Inspector::typehint(current($inspector));
            expect($typehint)->toBeA('string');
            expect($typehint)->toBe('callable');
        });
    });
});
Beispiel #3
0
 /**
  * Calls a registered matcher.
  *
  * @param  string  $name   The name of the matcher.
  * @param  array   $params The parameters to pass to the matcher.
  * @return boolean
  */
 public function __call($matcherName, $params)
 {
     $result = true;
     $spec = $this->_actual;
     $specification = $this->_classes['specification'];
     $closure = function () use($spec, $specification, $matcherName, $params, &$actual, &$result) {
         if ($spec instanceof $specification) {
             $actual = $spec->run();
             if (!$spec->passed()) {
                 return false;
             }
         } else {
             $actual = $spec;
         }
         array_unshift($params, $actual);
         $matcher = $this->_matcher($matcherName, $actual);
         $result = call_user_func_array($matcher . '::match', $params);
         return is_object($result) || $result === !$this->_not;
     };
     try {
         $this->_spin($closure);
     } catch (TimeoutException $e) {
         $data['params']['timeout'] = $e->getMessage();
     } finally {
         array_unshift($params, $actual);
         $matcher = $this->_matcher($matcherName, $actual);
         $params = Inspector::parameters($matcher, 'match', $params);
         $data = compact('matcherName', 'matcher', 'params');
         if ($spec instanceof $specification) {
             foreach ($spec->logs() as $value) {
                 $this->_logs[] = $value;
             }
             $this->_passed = $this->_passed && $spec->passed();
         }
     }
     if (!is_object($result)) {
         $data['description'] = $data['matcher']::description();
         $this->_log($result, $data);
         return $this;
     }
     $this->_deferred[] = $data + ['instance' => $result, 'not' => $this->_not];
     return $result;
 }