Skip to content

Commit

Permalink
cs whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 12, 2021
1 parent f19774a commit 5b6e3ec
Show file tree
Hide file tree
Showing 23 changed files with 106 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/CodeCoverage/Generators/AbstractGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@ public function render(string $file = null): void
$this->renderSelf();
} catch (\Throwable $e) {
}

ob_end_flush();
fclose($handle);

if (isset($e)) {
if ($file) {
unlink($file);
}

throw $e;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/CodeCoverage/Generators/CloverXMLGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function __construct(string $file, array $sources = [])
if (!extension_loaded('dom') || !extension_loaded('tokenizer')) {
throw new \LogicException('CloverXML generator requires DOM and Tokenizer extensions to be loaded.');
}

parent::__construct($file, $sources);
}

Expand Down Expand Up @@ -121,6 +122,7 @@ protected function renderSelf(): void
self::setMetricAttributes($elClassMetrics, $classMetrics);
self::appendMetrics($fileMetrics, $classMetrics);
}

self::setMetricAttributes($elFileMetrics, $fileMetrics);


Expand Down
2 changes: 2 additions & 0 deletions src/CodeCoverage/Generators/HtmlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ private function parse(): void
if ($flag >= self::CODE_UNTESTED) {
$total++;
}

if ($flag >= self::CODE_TESTED) {
$covered++;
}
}

$coverage = round($covered * 100 / $total);
$this->totalSum += $total;
$this->coveredSum += $covered;
Expand Down
6 changes: 6 additions & 0 deletions src/CodeCoverage/PhpParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public function parse(string $code): \stdClass
'methods' => [],
];
}

break;

case T_PUBLIC:
Expand Down Expand Up @@ -128,8 +129,10 @@ public function parse(string $code): \stdClass
'end' => null,
];
}

$functionLevel = $level + 1;
}

unset($visibility, $isAbstract);
break;

Expand All @@ -148,6 +151,7 @@ public function parse(string $code): \stdClass
$class->end = $line;
unset($class);
}

$level--;
break;

Expand Down Expand Up @@ -177,8 +181,10 @@ private static function fetch(array &$tokens, $take): ?string
} elseif (!in_array($token, [T_DOC_COMMENT, T_WHITESPACE, T_COMMENT], true)) {
break;
}

next($tokens);
}

return $res;
}
}
13 changes: 11 additions & 2 deletions src/Framework/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public static function notEqual($expected, $actual, string $description = null):
$res = self::isEqual($expected, $actual);
} catch (AssertException $e) {
}

if (empty($e) && $res) {
self::fail(self::describe('%1 should not be equal to %2', $description), $actual, $expected);
}
Expand Down Expand Up @@ -308,14 +309,12 @@ public static function type($type, $value, string $description = null): void
if (!is_array($value) || ($value && array_keys($value) !== range(0, count($value) - 1))) {
self::fail(self::describe("%1 should be $type", $description), $value);
}

} elseif (in_array($type, ['array', 'bool', 'callable', 'float',
'int', 'integer', 'null', 'object', 'resource', 'scalar', 'string', ], true)
) {
if (!("is_$type")($value)) {
self::fail(self::describe(gettype($value) . " should be $type", $description));
}

} elseif (!$value instanceof $type) {
$actual = is_object($value) ? get_class($value) : gettype($value);
$type = is_object($type) ? get_class($type) : $type;
Expand All @@ -339,6 +338,7 @@ public static function exception(
$function();
} catch (\Throwable $e) {
}

if ($e === null) {
self::fail("$class was expected, but none was thrown");

Expand All @@ -351,6 +351,7 @@ public static function exception(
} elseif ($code !== null && $e->getCode() !== $code) {
self::fail("$class with a code %2 was expected but got %1", $e->getCode(), $code);
}

return $e;
}

Expand Down Expand Up @@ -421,6 +422,7 @@ public static function error(callable $function, $expectedType, string $expected
if ($expected) {
self::fail('Error was expected, but was not generated');
}

return null;
}

Expand All @@ -433,6 +435,7 @@ public static function noError(callable $function): void
if (($count = func_num_args()) > 1) {
throw new \Exception(__METHOD__ . "() expects 1 parameter, $count given.");
}

self::error($function, []);
}

Expand Down Expand Up @@ -465,6 +468,7 @@ public static function match(string $pattern, $actual, string $description = nul
if (self::$expandPatterns) {
[$pattern, $actual] = self::expandMatchingPatterns($pattern, $actual);
}

self::fail(self::describe('%1 should match %2', $description), $actual, $pattern);
}
}
Expand All @@ -487,6 +491,7 @@ public static function matchFile(string $file, $actual, string $description = nu
if (self::$expandPatterns) {
[$pattern, $actual] = self::expandMatchingPatterns($pattern, $actual);
}

self::fail(self::describe('%1 should match %2', $description), $actual, $pattern, null, basename($file));
}
}
Expand Down Expand Up @@ -566,6 +571,7 @@ public static function isMatching(string $pattern, $actual, bool $strict = false
if ($res === false || preg_last_error()) {
throw new \Exception('Error while executing regular expression. (PREG Error Code ' . preg_last_error() . ')');
}

return (bool) $res;
}

Expand Down Expand Up @@ -655,6 +661,7 @@ private static function isEqual($expected, $actual, int $level = 0, $objects = n
} elseif ($expected === $actual) {
return true;
}

$objects[$expected] = $actual;
$objects[$actual] = $expected;
$expected = (array) $expected;
Expand All @@ -672,8 +679,10 @@ private static function isEqual($expected, $actual, int $level = 0, $objects = n
if (!self::isEqual($value, current($actual), $level + 1, $objects)) {
return false;
}

next($actual);
}

return true;

default:
Expand Down
4 changes: 3 additions & 1 deletion src/Framework/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public static function load(string $file, string $query = ''): array
} elseif (!is_array($data)) {
throw new \Exception("Data provider '$file' did not return array or Traversable.");
}

} else {
$data = @parse_ini_file($file, true); // @ is escalated to exception
if ($data === false) {
Expand Down Expand Up @@ -68,6 +67,7 @@ public static function testQuery(string $input, string $query): bool
return false;
}
}

return true;
}

Expand All @@ -93,6 +93,7 @@ private static function compare($l, string $operator, $r): bool
case '<>':
return $l != $r;
}

throw new \InvalidArgumentException("Unknown operator $operator.");
}

Expand All @@ -105,6 +106,7 @@ public static function parseAnnotation(string $annotation, string $file): array
if (!preg_match('#^(\??)\s*([^,\s]+)\s*,?\s*(\S.*)?()#', $annotation, $m)) {
throw new \Exception("Invalid @dataProvider value '$annotation'.");
}

return [dirname($file) . DIRECTORY_SEPARATOR . $m[2], $m[3], (bool) $m[1]];
}
}
3 changes: 3 additions & 0 deletions src/Framework/DomQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static function fromHtml(string $html): self
trigger_error(__METHOD__ . ": $error->message on line $error->line.", E_USER_WARNING);
}
}

return simplexml_import_dom($dom, self::class);
}

Expand Down Expand Up @@ -107,6 +108,7 @@ public static function css2xpath(string $css): string
$xpath .= "[$attr]";
continue;
}

$val = trim($m[5], '"\'');
if ($m[4] === '') {
$xpath .= "[$attr='$val']";
Expand All @@ -131,6 +133,7 @@ public static function css2xpath(string $css): string
$xpath .= '//*';
}
}

return $xpath;
}
}
14 changes: 14 additions & 0 deletions src/Framework/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static function toLine($var): string
} elseif (strlen($var) > self::$maxLength) {
$var = substr($var, 0, self::$maxLength) . '...';
}

return self::encodeStringLine($var);

} elseif (is_array($var)) {
Expand All @@ -62,10 +63,12 @@ public static function toLine($var): string
$out .= '...';
break;
}

$out .= ($k === $counter ? '' : self::toLine($k) . ' => ')
. (is_array($v) && $v ? '[...]' : self::toLine($v));
$counter = is_int($k) ? max($k + 1, $counter) : $counter;
}

return "[$out]";

} elseif ($var instanceof \Throwable) {
Expand Down Expand Up @@ -145,6 +148,7 @@ private static function _toPhp(&$var, array &$list = [], int $level = 0, int &$l
if ($marker === null) {
$marker = uniqid("\x00", true);
}

if (empty($var)) {
$out = '';

Expand All @@ -167,12 +171,14 @@ private static function _toPhp(&$var, array &$list = [], int $level = 0, int &$l
$line++;
}
}

unset($var[$marker]);
if (strpos($outShort, "\n") === false && strlen($outShort) < self::$maxLength) {
$line = $oldLine;
$out = $outShort;
}
}

return '[' . $out . ']';

} elseif ($var instanceof \Closure) {
Expand All @@ -183,6 +189,7 @@ private static function _toPhp(&$var, array &$list = [], int $level = 0, int &$l
if (($rc = new \ReflectionObject($var))->isAnonymous()) {
return "/* Anonymous class defined in file {$rc->getFileName()} on line {$rc->getStartLine()} */";
}

$arr = (array) $var;
$space = str_repeat("\t", $level);
$class = get_class($var);
Expand All @@ -205,11 +212,14 @@ private static function _toPhp(&$var, array &$list = [], int $level = 0, int &$l
if (isset($k[0]) && $k[0] === "\x00") {
$k = substr($k, strrpos($k, "\x00") + 1);
}

$out .= "$space\t" . self::_toPhp($k, $list, $level + 1, $line) . ' => ' . self::_toPhp($v, $list, $level + 1, $line) . ",\n";
$line++;
}

$out .= $space;
}

$hash = self::hash($var);
return $class === 'stdClass'
? "(object) /* $hash */ [$out]"
Expand Down Expand Up @@ -340,6 +350,7 @@ public static function dumpException(\Throwable $e): string
? "$m[1]$m[2]\n" . str_repeat(' ', $delta - 3) . "...$m[3]$m[4]"
: "$m[1]$m[2]$m[3]\n" . str_repeat(' ', strlen($m[1]) - 4) . "... $m[4]";
}

$message = strtr($message, [
'%1' => self::color('yellow') . self::toLine($actual) . self::color('white'),
'%2' => self::color('yellow') . self::toLine($expected) . self::color('white'),
Expand All @@ -357,6 +368,7 @@ public static function dumpException(\Throwable $e): string
if ($e instanceof AssertException && $item['file'] === __DIR__ . DIRECTORY_SEPARATOR . 'Assert.php') {
continue;
}

$line = $item['class'] === Assert::class && method_exists($item['class'], $item['function'])
&& strpos($tmp = file($item['file'])[$item['line'] - 1], "::$item[function](") ? $tmp : null;

Expand All @@ -382,6 +394,7 @@ public static function dumpException(\Throwable $e): string
if ($e->getPrevious()) {
$s .= "\n(previous) " . static::dumpException($e->getPrevious());
}

return $s;
}

Expand All @@ -395,6 +408,7 @@ public static function saveOutput(string $testFile, $content, string $suffix = '
if (!preg_match('#/|\w:#A', self::$dumpDir)) {
$path = dirname($testFile) . DIRECTORY_SEPARATOR . $path;
}

@mkdir(dirname($path)); // @ - directory may already exist
file_put_contents($path, is_string($content) ? $content : (self::toPhp($content) . "\n"));
return $path;
Expand Down
4 changes: 4 additions & 0 deletions src/Framework/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public static function setupErrors(): void
) {
self::handleException(new \ErrorException($message, 0, $severity, $file, $line));
}

return false;
});

Expand Down Expand Up @@ -202,6 +203,7 @@ public static function bypassFinals(): void
: $token;
}
}

return $code;
});
}
Expand All @@ -218,13 +220,15 @@ public static function loadData(): array
if (!array_key_exists($key, $data)) {
throw new \Exception("Missing dataset '$key' from data provider '$file'.");
}

return $data[$key];
}

$annotations = self::getTestAnnotations();
if (!isset($annotations['dataprovider'])) {
throw new \Exception('Missing annotation @dataProvider.');
}

$provider = (array) $annotations['dataprovider'];
[$file, $query] = DataProvider::parseAnnotation($provider[0], $annotations['file']);

Expand Down
2 changes: 2 additions & 0 deletions src/Framework/Expect.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function __call(string $method, array $args): self
$this->constraints[] = (object) ['method' => lcfirst($m[1]), 'args' => $args];
return $this;
}

throw new \Error('Call to undefined method ' . self::class . '::' . $method . '()');
}

Expand Down Expand Up @@ -119,6 +120,7 @@ public function dump(): string
$res[] = is_string($cstr) ? $cstr : 'user-expectation';
}
}

return implode(',', $res);
}
}
2 changes: 2 additions & 0 deletions src/Framework/FileMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public function stream_seek(int $offset, int $whence): bool
} elseif ($whence === SEEK_END) {
$offset += strlen($this->content);
}

if ($offset >= 0) {
$this->readingPos = $offset;
$this->writingPos = $this->appendMode ? $this->writingPos : $offset;
Expand Down Expand Up @@ -194,6 +195,7 @@ public function stream_metadata(string $path, int $option, $value): bool
case STREAM_META_TOUCH:
return true;
}

return false;
}

Expand Down
Loading

0 comments on commit 5b6e3ec

Please sign in to comment.