File tree Expand file tree Collapse file tree 3 files changed +22
-1
lines changed
Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 44
55namespace App \Service ;
66
7+ use Brick \Money \ISOCurrencyProvider ;
78use Brick \Money \Money ;
89
910class CurrencyService
@@ -374,4 +375,12 @@ public function getCurrencySymbol(string $currencyCode): string
374375
375376 return $ currencyCode ;
376377 }
378+
379+ public function getRandomCurrencyCode (): string
380+ {
381+ $ currencies = ISOCurrencyProvider::getInstance ()->getAvailableCurrencies ();
382+ $ currencyCodes = array_keys ($ currencies );
383+
384+ return $ currencyCodes [array_rand ($ currencyCodes )];
385+ }
377386}
Original file line number Diff line number Diff line change 1111use App \Enums \TimeFormat ;
1212use App \Models \Organization ;
1313use App \Models \User ;
14+ use App \Service \CurrencyService ;
1415use Illuminate \Database \Eloquent \Factories \Factory ;
1516
1617/**
@@ -27,7 +28,7 @@ public function definition(): array
2728 {
2829 return [
2930 'name ' => $ this ->faker ->unique ()->company (),
30- 'currency ' => $ this -> faker -> currencyCode (),
31+ 'currency ' => app (CurrencyService::class)-> getRandomCurrencyCode (),
3132 'billable_rate ' => null ,
3233 'user_id ' => User::factory (),
3334 'personal_team ' => true ,
Original file line number Diff line number Diff line change @@ -92,4 +92,15 @@ public function test_get_currency_symbol_for_currency_without_known_symbol(): vo
9292 // Assert
9393 $ this ->assertSame ('XXX ' , $ symbol );
9494 }
95+
96+ public function test_get_random_currency_code (): void
97+ {
98+ // Act
99+ $ currencyCode = $ this ->currencyService ->getRandomCurrencyCode ();
100+
101+ // Assert
102+ $ this ->assertNotEmpty ($ currencyCode );
103+ $ this ->assertIsString ($ currencyCode );
104+ $ this ->assertNotNull (Currency::of ($ currencyCode ));
105+ }
95106}
You can’t perform that action at this time.
0 commit comments