Skip to content

Instantly share code, notes, and snippets.

@korchasa
Created March 24, 2016 12:30
Show Gist options
  • Save korchasa/af0ead8727dc8a6c933e to your computer and use it in GitHub Desktop.
Save korchasa/af0ead8727dc8a6c933e to your computer and use it in GitHub Desktop.
Find phpunit tests with wrong name (not a "*Test.php")
#!/usr/bin/env php
<?php
require_once __DIR__.'/../src/test/bootstrap.php';
$finder = new \Symfony\Component\Finder\Finder();
$finder->in(__DIR__.'/../src')
->name('*.php')
->files();
foreach ($finder as $file) {
/** @var \Symfony\Component\Finder\SplFileInfo $file */
if (isTest($file->getRealPath()) && 'Test.php' !== substr($file->getFilename(), -8)) {
echo $file->getRealPath().PHP_EOL;
}
}
function isTest($filename)
{
$ref = new \Go\ParserReflection\ReflectionFile($filename);
foreach ($ref->getFileNamespaces() as $namespace) {
foreach ($namespace->getClasses() as $class) {
if (false === strpos($class->getName(), 'Test')) {
continue;
}
$return = @require_once $filename;
if ($class->isAbstract()) {
continue;
}
if (false !== $return) {
return $class->isSubclassOf(\PHPUnit_Framework_TestCase::class);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment