4 * This file is part of the Behat Testwork.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Testwork\Call;
13 use Behat\Testwork\Call\Exception\BadCallbackException;
14 use ReflectionFunction;
15 use ReflectionFunctionAbstract;
19 * Represents callee created and executed in the runtime.
21 * @author Konstantin Kudryashov <ever.zet@gmail.com>
23 class RuntimeCallee implements Callee
34 * @var ReflectionFunctionAbstract
45 * @param callable $callable
46 * @param null|string $description
48 * @throws BadCallbackException If invalid callback provided
50 public function __construct($callable, $description = null)
52 if (!is_array($callable) && !is_callable($callable)) {
53 throw new BadCallbackException(sprintf(
54 '%s expects a valid callable, but `%s` given',
60 if (is_array($callable)) {
61 $this->reflection = new ReflectionMethod($callable[0], $callable[1]);
62 $this->path = $callable[0] . '::' . $callable[1] . '()';
64 $this->reflection = new ReflectionFunction($callable);
65 $this->path = $this->reflection->getFileName() . ':' . $this->reflection->getStartLine();
68 $this->callable = $callable;
69 $this->description = $description;
73 * Returns callee description.
77 public function getDescription()
79 return $this->description;
83 * Returns callee definition path.
87 public function getPath()
97 public function getCallable()
99 return $this->callable;
103 * Returns callable reflection.
105 * @return ReflectionFunctionAbstract
107 public function getReflection()
109 return $this->reflection;
113 * Returns true if callee is a method, false otherwise.
117 public function isAMethod()
119 return $this->reflection instanceof ReflectionMethod;
123 * Returns true if callee is an instance (non-static) method, false otherwise.
127 public function isAnInstanceMethod()
129 return $this->reflection instanceof ReflectionMethod
130 && !$this->reflection->isStatic();