Skip to content

Commit

Permalink
Test all const are in uppercase
Browse files Browse the repository at this point in the history
  • Loading branch information
SpacePossum authored and keradus committed Jun 4, 2021
1 parent 15ddc20 commit 62c3af8
Showing 1 changed file with 29 additions and 0 deletions.
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
* @dataProvider provideTestClassCases
* @requires PHP 7.1
*/
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

0 comments on commit 62c3af8

Please sign in to comment.