From 8e08ff2d39e5f3af225830e48eec64b9bf9ee1ac Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 7 Jul 2018 22:28:08 +0200 Subject: [PATCH] Fix the transaction factory and associated tests. --- app/Factory/TransactionFactory.php | 10 +++------- app/Transformers/RuleGroupTransformer.php | 5 +++++ tests/Unit/Factory/TransactionFactoryTest.php | 7 ++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/Factory/TransactionFactory.php b/app/Factory/TransactionFactory.php index 71ac12cbc7..35a435faa7 100644 --- a/app/Factory/TransactionFactory.php +++ b/app/Factory/TransactionFactory.php @@ -96,7 +96,7 @@ class TransactionFactory */ public function createPair(TransactionJournal $journal, array $data): Collection { - Log::debug('Start of TransactionFactory::createPair()'); + Log::debug('Start of TransactionFactory::createPair()', $data); // all this data is the same for both transactions: $currency = $this->findCurrency($data['currency_id'], $data['currency_code']); $description = $journal->description === $data['description'] ? null : $data['description']; @@ -105,12 +105,8 @@ class TransactionFactory $sourceType = $this->accountType($journal, 'source'); $destinationType = $this->accountType($journal, 'destination'); - if (null === $sourceType || null === $destinationType) { - throw new FireflyException('Could not determine source or destination type.'); - } - - Log::debug(sprintf('Expect source account to be of type %s', $sourceType)); - Log::debug(sprintf('Expect source destination to be of type %s', $destinationType)); + Log::debug(sprintf('Expect source account to be of type "%s"', $sourceType)); + Log::debug(sprintf('Expect source destination to be of type "%s"', $destinationType)); // find source and destination account: $sourceAccount = $this->findAccount($sourceType, $data['source_id'], $data['source_name']); diff --git a/app/Transformers/RuleGroupTransformer.php b/app/Transformers/RuleGroupTransformer.php index d749f09945..bc7060cee7 100644 --- a/app/Transformers/RuleGroupTransformer.php +++ b/app/Transformers/RuleGroupTransformer.php @@ -62,6 +62,11 @@ class RuleGroupTransformer extends TransformerAbstract $this->parameters = $parameters; } + /** + * @param RuleGroup $ruleGroup + * + * @return FractalCollection + */ public function includeRules(RuleGroup $ruleGroup): FractalCollection { return $this->collection($ruleGroup->rules, new RuleTransformer($this->parameters), 'rules'); diff --git a/tests/Unit/Factory/TransactionFactoryTest.php b/tests/Unit/Factory/TransactionFactoryTest.php index f31966fa75..f34ad9524c 100644 --- a/tests/Unit/Factory/TransactionFactoryTest.php +++ b/tests/Unit/Factory/TransactionFactoryTest.php @@ -705,7 +705,8 @@ class TransactionFactoryTest extends TestCase { // objects: $asset = $this->user()->accounts()->where('account_type_id', 3)->first(); - $opposing = $this->user()->accounts()->where('id', '!=', $asset->id)->where('account_type_id', 3)->first(); + $reconAccount = $this->user()->accounts()->where('account_type_id', 10)->first(); + //$opposing = $this->user()->accounts()->where('id', '!=', $asset->id)->where('account_type_id', 3)->first(); $euro = TransactionCurrency::first(); $foreign = TransactionCurrency::where('id', '!=', $euro->id)->first(); @@ -721,7 +722,7 @@ class TransactionFactoryTest extends TestCase 'description' => null, 'source_id' => $asset->id, 'source_name' => null, - 'destination_id' => $opposing->id, + 'destination_id' => $reconAccount->id, 'destination_name' => null, 'amount' => '10', 'reconciled' => false, @@ -740,7 +741,7 @@ class TransactionFactoryTest extends TestCase $budgetFactory->shouldReceive('setUser'); $categoryFactory->shouldReceive('setUser'); // first search action is for the asset account, second is for expense account. - $accountRepos->shouldReceive('findNull')->andReturn($asset, $opposing); + $accountRepos->shouldReceive('findNull')->andReturn($asset, $reconAccount); // factories return various stuff: $budgetFactory->shouldReceive('find')->andReturn(null);