. */ declare(strict_types=1); namespace Tests\Feature\Controllers\Json; use FireflyIII\Models\CurrencyExchangeRate; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Services\Currency\ExchangeRateInterface; use Log; use Tests\TestCase; /** * Class ExchangeControllerTest * * @SuppressWarnings(PHPMD.TooManyPublicMethods) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class ExchangeControllerTest extends TestCase { /** * */ public function setUp(): void { parent::setUp(); Log::info(sprintf('Now in %s.', \get_class($this))); } /** * @covers \FireflyIII\Http\Controllers\Json\ExchangeController */ public function testGetRate(): void { $repository = $this->mock(CurrencyRepositoryInterface::class); $rate = factory(CurrencyExchangeRate::class)->make(); $repository->shouldReceive('getExchangeRate')->andReturn($rate); $this->be($this->user()); $response = $this->get(route('json.rate', ['EUR', 'USD', '20170101'])); $response->assertStatus(200); } /** * @covers \FireflyIII\Http\Controllers\Json\ExchangeController */ public function testGetRateAmount(): void { $repository = $this->mock(CurrencyRepositoryInterface::class); $rate = factory(CurrencyExchangeRate::class)->make(); $repository->shouldReceive('getExchangeRate')->andReturn($rate); $this->be($this->user()); $response = $this->get(route('json.rate', ['EUR', 'USD', '20170101']) . '?amount=10'); $response->assertStatus(200); } /** * @covers \FireflyIII\Http\Controllers\Json\ExchangeController */ public function testGetRateNull(): void { $repository = $this->mock(CurrencyRepositoryInterface::class); $rate = factory(CurrencyExchangeRate::class)->make(); $repository->shouldReceive('getExchangeRate')->andReturnNull(); $interface = $this->mock(ExchangeRateInterface::class); $interface->shouldReceive('setUser')->once(); $interface->shouldReceive('getRate')->andReturn($rate); $this->be($this->user()); $response = $this->get(route('json.rate', ['EUR', 'USD', '20170101'])); $response->assertStatus(200); } }