Skip to content

Commit

Permalink
private constants are PascalCase
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 22, 2022
1 parent 944560b commit 937ae82
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/CodeCoverage/Generators/HtmlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
class HtmlGenerator extends AbstractGenerator
{
private const CLASSES = [
private const Classes = [
self::CODE_TESTED => 't', // tested
self::CODE_UNTESTED => 'u', // untested
self::CODE_DEAD => 'dead', // dead code
Expand Down Expand Up @@ -47,7 +47,7 @@ protected function renderSelf(): void
$this->parse();

$title = $this->title;
$classes = self::CLASSES;
$classes = self::Classes;
$files = $this->files;
$coveredPercent = $this->getCoveredPercent();

Expand Down
4 changes: 2 additions & 2 deletions src/Framework/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class Assert
{
/** used by equal() for comparing floats */
private const EPSILON = 1e-10;
private const Epsilon = 1e-10;

/** used by match(); in values, each $ followed by number is backreference */
public static $patterns = [
Expand Down Expand Up @@ -652,7 +652,7 @@ private static function isEqual($expected, $actual, int $level = 0, $objects = n

case is_float($expected) && is_float($actual) && is_finite($expected) && is_finite($actual):
$diff = abs($expected - $actual);
return ($diff < self::EPSILON) || ($diff / max(abs($expected), abs($actual)) < self::EPSILON);
return ($diff < self::Epsilon) || ($diff / max(abs($expected), abs($actual)) < self::Epsilon);

case is_object($expected) && is_object($actual) && get_class($expected) === get_class($actual):
$objects = $objects ? clone $objects : new \SplObjectStorage;
Expand Down
8 changes: 4 additions & 4 deletions src/Framework/FileMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
class FileMock
{
private const PROTOCOL = 'mock';
private const Protocol = 'mock';

/** @var string[] */
public static $files = [];
Expand Down Expand Up @@ -47,16 +47,16 @@ public static function create(string $content = '', ?string $extension = null):
self::register();

static $id;
$name = self::PROTOCOL . '://' . (++$id) . '.' . $extension;
$name = self::Protocol . '://' . (++$id) . '.' . $extension;
self::$files[$name] = $content;
return $name;
}


public static function register(): void
{
if (!in_array(self::PROTOCOL, stream_get_wrappers(), true)) {
stream_wrapper_register(self::PROTOCOL, self::class);
if (!in_array(self::Protocol, stream_get_wrappers(), true)) {
stream_wrapper_register(self::Protocol, self::class);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/Framework/FileMutator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
class FileMutator
{
private const PROTOCOL = 'file';
private const Protocol = 'file';

/** @var resource|null */
public $context;
Expand All @@ -31,8 +31,8 @@ class FileMutator
public static function addMutator(callable $mutator): void
{
self::$mutators[] = $mutator;
stream_wrapper_unregister(self::PROTOCOL);
stream_wrapper_register(self::PROTOCOL, self::class);
stream_wrapper_unregister(self::Protocol);
stream_wrapper_register(self::Protocol, self::class);
}


Expand Down Expand Up @@ -224,12 +224,12 @@ public function url_stat(string $path, int $flags)

private function native(string $func)
{
stream_wrapper_restore(self::PROTOCOL);
stream_wrapper_restore(self::Protocol);
try {
return $func(...array_slice(func_get_args(), 1));
} finally {
stream_wrapper_unregister(self::PROTOCOL);
stream_wrapper_register(self::PROTOCOL, self::class);
stream_wrapper_unregister(self::Protocol);
stream_wrapper_register(self::Protocol, self::class);
}
}
}
10 changes: 5 additions & 5 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class TestCase
{
/** @internal */
public const
LIST_METHODS = 'nette-tester-list-methods',
METHOD_PATTERN = '#^test[A-Z0-9_]#';
ListMethods = 'nette-tester-list-methods',
MethodPattern = '#^test[A-Z0-9_]#';

/** @var bool */
private $handleErrors = false;
Expand All @@ -36,13 +36,13 @@ public function run(): void
throw new \LogicException('Calling TestCase::run($method) is deprecated. Use TestCase::runTest($method) instead.');
}

$methods = array_values(preg_grep(self::METHOD_PATTERN, array_map(function (\ReflectionMethod $rm): string {
$methods = array_values(preg_grep(self::MethodPattern, array_map(function (\ReflectionMethod $rm): string {
return $rm->getName();
}, (new \ReflectionObject($this))->getMethods())));

if (isset($_SERVER['argv']) && ($tmp = preg_filter('#--method=([\w-]+)$#Ai', '$1', $_SERVER['argv']))) {
$method = reset($tmp);
if ($method === self::LIST_METHODS) {
if ($method === self::ListMethods) {
$this->sendMethodList($methods);
return;
}
Expand Down Expand Up @@ -72,7 +72,7 @@ public function runTest(string $method, ?array $args = null): void
{
if (!method_exists($this, $method)) {
throw new TestCaseException("Method '$method' does not exist.");
} elseif (!preg_match(self::METHOD_PATTERN, $method)) {
} elseif (!preg_match(self::MethodPattern, $method)) {
throw new TestCaseException("Method '$method' is not a testing method.");
}

Expand Down
8 changes: 4 additions & 4 deletions src/Runner/TestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class TestHandler
{
private const HTTP_OK = 200;
private const HttpOk = 200;

/** @var Runner */
private $runner;
Expand Down Expand Up @@ -88,7 +88,7 @@ public function assess(Job $job): void
$test = $job->getTest();
$annotations = $this->getAnnotations($test->getFile())[0] += [
'exitcode' => Job::CODE_OK,
'httpcode' => self::HTTP_OK,
'httpcode' => self::HttpOk,
];

foreach (get_class_methods($this) as $method) {
Expand Down Expand Up @@ -195,7 +195,7 @@ private function initiateTestCase(Test $test, $foo, PhpInterpreter $interpreter)
}

if ($methods === null) {
$job = new Job($test->withArguments(['method' => TestCase::LIST_METHODS]), $interpreter, $this->runner->getEnvironmentVariables());
$job = new Job($test->withArguments(['method' => TestCase::ListMethods]), $interpreter, $this->runner->getEnvironmentVariables());
$job->run();

if (in_array($job->getExitCode(), [Job::CODE_ERROR, Job::CODE_FAIL, Job::CODE_SKIP], true)) {
Expand Down Expand Up @@ -259,7 +259,7 @@ private function assessHttpCode(Job $job, $code): ?Test
}

$headers = $job->getHeaders();
$actual = (int) ($headers['Status'] ?? self::HTTP_OK);
$actual = (int) ($headers['Status'] ?? self::HttpOk);
$code = (int) $code;
return $code && $code !== $actual
? $job->getTest()->withResult(Test::FAILED, "Exited with HTTP code $actual (expected $code)")
Expand Down

0 comments on commit 937ae82

Please sign in to comment.