. */ declare(strict_types=1); namespace Tests\Unit\Import\JobConfiguration; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Import\JobConfiguration\FinTSJobConfiguration; use FireflyIII\Models\ImportJob; use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; use FireflyIII\Support\Import\JobConfiguration\FinTS\ChooseAccountHandler; use FireflyIII\Support\Import\JobConfiguration\FinTS\NewFinTSJobHandler; use Log; use Tests\TestCase; /** * Class FinTSJobConfigurationTest * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ class FinTSJobConfigurationTest extends TestCase { /** * */ public function setUp(): void { parent::setUp(); Log::info(sprintf('Now in %s.', get_class($this))); } /** * @covers \FireflyIII\Import\JobConfiguration\FinTSJobConfiguration */ public function testConfigurationComplete(): void { $this->mock(ImportJobRepositoryInterface::class); $this->mock(NewFinTSJobHandler::class); $job = new ImportJob; $job->user_id = $this->user()->id; $job->key = 'fints_jc_A' . $this->randomInt(); $job->status = 'new'; $job->stage = 'go-for-import'; $job->provider = 'fints'; $job->file_type = ''; $job->configuration = []; $job->save(); $config = new FinTSJobConfiguration; $config->setImportJob($job); $this->assertTrue($config->configurationComplete()); } /** * @covers \FireflyIII\Import\JobConfiguration\FinTSJobConfiguration */ public function testConfigureJob(): void { $this->mock(ImportJobRepositoryInterface::class); $handler = $this->mock(NewFinTSJobHandler::class); $job = new ImportJob; $job->user_id = $this->user()->id; $job->key = 'fints_jc_B' . $this->randomInt(); $job->status = 'new'; $job->stage = 'new'; $job->provider = 'fints'; $job->file_type = ''; $job->configuration = []; $job->save(); $handler->shouldReceive('setImportJob')->atLeast()->once(); $handler->shouldReceive('configureJob')->atLeast()->once()->withArgs([[123]]); $config = new FinTSJobConfiguration; $config->setImportJob($job); try { $config->configureJob([123]); } catch (FireflyException $e) { $this->assertFalse(true, $e->getMessage()); } } /** * @covers \FireflyIII\Import\JobConfiguration\FinTSJobConfiguration */ public function testGetNextData(): void { $this->mock(ImportJobRepositoryInterface::class); $handler = $this->mock(ChooseAccountHandler::class); $job = new ImportJob; $job->user_id = $this->user()->id; $job->key = 'fints_jc_C' . $this->randomInt(); $job->status = 'new'; $job->stage = 'choose_account'; $job->provider = 'fints'; $job->file_type = ''; $job->configuration = []; $job->save(); $handler->shouldReceive('setImportJob')->atLeast()->once(); $handler->shouldReceive('getNextData')->atLeast()->once()->withNoArgs()->andReturn([456]); $res = []; $config = new FinTSJobConfiguration; $config->setImportJob($job); try { $res = $config->getNextData(); } catch (FireflyException $e) { $this->assertFalse(true, $e->getMessage()); } $this->assertEquals([456], $res); } /** * @covers \FireflyIII\Import\JobConfiguration\FinTSJobConfiguration */ public function testGetNextView(): void { $this->mock(ImportJobRepositoryInterface::class); $this->mock(ChooseAccountHandler::class); $job = new ImportJob; $job->user_id = $this->user()->id; $job->key = 'fints_jc_D' . $this->randomInt(); $job->status = 'new'; $job->stage = 'choose_account'; $job->provider = 'fints'; $job->file_type = ''; $job->configuration = []; $job->save(); $res = []; $config = new FinTSJobConfiguration; $config->setImportJob($job); try { $res = $config->getNextView(); } catch (FireflyException $e) { $this->assertFalse(true, $e->getMessage()); } $this->assertEquals('import.fints.choose_account', $res); } }