Files
InvoiceShelf/tests/Unit/ExchangeRateDriverFactoryTest.php
Darko Gjorgjijoski 947d00a9f1 refactor(services): Documents→Document + ExchangeRate→Integrations/ExchangeRate
Two follow-ups to the Services reorg that landed in 6d1816bd.

**Documents → Document** (singular). Documents/ was the only plural subdir in app/Services/ — every other bucket (Company, Mail, Module, Pdf, Storage, Update, ExchangeRate) was singular. Renaming to Document/ normalizes the whole tree.

**ExchangeRate → Integrations/ExchangeRate**. Introduces Integrations/ as an umbrella for external-service adapter subsystems. Exchange rate providers move in first; AI providers, payment gateways, and any other driver-pattern integrations land as sibling subdirs (Integrations/Ai/, Integrations/Payment/) without another reorg. Integrations/ was chosen over Providers/ to avoid conceptual collision with Laravel's app/Providers/ — 'check the providers' shouldn't be ambiguous.

17 files moved, 21 consumer files rewritten to point at the new namespaces via literal-string replacement (same approach as the previous reorg). 350 tests pass, Pint clean.
2026-04-11 11:30:00 +02:00

68 lines
2.1 KiB
PHP

<?php
use App\Services\Integrations\ExchangeRate\CurrencyFreakDriver;
use App\Services\Integrations\ExchangeRate\ExchangeRateDriver;
use App\Services\Integrations\ExchangeRate\ExchangeRateDriverFactory;
use InvoiceShelf\Modules\Registry;
test('make resolves built-in drivers from the factory map', function () {
$driver = ExchangeRateDriverFactory::make('currency_freak', 'fake-key');
expect($driver)->toBeInstanceOf(CurrencyFreakDriver::class);
});
test('make resolves Registry-only drivers via metadata', function () {
$fakeClass = new class('', []) extends ExchangeRateDriver
{
public function getExchangeRate(string $baseCurrency, string $targetCurrency): array
{
return [];
}
public function getSupportedCurrencies(): array
{
return [];
}
public function validateConnection(): array
{
return [];
}
};
Registry::registerExchangeRateDriver('registry_only_driver', [
'class' => $fakeClass::class,
'label' => 'test.label',
]);
try {
$driver = ExchangeRateDriverFactory::make('registry_only_driver', 'fake-key');
expect($driver)->toBeInstanceOf(ExchangeRateDriver::class);
} finally {
unset(Registry::$drivers['exchange_rate']['registry_only_driver']);
}
});
test('make throws for unknown drivers', function () {
expect(fn () => ExchangeRateDriverFactory::make('definitely_not_a_real_driver', 'k'))
->toThrow(InvalidArgumentException::class);
});
test('availableDrivers merges built-in and Registry-registered drivers', function () {
Registry::registerExchangeRateDriver('extra_driver', [
'class' => CurrencyFreakDriver::class,
'label' => 'extra.label',
]);
try {
$available = ExchangeRateDriverFactory::availableDrivers();
expect($available)
->toContain('currency_freak')
->toContain('currency_converter')
->toContain('extra_driver');
} finally {
unset(Registry::$drivers['exchange_rate']['extra_driver']);
}
});