multi-downloader-client/tests/MultiDownloaderClientTest.php

61 lines
1.7 KiB
PHP
Raw Normal View History

2024-01-11 10:33:29 +00:00
<?php
include __DIR__ . '/../vendor/autoload.php';
2024-01-11 12:23:26 +00:00
use Nwb\MultiDownloaderClient\FileRequest;
2024-01-11 10:33:29 +00:00
use Nwb\MultiDownloaderClient\MultiDownloaderClient;
use PHPUnit\Framework\TestCase;
class MultiDownloaderClientTest extends TestCase
{
public static function getProperty($object, $property)
{
$reflectedClass = new \ReflectionClass($object);
$reflection = $reflectedClass->getProperty($property);
$reflection->setAccessible(true);
return $reflection->getValue($object);
}
2024-01-11 12:23:26 +00:00
public function testRequest()
{
$client = new MultiDownloaderClient();
$files = [
new FileRequest('https://s3.eu-central-1.wasabisys.com/dev-data-nwb/multi-downloader-sat/tests/img/watermarks/portrait.png'),
new FileRequest('https://s3.eu-central-1.wasabisys.com/dev-data-nwb/multi-downloader-sat/tests/img/watermarks/paysage.png')
];
$response = $client->download($files);
var_dump($response);
}
2024-01-11 10:33:29 +00:00
public function testApiKeyEnv()
{
putenv('MULTI_DOWNLOADER_API_KEY=1234567890');
$client = new MultiDownloaderClient();
$apiKey = self::getProperty($client, 'apiKey');
$this->assertEquals('1234567890', $apiKey);
}
public function testApiKeyParam()
{
$client = new MultiDownloaderClient('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_API_KEY');
new MultiDownloaderClient();
}
}