mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-07-16 22:05:20 +00:00
Services/Integrations/ExchangeRate/ and Services/Pdf/ were both mostly Support-shaped: interfaces, abstract classes, static factories, concrete adapter drivers, DTOs, and exceptions — infrastructure that doesn't carry business logic. They only each had one real DI-injected service mixed in. This commit applies the same Services=DI-business-logic / Support=stateless-plumbing rule we've been using throughout the reorg: **Moved to Support/Integrations/ExchangeRate/** (7 files): ExchangeRateDriver (abstract), ExchangeRateDriverFactory (static), ExchangeRateException, and the four concrete drivers (CurrencyConverter, CurrencyFreak, CurrencyLayer, OpenExchangeRate). These are HTTP adapters over third-party currency APIs — same shape as the Hashids library wrapper classes already in Support. **Moved to Support/Pdf/** (6 files, merging with existing Pdf utilities): PdfDriver (interface), PdfDriverFactory (static), PdfService (static facade), GotenbergPdfDriver, GotenbergPdfResponse (DTO), ResponseStream (interface). The Support/Pdf/ dir now contains the full PDF rendering subsystem — drivers + sanitizer + template/image utilities. **Promoted to Services/ root** (the real DI services): ExchangeRateProviderService (CRUD for ExchangeRateProvider model) and FontService (font package install/download orchestration). Both are proper DI services — instance methods, model writes, HTTP side effects. Services/Integrations/ and Services/Pdf/ are now empty and deleted. Services/ holds only DI-injected classes; Support/ holds all the plumbing. 17 files renamed (git detects 90-99% similarity), 4 consumer files updated (DriverRegistryProvider, PdfServiceProvider, ExchangeRateProviderController, FontController, GeneratesPdfTrait, test). 350 tests pass, Pint clean.
68 lines
2.1 KiB
PHP
68 lines
2.1 KiB
PHP
<?php
|
|
|
|
use App\Support\Integrations\ExchangeRate\CurrencyFreakDriver;
|
|
use App\Support\Integrations\ExchangeRate\ExchangeRateDriver;
|
|
use App\Support\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']);
|
|
}
|
|
});
|