/** * @param string $syntax * @param array $data * @throws NoMatcherFoundException * @return array */ public function getMatcherForSyntax($syntax, array $data = array()) { ArgumentChecker::check($syntax, 'string'); $rawSyntax = $this->getRawSyntax($syntax); $endsWith = ' on error ?'; if ($this->endsWith($rawSyntax, $endsWith)) { $rawSyntax = substr($rawSyntax, 0, strlen($rawSyntax) - strlen($endsWith)); } foreach ($this->modules as $module) { $reflectionClass = new ReflectionClass($module); foreach ($reflectionClass->getMethods() as $method) { $doc = $method->getDocComment(); foreach (explode("\n", $doc) as $line) { $pos = strpos($line, '@syntax'); if ($pos !== false) { $s = new Syntax(trim(substr($line, $pos + 7)), $method->getDeclaringClass()->getName() . '::' . $method->getName()); if ($s->getRawSyntax() == $rawSyntax) { $class = $s->getClass(); $r = array('matcher' => new $class(), 'originalSyntax' => $s->getSyntax()); if ($this->endsWith($this->getRawSyntax($syntax), $endsWith)) { $r['on_error'] = $data[count($data) - 1]; } return $r; } } } } } throw new NoMatcherFoundException(array($syntax)); }
/** * @param string $filePath * @return string */ public function process($filePath) { ArgumentChecker::check($filePath, 'string'); $cwd = getcwd(); if (substr($filePath, 0, strlen($cwd)) === $cwd) { return substr($filePath, strlen($cwd) + 1); } return $filePath; }
public function render($value = 0) { ArgumentChecker::check($value, 'integer'); $this->atLeastZero($value, 'Value'); $r = $value . ' / ' . max($value, $this->total); if ($this->showPercentage) { $r .= sprintf(' (%3s%%)', min(100, $this->getPercentage($value))); } return $r; }
/** * @param integer $status * @param integer $issueNumber * @param PHPUnit_Framework_Test $test * @param Exception $e * @return string */ public function render($status, $issueNumber, PHPUnit_Framework_Test $test, Exception $e) { ArgumentChecker::check($issueNumber, 'integer'); $c = new Color(); $top = $this->getHeading($status, $issueNumber, $test); $message = $e->getMessage() . "\n"; $message .= $this->getPHPUnitDiff($e); $message .= "\n" . $this->prefixLines("[90m", $this->traceSimplifier->render($e->getTrace())) . "[0m"; $pad = str_repeat(' ', strlen($issueNumber)); return $top . $this->prefixLines($c(" ")->highlight($this->colors[$status]) . $pad, rtrim($message)); }
/** * @param string $syntax * @param array $data * @return string */ public function render($syntax, array $data = array()) { ArgumentChecker::check($syntax, 'string'); $renderer = new ValueRenderer(); if (self::$color) { $renderer->setTheme(new DefaultTheme()); } return preg_replace_callback('/\\?/', function () use(&$data, $renderer) { $r = $renderer->render(array_shift($data)); return $r; }, $syntax); }
/** * Render the progress bar. * * @param integer $size The width (in column/characters of the progress * bar). * @param array $parts The individual [color => value] that make up the * progress bar. * @return string */ public function render($size, array $parts) { ArgumentChecker::check($size, 'integer'); $this->calculateTotal($parts); $this->size = $size; $this->parts = $parts; $r = ''; foreach ($parts as $color => $x) { $bars = $this->valueToBars($x); $r .= $this->colorSpaces($bars, $color); } $r = $this->fillToSize($r); return $r; }
/** * @param integer $number * @return string */ public function convert($number) { ArgumentChecker::check($number, 'integer'); if ($number === 0) { return 'never'; } if ($number === 1) { return 'once'; } if ($number === 2) { return 'twice'; } return "{$number} times"; }
/** * @param integer $size * @param integer $total * @param array $parts * @return string */ public function renderProportional($size, $total, array $parts) { ArgumentChecker::check($size, 'integer'); ArgumentChecker::check($total, 'integer', 2); $this->calculateTotal($parts); if (0 === $total) { $total = $this->total; } if (0 === $total) { return str_repeat('_', $size); } $barSize = min($size * $this->total / $total, $size); $bar = parent::render((int) $barSize, $parts); $spaces = max(0, $size - substr_count($bar, ' ')); return $bar . str_repeat('_', $spaces); }
/** * @param string $method * @return string */ public function getPrototypeForNonExistentMethod($method) { ArgumentChecker::check($method, 'string'); return "public function {$method}()"; }
public function testMultipleTypesCanBeCommaSeparated() { $this->assert(ArgumentChecker::check(123, 'int,float'))->exactlyEquals(123); }
/** * @param object $instance * @return MockBuilder */ public function partialMock($instance) { ArgumentChecker::check($instance, 'object'); $mockBuilder = new MockBuilder($this, get_class($instance), true, array()); $mockBuilder->disableConstructor(); $mockBuilder->setObjectState($instance); return $mockBuilder; }
/** * @param string $name * @param mixed $value * @throws Exception * @return MockBuilder */ public function setProperty($name, $value) { ArgumentChecker::check($name, 'string'); $this->propertiesCannotBeSetOnAnInterface(); $this->properties[$name] = $value; return $this; }