increase test coverage (#117)

70% test coverage
remove socialite
This commit is contained in:
Saeed Vaziry
2024-03-15 22:23:45 +01:00
committed by GitHub
parent 4f12de9586
commit a406491160
62 changed files with 1102 additions and 639 deletions

View File

@ -1,78 +0,0 @@
<?php
namespace App\Support\SocialiteProviders;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Arr;
use Laravel\Socialite\Two\AbstractProvider;
use Laravel\Socialite\Two\ProviderInterface;
use Laravel\Socialite\Two\User;
class DropboxProvider extends AbstractProvider implements ProviderInterface
{
/**
* Unique Provider Identifier.
*/
public const IDENTIFIER = 'DROPBOX';
/**
* {@inheritdoc}
*/
protected $scopeSeparator = ' ';
/**
* {@inheritdoc}
*/
protected function getAuthUrl($state): string
{
return $this->buildAuthUrlFromBase('https://www.dropbox.com/oauth2/authorize', $state);
}
/**
* {@inheritdoc}
*/
protected function getTokenUrl(): string
{
return 'https://api.dropboxapi.com/oauth2/token';
}
/**
* {@inheritdoc}
*/
protected function getTokenFields($code): array
{
return array_merge(parent::getTokenFields($code), [
'grant_type' => 'authorization_code',
]);
}
/**
* {@inheritdoc}
*
* @throws GuzzleException
*/
protected function getUserByToken($token)
{
$response = $this->getHttpClient()->post('https://api.dropboxapi.com/2/users/get_current_account', [
'headers' => [
'Authorization' => 'Bearer '.$token,
],
]);
return json_decode($response->getBody(), true);
}
/**
* {@inheritdoc}
*/
protected function mapUserToObject(array $user): User
{
return (new User)->setRaw($user)->map([
'id' => $user['account_id'],
'nickname' => null,
'name' => $user['name']['display_name'],
'email' => $user['email'],
'avatar' => Arr::get($user, 'profile_photo_url'),
]);
}
}

View File

@ -2,6 +2,7 @@
namespace App\Support\Testing;
use App\Exceptions\SSHConnectionError;
use App\Helpers\SSH;
use Illuminate\Support\Traits\ReflectsClosures;
use PHPUnit\Framework\Assert;
@ -14,11 +15,25 @@ class SSHFake extends SSH
protected ?string $output;
protected bool $connectionWillFail = false;
public function __construct(?string $output = null)
{
$this->output = $output;
}
public function connectionWillFail(): void
{
$this->connectionWillFail = true;
}
public function connect(bool $sftp = false): void
{
if ($this->connectionWillFail) {
throw new SSHConnectionError('Connection failed');
}
}
public function exec(string|array $commands, string $log = '', ?int $siteId = null): string
{
if ($log) {
@ -45,6 +60,11 @@ public function exec(string|array $commands, string $log = '', ?int $siteId = nu
return $output;
}
public function upload(string $local, string $remote): void
{
$this->log = null;
}
public function assertExecuted(array|string $commands): void
{
if (! $this->commands) {