Cleaned up some unused use statements, added code coverage script. 79% covered already
This commit is contained in:
parent
6d5e93b07c
commit
c4b1409f13
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
.DS_Store
|
||||
vendor
|
||||
tests/tmp/*
|
||||
tests/tmp/*
|
||||
tests/coverage
|
1
run_coverage.sh
Executable file
1
run_coverage.sh
Executable file
@ -0,0 +1 @@
|
||||
XDEBUG_MODE=coverage ./vendor/bin/phpunit tests --coverage-filter src --coverage-html tests/coverage
|
@ -139,6 +139,8 @@ class Server {
|
||||
if (!is_callable($httpGetWithEffectiveUrl)) {
|
||||
if (class_exists('\GuzzleHttp\Client')) {
|
||||
$httpGetWithEffectiveUrl = function (string $uri) {
|
||||
// This code can’t be tested, ignore it for coverage purposes.
|
||||
// @codeCoverageIgnoreStart
|
||||
$resp = (new \GuzzleHttp\Client([
|
||||
\GuzzleHttp\RequestOptions::ALLOW_REDIRECTS => [
|
||||
'max' => 10,
|
||||
@ -152,6 +154,7 @@ class Server {
|
||||
$effectiveUrl = empty($rdh) ? $uri : array_values($rdh)[count($rdh) - 1];
|
||||
|
||||
return [$resp, $effectiveUrl];
|
||||
// @codeCoverageIgnoreEnd
|
||||
};
|
||||
} else {
|
||||
throw new Exception('No valid $httpGetWithEffectiveUrl was provided, and guzzlehttp/guzzle was not installed. Either require guzzlehttp/guzzle, or provide a valid callable.');
|
||||
@ -255,8 +258,10 @@ class Server {
|
||||
// In theory this code should never be reached, as we already checked the request for valid parameters.
|
||||
// However, it’s possible for hashAuthorizationRequestParameters() to return null, and if for whatever
|
||||
// reason it does, the library should handle that case as elegantly as possible.
|
||||
// @codeCoverageIgnoreStart
|
||||
$this->logger->warning("Calculating the expected hash for an authorization approval request failed. This SHOULD NOT happen; if you encounter this error please contact the maintainers of taproot/indieauth.");
|
||||
throw IndieAuthException::create(IndieAuthException::REQUEST_MISSING_PARAMETER, $request);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
if (!array_key_exists(self::HASH_QUERY_STRING_KEY, $queryParams)) {
|
||||
|
@ -3,17 +3,16 @@
|
||||
namespace Taproot\IndieAuth;
|
||||
|
||||
use Exception;
|
||||
use IndieAuth\Client;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Log\LoggerAwareInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
use function BarnabyWalters\Mf2\parseUrl;
|
||||
|
||||
// From https://github.com/indieweb/indieauth-client-php/blob/main/src/IndieAuth/Client.php, thanks aaronpk.
|
||||
function generateRandomString($numBytes) {
|
||||
if (function_exists('random_bytes')) {
|
||||
$bytes = random_bytes($numBytes);
|
||||
// We can’t easily test the following code.
|
||||
// @codeCoverageIgnoreStart
|
||||
} elseif (function_exists('openssl_random_pseudo_bytes')){
|
||||
$bytes = openssl_random_pseudo_bytes($numBytes);
|
||||
} else {
|
||||
@ -21,6 +20,7 @@ function generateRandomString($numBytes) {
|
||||
for($i=0, $bytes=''; $i < $numBytes; $i++) {
|
||||
$bytes .= chr(mt_rand(0, 255));
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
return bin2hex($bytes);
|
||||
}
|
||||
|
@ -6,15 +6,11 @@ use Exception;
|
||||
use Nyholm\Psr7\Response;
|
||||
use Nyholm\Psr7\ServerRequest;
|
||||
use Nyholm\Psr7\Request;
|
||||
use PDO;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Taproot\IndieAuth\Callback\DefaultAuthorizationForm;
|
||||
use Taproot\IndieAuth\Callback\SingleUserPasswordAuthenticationCallback;
|
||||
use Taproot\IndieAuth\IndieAuthException;
|
||||
use Taproot\IndieAuth\Middleware\NoOpMiddleware;
|
||||
use Taproot\IndieAuth\Server;
|
||||
use Taproot\IndieAuth\Storage\FilesystemJsonStorage;
|
||||
|
||||
|
Reference in New Issue
Block a user