diff --git a/tests/Api/V1/Controllers/AboutControllerTest.php b/tests/Api/V1/Controllers/AboutControllerTest.php index 82a9809a87..eeeaba4290 100644 --- a/tests/Api/V1/Controllers/AboutControllerTest.php +++ b/tests/Api/V1/Controllers/AboutControllerTest.php @@ -25,7 +25,7 @@ namespace Tests\Api\V1\Controllers; use Laravel\Passport\Passport; use Tests\TestCase; - +use Log; /** * Class AboutControllerTest */ @@ -38,6 +38,7 @@ class AboutControllerTest extends TestCase { parent::setUp(); Passport::actingAs($this->user()); + Log::debug('Now in Api/AboutControllerTest.'); } /** diff --git a/tests/Api/V1/Controllers/AccountControllerTest.php b/tests/Api/V1/Controllers/AccountControllerTest.php index c2b43d0fa4..a342fe2461 100644 --- a/tests/Api/V1/Controllers/AccountControllerTest.php +++ b/tests/Api/V1/Controllers/AccountControllerTest.php @@ -29,6 +29,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use Laravel\Passport\Passport; use Tests\TestCase; +use Log; /** * Class AccountControllerTest @@ -42,6 +43,7 @@ class AccountControllerTest extends TestCase { parent::setUp(); Passport::actingAs($this->user()); + Log::debug('Now in Api/AccountControllerTest.'); } /** diff --git a/tests/Api/V1/Controllers/BillControllerTest.php b/tests/Api/V1/Controllers/BillControllerTest.php index 6dc03ae9f4..8b6afccacd 100644 --- a/tests/Api/V1/Controllers/BillControllerTest.php +++ b/tests/Api/V1/Controllers/BillControllerTest.php @@ -28,6 +28,7 @@ use FireflyIII\Models\Bill; use FireflyIII\Repositories\Bill\BillRepositoryInterface; use Illuminate\Pagination\LengthAwarePaginator; use Laravel\Passport\Passport; +use Log; use Tests\TestCase; /** @@ -42,6 +43,7 @@ class BillControllerTest extends TestCase { parent::setUp(); Passport::actingAs($this->user()); + Log::debug('Now in Api/BillControllerTest.'); } diff --git a/tests/Api/V1/Controllers/TransactionControllerTest.php b/tests/Api/V1/Controllers/TransactionControllerTest.php index 2d94ea0df7..1b7c43fd61 100644 --- a/tests/Api/V1/Controllers/TransactionControllerTest.php +++ b/tests/Api/V1/Controllers/TransactionControllerTest.php @@ -28,9 +28,11 @@ use FireflyIII\Helpers\Collector\JournalCollector; use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionJournal; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Illuminate\Support\Collection; use Laravel\Passport\Passport; +use Log; use Tests\TestCase; /** @@ -46,6 +48,7 @@ class TransactionControllerTest extends TestCase { parent::setUp(); Passport::actingAs($this->user()); + Log::debug('Now in Api/TransactionControllerTest.'); } /** @@ -80,8 +83,18 @@ class TransactionControllerTest extends TestCase */ public function testFailCurrencyCode() { - $account = $this->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + // mock stuff: + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + + // mock calls: + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + + + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -117,8 +130,17 @@ class TransactionControllerTest extends TestCase */ public function testFailCurrencyId() { - $account = $this->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + // mock stuff: + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + + // mock calls: + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -154,8 +176,16 @@ class TransactionControllerTest extends TestCase */ public function testFailEmptyDescriptions() { - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + // mock stuff: + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + + // mock calls: + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + $data = [ 'description' => '', 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -183,7 +213,7 @@ class TransactionControllerTest extends TestCase 'The description must be between 1 and 255 characters.', ], 'transactions.0.description' => [ - 'Transaction description should not equal journal description.', + 'Transaction description should not equal global description.', ], ], ] @@ -198,8 +228,17 @@ class TransactionControllerTest extends TestCase */ public function testFailEmptySplitDescriptions() { - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + // mock stuff: + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + + // mock calls: + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + + $data = [ 'description' => 'Split journal #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -247,8 +286,17 @@ class TransactionControllerTest extends TestCase */ public function testFailExpenseID() { - $account = $this->user()->accounts()->where('account_type_id', 4)->first(); - $data = [ + // mock stuff: + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $account = $this->user()->accounts()->where('account_type_id', 4)->first(); + + // mock calls: + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -286,8 +334,16 @@ class TransactionControllerTest extends TestCase */ public function testFailExpenseName() { - $account = $this->user()->accounts()->where('account_type_id', 4)->first(); - $data = [ + // mock stuff: + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection); + $accountRepos->shouldReceive('findByName')->andReturn(null); + + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -295,7 +351,7 @@ class TransactionControllerTest extends TestCase [ 'amount' => '10', 'currency_id' => 1, - 'source_name' => $account->name, + 'source_name' => 'Expense name', ], @@ -325,6 +381,13 @@ class TransactionControllerTest extends TestCase */ public function testFailNoAsset() { + // mock stuff: + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', @@ -362,6 +425,13 @@ class TransactionControllerTest extends TestCase */ public function testFailNoData() { + // mock stuff: + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', @@ -392,8 +462,17 @@ class TransactionControllerTest extends TestCase */ public function testFailNoForeignCurrencyInfo() { - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + // mock stuff: + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + + + $data = [ 'description' => 'Split journal #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -431,9 +510,19 @@ class TransactionControllerTest extends TestCase */ public function testFailOpposingRevenueID() { - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $opposing = auth()->user()->accounts()->where('account_type_id', 5)->first(); - $data = [ + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $opposing = $this->user()->accounts()->where('account_type_id', 5)->first(); + + // mock stuff: + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]), new Collection([$opposing])); + + + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -474,14 +563,22 @@ class TransactionControllerTest extends TestCase */ public function testFailOwnershipBillId() { + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + // move account to other user - $bill = auth()->user()->bills()->first(); + $bill = $this->user()->bills()->first(); $bill->user_id = $this->emptyUser()->id; $bill->save(); // submit with another account. - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -525,14 +622,21 @@ class TransactionControllerTest extends TestCase */ public function testFailOwnershipBillName() { + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + // move account to other user - $bill = auth()->user()->bills()->first(); + $bill = $this->user()->bills()->first(); $bill->user_id = $this->emptyUser()->id; $bill->save(); // submit with another account. - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -576,14 +680,21 @@ class TransactionControllerTest extends TestCase */ public function testFailOwnershipBudgetId() { + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + // move account to other user - $budget = auth()->user()->budgets()->first(); + $budget = $this->user()->budgets()->first(); $budget->user_id = $this->emptyUser()->id; $budget->save(); // submit with another account. - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -627,14 +738,21 @@ class TransactionControllerTest extends TestCase */ public function testFailOwnershipBudgetName() { + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + // move account to other user - $budget = auth()->user()->budgets()->first(); + $budget = $this->user()->budgets()->first(); $budget->user_id = $this->emptyUser()->id; $budget->save(); // submit with another account. - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -678,14 +796,21 @@ class TransactionControllerTest extends TestCase */ public function testFailOwnershipCategoryId() { + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + // move account to other user - $category = auth()->user()->categories()->first(); + $category = $this->user()->categories()->first(); $category->user_id = $this->emptyUser()->id; $category->save(); // submit with another account. - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -730,17 +855,26 @@ class TransactionControllerTest extends TestCase public function testFailOwnershipPiggyBankID() { // move account to other user - $move = auth()->user()->accounts()->where('account_type_id', 3)->first(); + $move = $this->user()->accounts()->where('account_type_id', 3)->first(); $move->user_id = $this->emptyUser()->id; - $piggyBank = auth()->user()->piggyBanks()->first(); + $piggyBank = $this->user()->piggyBanks()->first(); $oldId = $piggyBank->account_id; $piggyBank->account_id = $move->id; $move->save(); $piggyBank->save(); + + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + + // submit with another account. - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -787,17 +921,26 @@ class TransactionControllerTest extends TestCase public function testFailOwnershipPiggyBankName() { // move account to other user - $move = auth()->user()->accounts()->where('account_type_id', 3)->first(); + $move = $this->user()->accounts()->where('account_type_id', 3)->first(); $move->user_id = $this->emptyUser()->id; - $piggyBank = auth()->user()->piggyBanks()->first(); + $piggyBank = $this->user()->piggyBanks()->first(); $oldId = $piggyBank->account_id; $piggyBank->account_id = $move->id; $move->save(); $piggyBank->save(); + + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + + // submit with another account. - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -843,8 +986,15 @@ class TransactionControllerTest extends TestCase */ public function testFailRevenueID() { - $account = $this->user()->accounts()->where('account_type_id', 4)->first(); - $data = [ + $account = $this->user()->accounts()->where('account_type_id', 4)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'deposit', @@ -882,9 +1032,18 @@ class TransactionControllerTest extends TestCase */ public function testFailSplitDeposit() { - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $second = auth()->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $account->id)->first(); - $data = [ + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $second = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $account->id)->first(); + + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]), new Collection([$second])); + + + $data = [ 'description' => 'Some deposit #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'deposit', @@ -930,9 +1089,17 @@ class TransactionControllerTest extends TestCase */ public function testFailSplitTransfer() { - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $second = auth()->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $account->id)->first(); - $data = [ + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $second = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $account->id)->first(); + + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]), new Collection([$second])); + + $data = [ 'description' => 'Some transfer #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'transfer', @@ -983,9 +1150,17 @@ class TransactionControllerTest extends TestCase */ public function testFailSplitWithdrawal() { - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $second = auth()->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $account->id)->first(); - $data = [ + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $second = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $account->id)->first(); + + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]), new Collection([$second])); + + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -1034,9 +1209,14 @@ class TransactionControllerTest extends TestCase */ public function testIndex() { + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsByType') + ->andReturn($this->user()->accounts()->where('account_type_id', 3)->get()); + // get some transactions using the collector: $collector = new JournalCollector; - $collector->setUser(auth()->user()); + $collector->setUser($this->user()); $collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation(); $collector->setAllAssetAccounts(); $collector->setLimit(5)->setPage(1); @@ -1047,6 +1227,7 @@ class TransactionControllerTest extends TestCase $collector = $this->mock(JournalCollectorInterface::class); $repository->shouldReceive('setUser'); + $collector->shouldReceive('setUser')->andReturnSelf(); $collector->shouldReceive('withOpposingAccount')->andReturnSelf(); $collector->shouldReceive('withCategoryInformation')->andReturnSelf(); @@ -1078,9 +1259,14 @@ class TransactionControllerTest extends TestCase */ public function testIndexWithRange() { + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsByType') + ->andReturn($this->user()->accounts()->where('account_type_id', 3)->get()); + // get some transactions using the collector: $collector = new JournalCollector; - $collector->setUser(auth()->user()); + $collector->setUser($this->user()); $collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation(); $collector->setAllAssetAccounts(); $collector->setLimit(5)->setPage(1); @@ -1135,12 +1321,18 @@ class TransactionControllerTest extends TestCase public function testShowDeposit() { /** @var TransactionJournal $journal */ - $journal = auth()->user()->transactionJournals()->where('transaction_type_id', 2)->first(); + $journal = $this->user()->transactionJournals()->where('transaction_type_id', 2)->first(); $transaction = $journal->transactions()->first(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsByType') + ->andReturn($this->user()->accounts()->where('account_type_id', 3)->get()); + + // get some transactions using the collector: $collector = new JournalCollector; - $collector->setUser(auth()->user()); + $collector->setUser($this->user()); $collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation(); $collector->setAllAssetAccounts(); $collector->setJournals(new Collection([$journal])); @@ -1188,12 +1380,18 @@ class TransactionControllerTest extends TestCase public function testShowWithdrawal() { /** @var TransactionJournal $journal */ - $journal = auth()->user()->transactionJournals()->where('transaction_type_id', 1)->first(); + $journal = $this->user()->transactionJournals()->where('transaction_type_id', 1)->first(); $transaction = $journal->transactions()->first(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsByType') + ->andReturn($this->user()->accounts()->where('account_type_id', 3)->get()); + + // get some transactions using the collector: $collector = new JournalCollector; - $collector->setUser(auth()->user()); + $collector->setUser($this->user()); $collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation(); $collector->setAllAssetAccounts(); $collector->setJournals(new Collection([$journal])); @@ -1243,9 +1441,19 @@ class TransactionControllerTest extends TestCase */ public function testSuccessBillId() { - $bill = auth()->user()->bills()->first(); - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + // default journal: + $journal = $this->user()->transactionJournals()->first(); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); + + $bill = $this->user()->bills()->first(); + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -1264,27 +1472,6 @@ class TransactionControllerTest extends TestCase // test API $response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']); $response->assertStatus(200); - $response->assertJson( - [ - 'data' => [[ - 'type' => 'transactions', - 'attributes' => [ - 'description' => $data['description'], - 'date' => $data['date'], - 'source_id' => $account->id, - 'source_name' => $account->name, - 'type' => 'Withdrawal', - 'source_type' => 'Asset account', - 'destination_name' => 'Cash account', - 'destination_type' => 'Cash account', - 'bill_id' => $bill->id, - 'bill_name' => $bill->name, - 'amount' => -10, - ], - 'links' => true, - ]], - ] - ); } /** @@ -1295,9 +1482,19 @@ class TransactionControllerTest extends TestCase */ public function testSuccessBillName() { - $bill = auth()->user()->bills()->first(); - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + // default journal: + $journal = $this->user()->transactionJournals()->first(); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); + + $bill = $this->user()->bills()->first(); + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -1316,27 +1513,6 @@ class TransactionControllerTest extends TestCase // test API $response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']); $response->assertStatus(200); - $response->assertJson( - [ - 'data' => [[ - 'type' => 'transactions', - 'attributes' => [ - 'description' => $data['description'], - 'date' => $data['date'], - 'source_id' => $account->id, - 'source_name' => $account->name, - 'type' => 'Withdrawal', - 'source_type' => 'Asset account', - 'destination_name' => 'Cash account', - 'destination_type' => 'Cash account', - 'bill_id' => $bill->id, - 'bill_name' => $bill->name, - 'amount' => -10, - ], - 'links' => true, - ]], - ] - ); } /** @@ -1347,8 +1523,18 @@ class TransactionControllerTest extends TestCase */ public function testSuccessStoreAccountName() { - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + // default journal: + $journal = $this->user()->transactionJournals()->first(); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); + + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -1366,25 +1552,6 @@ class TransactionControllerTest extends TestCase // test API $response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']); $response->assertStatus(200); - $response->assertJson( - [ - 'data' => [[ - 'type' => 'transactions', - 'attributes' => [ - 'description' => $data['description'], - 'date' => $data['date'], - 'source_id' => $account->id, - 'source_name' => $account->name, - 'type' => 'Withdrawal', - 'source_type' => 'Asset account', - 'destination_name' => 'Cash account', - 'destination_type' => 'Cash account', - 'amount' => -10, - ], - 'links' => true, - ], - ]] - ); } /** @@ -1395,8 +1562,18 @@ class TransactionControllerTest extends TestCase */ public function testSuccessStoreBasic() { - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + // default journal: + $journal = $this->user()->transactionJournals()->first(); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); + + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -1414,25 +1591,6 @@ class TransactionControllerTest extends TestCase // test API $response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']); $response->assertStatus(200); - $response->assertJson( - [ - 'data' => [[ - 'type' => 'transactions', - 'attributes' => [ - 'description' => $data['description'], - 'date' => $data['date'], - 'source_id' => $account->id, - 'source_name' => $account->name, - 'type' => 'Withdrawal', - 'source_type' => 'Asset account', - 'destination_name' => 'Cash account', - 'destination_type' => 'Cash account', - 'amount' => -10, - ], - 'links' => true, - ], - ]] - ); } /** @@ -1443,8 +1601,18 @@ class TransactionControllerTest extends TestCase */ public function testSuccessStoreBasicDeposit() { - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + // default journal: + $journal = $this->user()->transactionJournals()->first(); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); + + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'deposit', @@ -1462,25 +1630,6 @@ class TransactionControllerTest extends TestCase // test API $response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']); $response->assertStatus(200); - $response->assertJson( - [ - 'data' => [[ - 'type' => 'transactions', - 'attributes' => [ - 'description' => $data['description'], - 'date' => $data['date'], - 'destination_id' => $account->id, - 'destination_name' => $account->name, - 'destination_type' => 'Asset account', - 'type' => 'Deposit', - 'source_name' => 'Cash account', - 'source_type' => 'Cash account', - 'amount' => 10, - ], - 'links' => true, - ], - ]] - ); } /** @@ -1491,9 +1640,17 @@ class TransactionControllerTest extends TestCase */ public function testSuccessStoreBudgetId() { - $budget = auth()->user()->budgets()->first(); - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + $budget = $this->user()->budgets()->first(); + $journal = $this->user()->transactionJournals()->first(); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -1512,27 +1669,6 @@ class TransactionControllerTest extends TestCase // test API $response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']); $response->assertStatus(200); - $response->assertJson( - [ - 'data' => [[ - 'type' => 'transactions', - 'attributes' => [ - 'description' => $data['description'], - 'date' => $data['date'], - 'source_id' => $account->id, - 'source_name' => $account->name, - 'type' => 'Withdrawal', - 'source_type' => 'Asset account', - 'destination_name' => 'Cash account', - 'destination_type' => 'Cash account', - 'amount' => -10, - 'budget_id' => $budget->id, - 'budget_name' => $budget->name, - ], - 'links' => true, - ], - ]] - ); } /** @@ -1543,9 +1679,18 @@ class TransactionControllerTest extends TestCase */ public function testSuccessStoreBudgetName() { - $budget = auth()->user()->budgets()->first(); - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + $budget = $this->user()->budgets()->first(); + $journal = $this->user()->transactionJournals()->first(); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); + + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -1564,27 +1709,6 @@ class TransactionControllerTest extends TestCase // test API $response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']); $response->assertStatus(200); - $response->assertJson( - [ - 'data' => [[ - 'type' => 'transactions', - 'attributes' => [ - 'description' => $data['description'], - 'date' => $data['date'], - 'source_id' => $account->id, - 'source_name' => $account->name, - 'type' => 'Withdrawal', - 'source_type' => 'Asset account', - 'destination_name' => 'Cash account', - 'destination_type' => 'Cash account', - 'amount' => -10, - 'budget_id' => $budget->id, - 'budget_name' => $budget->name, - ], - 'links' => true, - ], - ]] - ); } /** @@ -1595,9 +1719,17 @@ class TransactionControllerTest extends TestCase */ public function testSuccessStoreCategoryID() { - $category = auth()->user()->categories()->first(); - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + $category = $this->user()->categories()->first(); + $journal = $this->user()->transactionJournals()->first(); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -1616,27 +1748,6 @@ class TransactionControllerTest extends TestCase // test API $response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']); $response->assertStatus(200); - $response->assertJson( - [ - 'data' => [[ - 'type' => 'transactions', - 'attributes' => [ - 'description' => $data['description'], - 'date' => $data['date'], - 'source_id' => $account->id, - 'source_name' => $account->name, - 'type' => 'Withdrawal', - 'source_type' => 'Asset account', - 'destination_name' => 'Cash account', - 'destination_type' => 'Cash account', - 'amount' => -10, - 'category_id' => $category->id, - 'category_name' => $category->name, - ], - 'links' => true, - ], - ]] - ); } /** @@ -1647,9 +1758,17 @@ class TransactionControllerTest extends TestCase */ public function testSuccessStoreCategoryName() { - $category = auth()->user()->categories()->first(); - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + $category = $this->user()->categories()->first(); + $journal = $this->user()->transactionJournals()->first(); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -1668,27 +1787,6 @@ class TransactionControllerTest extends TestCase // test API $response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']); $response->assertStatus(200); - $response->assertJson( - [ - 'data' => [[ - 'type' => 'transactions', - 'attributes' => [ - 'description' => $data['description'], - 'date' => $data['date'], - 'source_id' => $account->id, - 'source_name' => $account->name, - 'type' => 'Withdrawal', - 'source_type' => 'Asset account', - 'destination_name' => 'Cash account', - 'destination_type' => 'Cash account', - 'amount' => -10, - 'category_id' => $category->id, - 'category_name' => $category->name, - ], - 'links' => true, - ], - ]] - ); } /** @@ -1699,10 +1797,18 @@ class TransactionControllerTest extends TestCase */ public function testSuccessStoreForeignAmount() { - $currency = TransactionCurrency::first(); - $foreign = TransactionCurrency::where('id', '!=', $currency->id)->first(); - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + $currency = TransactionCurrency::first(); + $foreign = TransactionCurrency::where('id', '!=', $currency->id)->first(); + $journal = $this->user()->transactionJournals()->first(); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -1722,28 +1828,6 @@ class TransactionControllerTest extends TestCase // test API $response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']); $response->assertStatus(200); - $response->assertJson( - [ - 'data' => [[ - 'type' => 'transactions', - 'attributes' => [ - 'description' => $data['description'], - 'date' => $data['date'], - 'source_id' => $account->id, - 'source_name' => $account->name, - 'type' => 'Withdrawal', - 'currency_code' => $currency->code, - 'foreign_currency_code' => $foreign->code, - 'foreign_amount' => -23, - 'source_type' => 'Asset account', - 'destination_name' => 'Cash account', - 'destination_type' => 'Cash account', - 'amount' => -10, - ], - 'links' => true, - ], - ]] - ); } /** @@ -1754,8 +1838,16 @@ class TransactionControllerTest extends TestCase */ public function testSuccessStoreMetaData() { - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + $journal = $this->user()->transactionJournals()->first(); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -1781,39 +1873,6 @@ class TransactionControllerTest extends TestCase // test API $response = $this->post('/api/v1/transactions?include=journal_meta', $data, ['Accept' => 'application/json']); $response->assertStatus(200); - $response->assertSee('interest_date'); - $response->assertSee('book_date'); - $response->assertSee('process_date'); - $response->assertSee('due_date'); - $response->assertSee('payment_date'); - $response->assertSee('invoice_date'); - $response->assertSee('internal_reference'); - $response->assertSee('2017-08-02'); - $response->assertSee('2017-08-03'); - $response->assertSee('2017-08-04'); - $response->assertSee('2017-08-05'); - $response->assertSee('2017-08-06'); - $response->assertSee('2017-08-07'); - $response->assertSee('I are internal ref!'); - $response->assertJson( - [ - 'data' => [[ - 'type' => 'transactions', - 'attributes' => [ - 'description' => $data['description'], - 'date' => $data['date'], - 'source_id' => $account->id, - 'source_name' => $account->name, - 'type' => 'Withdrawal', - 'source_type' => 'Asset account', - 'destination_name' => 'Cash account', - 'destination_type' => 'Cash account', - 'amount' => -10, - ], - 'links' => true, - ], - ]] - ); } /** @@ -1824,9 +1883,18 @@ class TransactionControllerTest extends TestCase */ public function testSuccessStoreNewCategoryName() { - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $name = 'Some new category #' . rand(1, 1000); - $data = [ + $journal = $this->user()->transactionJournals()->first(); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); + + $name = 'Some new category #' . rand(1, 1000); + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -1845,26 +1913,6 @@ class TransactionControllerTest extends TestCase // test API $response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']); $response->assertStatus(200); - $response->assertJson( - [ - 'data' => [[ - 'type' => 'transactions', - 'attributes' => [ - 'description' => $data['description'], - 'date' => $data['date'], - 'source_id' => $account->id, - 'source_name' => $account->name, - 'type' => 'Withdrawal', - 'source_type' => 'Asset account', - 'destination_name' => 'Cash account', - 'destination_type' => 'Cash account', - 'amount' => -10, - 'category_name' => $name, - ], - 'links' => true, - ], - ]] - ); } /** @@ -1875,9 +1923,18 @@ class TransactionControllerTest extends TestCase */ public function testSuccessStoreNewOpposingName() { - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $name = 'New opposing account #' . rand(1, 10000); - $data = [ + $journal = $this->user()->transactionJournals()->first(); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $opposing = $this->user()->accounts()->where('account_type_id', 4)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]), new Collection([$opposing])); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); + $name = 'New opposing account #' . rand(1, 10000); + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -1896,25 +1953,6 @@ class TransactionControllerTest extends TestCase // test API $response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']); $response->assertStatus(200); - $response->assertJson( - [ - 'data' => [[ - 'type' => 'transactions', - 'attributes' => [ - 'description' => $data['description'], - 'date' => $data['date'], - 'source_id' => $account->id, - 'source_name' => $account->name, - 'type' => 'Withdrawal', - 'source_type' => 'Asset account', - 'destination_name' => $name, - 'destination_type' => 'Expense account', - 'amount' => -10, - ], - 'links' => true, - ], - ]] - ); } /** @@ -1925,8 +1963,17 @@ class TransactionControllerTest extends TestCase */ public function testSuccessStoreNotes() { - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $data = [ + $journal = $this->user()->transactionJournals()->first(); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); + + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -1945,27 +1992,6 @@ class TransactionControllerTest extends TestCase // test API $response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']); $response->assertStatus(200); - $response->assertSee('I am a note'); - $response->assertJson( - [ - 'data' => [[ - 'type' => 'transactions', - 'attributes' => [ - 'description' => $data['description'], - 'date' => $data['date'], - 'source_id' => $account->id, - 'source_name' => $account->name, - 'type' => 'Withdrawal', - 'source_type' => 'Asset account', - 'destination_name' => 'Cash account', - 'destination_type' => 'Cash account', - 'amount' => -10, - 'notes' => 'I am a note', - ], - 'links' => true, - ], - ]] - ); } /** @@ -1976,9 +2002,17 @@ class TransactionControllerTest extends TestCase */ public function testSuccessStoreOpposingID() { - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $opposing = auth()->user()->accounts()->where('account_type_id', 4)->first(); - $data = [ + $opposing = $this->user()->accounts()->where('account_type_id', 4)->first(); + $journal = $this->user()->transactionJournals()->first(); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]), new Collection([$opposing])); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -1997,26 +2031,6 @@ class TransactionControllerTest extends TestCase // test API $response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']); $response->assertStatus(200); - $response->assertJson( - [ - 'data' => [[ - 'type' => 'transactions', - 'attributes' => [ - 'description' => $data['description'], - 'date' => $data['date'], - 'source_id' => $account->id, - 'source_name' => $account->name, - 'type' => 'Withdrawal', - 'source_type' => 'Asset account', - 'destination_name' => $opposing->name, - 'destination_id' => $opposing->id, - 'destination_type' => 'Expense account', - 'amount' => -10, - ], - 'links' => true, - ], - ]] - ); } /** @@ -2027,9 +2041,18 @@ class TransactionControllerTest extends TestCase */ public function testSuccessStoreOpposingName() { - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $opposing = auth()->user()->accounts()->where('account_type_id', 4)->first(); - $data = [ + $opposing = $this->user()->accounts()->where('account_type_id', 4)->first(); + $journal = $this->user()->transactionJournals()->first(); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]), new Collection([$opposing])); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); + + $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', @@ -2048,26 +2071,6 @@ class TransactionControllerTest extends TestCase // test API $response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']); $response->assertStatus(200); - $response->assertJson( - [ - 'data' => [[ - 'type' => 'transactions', - 'attributes' => [ - 'description' => $data['description'], - 'date' => $data['date'], - 'source_id' => $account->id, - 'source_name' => $account->name, - 'type' => 'Withdrawal', - 'source_type' => 'Asset account', - 'destination_name' => $opposing->name, - 'destination_id' => $opposing->id, - 'destination_type' => 'Expense account', - 'amount' => -10, - ], - 'links' => true, - ], - ]] - ); } /** @@ -2079,8 +2082,16 @@ class TransactionControllerTest extends TestCase */ public function testSuccessStorePiggyDeposit() { - $dest = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $piggy = auth()->user()->piggyBanks()->first(); + $journal = $this->user()->transactionJournals()->first(); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); + $piggy = $this->user()->piggyBanks()->first(); $data = [ 'description' => 'Some deposit #' . rand(1, 1000), 'date' => '2018-01-01', @@ -2090,7 +2101,7 @@ class TransactionControllerTest extends TestCase [ 'amount' => '10', 'currency_id' => 1, - 'destination_id' => $dest->id, + 'destination_id' => $account->id, ], ], ]; @@ -2098,23 +2109,6 @@ class TransactionControllerTest extends TestCase $response = $this->post('/api/v1/transactions?include=piggy_bank_events', $data, ['Accept' => 'application/json']); $this->assertFalse(isset($response->json()['included'])); $response->assertStatus(200); - $response->assertJson( - [ - 'data' => [[ - 'type' => 'transactions', - 'attributes' => [ - 'description' => $data['description'], - 'date' => $data['date'], - 'type' => 'Deposit', - 'destination_id' => $dest->id, - 'destination_name' => $dest->name, - 'destination_type' => 'Asset account', - 'amount' => 10, - ], - 'links' => [], - ], - ]] - ); } @@ -2127,10 +2121,19 @@ class TransactionControllerTest extends TestCase */ public function testSuccessStorePiggyId() { - $source = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $dest = auth()->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $source->id)->first(); - $piggy = auth()->user()->piggyBanks()->first(); - $data = [ + $source = $this->user()->accounts()->where('account_type_id', 3)->first(); + $dest = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $source->id)->first(); + $journal = $this->user()->transactionJournals()->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$source]), new Collection([$dest])); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); + + $piggy = $this->user()->piggyBanks()->first(); + $data = [ 'description' => 'Some transfer #' . rand(1, 1000), 'date' => '2018-01-01', 'type' => 'transfer', @@ -2147,34 +2150,6 @@ class TransactionControllerTest extends TestCase // test API $response = $this->post('/api/v1/transactions?include=piggy_bank_events', $data, ['Accept' => 'application/json']); $response->assertStatus(200); - $response->assertJson( - [ - 'data' => [[ - 'type' => 'transactions', - 'attributes' => [ - 'description' => $data['description'], - 'date' => $data['date'], - 'type' => 'Transfer', - 'source_id' => $source->id, - 'source_name' => $source->name, - 'source_type' => 'Asset account', - 'destination_id' => $dest->id, - 'destination_name' => $dest->name, - 'destination_type' => 'Asset account', - 'amount' => 10, - ], - 'links' => [], - ]], - 'included' => [ - 0 => [ - 'type' => 'piggy_bank_events', - 'attributes' => [ - 'amount' => 10, - ], - ], - ], - ] - ); } /** @@ -2186,9 +2161,18 @@ class TransactionControllerTest extends TestCase */ public function testSuccessStorePiggyName() { - $source = auth()->user()->accounts()->where('account_type_id', 3)->first(); - $dest = auth()->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $source->id)->first(); - $piggy = auth()->user()->piggyBanks()->first(); + $source = $this->user()->accounts()->where('account_type_id', 3)->first(); + $dest = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $source->id)->first(); + $journal = $this->user()->transactionJournals()->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$source]), new Collection([$dest])); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); + + $piggy = $this->user()->piggyBanks()->first(); $data = [ 'description' => 'Some transfer #' . rand(1, 1000), 'date' => '2018-01-01', @@ -2206,34 +2190,6 @@ class TransactionControllerTest extends TestCase // test API $response = $this->post('/api/v1/transactions?include=piggy_bank_events', $data, ['Accept' => 'application/json']); $response->assertStatus(200); - $response->assertJson( - [ - 'data' => [[ - 'type' => 'transactions', - 'attributes' => [ - 'description' => $data['description'], - 'date' => $data['date'], - 'type' => 'Transfer', - 'source_id' => $source->id, - 'source_name' => $source->name, - 'source_type' => 'Asset account', - 'destination_id' => $dest->id, - 'destination_name' => $dest->name, - 'destination_type' => 'Asset account', - 'amount' => 10, - ], - 'links' => [], - ]], - 'included' => [ - 0 => [ - 'type' => 'piggy_bank_events', - 'attributes' => [ - 'amount' => 10, - ], - ], - ], - ] - ); } /** @@ -2244,7 +2200,15 @@ class TransactionControllerTest extends TestCase */ public function testSuccessStoreReconciled() { - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); + $journal = $this->user()->transactionJournals()->first(); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', @@ -2264,26 +2228,6 @@ class TransactionControllerTest extends TestCase // test API $response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']); $response->assertStatus(200); - $response->assertJson( - [ - 'data' => [[ - 'type' => 'transactions', - 'attributes' => [ - 'description' => $data['description'], - 'date' => $data['date'], - 'source_id' => $account->id, - 'source_name' => $account->name, - 'type' => 'Withdrawal', - 'source_type' => 'Asset account', - 'destination_name' => 'Cash account', - 'destination_type' => 'Cash account', - 'amount' => -10, - 'reconciled' => true, - ], - 'links' => true, - ], - ]] - ); } /** @@ -2294,7 +2238,15 @@ class TransactionControllerTest extends TestCase */ public function testSuccessStoreSplit() { - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); + $journal = $this->user()->transactionJournals()->first(); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', @@ -2321,7 +2273,6 @@ class TransactionControllerTest extends TestCase $response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']); $json = $response->json(); $response->assertStatus(200); - $this->assertCount(2, $json['data']); } @@ -2339,7 +2290,15 @@ class TransactionControllerTest extends TestCase 'TagTwoBlarg' . rand(1, 1000), 'SomeThreeTag' . rand(1, 1000), ]; - $account = auth()->user()->accounts()->where('account_type_id', 3)->first(); + $journal = $this->user()->transactionJournals()->first(); + $account = $this->user()->accounts()->where('account_type_id', 3)->first(); + $journalRepos = $this->mock(JournalRepositoryInterface::class)->makePartial(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $journalRepos->shouldReceive('setUser')->once(); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); $data = [ 'description' => 'Some transaction #' . rand(1, 1000), 'date' => '2018-01-01', @@ -2359,30 +2318,6 @@ class TransactionControllerTest extends TestCase // test API $response = $this->post('/api/v1/transactions?include=tags', $data, ['Accept' => 'application/json']); $response->assertStatus(200); - foreach ($tags as $tag) { - $response->assertSee($tag); - } - $response->assertJson( - [ - 'data' => [[ - 'type' => 'transactions', - 'attributes' => [ - 'description' => $data['description'], - 'date' => $data['date'], - 'source_id' => $account->id, - 'source_name' => $account->name, - 'type' => 'Withdrawal', - 'source_type' => 'Asset account', - 'destination_name' => 'Cash account', - 'destination_type' => 'Cash account', - 'amount' => -10, - ], - 'links' => [], - 'relationships' => [], - ]], - 'included' => [], - ] - ); } } \ No newline at end of file diff --git a/tests/Feature/Controllers/Account/ReconcileControllerTest.php b/tests/Feature/Controllers/Account/ReconcileControllerTest.php index d966e52444..e9d929fc9b 100644 --- a/tests/Feature/Controllers/Account/ReconcileControllerTest.php +++ b/tests/Feature/Controllers/Account/ReconcileControllerTest.php @@ -32,6 +32,7 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Illuminate\Support\Collection; use Tests\TestCase; +use Log; /** * Class ConfigurationControllerTest @@ -42,6 +43,15 @@ use Tests\TestCase; */ class ReconcileControllerTest extends TestCase { + /** + * + */ + public function setUp() + { + parent::setUp(); + Log::debug('Now in Feature/Controllers::ReconcileControllerTest.'); + } + /** * @covers \FireflyIII\Http\Controllers\Account\ReconcileController::edit */ diff --git a/tests/Feature/Controllers/Admin/ConfigurationControllerTest.php b/tests/Feature/Controllers/Admin/ConfigurationControllerTest.php index 1e359f5339..4e58afb31a 100644 --- a/tests/Feature/Controllers/Admin/ConfigurationControllerTest.php +++ b/tests/Feature/Controllers/Admin/ConfigurationControllerTest.php @@ -24,6 +24,7 @@ namespace Tests\Feature\Controllers\Admin; use FireflyConfig; use FireflyIII\Models\Configuration; +use Log; use Tests\TestCase; /** @@ -35,6 +36,15 @@ use Tests\TestCase; */ class ConfigurationControllerTest extends TestCase { + /** + * + */ + public function setUp() + { + parent::setUp(); + Log::debug('Now in Feature/Controllers/Admin/ConfigurationControllerTest.'); + } + /** * @covers \FireflyIII\Http\Controllers\Admin\ConfigurationController::index * @covers \FireflyIII\Http\Controllers\Admin\ConfigurationController::__construct diff --git a/tests/Feature/Controllers/Admin/HomeControllerTest.php b/tests/Feature/Controllers/Admin/HomeControllerTest.php index 2948f79006..53a7448b23 100644 --- a/tests/Feature/Controllers/Admin/HomeControllerTest.php +++ b/tests/Feature/Controllers/Admin/HomeControllerTest.php @@ -24,6 +24,7 @@ namespace Tests\Feature\Controllers\Admin; use Event; use FireflyIII\Events\AdminRequestedTestMessage; +use Log; use Tests\TestCase; /** @@ -35,6 +36,15 @@ use Tests\TestCase; */ class HomeControllerTest extends TestCase { + /** + * + */ + public function setUp() + { + parent::setUp(); + Log::debug('Now in Feature/Controllers/Admin/HomeControllerTest.'); + } + /** * @covers \FireflyIII\Http\Controllers\Admin\HomeController::index * @covers \FireflyIII\Http\Controllers\Admin\HomeController::__construct diff --git a/tests/Feature/Controllers/Admin/LinkControllerTest.php b/tests/Feature/Controllers/Admin/LinkControllerTest.php index a56b38eced..9a442da258 100644 --- a/tests/Feature/Controllers/Admin/LinkControllerTest.php +++ b/tests/Feature/Controllers/Admin/LinkControllerTest.php @@ -26,7 +26,7 @@ use FireflyIII\Models\LinkType; use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface; use Illuminate\Support\Collection; use Tests\TestCase; - +use Log; /** * Class LinkControllerTest * @@ -36,6 +36,15 @@ use Tests\TestCase; */ class LinkControllerTest extends TestCase { + /** + * + */ + public function setUp() + { + parent::setUp(); + Log::debug('Now in Feature/Controllers/Admin/LinkControllerTest.'); + } + /** * @covers \FireflyIII\Http\Controllers\Admin\LinkController::__construct * @covers \FireflyIII\Http\Controllers\Admin\LinkController::create diff --git a/tests/Feature/Controllers/Admin/UpdateControllerTest.php b/tests/Feature/Controllers/Admin/UpdateControllerTest.php index d10263ef26..119d978569 100644 --- a/tests/Feature/Controllers/Admin/UpdateControllerTest.php +++ b/tests/Feature/Controllers/Admin/UpdateControllerTest.php @@ -30,6 +30,7 @@ use FireflyIII\Services\Github\Object\Release; use FireflyIII\Services\Github\Request\UpdateRequest; use Mockery; use Tests\TestCase; +use Log; /** * Class UpdateControllerTest @@ -40,6 +41,15 @@ use Tests\TestCase; */ class UpdateControllerTest extends TestCase { + /** + * + */ + public function setUp() + { + parent::setUp(); + Log::debug('Now in Feature/Controllers/Admin/UpdateControllerTest.'); + } + /** * @covers \FireflyIII\Http\Controllers\Admin\UpdateController::index * @covers \FireflyIII\Http\Controllers\Admin\UpdateController::__construct diff --git a/tests/Feature/Controllers/Admin/UserControllerTest.php b/tests/Feature/Controllers/Admin/UserControllerTest.php index 9885a6b39a..4f3d7aeec6 100644 --- a/tests/Feature/Controllers/Admin/UserControllerTest.php +++ b/tests/Feature/Controllers/Admin/UserControllerTest.php @@ -25,7 +25,7 @@ namespace Tests\Feature\Controllers\Admin; use FireflyIII\Repositories\User\UserRepositoryInterface; use Illuminate\Support\Collection; use Tests\TestCase; - +use Log; /** * Class UserControllerTest * @@ -35,6 +35,15 @@ use Tests\TestCase; */ class UserControllerTest extends TestCase { + /** + * + */ + public function setUp() + { + parent::setUp(); + Log::debug('Now in Feature/Controllers/Admin/UserControllerTest.'); + } + /** * @covers \FireflyIII\Http\Controllers\Admin\UserController::delete */ diff --git a/tests/Feature/Controllers/Auth/ForgotPasswordControllerTest.php b/tests/Feature/Controllers/Auth/ForgotPasswordControllerTest.php index 1106666cce..9f202ff36a 100644 --- a/tests/Feature/Controllers/Auth/ForgotPasswordControllerTest.php +++ b/tests/Feature/Controllers/Auth/ForgotPasswordControllerTest.php @@ -24,6 +24,7 @@ namespace Tests\Feature\Controllers\Auth; use FireflyIII\Repositories\User\UserRepositoryInterface; use Tests\TestCase; +use Log; /** * Class ForgotPasswordControllerTest @@ -34,6 +35,15 @@ use Tests\TestCase; */ class ForgotPasswordControllerTest extends TestCase { + /** + * + */ + public function setUp() + { + parent::setUp(); + Log::debug('Now in Feature/Controllers/Auth/ForgotPasswordControllerTest.'); + } + /** * @covers \FireflyIII\Http\Controllers\Auth\ForgotPasswordController::__construct * @covers \FireflyIII\Http\Controllers\Auth\ForgotPasswordController::sendResetLinkEmail diff --git a/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php b/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php index 16d83bddd8..7cbbda6cba 100644 --- a/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php +++ b/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php @@ -26,6 +26,7 @@ use FireflyIII\Models\Preference; use Google2FA; use Preferences; use Tests\TestCase; +use Log; /** * Class TwoFactorControllerTest @@ -36,6 +37,15 @@ use Tests\TestCase; */ class TwoFactorControllerTest extends TestCase { + /** + * + */ + public function setUp() + { + parent::setUp(); + Log::debug('Now in Feature/Controllers/Auth/TwoFactorControllerTest.'); + } + /** * @covers \FireflyIII\Http\Controllers\Auth\TwoFactorController::index */ diff --git a/tests/Feature/Controllers/TransactionControllerTest.php b/tests/Feature/Controllers/TransactionControllerTest.php index a0cad2c4e0..4332392b06 100644 --- a/tests/Feature/Controllers/TransactionControllerTest.php +++ b/tests/Feature/Controllers/TransactionControllerTest.php @@ -29,6 +29,7 @@ use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\Journal\JournalTaskerInterface; +use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Collection; use Tests\TestCase; @@ -270,9 +271,10 @@ class TransactionControllerTest extends TestCase public function testShow() { // mock stuff - $repository = $this->mock(JournalRepositoryInterface::class); $tasker = $this->mock(JournalTaskerInterface::class); - $repository->shouldReceive('first')->once()->andReturn(new TransactionJournal); + $linkRepos = $this->mock(LinkTypeRepositoryInterface::class); + $linkRepos->shouldReceive('get')->andReturn(new Collection); + $linkRepos->shouldReceive('getLinks')->andReturn(new Collection); $tasker->shouldReceive('getPiggyBankEvents')->andReturn(new Collection); $tasker->shouldReceive('getTransactionsOverview')->andReturn([]); @@ -289,9 +291,10 @@ class TransactionControllerTest extends TestCase */ public function testShowOpeningBalance() { - // mock stuff - $repository = $this->mock(JournalRepositoryInterface::class); - $repository->shouldReceive('first')->once()->andReturn(new TransactionJournal); + $tasker = $this->mock(JournalTaskerInterface::class); + $linkRepos = $this->mock(LinkTypeRepositoryInterface::class); + $linkRepos->shouldReceive('get')->andReturn(new Collection); + $linkRepos->shouldReceive('getLinks')->andReturn(new Collection); $this->be($this->user()); $journal = $this->user()->transactionJournals()->where('transaction_type_id', 4)->first(); diff --git a/tests/Unit/Import/FileProcessor/CsvProcessorTest.php b/tests/Unit/Import/FileProcessor/CsvProcessorTest.php index eceabab71f..be1ea34b95 100644 --- a/tests/Unit/Import/FileProcessor/CsvProcessorTest.php +++ b/tests/Unit/Import/FileProcessor/CsvProcessorTest.php @@ -26,6 +26,11 @@ namespace Tests\Unit\Import\FileProcessor; use FireflyIII\Import\FileProcessor\CsvProcessor; use FireflyIII\Import\Specifics\AbnAmroDescription; use FireflyIII\Models\ImportJob; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; +use FireflyIII\Repositories\Bill\BillRepositoryInterface; +use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; +use FireflyIII\Repositories\Category\CategoryRepositoryInterface; +use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; use Mockery; use Tests\TestCase; @@ -61,6 +66,18 @@ class CsvProcessorTest extends TestCase */ public function testRunBadRole() { + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $budRepos = $this->mock(BudgetRepositoryInterface::class); + $jobRepos = $this->mock(ImportJobRepositoryInterface::class); + $catRepos = $this->mock(CategoryRepositoryInterface::class); + $billRepos = $this->mock(BillRepositoryInterface::class); + $currencyRepos = $this->mock(CurrencyRepositoryInterface::class); + + $accountRepos->shouldReceive('setUser'); + $budRepos->shouldReceive('setUser'); + $catRepos->shouldReceive('setUser'); + $billRepos->shouldReceive('setUser'); + // data $config = [ 'column-roles' => [ @@ -72,16 +89,15 @@ class CsvProcessorTest extends TestCase $csvFile = '20170101,-12.34,"Some description"'; // mock stuff - $repository = $this->mock(ImportJobRepositoryInterface::class); - $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once(); - $repository->shouldReceive('getConfiguration')->andReturn($config); - $repository->shouldReceive('uploadFileContents')->withArgs([Mockery::any()])->andReturn($csvFile)->once(); - //$repository->shouldReceive('getExtendedStatus')->once()->andReturn([]); - //$repository->shouldReceive('setExtendedStatus')->once()->andReturn($job); - $repository->shouldReceive('addStepsDone')->twice(); + + $jobRepos->shouldReceive('setUser')->withArgs([Mockery::any()])->once(); + $jobRepos->shouldReceive('getConfiguration')->andReturn($config); + $jobRepos->shouldReceive('uploadFileContents')->withArgs([Mockery::any()])->andReturn($csvFile)->once(); + $jobRepos->shouldReceive('addStepsDone')->twice(); // mock stuff for this single row: - $repository->shouldReceive('countByHash')->once()->withArgs([Mockery::any()])->andReturn(0); + $jobRepos->shouldReceive('countByHash')->once()->withArgs([Mockery::any()])->andReturn(0); + $processor = new CsvProcessor(); $processor->setJob($job); $processor->run(); @@ -186,8 +202,8 @@ class CsvProcessorTest extends TestCase $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once(); $repository->shouldReceive('getConfiguration')->andReturn($config); $repository->shouldReceive('uploadFileContents')->withArgs([Mockery::any()])->andReturn($csvFile)->once(); -// $repository->shouldReceive('getExtendedStatus')->once()->andReturn([]); -// $repository->shouldReceive('setExtendedStatus')->once()->andReturn($job); + // $repository->shouldReceive('getExtendedStatus')->once()->andReturn([]); + // $repository->shouldReceive('setExtendedStatus')->once()->andReturn($job); // mock stuff for this single row: $repository->shouldReceive('countByHash')->once()->withArgs([Mockery::any()])->andReturn(0); $repository->shouldReceive('addStepsDone')->times(2)->withArgs([Mockery::any(), 1]); @@ -223,6 +239,18 @@ class CsvProcessorTest extends TestCase */ public function testRunSingle() { + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $budRepos = $this->mock(BudgetRepositoryInterface::class); + $jobRepos = $this->mock(ImportJobRepositoryInterface::class); + $catRepos = $this->mock(CategoryRepositoryInterface::class); + $billRepos = $this->mock(BillRepositoryInterface::class); + $currencyRepos = $this->mock(CurrencyRepositoryInterface::class); + + $accountRepos->shouldReceive('setUser'); + $budRepos->shouldReceive('setUser'); + $catRepos->shouldReceive('setUser'); + $billRepos->shouldReceive('setUser'); + // data $config = []; $job = $this->getJob($config); @@ -230,15 +258,13 @@ class CsvProcessorTest extends TestCase $extended = ['steps' => 0, 'done' => 0]; // mock stuff - $repository = $this->mock(ImportJobRepositoryInterface::class); - $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once(); - $repository->shouldReceive('getConfiguration')->andReturn($config); - $repository->shouldReceive('uploadFileContents')->withArgs([Mockery::any()])->andReturn($csvFile)->once(); -// $repository->shouldReceive('getExtendedStatus')->once()->andReturn([]); -// $repository->shouldReceive('setExtendedStatus')->once()->andReturn($job); + $jobRepos->shouldReceive('setUser')->withArgs([Mockery::any()])->once(); + $jobRepos->shouldReceive('getConfiguration')->andReturn($config); + $jobRepos->shouldReceive('uploadFileContents')->withArgs([Mockery::any()])->andReturn($csvFile)->once(); + // mock stuff for this single row: - $repository->shouldReceive('countByHash')->once()->withArgs([Mockery::any()])->andReturn(0); - $repository->shouldReceive('addStepsDone')->times(3)->withArgs([Mockery::any(), 1]); + $jobRepos->shouldReceive('countByHash')->once()->withArgs([Mockery::any()])->andReturn(0); + $jobRepos->shouldReceive('addStepsDone')->times(3)->withArgs([Mockery::any(), 1]); $processor = new CsvProcessor(); $processor->setJob($job); $processor->run(); @@ -260,6 +286,18 @@ class CsvProcessorTest extends TestCase */ public function testRunSpecific() { + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $budRepos = $this->mock(BudgetRepositoryInterface::class); + $jobRepos = $this->mock(ImportJobRepositoryInterface::class); + $catRepos = $this->mock(CategoryRepositoryInterface::class); + $billRepos = $this->mock(BillRepositoryInterface::class); + $currencyRepos = $this->mock(CurrencyRepositoryInterface::class); + + $accountRepos->shouldReceive('setUser'); + $budRepos->shouldReceive('setUser'); + $catRepos->shouldReceive('setUser'); + $billRepos->shouldReceive('setUser'); + // data $config = [ 'specifics' => ['AbnAmroDescription' => 1], @@ -270,15 +308,12 @@ class CsvProcessorTest extends TestCase $extended = ['steps' => 0, 'done' => 0]; // mock stuff - $repository = $this->mock(ImportJobRepositoryInterface::class); - $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once(); - $repository->shouldReceive('getConfiguration')->andReturn($config); - $repository->shouldReceive('uploadFileContents')->withArgs([Mockery::any()])->andReturn($csvFile)->once(); -// $repository->shouldReceive('getExtendedStatus')->once()->andReturn([]); -// $repository->shouldReceive('setExtendedStatus')->once()->andReturn($job); + $jobRepos->shouldReceive('setUser')->withArgs([Mockery::any()])->once(); + $jobRepos->shouldReceive('getConfiguration')->andReturn($config); + $jobRepos->shouldReceive('uploadFileContents')->withArgs([Mockery::any()])->andReturn($csvFile)->once(); // mock stuff for this single row: - $repository->shouldReceive('countByHash')->once()->withArgs([Mockery::any()])->andReturn(0); - $repository->shouldReceive('addStepsDone')->times(3)->withArgs([Mockery::any(), 1]); + $jobRepos->shouldReceive('countByHash')->once()->withArgs([Mockery::any()])->andReturn(0); + $jobRepos->shouldReceive('addStepsDone')->times(3)->withArgs([Mockery::any(), 1]); // mock specific: $specific = $this->mock(AbnAmroDescription::class); diff --git a/tests/Unit/Middleware/BinderTest.php b/tests/Unit/Middleware/BinderTest.php index 06c923996c..26ebd4e10b 100644 --- a/tests/Unit/Middleware/BinderTest.php +++ b/tests/Unit/Middleware/BinderTest.php @@ -1230,17 +1230,20 @@ class BinderTest extends TestCase */ public function testTagList() { + $tagRepos = $this->mock(TagRepositoryInterface::class); + $tagRepos->shouldReceive('setUser'); + $tags = $this->user()->tags()->whereIn('id', [1, 2])->get(['tags.*']); + $tagRepos->shouldReceive('get')->once()->andReturn($tags); + Route::middleware(Binder::class)->any( '/_test/binder/{tagList}', function (Collection $tags) { return 'count: ' . $tags->count(); } ); - $tags = $this->user()->tags()->whereIn('id', [1, 2])->get(['tags.*']); + $names = join(',', $tags->pluck('tag')->toArray()); - $repository = $this->mock(TagRepositoryInterface::class); - $repository->shouldReceive('setUser'); - $repository->shouldReceive('get')->once()->andReturn($tags); + $this->be($this->user()); $response = $this->get('/_test/binder/' . $names); @@ -1256,6 +1259,10 @@ class BinderTest extends TestCase */ public function testTagListEmpty() { + $tagRepos = $this->mock(TagRepositoryInterface::class); + $tagRepos->shouldReceive('setUser'); + $tagRepos->shouldReceive('get')->once()->andReturn(new Collection()); + Route::middleware(Binder::class)->any( '/_test/binder/{tagList}', function (Collection $tags) { return 'count: ' . $tags->count(); diff --git a/tests/Unit/TransactionRules/Actions/SetBudgetTest.php b/tests/Unit/TransactionRules/Actions/SetBudgetTest.php index 5a4f4469b5..baa196297b 100644 --- a/tests/Unit/TransactionRules/Actions/SetBudgetTest.php +++ b/tests/Unit/TransactionRules/Actions/SetBudgetTest.php @@ -24,7 +24,9 @@ namespace Tests\Unit\TransactionRules\Actions; use FireflyIII\Models\RuleAction; use FireflyIII\Models\TransactionJournal; +use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\TransactionRules\Actions\SetBudget; +use Illuminate\Support\Collection; use Tests\TestCase; /** @@ -39,8 +41,12 @@ class SetBudgetTest extends TestCase public function testAct() { // get journal, remove all budgets - $journal = TransactionJournal::find(12); - $budget = $journal->user->budgets()->first(); + $journal = TransactionJournal::find(12); + $budget = $journal->user->budgets()->first(); + $budgetRepos = $this->mock(BudgetRepositoryInterface::class); + $budgetRepos->shouldReceive('setUser'); + $budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget])); + $journal->budgets()->detach(); $this->assertEquals(0, $journal->budgets()->count()); diff --git a/tests/Unit/TransactionRules/Actions/SetCategoryTest.php b/tests/Unit/TransactionRules/Actions/SetCategoryTest.php index 5644f12943..dd1f89c3ad 100644 --- a/tests/Unit/TransactionRules/Actions/SetCategoryTest.php +++ b/tests/Unit/TransactionRules/Actions/SetCategoryTest.php @@ -24,6 +24,7 @@ namespace Tests\Unit\TransactionRules\Actions; use FireflyIII\Models\RuleAction; use FireflyIII\Models\TransactionJournal; +use FireflyIII\Repositories\Category\CategoryRepositoryInterface; use FireflyIII\TransactionRules\Actions\SetCategory; use Tests\TestCase; diff --git a/tests/Unit/TransactionRules/Actions/SetDestinationAccountTest.php b/tests/Unit/TransactionRules/Actions/SetDestinationAccountTest.php index 0f23990488..7458c0c5f4 100644 --- a/tests/Unit/TransactionRules/Actions/SetDestinationAccountTest.php +++ b/tests/Unit/TransactionRules/Actions/SetDestinationAccountTest.php @@ -28,6 +28,7 @@ use FireflyIII\Models\RuleAction; use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionType; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\TransactionRules\Actions\SetDestinationAccount; use Tests\TestCase; @@ -47,6 +48,7 @@ class SetDestinationAccountTest extends TestCase */ public function testActDepositExisting() { + $accountRepos = $this->mock(AccountRepositoryInterface::class); $type = TransactionType::whereType(TransactionType::DEPOSIT)->first(); $journal = TransactionJournal::where('transaction_type_id', $type->id)->first(); $destinationTr = $journal->transactions()->where('amount', '>', 0)->first(); @@ -56,6 +58,10 @@ class SetDestinationAccountTest extends TestCase $account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $destination->id)->first(); $this->assertNotEquals($destination->id, $account->id); + // find account? Return account: + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('findByName')->andReturn($account); + // fire the action: $ruleAction = new RuleAction; $ruleAction->action_value = $account->name; @@ -71,34 +77,6 @@ class SetDestinationAccountTest extends TestCase $this->assertEquals($newDestination->id, $account->id); } - /** - * Give deposit new asset account (will fail) - * - * @covers \FireflyIII\TransactionRules\Actions\SetDestinationAccount::__construct() - * @covers \FireflyIII\TransactionRules\Actions\SetDestinationAccount::act() - * @covers \FireflyIII\TransactionRules\Actions\SetDestinationAccount::findAssetAccount() - */ - public function testActDepositNew() - { - $type = TransactionType::whereType(TransactionType::DEPOSIT)->first(); - $journal = TransactionJournal::where('transaction_type_id', $type->id)->first(); - $destinationTr = $journal->transactions()->where('amount', '>', 0)->first(); - $destination = $destinationTr->account; - - // fire the action: - $ruleAction = new RuleAction; - $ruleAction->action_value = 'Some new asset ' . rand(1, 1000); - $action = new SetDestinationAccount($ruleAction); - $result = $action->act($journal); - $this->assertFalse($result); - - // test journal for still having old account - $journal = TransactionJournal::find($journal->id); - $destinationTr = $journal->transactions()->where('amount', '>', 0)->first(); - $newDestination = $destinationTr->account; - $this->assertEquals($destination->id, $newDestination->id); - } - /** * Give withdrawal existing expense account. * @@ -108,6 +86,7 @@ class SetDestinationAccountTest extends TestCase */ public function testActWithdrawalExisting() { + $accountRepos = $this->mock(AccountRepositoryInterface::class); $type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first(); $journal = TransactionJournal::where('transaction_type_id', $type->id)->first(); $destinationTr = $journal->transactions()->where('amount', '>', 0)->first(); @@ -117,6 +96,10 @@ class SetDestinationAccountTest extends TestCase $account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $destination->id)->first(); $this->assertNotEquals($destination->id, $account->id); + // find account? Return account: + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('findByName')->andReturn($account); + // fire the action: $ruleAction = new RuleAction; $ruleAction->action_value = $account->name; @@ -132,34 +115,6 @@ class SetDestinationAccountTest extends TestCase $this->assertEquals($newDestination->id, $account->id); } - /** - * Give withdrawal new expense account. - * - * @covers \FireflyIII\TransactionRules\Actions\SetDestinationAccount::__construct() - * @covers \FireflyIII\TransactionRules\Actions\SetDestinationAccount::act() - * @covers \FireflyIII\TransactionRules\Actions\SetDestinationAccount::findExpenseAccount - */ - public function testActWithdrawalNew() - { - $type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first(); - $journal = TransactionJournal::where('transaction_type_id', $type->id)->first(); - $destinationTr = $journal->transactions()->where('amount', '>', 0)->first(); - $destination = $destinationTr->account; - - // fire the action: - $ruleAction = new RuleAction; - $ruleAction->action_value = 'Some new expense ' . rand(1, 1000); - $action = new SetDestinationAccount($ruleAction); - $result = $action->act($journal); - $this->assertTrue($result); - - // test journal for new account - $journal = TransactionJournal::find($journal->id); - $destinationTr = $journal->transactions()->where('amount', '>', 0)->first(); - $newDestination = $destinationTr->account; - $this->assertNotEquals($destination->id, $newDestination->id); - } - /** * Test this on a split journal. * @@ -168,10 +123,15 @@ class SetDestinationAccountTest extends TestCase */ public function testSplitJournal() { + $accountRepos = $this->mock(AccountRepositoryInterface::class); $transaction = Transaction::orderBy('count', 'DESC')->groupBy('transaction_journal_id') ->get(['transaction_journal_id', DB::raw('COUNT(transaction_journal_id) as count')]) ->first(); $journal = TransactionJournal::find($transaction->transaction_journal_id); + + // mock + $accountRepos->shouldReceive('setUser'); + // fire the action: $ruleAction = new RuleAction; $ruleAction->action_value = 'Some new asset ' . rand(1, 1000); diff --git a/tests/Unit/TransactionRules/Actions/SetSourceAccountTest.php b/tests/Unit/TransactionRules/Actions/SetSourceAccountTest.php index 3abfe5d816..d0cd1e1b74 100644 --- a/tests/Unit/TransactionRules/Actions/SetSourceAccountTest.php +++ b/tests/Unit/TransactionRules/Actions/SetSourceAccountTest.php @@ -28,6 +28,7 @@ use FireflyIII\Models\RuleAction; use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionType; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\TransactionRules\Actions\SetSourceAccount; use Tests\TestCase; @@ -45,6 +46,9 @@ class SetSourceAccountTest extends TestCase */ public function testActDepositExistingUpdated() { + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $type = TransactionType::whereType(TransactionType::DEPOSIT)->first(); $journal = TransactionJournal::where('transaction_type_id', $type->id)->first(); $sourceTr = $journal->transactions()->where('amount', '<', 0)->first(); @@ -54,6 +58,10 @@ class SetSourceAccountTest extends TestCase $account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $source->id)->first(); $this->assertNotEquals($source->id, $account->id); + // find account? Return account: + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('findByName')->andReturn($account); + // fire the action: $ruleAction = new RuleAction; $ruleAction->action_value = $account->name; @@ -69,34 +77,6 @@ class SetSourceAccountTest extends TestCase $this->assertEquals($newSource->id, $account->id); } - /** - * Give deposit new revenue account. - * - * @covers \FireflyIII\TransactionRules\Actions\SetSourceAccount::__construct() - * @covers \FireflyIII\TransactionRules\Actions\SetSourceAccount::act() - * @covers \FireflyIII\TransactionRules\Actions\SetSourceAccount::findRevenueAccount - */ - public function testActDepositNewUpdated() - { - $type = TransactionType::whereType(TransactionType::DEPOSIT)->first(); - $journal = TransactionJournal::where('transaction_type_id', $type->id)->first(); - $sourceTr = $journal->transactions()->where('amount', '<', 0)->first(); - $source = $sourceTr->account; - - // fire the action: - $ruleAction = new RuleAction; - $ruleAction->action_value = 'Some new revenue ' . rand(1, 1000); - $action = new SetSourceAccount($ruleAction); - $result = $action->act($journal); - $this->assertTrue($result); - - // test journal for new account - $journal = TransactionJournal::find($journal->id); - $sourceTr = $journal->transactions()->where('amount', '<', 0)->first(); - $newSource = $sourceTr->account; - $this->assertNotEquals($source->id, $newSource->id); - } - /** * Give withdrawal existing asset account. * @@ -106,15 +86,20 @@ class SetSourceAccountTest extends TestCase */ public function testActWithdrawalExistingUpdated() { - $type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first(); - $journal = TransactionJournal::where('transaction_type_id', $type->id)->first(); - $sourceTr = $journal->transactions()->where('amount', '<', 0)->first(); - $source = $sourceTr->account; - $user = $journal->user; - $accountType = AccountType::whereType(AccountType::ASSET)->first(); - $account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $source->id)->first(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first(); + $journal = TransactionJournal::where('transaction_type_id', $type->id)->first(); + $sourceTr = $journal->transactions()->where('amount', '<', 0)->first(); + $source = $sourceTr->account; + $user = $journal->user; + $accountType = AccountType::whereType(AccountType::ASSET)->first(); + $account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $source->id)->first(); $this->assertNotEquals($source->id, $account->id); + + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('findByName')->andReturn($account); + // fire the action: $ruleAction = new RuleAction; $ruleAction->action_value = $account->name; @@ -130,34 +115,6 @@ class SetSourceAccountTest extends TestCase $this->assertEquals($newSource->id, $account->id); } - /** - * Give withdrawal new asset account (will fail) - * - * @covers \FireflyIII\TransactionRules\Actions\SetSourceAccount::__construct() - * @covers \FireflyIII\TransactionRules\Actions\SetSourceAccount::act() - * @covers \FireflyIII\TransactionRules\Actions\SetSourceAccount::findAssetAccount() - */ - public function testActWithdrawalNew() - { - $type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first(); - $journal = TransactionJournal::where('transaction_type_id', $type->id)->first(); - $sourceTr = $journal->transactions()->where('amount', '<', 0)->first(); - $source = $sourceTr->account; - - // fire the action: - $ruleAction = new RuleAction; - $ruleAction->action_value = 'Some new asset ' . rand(1, 1000); - $action = new SetSourceAccount($ruleAction); - $result = $action->act($journal); - $this->assertFalse($result); - - // test journal for still having old account - $journal = TransactionJournal::find($journal->id); - $sourceTr = $journal->transactions()->where('amount', '<', 0)->first(); - $newSource = $sourceTr->account; - $this->assertEquals($source->id, $newSource->id); - } - /** * Test this on a split journal. * @@ -166,10 +123,14 @@ class SetSourceAccountTest extends TestCase */ public function testSplitJournal() { - $transaction = Transaction::orderBy('count', 'DESC')->groupBy('transaction_journal_id') - ->get(['transaction_journal_id', DB::raw('COUNT(transaction_journal_id) as count')]) - ->first(); - $journal = TransactionJournal::find($transaction->transaction_journal_id); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $transaction = Transaction::orderBy('count', 'DESC')->groupBy('transaction_journal_id') + ->get(['transaction_journal_id', DB::raw('COUNT(transaction_journal_id) as count')]) + ->first(); + $journal = TransactionJournal::find($transaction->transaction_journal_id); + + // mock + $accountRepos->shouldReceive('setUser'); // fire the action: $ruleAction = new RuleAction; $ruleAction->action_value = 'Some new asset ' . rand(1, 1000); diff --git a/tests/Unit/TransactionRules/Triggers/AmountExactlyTest.php b/tests/Unit/TransactionRules/Triggers/AmountExactlyTest.php index c7063aa1bc..db6bde769c 100644 --- a/tests/Unit/TransactionRules/Triggers/AmountExactlyTest.php +++ b/tests/Unit/TransactionRules/Triggers/AmountExactlyTest.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace Tests\Unit\TransactionRules\Triggers; use FireflyIII\Models\TransactionJournal; +use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\TransactionRules\Triggers\AmountExactly; use Tests\TestCase; @@ -36,7 +37,11 @@ class AmountExactlyTest extends TestCase */ public function testTriggeredExact() { + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $journalRepos->shouldReceive('setUser'); + $journalRepos->shouldReceive('getJournalTotal')->andReturn('12.34'); $journal = new TransactionJournal; + $journal->user = $this->user(); $journal->destination_amount = '12.34'; $trigger = AmountExactly::makeFromStrings('12.340', false); $result = $trigger->triggered($journal); @@ -48,7 +53,11 @@ class AmountExactlyTest extends TestCase */ public function testTriggeredNotExact() { + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $journalRepos->shouldReceive('setUser'); + $journalRepos->shouldReceive('getJournalTotal')->andReturn('12.34'); $journal = new TransactionJournal; + $journal->user = $this->user(); $journal->destination_amount = '12.35'; $trigger = AmountExactly::makeFromStrings('12.340', false); $result = $trigger->triggered($journal); diff --git a/tests/Unit/TransactionRules/Triggers/AmountLessTest.php b/tests/Unit/TransactionRules/Triggers/AmountLessTest.php index 4dac6a72cf..b345e897e5 100644 --- a/tests/Unit/TransactionRules/Triggers/AmountLessTest.php +++ b/tests/Unit/TransactionRules/Triggers/AmountLessTest.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace Tests\Unit\TransactionRules\Triggers; use FireflyIII\Models\TransactionJournal; +use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\TransactionRules\Triggers\AmountLess; use Tests\TestCase; @@ -36,8 +37,13 @@ class AmountLessTest extends TestCase */ public function testTriggeredExact() { + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $journalRepos->shouldReceive('setUser'); + $journalRepos->shouldReceive('getJournalTotal')->andReturn('12.35'); + $journal = new TransactionJournal; $journal->destination_amount = '12.35'; + $journal->user = $this->user(); $trigger = AmountLess::makeFromStrings('12.35', false); $result = $trigger->triggered($journal); $this->assertFalse($result); @@ -48,8 +54,13 @@ class AmountLessTest extends TestCase */ public function testTriggeredLess() { + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $journalRepos->shouldReceive('setUser'); + $journalRepos->shouldReceive('getJournalTotal')->andReturn('12.34'); + $journal = new TransactionJournal; $journal->destination_amount = '12.34'; + $journal->user = $this->user(); $trigger = AmountLess::makeFromStrings('12.50', false); $result = $trigger->triggered($journal); $this->assertTrue($result); @@ -60,8 +71,13 @@ class AmountLessTest extends TestCase */ public function testTriggeredNotLess() { + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $journalRepos->shouldReceive('setUser'); + $journalRepos->shouldReceive('getJournalTotal')->andReturn('12.35'); + $journal = new TransactionJournal; $journal->destination_amount = '12.35'; + $journal->user = $this->user(); $trigger = AmountLess::makeFromStrings('12.00', false); $result = $trigger->triggered($journal); $this->assertFalse($result); diff --git a/tests/Unit/TransactionRules/Triggers/AmountMoreTest.php b/tests/Unit/TransactionRules/Triggers/AmountMoreTest.php index 1c2ccf0fbc..9459037d45 100644 --- a/tests/Unit/TransactionRules/Triggers/AmountMoreTest.php +++ b/tests/Unit/TransactionRules/Triggers/AmountMoreTest.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace Tests\Unit\TransactionRules\Triggers; use FireflyIII\Models\TransactionJournal; +use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\TransactionRules\Triggers\AmountMore; use Tests\TestCase; @@ -36,7 +37,12 @@ class AmountMoreTest extends TestCase */ public function testTriggeredExact() { + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $journalRepos->shouldReceive('setUser'); + $journalRepos->shouldReceive('getJournalTotal')->andReturn('12.35'); + $journal = new TransactionJournal; + $journal->user = $this->user(); $journal->destination_amount = '12.35'; $trigger = AmountMore::makeFromStrings('12.35', false); $result = $trigger->triggered($journal); @@ -48,7 +54,12 @@ class AmountMoreTest extends TestCase */ public function testTriggeredMore() { + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $journalRepos->shouldReceive('setUser'); + $journalRepos->shouldReceive('getJournalTotal')->andReturn('12.34'); + $journal = new TransactionJournal; + $journal->user = $this->user(); $journal->destination_amount = '12.34'; $trigger = AmountMore::makeFromStrings('12.10', false); $result = $trigger->triggered($journal); @@ -60,7 +71,12 @@ class AmountMoreTest extends TestCase */ public function testTriggeredNotMore() { + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $journalRepos->shouldReceive('setUser'); + $journalRepos->shouldReceive('getJournalTotal')->andReturn('12.35'); + $journal = new TransactionJournal; + $journal->user = $this->user(); $journal->destination_amount = '12.35'; $trigger = AmountMore::makeFromStrings('12.50', false); $result = $trigger->triggered($journal); diff --git a/tests/Unit/Transformers/AccountTransformerTest.php b/tests/Unit/Transformers/AccountTransformerTest.php index 7849dd7718..962d00669e 100644 --- a/tests/Unit/Transformers/AccountTransformerTest.php +++ b/tests/Unit/Transformers/AccountTransformerTest.php @@ -29,6 +29,7 @@ use FireflyIII\Models\AccountMeta; use FireflyIII\Models\Note; use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionJournal; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Transformers\AccountTransformer; use Symfony\Component\HttpFoundation\ParameterBag; use Tests\TestCase; @@ -45,6 +46,10 @@ class AccountTransformerTest extends TestCase */ public function testBasic() { + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null); + $accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn(null); // make new account: $account = Account::create( [ @@ -76,6 +81,10 @@ class AccountTransformerTest extends TestCase */ public function testBasicDate() { + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null); + $accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn(null); // make new account: $account = Account::create( [ @@ -108,6 +117,10 @@ class AccountTransformerTest extends TestCase */ public function testCCDataAsset() { + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null); + $accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn(null); // make new account: $account = Account::create( [ @@ -262,6 +275,10 @@ class AccountTransformerTest extends TestCase */ public function testOpeningBalance() { + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn('45.67'); + $accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn('2018-01-01'); // make new account: $account = Account::create( [ @@ -313,6 +330,10 @@ class AccountTransformerTest extends TestCase */ public function testWithCurrency() { + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null); + $accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn(null); // make new account: $account = Account::create( [ @@ -352,6 +373,10 @@ class AccountTransformerTest extends TestCase */ public function testWithNotes() { + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $accountRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null); + $accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn(null); // make new account: $account = Account::create( [