Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test all const are in uppercase #5750

Merged
merged 1 commit into from
Jun 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions tests/AutoReview/ProjectCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public function testThatSrcClassesNotExposeProperties($className)
$allowedProps = array_map(static function (\ReflectionProperty $item) {
return $item->getName();
}, $allowedProps);

$definedProps = array_map(static function (\ReflectionProperty $item) {
return $item->getName();
}, $definedProps);
Expand Down Expand Up @@ -384,12 +385,14 @@ static function (Token $token) {
return $token->isGivenKind(T_STRING);
}
);

$strings = array_map(
static function (Token $token) {
return $token->getContent();
},
$stringTokens
);

$strings = array_unique($strings);
$message = sprintf('Class %s must not use preg_*, it shall use Preg::* instead.', $className);
static::assertNotContains('preg_filter', $strings, $message);
Expand Down Expand Up @@ -588,6 +591,7 @@ static function (\ReflectionMethod $rm) {
return false !== $rm->getDocComment() && stripos($rm->getDocComment(), '@inheritdoc');
}
);

$methodsWithInheritdoc = array_map(
static function (\ReflectionMethod $rm) {
return $rm->getName();
Expand Down Expand Up @@ -742,6 +746,31 @@ public function providePhpUnitFixerExtendsAbstractPhpUnitFixerCases()
}
}

/**
* @param string $className
*
* @dataProvider provideSrcClassCases
SpacePossum marked this conversation as resolved.
Show resolved Hide resolved
* @dataProvider provideTestClassCases
* @requires PHP 7.1
SpacePossum marked this conversation as resolved.
Show resolved Hide resolved
*/
public function testConstantsAreInUpperCase($className)
{
$rc = new \ReflectionClass($className);

$reflectionClassConstants = $rc->getReflectionConstants();

if (\count($reflectionClassConstants) < 1) {
$this->addToAssertionCount(1);

return;
}

foreach ($reflectionClassConstants as $constant) {
$constantName = $constant->getName();
static::assertSame(strtoupper($constantName), $constantName, $className);
}
}

private function getUsedDataProviderMethodNames($testClassName)
{
$dataProviderMethodNames = [];
Expand Down