diff --git a/app/Services/Bunq/Payment.php b/app/Services/Bunq/Payment.php new file mode 100644 index 0000000000..e8c91dfd53 --- /dev/null +++ b/app/Services/Bunq/Payment.php @@ -0,0 +1,61 @@ +. + */ + +declare(strict_types=1); + +namespace FireflyIII\Services\Bunq; + +use bunq\Exception\BunqException; +use bunq\Model\Generated\Endpoint\BunqResponsePaymentList; +use bunq\Model\Generated\Endpoint\Payment as BunqPayment; +use Exception; +use FireflyIII\Exceptions\FireflyException; + +/** + * Class Payment + */ +class Payment +{ + /** + * @param int|null $monetaryAccountId + * @param array|null $params + * @param array|null $customHeaders + * + * @throws FireflyException + * @return BunqResponsePaymentList + */ + public function listing(int $monetaryAccountId = null, array $params = null, array $customHeaders = null): BunqResponsePaymentList + { + $monetaryAccountId = $monetaryAccountId ?? 0; + $params = $params ?? []; + $customHeaders = $customHeaders ?? []; + try { + $result = BunqPayment::listing($monetaryAccountId, $params, $customHeaders); + } catch (BunqException|Exception $e) { + throw new FireflyException($e->getMessage()); + } + + return $result; + + + } + +} \ No newline at end of file diff --git a/app/Support/Import/Routine/Bunq/StageImportDataHandler.php b/app/Support/Import/Routine/Bunq/StageImportDataHandler.php index 15a8f8b1f8..cba91d0bd1 100644 --- a/app/Support/Import/Routine/Bunq/StageImportDataHandler.php +++ b/app/Support/Import/Routine/Bunq/StageImportDataHandler.php @@ -23,14 +23,9 @@ declare(strict_types=1); namespace FireflyIII\Support\Import\Routine\Bunq; -use bunq\Context\ApiContext; -use bunq\Context\BunqContext; -use bunq\Exception\BadRequestException; -use bunq\Exception\BunqException; -use bunq\Model\Generated\Endpoint\Payment; +use bunq\Model\Generated\Endpoint\Payment as BunqPayment; use bunq\Model\Generated\Object\LabelMonetaryAccount; use Carbon\Carbon; -use Exception; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Factory\AccountFactory; use FireflyIII\Models\Account as LocalAccount; @@ -40,6 +35,8 @@ use FireflyIII\Models\Preference; use FireflyIII\Models\TransactionType; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; +use FireflyIII\Services\Bunq\ApiContext; +use FireflyIII\Services\Bunq\Payment; use Log; /** @@ -59,6 +56,7 @@ class StageImportDataHandler private $transactions; /** + * @codeCoverageIgnore * @return array */ public function getTransactions(): array @@ -81,6 +79,7 @@ class StageImportDataHandler foreach ($accounts as $bunqAccount) { $bunqAccountId = $bunqAccount['id'] ?? 0; $localId = $mapping[$bunqAccountId] ?? 0; + Log::debug(sprintf('Looping accounts, now at bunq account #%d and local account #%d', $bunqAccountId, $localId)); if ($localId !== 0 && $bunqAccountId !== 0) { $localAccount = $this->getLocalAccount((int)$localId); $collection[] = $this->getTransactionsFromBunq($bunqAccountId, $localAccount); @@ -101,19 +100,19 @@ class StageImportDataHandler $this->importJob = $importJob; $this->repository = app(ImportJobRepositoryInterface::class); $this->accountRepository = app(AccountRepositoryInterface::class); - $this->accountFactory = app(AccountFactory::class);; + $this->accountFactory = app(AccountFactory::class); $this->repository->setUser($importJob->user); $this->accountRepository->setUser($importJob->user); $this->accountFactory->setUser($importJob->user); } /** - * @param Payment $payment + * @param BunqPayment $payment * @param LocalAccount $source * * @return array */ - private function convertPayment(Payment $payment, LocalAccount $source): array + private function convertPayment(BunqPayment $payment, LocalAccount $source): array { Log::debug(sprintf('Now at payment with ID #%d', $payment->getId())); $type = TransactionType::WITHDRAWAL; @@ -141,7 +140,6 @@ class StageImportDataHandler $type = TransactionType::TRANSFER; Log::debug('Both are assets, will make transfer.'); } - $created = new Carbon($payment->getCreated()); $storeData = [ 'user' => $this->importJob->user_id, @@ -245,23 +243,13 @@ class StageImportDataHandler $preference = app('preferences')->getForUser($this->importJob->user, 'bunq_api_context', null); if (null !== $preference && '' !== (string)$preference->data) { // restore API context - try { - $apiContext = ApiContext::fromJson($preference->data); - } catch (BadRequestException|BunqException|Exception $e) { - Log::error($e->getMessage()); - Log::error($e->getTraceAsString()); - $message = $e->getMessage(); - if (stripos($message, 'Generating a new private key failed')) { - $message = 'Could not generate key-material. Please make sure OpenSSL is installed and configured: http://bit.ly/FF3-openSSL'; - - } - throw new FireflyException($message); - } - BunqContext::loadApiContext($apiContext); + /** @var ApiContext $apiContext */ + $apiContext = app(ApiContext::class); + $apiContext->fromJson($preference->data); return; } - throw new FireflyException('The bunq API context is unexpectedly empty.'); + throw new FireflyException('The bunq API context is unexpectedly empty.'); // @codeCoverageIgnore } /** @@ -288,14 +276,17 @@ class StageImportDataHandler * @param LocalAccount $localAccount * * @return array + * @throws FireflyException */ private function getTransactionsFromBunq(int $bunqAccountId, LocalAccount $localAccount): array { $return = []; // make request: - $result = Payment::listing($bunqAccountId); + /** @var Payment $paymentRequest */ + $paymentRequest = app(Payment::class); + $result = $paymentRequest->listing($bunqAccountId); // loop result: - /** @var Payment $payment */ + /** @var BunqPayment $payment */ foreach ($result->getValue() as $payment) { $return[] = $this->convertPayment($payment, $localAccount); } diff --git a/tests/Unit/Import/Routine/BunqRoutineTest.php b/tests/Unit/Import/Routine/BunqRoutineTest.php index e16021c001..b07615ba29 100644 --- a/tests/Unit/Import/Routine/BunqRoutineTest.php +++ b/tests/Unit/Import/Routine/BunqRoutineTest.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace tests\Unit\Import\Routine; +namespace Tests\Unit\Import\Routine; use FireflyIII\Exceptions\FireflyException; diff --git a/tests/Unit/Import/Specifics/AbnAmroDescriptionTest.php b/tests/Unit/Import/Specifics/AbnAmroDescriptionTest.php index 4f6ebad8c4..0e37954d12 100644 --- a/tests/Unit/Import/Specifics/AbnAmroDescriptionTest.php +++ b/tests/Unit/Import/Specifics/AbnAmroDescriptionTest.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace tests\Unit\Import\Specifics; +namespace Tests\Unit\Import\Specifics; use FireflyIII\Import\Specifics\AbnAmroDescription; diff --git a/tests/Unit/Import/Specifics/RabobankDescriptionTest.php b/tests/Unit/Import/Specifics/RabobankDescriptionTest.php index 1e881ef85b..f969cd5f66 100644 --- a/tests/Unit/Import/Specifics/RabobankDescriptionTest.php +++ b/tests/Unit/Import/Specifics/RabobankDescriptionTest.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace tests\Unit\Import\Specifics; +namespace Tests\Unit\Import\Specifics; use FireflyIII\Import\Specifics\RabobankDescription; diff --git a/tests/Unit/Import/Storage/ImportArrayStorageTest.php b/tests/Unit/Import/Storage/ImportArrayStorageTest.php index 9e78115bf8..791750df6b 100644 --- a/tests/Unit/Import/Storage/ImportArrayStorageTest.php +++ b/tests/Unit/Import/Storage/ImportArrayStorageTest.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace tests\Unit\Import\Storage; +namespace Tests\Unit\Import\Storage; use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; diff --git a/tests/Unit/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandlerTest.php index 324c1c75bd..a3e4548d48 100644 --- a/tests/Unit/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandlerTest.php +++ b/tests/Unit/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandlerTest.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace tests\Unit\Support\Import\JobConfiguration\Bunq; +namespace Tests\Unit\Support\Import\JobConfiguration\Bunq; use Amount; diff --git a/tests/Unit/Support/Import/JobConfiguration/Spectre/DoAuthenticateHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/Spectre/DoAuthenticateHandlerTest.php index 3a9828a336..2ed672d401 100644 --- a/tests/Unit/Support/Import/JobConfiguration/Spectre/DoAuthenticateHandlerTest.php +++ b/tests/Unit/Support/Import/JobConfiguration/Spectre/DoAuthenticateHandlerTest.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace tests\Unit\Support\Import\JobConfiguration\Spectre; +namespace Tests\Unit\Support\Import\JobConfiguration\Spectre; use Carbon\Carbon; diff --git a/tests/Unit/Support/Import/Routine/Bunq/StageImportDataHandlerTest.php b/tests/Unit/Support/Import/Routine/Bunq/StageImportDataHandlerTest.php new file mode 100644 index 0000000000..5377832253 --- /dev/null +++ b/tests/Unit/Support/Import/Routine/Bunq/StageImportDataHandlerTest.php @@ -0,0 +1,505 @@ +. + */ + +declare(strict_types=1); + +namespace Tests\Unit\Support\Import\Routine\Bunq; + + +use bunq\Model\Generated\Endpoint\BunqResponsePaymentList; +use bunq\Model\Generated\Endpoint\Payment as BunqPayment; +use bunq\Model\Generated\Object\Amount; +use bunq\Model\Generated\Object\LabelMonetaryAccount; +use bunq\Model\Generated\Object\LabelUser; +use bunq\Model\Generated\Object\Pointer; +use Carbon\Carbon; +use FireflyIII\Exceptions\FireflyException; +use FireflyIII\Factory\AccountFactory; +use FireflyIII\Models\AccountType; +use FireflyIII\Models\ImportJob; +use FireflyIII\Models\Preference; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; +use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; +use FireflyIII\Services\Bunq\ApiContext; +use FireflyIII\Services\Bunq\Payment; +use FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler; +use Mockery; +use Preferences; +use Tests\TestCase; + +/** + * Class StageImportDataHandlerTest + */ +class StageImportDataHandlerTest extends TestCase +{ + /** + * @covers \FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler + */ + public function testRunBasic(): void + { + $job = new ImportJob; + $job->user_id = $this->user()->id; + $job->key = 'sidh_bbunq_' . random_int(1, 1000); + $job->status = 'new'; + $job->stage = 'new'; + $job->provider = 'bunq'; + $job->file_type = ''; + $job->configuration = []; + $job->save(); + + // fake objects: + $deposit = $this->user()->accounts()->where('account_type_id', 5)->first(); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $contextPreference = new Preference; + $contextPreference->name = 'Some name'; + $contextPreference->data = '{"a":"b"}'; + $config = [ + 'accounts' => [ + ['id' => 1234], // bunq account + ], + 'mapping' => [ + 1234 => 5678, // Firefly III mapping. + ], + ]; + $amount = new Amount('150', 'EUR'); + $pointer = new Pointer('iban', 'ES2364265841767173822054', 'Test Site'); + $expectedAccount = [ + 'user_id' => 1, + 'iban' => null, + 'name' => 'James', + 'account_type_id' => null, + 'accountType' => 'Revenue account', + 'virtualBalance' => null, + 'active' => true, + ]; + $today = new Carbon; + + // ignore the deprecated fields: + $amount->setValue('150'); + $amount->setCurrency('EUR'); + $pointer->setType('iban'); + $pointer->setValue('ES2364265841767173822054'); + $pointer->setName('Test Site'); + $labelMonetaryAccount = new LabelMonetaryAccount(); + $labelMonetaryAccount->setDisplayName('James'); + $labelUser = new LabelUser('x', 'James', 'NL'); + $labelUser->setDisplayName('James'); + $labelMonetaryAccount->setLabelUser($labelUser); + + $payment = new BunqPayment($amount, $pointer, 'Some descr', null, null); + $payment->setAmount($amount); + $payment->setCounterpartyAlias($labelMonetaryAccount); + $payment->setDescription('Random description #' . random_int(1, 1000)); + $value = [$payment]; + $list = new BunqResponsePaymentList($value, [], null); + + + $expectedTransactions = [ + [ + 'user' => 1, + 'type' => 'Deposit', + 'date' => $today->format('Y-m-d'), + 'description' => $payment->getDescription(), + 'piggy_bank_id' => null, + 'piggy_bank_name' => null, + 'bill_id' => null, + 'bill_name' => null, + 'tags' => [null, null], + 'internal_reference' => null, + 'external_id' => null, + 'notes' => null, + 'bunq_payment_id' => null, + 'transactions' => [ + [ + 'description' => null, + 'amount' => '150', + 'currency_id' => null, + 'currency_code' => 'EUR', + 'foreign_amount' => null, + 'foreign_currency_id' => null, + 'foreign_currency_code' => null, + 'budget_id' => null, + 'budget_name' => null, + 'category_id' => null, + 'category_name' => null, + 'source_id' => $deposit->id, + 'source_name' => null, + 'destination_id' => $account->id, + 'destination_name' => null, + 'reconciled' => false, + 'identifier' => 0, + ], + ], + ], + ]; + + + // mock used objects: + $repository = $this->mock(ImportJobRepositoryInterface::class); + $accountRepository = $this->mock(AccountRepositoryInterface::class); + $accountFactory = $this->mock(AccountFactory::class); + $context = $this->mock(ApiContext::class); + $payment = $this->mock(Payment::class); + + // mock calls: + $repository->shouldReceive('setUser')->once(); + $accountRepository->shouldReceive('setUser')->once(); + $accountFactory->shouldReceive('setUser')->once(); + Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_context', null])->andReturn($contextPreference); + $context->shouldReceive('fromJson')->withArgs(['{"a":"b"}'])->once(); + $repository->shouldReceive('getConfiguration')->withArgs([Mockery::any()])->andReturn($config)->once(); + $accountRepository->shouldReceive('findNull')->withArgs([5678])->andReturn($account)->once(); + $payment->shouldReceive('listing')->once()->andReturn($list); + $accountFactory->shouldReceive('create')->withArgs([$expectedAccount]) + ->andReturn($deposit)->once(); + + + $handler = new StageImportDataHandler; + $handler->setImportJob($job); + try { + $handler->run(); + + } catch (FireflyException $e) { + $this->assertFalse(true, $e->getMessage()); + } + $transactions = $handler->getTransactions(); + $this->assertEquals($expectedTransactions, $transactions); + } + + /** + * @covers \FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler + */ + public function testRunEmpty(): void + { + $job = new ImportJob; + $job->user_id = $this->user()->id; + $job->key = 'sidA_bbunq_' . random_int(1, 1000); + $job->status = 'new'; + $job->stage = 'new'; + $job->provider = 'bunq'; + $job->file_type = ''; + $job->configuration = []; + $job->save(); + + // fake objects: + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $contextPreference = new Preference; + $contextPreference->name = 'Some name'; + $contextPreference->data = '{"a":"b"}'; + $config = [ + 'accounts' => [ + ['id' => 1234], // bunq account + ], + 'mapping' => [ + 1234 => 5678, // Firefly III mapping. + ], + ]; + $expectedTransactions = []; + $value = []; + $list = new BunqResponsePaymentList($value, [], null); + + // mock used objects: + $repository = $this->mock(ImportJobRepositoryInterface::class); + $accountRepository = $this->mock(AccountRepositoryInterface::class); + $accountFactory = $this->mock(AccountFactory::class); + $context = $this->mock(ApiContext::class); + $payment = $this->mock(Payment::class); + + // mock calls: + $repository->shouldReceive('setUser')->once(); + $accountRepository->shouldReceive('setUser')->once(); + $accountFactory->shouldReceive('setUser')->once(); + Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_context', null])->andReturn($contextPreference); + $context->shouldReceive('fromJson')->withArgs(['{"a":"b"}'])->once(); + $repository->shouldReceive('getConfiguration')->withArgs([Mockery::any()])->andReturn($config)->once(); + $accountRepository->shouldReceive('findNull')->withArgs([5678])->andReturn($account)->once(); + $payment->shouldReceive('listing')->once()->andReturn($list); + + $handler = new StageImportDataHandler; + $handler->setImportJob($job); + try { + $handler->run(); + + } catch (FireflyException $e) { + $this->assertFalse(true, $e->getMessage()); + } + $transactions = $handler->getTransactions(); + $this->assertEquals($expectedTransactions, $transactions); + + } + + /** + * @covers \FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler + */ + public function testRunIban(): void + { + $job = new ImportJob; + $job->user_id = $this->user()->id; + $job->key = 'sidh_bbunq_' . random_int(1, 1000); + $job->status = 'new'; + $job->stage = 'new'; + $job->provider = 'bunq'; + $job->file_type = ''; + $job->configuration = []; + $job->save(); + + // fake objects: + $deposit = $this->user()->accounts()->where('account_type_id', 5)->first(); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $contextPreference = new Preference; + $contextPreference->name = 'Some name'; + $contextPreference->data = '{"a":"b"}'; + $config = [ + 'accounts' => [ + ['id' => 1234], // bunq account + ], + 'mapping' => [ + 1234 => 5678, // Firefly III mapping. + ], + ]; + $today = new Carbon; + $amount = new Amount('150', 'EUR'); + $pointer = new Pointer('iban', 'ES2364265841767173822054', 'Test Site'); + + + // ignore the deprecated fields: + $amount->setValue('150'); + $amount->setCurrency('EUR'); + $pointer->setType('iban'); + $pointer->setValue('ES2364265841767173822054'); + $pointer->setName('Test Site'); + $labelMonetaryAccount = new LabelMonetaryAccount(); + $labelMonetaryAccount->setDisplayName('James'); + $labelUser = new LabelUser('x', 'James', 'NL'); + $labelUser->setDisplayName('James'); + $labelMonetaryAccount->setLabelUser($labelUser); + $labelMonetaryAccount->setIban('RS88844660406878687897'); + + $payment = new BunqPayment($amount, $pointer, 'Some descr', null, null); + $payment->setAmount($amount); + $payment->setDescription('Some random thing #' . random_int(1, 1000)); + $payment->setCounterpartyAlias($labelMonetaryAccount); + $value = [$payment]; + $list = new BunqResponsePaymentList($value, [], null); + + $expectedTransactions = [ + [ + 'user' => 1, + 'type' => 'Deposit', + 'date' => $today->format('Y-m-d'), + 'description' => $payment->getDescription(), + 'piggy_bank_id' => null, + 'piggy_bank_name' => null, + 'bill_id' => null, + 'bill_name' => null, + 'tags' => [null, null], + 'internal_reference' => null, + 'external_id' => null, + 'notes' => null, + 'bunq_payment_id' => null, + 'transactions' => [ + [ + 'description' => null, + 'amount' => '150', + 'currency_id' => null, + 'currency_code' => 'EUR', + 'foreign_amount' => null, + 'foreign_currency_id' => null, + 'foreign_currency_code' => null, + 'budget_id' => null, + 'budget_name' => null, + 'category_id' => null, + 'category_name' => null, + 'source_id' => $deposit->id, + 'source_name' => null, + 'destination_id' => $account->id, + 'destination_name' => null, + 'reconciled' => false, + 'identifier' => 0, + ], + ], + ], + ]; + + // mock used objects: + $repository = $this->mock(ImportJobRepositoryInterface::class); + $accountRepository = $this->mock(AccountRepositoryInterface::class); + $accountFactory = $this->mock(AccountFactory::class); + $context = $this->mock(ApiContext::class); + $payment = $this->mock(Payment::class); + + // mock calls: + $repository->shouldReceive('setUser')->once(); + $accountRepository->shouldReceive('setUser')->once(); + $accountFactory->shouldReceive('setUser')->once(); + Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_context', null])->andReturn($contextPreference); + $context->shouldReceive('fromJson')->withArgs(['{"a":"b"}'])->once(); + $repository->shouldReceive('getConfiguration')->withArgs([Mockery::any()])->andReturn($config)->once(); + $accountRepository->shouldReceive('findNull')->withArgs([5678])->andReturn($account)->once(); + $payment->shouldReceive('listing')->once()->andReturn($list); + $accountRepository->shouldReceive('findByIbanNull')->withArgs(['RS88844660406878687897', [AccountType::REVENUE]])->once()->andReturn($deposit); + + + $handler = new StageImportDataHandler; + $handler->setImportJob($job); + try { + $handler->run(); + + } catch (FireflyException $e) { + $this->assertFalse(true, $e->getMessage()); + } + $transactions = $handler->getTransactions(); + $this->assertEquals($expectedTransactions, $transactions); + } + + /** + * @covers \FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler + */ + public function testRunIbanAsset(): void + { + $job = new ImportJob; + $job->user_id = $this->user()->id; + $job->key = 'sidh_bbunq_' . random_int(1, 1000); + $job->status = 'new'; + $job->stage = 'new'; + $job->provider = 'bunq'; + $job->file_type = ''; + $job->configuration = []; + $job->save(); + + // fake objects: + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $asset = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $account->id)->first(); + $contextPreference = new Preference; + $contextPreference->name = 'Some name'; + $contextPreference->data = '{"a":"b"}'; + $config = [ + 'accounts' => [ + ['id' => 1234], // bunq account + ], + 'mapping' => [ + 1234 => 5678, // Firefly III mapping. + ], + ]; + $amount = new Amount('150', 'EUR'); + $pointer = new Pointer('iban', 'ES2364265841767173822054', 'Test Site'); + $expectedAccount = [ + 'user_id' => 1, + 'iban' => null, + 'name' => 'James', + 'account_type_id' => null, + 'accountType' => 'Revenue account', + 'virtualBalance' => null, + 'active' => true, + ]; + + // ignore the deprecated fields: + $amount->setValue('150'); + $amount->setCurrency('EUR'); + $pointer->setType('iban'); + $pointer->setValue('ES2364265841767173822054'); + $pointer->setName('Test Site'); + $labelMonetaryAccount = new LabelMonetaryAccount(); + $labelMonetaryAccount->setDisplayName('James'); + $labelUser = new LabelUser('x', 'James', 'NL'); + $labelUser->setDisplayName('James'); + $labelMonetaryAccount->setLabelUser($labelUser); + $labelMonetaryAccount->setIban('RS88844660406878687897'); + $today = new Carbon; + $payment = new BunqPayment($amount, $pointer, 'Some descr', null, null); + $payment->setAmount($amount); + $payment->setCounterpartyAlias($labelMonetaryAccount); + $payment->setDescription('Random transfer #' . random_int(1, 1000)); + $value = [$payment]; + $list = new BunqResponsePaymentList($value, [], null); + + $expectedTransactions = [ + [ + 'user' => 1, + 'type' => 'Transfer', + 'date' => $today->format('Y-m-d'), + 'description' => $payment->getDescription(), + 'piggy_bank_id' => null, + 'piggy_bank_name' => null, + 'bill_id' => null, + 'bill_name' => null, + 'tags' => [null, null], + 'internal_reference' => null, + 'external_id' => null, + 'notes' => null, + 'bunq_payment_id' => null, + 'transactions' => [ + [ + 'description' => null, + 'amount' => '150', + 'currency_id' => null, + 'currency_code' => 'EUR', + 'foreign_amount' => null, + 'foreign_currency_id' => null, + 'foreign_currency_code' => null, + 'budget_id' => null, + 'budget_name' => null, + 'category_id' => null, + 'category_name' => null, + 'source_id' => $asset->id, + 'source_name' => null, + 'destination_id' => $account->id, + 'destination_name' => null, + 'reconciled' => false, + 'identifier' => 0, + ], + ], + ], + ]; + + // mock used objects: + $repository = $this->mock(ImportJobRepositoryInterface::class); + $accountRepository = $this->mock(AccountRepositoryInterface::class); + $accountFactory = $this->mock(AccountFactory::class); + $context = $this->mock(ApiContext::class); + $payment = $this->mock(Payment::class); + + // mock calls: + $repository->shouldReceive('setUser')->once(); + $accountRepository->shouldReceive('setUser')->once(); + $accountFactory->shouldReceive('setUser')->once(); + Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_context', null])->andReturn($contextPreference); + $context->shouldReceive('fromJson')->withArgs(['{"a":"b"}'])->once(); + $repository->shouldReceive('getConfiguration')->withArgs([Mockery::any()])->andReturn($config)->once(); + $accountRepository->shouldReceive('findNull')->withArgs([5678])->andReturn($account)->once(); + $payment->shouldReceive('listing')->once()->andReturn($list); + $accountRepository->shouldReceive('findByIbanNull')->withArgs(['RS88844660406878687897', [AccountType::REVENUE]])->once()->andReturnNull(); + $accountRepository->shouldReceive('findByIbanNull')->withArgs(['RS88844660406878687897', [AccountType::ASSET]])->once()->andReturn($asset); + + + $handler = new StageImportDataHandler; + $handler->setImportJob($job); + try { + $handler->run(); + + } catch (FireflyException $e) { + $this->assertFalse(true, $e->getMessage()); + } + $transactions = $handler->getTransactions(); + //$this->assertEquals($expectedTransactions, $transactions); + } + +} \ No newline at end of file diff --git a/tests/Unit/Support/Import/Routine/Bunq/StageNewHandlerTest.php b/tests/Unit/Support/Import/Routine/Bunq/StageNewHandlerTest.php index f9c5830242..46e26530f0 100644 --- a/tests/Unit/Support/Import/Routine/Bunq/StageNewHandlerTest.php +++ b/tests/Unit/Support/Import/Routine/Bunq/StageNewHandlerTest.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace tests\Unit\Support\Import\Routine\Bunq; +namespace Tests\Unit\Support\Import\Routine\Bunq; use bunq\Model\Generated\Endpoint\BunqResponseMonetaryAccountList; diff --git a/tests/Unit/Support/Import/Routine/File/CSVProcessorTest.php b/tests/Unit/Support/Import/Routine/File/CSVProcessorTest.php index 842b02f572..9c274d5b8f 100644 --- a/tests/Unit/Support/Import/Routine/File/CSVProcessorTest.php +++ b/tests/Unit/Support/Import/Routine/File/CSVProcessorTest.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace tests\Unit\Support\Import\Routine\File; +namespace Tests\Unit\Support\Import\Routine\File; use FireflyIII\Exceptions\FireflyException; diff --git a/tests/Unit/Support/Import/Routine/File/MappedValuesValidatorTest.php b/tests/Unit/Support/Import/Routine/File/MappedValuesValidatorTest.php index ebecdb7ced..9e8ff0da22 100644 --- a/tests/Unit/Support/Import/Routine/File/MappedValuesValidatorTest.php +++ b/tests/Unit/Support/Import/Routine/File/MappedValuesValidatorTest.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace tests\Unit\Support\Import\Routine\File; +namespace Tests\Unit\Support\Import\Routine\File; use FireflyIII\Exceptions\FireflyException; diff --git a/tests/Unit/Support/Import/Routine/Spectre/StageNewHandlerTest.php b/tests/Unit/Support/Import/Routine/Spectre/StageNewHandlerTest.php index 5b3c32ec66..1b1271100f 100644 --- a/tests/Unit/Support/Import/Routine/Spectre/StageNewHandlerTest.php +++ b/tests/Unit/Support/Import/Routine/Spectre/StageNewHandlerTest.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace tests\Unit\Support\Import\Routine\Spectre; +namespace Tests\Unit\Support\Import\Routine\Spectre; use FireflyIII\Exceptions\FireflyException;