apiKey
This commit is contained in:
45
tests/MultiDownloaderClientTest.php
Normal file
45
tests/MultiDownloaderClientTest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
include __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user