43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use ReflectionClass;
|
|
use Services\CurrencyRate;
|
|
use Services\CurrencyRate\Client;
|
|
use System\Classes\Config;
|
|
use System\Classes\MyException;
|
|
|
|
class CurrencyRateTest extends TestCase
|
|
{
|
|
protected function tearDown(): void
|
|
{
|
|
$ref = new ReflectionClass(CurrencyRate::class);
|
|
$prop = $ref->getProperty('_instances');
|
|
$prop->setAccessible(true);
|
|
$prop->setValue(null, []);
|
|
|
|
$ref = new ReflectionClass(Config::class);
|
|
$prop = $ref->getProperty('config');
|
|
$prop->setAccessible(true);
|
|
$prop->setValue(null, null);
|
|
}
|
|
|
|
public function testDefaultConnectionReturnsClient(): void
|
|
{
|
|
$this->assertInstanceOf(Client::class, CurrencyRate::instance());
|
|
}
|
|
|
|
public function testInstanceIsCachedPerConnectionName(): void
|
|
{
|
|
$this->assertSame(CurrencyRate::instance('default'), CurrencyRate::instance('default'));
|
|
}
|
|
|
|
public function testUnknownConnectionNameThrows(): void
|
|
{
|
|
$this->expectException(MyException::class);
|
|
CurrencyRate::instance('nonexistent');
|
|
}
|
|
}
|