Skip to content

Instantly share code, notes, and snippets.

@xiian
Created November 18, 2019 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xiian/22c4c38c1e9ac0534bd69ccafbde07e5 to your computer and use it in GitHub Desktop.
Save xiian/22c4c38c1e9ac0534bd69ccafbde07e5 to your computer and use it in GitHub Desktop.
Test that the composer autoloader can find every class given in a file
<?php
function main()
{
$classnames = file(realpath(__DIR__) . '/classnames.txt', FILE_IGNORE_NEW_LINES);
$cnt = 0;
$loader = require realpath(__DIR__) . '/vendor/autoload.php';
$total = 0;
foreach ($classnames as $cn) {
++$total;
try {
$trimmedCN = ltrim($cn, '\\');
$file = $loader->findFile($trimmedCN);
if ($file == false) {
echo '- ' . $trimmedCN . ' is unknown' . PHP_EOL;
++$cnt;
}
} catch (\Throwable $e) {
echo 'Exception thrown when loading ' . $cn . ': (' . get_class($e) . ') ' . $e->getMessage() . PHP_EOL;
}
}
echo 'Unable to find ' . $cnt . ' classes (out of ' . $total . ')' . PHP_EOL;
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment