Refactor MultiDownloaderClientTest class and update constructor usage
Some checks reported errors
continuous-integration/drone/push Build encountered an error

This commit is contained in:
Nicolas COMPAIN 2024-01-12 09:46:25 +00:00
parent 43fd2c26cb
commit 941202e925

View File

@ -20,18 +20,9 @@ class MultiDownloaderClientTest extends TestCase
}, $this->testFiles);
}
public static function getProperty($object, $property)
{
$reflectedClass = new \ReflectionClass($object);
$reflection = $reflectedClass->getProperty($property);
$reflection->setAccessible(true);
return $reflection->getValue($object);
}
public function testDownloadAsString()
{
$client = new MultiDownloaderClient();
$client = new MultiDownloaderClient(['apiKey' => 'test', 'apiSecret' => 'test' ]);
$client->setFiles($this->testFiles());
@ -44,7 +35,7 @@ class MultiDownloaderClientTest extends TestCase
public function testDownloadTo()
{
$client = new MultiDownloaderClient();
$client = new MultiDownloaderClient(['apiKey' => 'test', 'apiSecret' => 'test' ]);
$path = sys_get_temp_dir() . '/testDownloadTo.zip';
@ -57,40 +48,11 @@ class MultiDownloaderClientTest extends TestCase
$this->assertEquals('ea9726d2ecbe6b820899ba125bf0ae94', $md5);
}
public function testApiKeyEnv()
{
putenv('MULTI_DOWNLOADER_ACCESS_KEY=1234567890');
$client = new MultiDownloaderClient();
$apiKey = self::getProperty($client, 'apiKey');
$this->assertEquals('1234567890', $apiKey);
}
public function testForm()
{
$client = new MultiDownloaderClient();
$client = new MultiDownloaderClient(['apiKey' => 'test', 'apiSecret' => 'test' ]);
$client->setFiles($this->testFiles());
echo $client->htmlForm($this->testFiles());
}
public function testApiKeyParam()
{
$client = new MultiDownloaderClient([
'apiKey' => 'test_key'
]);
$apiKey = self::getProperty($client, 'apiKey');
$this->assertEquals('test_key', $apiKey);
}
public function testApiKeyMissing()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('API key is required');
putenv('MULTI_DOWNLOADER_ACCESS_KEY');
new MultiDownloaderClient();
}
}