Created
November 18, 2019 15:06
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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