From 0a710775133b03503125f58025f3f1c0535ffb2e Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 28 Mar 2018 19:38:20 +0200 Subject: [PATCH] Push updated tests. --- .../V1/Controllers/AccountControllerTest.php | 10 +- .../Api/V1/Controllers/BillControllerTest.php | 12 +- .../Controllers/TransactionControllerTest.php | 152 +++++++++++------- .../Api/V1/Controllers/UserControllerTest.php | 10 +- .../Account/ReconcileControllerTest.php | 3 + .../Controllers/AccountControllerTest.php | 17 +- .../Controllers/Admin/LinkControllerTest.php | 30 ++-- .../Admin/UpdateControllerTest.php | 11 +- .../Controllers/AttachmentControllerTest.php | 2 +- .../Controllers/BillControllerTest.php | 4 +- .../Controllers/BudgetControllerTest.php | 8 +- .../Controllers/CategoryControllerTest.php | 8 +- .../Chart/AccountControllerTest.php | 2 +- .../Controllers/JavascriptControllerTest.php | 6 + .../Controllers/Json/BoxControllerTest.php | 6 + .../Controllers/PiggyBankControllerTest.php | 4 +- .../Popup/ReportControllerTest.php | 25 ++- .../Feature/Controllers/TagControllerTest.php | 4 +- .../Controllers/TransactionControllerTest.php | 28 +++- tests/Unit/Factory/AccountFactoryTest.php | 18 +-- tests/Unit/Factory/BillFactoryTest.php | 10 +- tests/Unit/Factory/BudgetFactoryTest.php | 2 +- tests/Unit/Factory/CategoryFactoryTest.php | 4 +- tests/Unit/Factory/PiggyBankFactoryTest.php | 2 +- tests/Unit/Factory/TagFactoryTest.php | 2 +- tests/Unit/Helpers/MetaPieChartTest.php | 20 +-- .../Configuration/FileConfiguratorTest.php | 2 +- .../Import/FileProcessor/CsvProcessorTest.php | 2 +- .../Destroy/AccountDestroyServiceTest.php | 8 +- .../Update/AccountUpdateServiceTest.php | 22 +-- .../Update/JournalUpdateServiceTest.php | 6 +- .../TransactionRules/Actions/AddTagTest.php | 2 +- .../Actions/PrependDescriptionTest.php | 4 +- .../Actions/RemoveTagTest.php | 4 +- .../Actions/SetDescriptionTest.php | 4 +- .../Actions/SetDestinationAccountTest.php | 6 +- .../TransactionRules/Actions/SetNotesTest.php | 4 +- .../Actions/SetSourceAccountTest.php | 6 +- .../Triggers/FromAccountContainsTest.php | 2 +- .../Triggers/FromAccountEndsTest.php | 2 +- .../Triggers/FromAccountIsTest.php | 2 +- .../Triggers/FromAccountStartsTest.php | 2 +- .../Triggers/ToAccountContainsTest.php | 2 +- .../Triggers/ToAccountEndsTest.php | 2 +- .../Triggers/ToAccountIsTest.php | 2 +- .../Triggers/ToAccountStartsTest.php | 2 +- .../Transformers/AccountTransformerTest.php | 20 +-- .../AttachmentTransformerTest.php | 2 +- .../Unit/Transformers/BillTransformerTest.php | 14 +- .../Transformers/BudgetTransformerTest.php | 2 +- .../Transformers/CategoryTransformerTest.php | 2 +- .../PiggyBankEventTransformerTest.php | 8 +- .../Transformers/PiggyBankTransformerTest.php | 12 +- .../Unit/Transformers/TagTransformerTest.php | 2 +- .../TransactionTransformerTest.php | 62 +++---- 55 files changed, 344 insertions(+), 266 deletions(-) diff --git a/tests/Api/V1/Controllers/AccountControllerTest.php b/tests/Api/V1/Controllers/AccountControllerTest.php index 3d8bf7e88d..a23e096cf4 100644 --- a/tests/Api/V1/Controllers/AccountControllerTest.php +++ b/tests/Api/V1/Controllers/AccountControllerTest.php @@ -127,7 +127,7 @@ class AccountControllerTest extends TestCase // data to submit $data = [ - 'name' => 'Some new asset account #' . rand(1, 10000), + 'name' => 'Some new asset account #' . random_int(1, 10000), 'currency_id' => 1, 'type' => 'asset', 'active' => 1, @@ -169,7 +169,7 @@ class AccountControllerTest extends TestCase // data to submit $data = [ - 'name' => 'Some new asset account #' . rand(1, 10000), + 'name' => 'Some new asset account #' . random_int(1, 10000), 'type' => 'asset', 'active' => 1, 'account_role' => 'ccAsset', @@ -211,7 +211,7 @@ class AccountControllerTest extends TestCase // data to submit $data = [ - 'name' => 'Some new asset account #' . rand(1, 10000), + 'name' => 'Some new asset account #' . random_int(1, 10000), 'type' => 'asset', 'active' => 1, 'account_role' => 'defaultAsset', @@ -336,7 +336,7 @@ class AccountControllerTest extends TestCase // data to submit $data = [ - 'name' => 'Some new asset account #' . rand(1, 10000), + 'name' => 'Some new asset account #' . random_int(1, 10000), 'currency_id' => 1, 'type' => 'asset', 'active' => 1, @@ -384,7 +384,7 @@ class AccountControllerTest extends TestCase // data to submit $data = [ - 'name' => 'Some new asset account #' . rand(1, 10000), + 'name' => 'Some new asset account #' . random_int(1, 10000), 'currency_code' => 'EUR', 'type' => 'asset', 'active' => 1, diff --git a/tests/Api/V1/Controllers/BillControllerTest.php b/tests/Api/V1/Controllers/BillControllerTest.php index ffce0c30d6..ebb886fede 100644 --- a/tests/Api/V1/Controllers/BillControllerTest.php +++ b/tests/Api/V1/Controllers/BillControllerTest.php @@ -140,8 +140,8 @@ class BillControllerTest extends TestCase // data to submit: $data = [ - 'name' => 'New bill #' . rand(1, 1000), - 'match' => 'some,words,' . rand(1, 1000), + 'name' => 'New bill #' . random_int(1, 1000), + 'match' => 'some,words,' . random_int(1, 1000), 'amount_min' => '66.34', 'amount_max' => '45.67', 'date' => '2018-01-01', @@ -184,8 +184,8 @@ class BillControllerTest extends TestCase // data to submit: $data = [ - 'name' => 'New bill #' . rand(1, 1000), - 'match' => 'some,words,' . rand(1, 1000), + 'name' => 'New bill #' . random_int(1, 1000), + 'match' => 'some,words,' . random_int(1, 1000), 'amount_min' => '12.34', 'amount_max' => '45.67', 'date' => '2018-01-01', @@ -222,8 +222,8 @@ class BillControllerTest extends TestCase // data to submit: $data = [ - 'name' => 'New bill #' . rand(1, 1000), - 'match' => 'some,words,' . rand(1, 1000), + 'name' => 'New bill #' . random_int(1, 1000), + 'match' => 'some,words,' . random_int(1, 1000), 'amount_min' => '12.34', 'amount_max' => '45.67', 'date' => '2018-01-01', diff --git a/tests/Api/V1/Controllers/TransactionControllerTest.php b/tests/Api/V1/Controllers/TransactionControllerTest.php index 7a307699aa..1ca6805406 100644 --- a/tests/Api/V1/Controllers/TransactionControllerTest.php +++ b/tests/Api/V1/Controllers/TransactionControllerTest.php @@ -95,7 +95,7 @@ class TransactionControllerTest extends TestCase $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -141,7 +141,7 @@ class TransactionControllerTest extends TestCase $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -239,7 +239,7 @@ class TransactionControllerTest extends TestCase $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); $data = [ - 'description' => 'Split journal #' . rand(1, 1000), + 'description' => 'Split journal #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -297,7 +297,7 @@ class TransactionControllerTest extends TestCase $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -341,10 +341,10 @@ class TransactionControllerTest extends TestCase $journalRepos->shouldReceive('setUser')->once(); $accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection); - $accountRepos->shouldReceive('findByName')->andReturn(null); + $accountRepos->shouldReceive('findByNameNull')->andReturn(null); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -389,7 +389,7 @@ class TransactionControllerTest extends TestCase $accountRepos->shouldReceive('setUser'); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -433,7 +433,7 @@ class TransactionControllerTest extends TestCase $accountRepos->shouldReceive('setUser'); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [], @@ -473,7 +473,7 @@ class TransactionControllerTest extends TestCase $data = [ - 'description' => 'Split journal #' . rand(1, 1000), + 'description' => 'Split journal #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -523,7 +523,7 @@ class TransactionControllerTest extends TestCase $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -579,7 +579,7 @@ class TransactionControllerTest extends TestCase // submit with another account. $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'bill_id' => $bill->id, @@ -637,7 +637,7 @@ class TransactionControllerTest extends TestCase // submit with another account. $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'bill_name' => $bill->name, @@ -695,7 +695,7 @@ class TransactionControllerTest extends TestCase // submit with another account. $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -753,7 +753,7 @@ class TransactionControllerTest extends TestCase // submit with another account. $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -811,7 +811,7 @@ class TransactionControllerTest extends TestCase // submit with another account. $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -875,7 +875,7 @@ class TransactionControllerTest extends TestCase // submit with another account. $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'piggy_bank_id' => $piggyBank->id, @@ -941,7 +941,7 @@ class TransactionControllerTest extends TestCase // submit with another account. $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'piggy_bank_name' => $piggyBank->name, @@ -995,7 +995,7 @@ class TransactionControllerTest extends TestCase $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'deposit', 'transactions' => [ @@ -1044,7 +1044,7 @@ class TransactionControllerTest extends TestCase $data = [ - 'description' => 'Some deposit #' . rand(1, 1000), + 'description' => 'Some deposit #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'deposit', 'transactions' => [ @@ -1100,7 +1100,7 @@ class TransactionControllerTest extends TestCase $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]), new Collection([$second])); $data = [ - 'description' => 'Some transfer #' . rand(1, 1000), + 'description' => 'Some transfer #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'transfer', 'transactions' => [ @@ -1137,7 +1137,7 @@ class TransactionControllerTest extends TestCase 'All accounts in this field must be equal.', ], 'transactions.1.destination_id' => [ - 'The source account equals the destination account' + 'The source account equals the destination account', ], ], ] @@ -1164,7 +1164,7 @@ class TransactionControllerTest extends TestCase $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]), new Collection([$second])); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -1465,7 +1465,7 @@ class TransactionControllerTest extends TestCase $bill = $this->user()->bills()->first(); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'bill_id' => $bill->id, @@ -1506,7 +1506,7 @@ class TransactionControllerTest extends TestCase $bill = $this->user()->bills()->first(); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'bill_name' => $bill->name, @@ -1545,7 +1545,7 @@ class TransactionControllerTest extends TestCase $journalRepos->shouldReceive('store')->andReturn($journal)->once(); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -1553,7 +1553,7 @@ class TransactionControllerTest extends TestCase 'amount' => '10', 'currency_id' => 1, 'source_id' => $account->id, - 'destination_name' => 'New expense account #' . rand(1, 1000), + 'destination_name' => 'New expense account #' . random_int(1, 1000), ], @@ -1586,7 +1586,7 @@ class TransactionControllerTest extends TestCase $journalRepos->shouldReceive('store')->andReturn($journal)->once(); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -1625,7 +1625,7 @@ class TransactionControllerTest extends TestCase $journalRepos->shouldReceive('store')->andReturn($journal)->once(); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -1644,6 +1644,47 @@ class TransactionControllerTest extends TestCase $response->assertStatus(200); } + /** + * Submit the minimum amount of data required to create a withdrawal. + * + * @covers \FireflyIII\Api\V1\Controllers\TransactionController::store + * @covers \FireflyIII\Api\V1\Requests\TransactionRequest + */ + public function testSuccessStoreBasicByName() + { + // default journal: + $journal = $this->user()->transactionJournals()->where('transaction_type_id', 1)->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); + $accountRepos->shouldReceive('findByNameNull')->andReturn($account); + $journalRepos->shouldReceive('store')->andReturn($journal)->once(); + + + $data = [ + 'description' => 'Some transaction #' . random_int(1, 1000), + 'date' => '2018-01-01', + 'type' => 'withdrawal', + 'transactions' => [ + [ + 'amount' => '10', + 'currency_id' => 1, + 'source_name' => $account->name, + ], + + + ], + ]; + + // test API + $response = $this->post('/api/v1/transactions', $data, ['Accept' => 'application/json']); + $response->assertStatus(200); + } + /** * Submit the minimum amount of data required to create a deposit. * @@ -1664,7 +1705,7 @@ class TransactionControllerTest extends TestCase $journalRepos->shouldReceive('store')->andReturn($journal)->once(); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'deposit', 'transactions' => [ @@ -1702,7 +1743,7 @@ class TransactionControllerTest extends TestCase $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); $journalRepos->shouldReceive('store')->andReturn($journal)->once(); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -1742,7 +1783,7 @@ class TransactionControllerTest extends TestCase $journalRepos->shouldReceive('store')->andReturn($journal)->once(); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -1781,7 +1822,7 @@ class TransactionControllerTest extends TestCase $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); $journalRepos->shouldReceive('store')->andReturn($journal)->once(); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -1820,7 +1861,7 @@ class TransactionControllerTest extends TestCase $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); $journalRepos->shouldReceive('store')->andReturn($journal)->once(); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -1860,7 +1901,7 @@ class TransactionControllerTest extends TestCase $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); $journalRepos->shouldReceive('store')->andReturn($journal)->once(); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -1899,7 +1940,7 @@ class TransactionControllerTest extends TestCase $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); $journalRepos->shouldReceive('store')->andReturn($journal)->once(); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', // store date meta fields (if present): @@ -1944,9 +1985,9 @@ class TransactionControllerTest extends TestCase $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); $journalRepos->shouldReceive('store')->andReturn($journal)->once(); - $name = 'Some new category #' . rand(1, 1000); + $name = 'Some new category #' . random_int(1, 1000); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -1984,9 +2025,9 @@ class TransactionControllerTest extends TestCase $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); + $name = 'New opposing account #' . random_int(1, 10000); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -2025,7 +2066,7 @@ class TransactionControllerTest extends TestCase $journalRepos->shouldReceive('store')->andReturn($journal)->once(); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'notes' => 'I am a note', @@ -2064,7 +2105,7 @@ class TransactionControllerTest extends TestCase $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]), new Collection([$opposing])); $journalRepos->shouldReceive('store')->andReturn($journal)->once(); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -2104,7 +2145,7 @@ class TransactionControllerTest extends TestCase $journalRepos->shouldReceive('store')->andReturn($journal)->once(); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -2144,7 +2185,7 @@ class TransactionControllerTest extends TestCase $journalRepos->shouldReceive('store')->andReturn($journal)->once(); $piggy = $this->user()->piggyBanks()->first(); $data = [ - 'description' => 'Some deposit #' . rand(1, 1000), + 'description' => 'Some deposit #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'deposit', 'piggy_bank_name' => $piggy->name, @@ -2185,7 +2226,7 @@ class TransactionControllerTest extends TestCase $piggy = $this->user()->piggyBanks()->first(); $data = [ - 'description' => 'Some transfer #' . rand(1, 1000), + 'description' => 'Some transfer #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'transfer', 'piggy_bank_id' => $piggy->id, @@ -2225,7 +2266,7 @@ class TransactionControllerTest extends TestCase $piggy = $this->user()->piggyBanks()->first(); $data = [ - 'description' => 'Some transfer #' . rand(1, 1000), + 'description' => 'Some transfer #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'transfer', 'piggy_bank_name' => $piggy->name, @@ -2261,7 +2302,7 @@ class TransactionControllerTest extends TestCase $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); $journalRepos->shouldReceive('store')->andReturn($journal)->once(); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -2299,7 +2340,7 @@ class TransactionControllerTest extends TestCase $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); $journalRepos->shouldReceive('store')->andReturn($journal)->once(); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'transactions' => [ @@ -2337,9 +2378,9 @@ class TransactionControllerTest extends TestCase public function testSuccessStoreTags() { $tags = [ - 'TagOne' . rand(1, 1000), - 'TagTwoBlarg' . rand(1, 1000), - 'SomeThreeTag' . rand(1, 1000), + 'TagOne' . random_int(1, 1000), + 'TagTwoBlarg' . random_int(1, 1000), + 'SomeThreeTag' . random_int(1, 1000), ]; $journal = $this->user()->transactionJournals()->first(); $account = $this->user()->accounts()->where('account_type_id', 3)->first(); @@ -2351,7 +2392,7 @@ class TransactionControllerTest extends TestCase $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); $journalRepos->shouldReceive('store')->andReturn($journal)->once(); $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'type' => 'withdrawal', 'tags' => join(',', $tags), @@ -2386,8 +2427,8 @@ class TransactionControllerTest extends TestCase $accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('getAccountsById')->withArgs([[$account->id]])->andReturn(new Collection([$account])); - $data = [ - 'description' => 'Some deposit #' . rand(1, 1000), + $data = [ + 'description' => 'Some deposit #' . random_int(1, 1000), 'date' => '2018-01-01', 'transactions' => [ [ @@ -2428,8 +2469,8 @@ class TransactionControllerTest extends TestCase $accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('getAccountsById')->withArgs([[$account->id]])->andReturn(new Collection([$account])); - $data = [ - 'description' => 'Some transaction #' . rand(1, 1000), + $data = [ + 'description' => 'Some transaction #' . random_int(1, 1000), 'date' => '2018-01-01', 'transactions' => [ [ @@ -2446,7 +2487,6 @@ class TransactionControllerTest extends TestCase } while ($count !== 2); - $transaction = $withdrawal->transactions()->first(); $repository->shouldReceive('setUser'); $repository->shouldReceive('update')->andReturn($withdrawal)->once(); diff --git a/tests/Api/V1/Controllers/UserControllerTest.php b/tests/Api/V1/Controllers/UserControllerTest.php index 90b5166189..85e8bc88fb 100644 --- a/tests/Api/V1/Controllers/UserControllerTest.php +++ b/tests/Api/V1/Controllers/UserControllerTest.php @@ -57,7 +57,7 @@ class UserControllerTest extends TestCase public function testDelete() { // create a user first: - $user = User::create(['email' => 'some@newu' . rand(1, 1000) . 'ser.nl', 'password' => 'hello', 'blocked' => 0]); + $user = User::create(['email' => 'some@newu' . random_int(1, 1000) . 'ser.nl', 'password' => 'hello', 'blocked' => 0]); // call API $response = $this->delete('/api/v1/users/' . $user->id); @@ -77,7 +77,7 @@ class UserControllerTest extends TestCase Passport::actingAs($this->emptyUser()); // create a user first: - $user = User::create(['email' => 'some@newu' . rand(1, 1000) . 'ser.nl', 'password' => 'hello', 'blocked' => 0]); + $user = User::create(['email' => 'some@newu' . random_int(1, 1000) . 'ser.nl', 'password' => 'hello', 'blocked' => 0]); // call API $response = $this->delete('/api/v1/users/' . $user->id); @@ -130,7 +130,7 @@ class UserControllerTest extends TestCase public function testStoreBasic() { $data = [ - 'email' => 'some_new@user' . rand(1, 1000) . '.com', + 'email' => 'some_new@user' . random_int(1, 1000) . '.com', 'blocked' => 0, ]; @@ -180,11 +180,11 @@ class UserControllerTest extends TestCase public function testUpdate() { // create a user first: - $user = User::create(['email' => 'some@newu' . rand(1, 1000) . 'ser.nl', 'password' => 'hello', 'blocked' => 0]); + $user = User::create(['email' => 'some@newu' . random_int(1, 1000) . 'ser.nl', 'password' => 'hello', 'blocked' => 0]); // data: $data = [ - 'email' => 'some-new@email' . rand(1, 1000) . '.com', + 'email' => 'some-new@email' . random_int(1, 1000) . '.com', 'blocked' => 0, ]; diff --git a/tests/Feature/Controllers/Account/ReconcileControllerTest.php b/tests/Feature/Controllers/Account/ReconcileControllerTest.php index 0931402d71..9b40892024 100644 --- a/tests/Feature/Controllers/Account/ReconcileControllerTest.php +++ b/tests/Feature/Controllers/Account/ReconcileControllerTest.php @@ -33,6 +33,7 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Illuminate\Support\Collection; use Log; use Tests\TestCase; +use Mockery; /** * Class ConfigurationControllerTest @@ -248,6 +249,8 @@ class ReconcileControllerTest extends TestCase $journalRepos->shouldReceive('store')->andReturn(new TransactionJournal); $repository->shouldReceive('getReconciliation')->andReturn(new Account); $repository->shouldReceive('findNull')->andReturn(new Account); + $repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(),'currency_id'])->andReturn('1'); + $data = [ 'transactions' => [1, 2, 3], 'reconcile' => 'create', diff --git a/tests/Feature/Controllers/AccountControllerTest.php b/tests/Feature/Controllers/AccountControllerTest.php index 7d331a01e6..2234820e49 100644 --- a/tests/Feature/Controllers/AccountControllerTest.php +++ b/tests/Feature/Controllers/AccountControllerTest.php @@ -40,7 +40,7 @@ use Log; use Preferences; use Steam; use Tests\TestCase; - +use Mockery; /** * Class AccountControllerTest * @@ -142,6 +142,12 @@ class AccountControllerTest extends TestCase $accountRepos->shouldReceive('getNote')->andReturn($note)->once(); $accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturnNull(); $accountRepos->shouldReceive('getOpeningBalanceDate')->andReturnNull(); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(),'currency_id'])->andReturn('1'); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(),'accountNumber'])->andReturn('123'); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(),'accountRole'])->andReturn('defaultAsset'); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(),'ccType'])->andReturn(''); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(),'ccMonthlyPaymentDate'])->andReturn(''); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(),'BIC'])->andReturn('BIC'); $this->be($this->user()); $account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first(); @@ -236,6 +242,7 @@ class AccountControllerTest extends TestCase { // mock $journalRepos = $this->mock(JournalRepositoryInterface::class); + $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $currencyRepos = $this->mock(CurrencyRepositoryInterface::class); $this->session(['start' => '2018-01-01', 'end' => '2017-12-01']); @@ -342,7 +349,7 @@ class AccountControllerTest extends TestCase $this->session(['accounts.create.uri' => 'http://localhost']); $this->be($this->user()); $data = [ - 'name' => 'new account ' . rand(1000, 9999), + 'name' => 'new account ' . random_int(1000, 9999), 'what' => 'asset', ]; @@ -368,7 +375,7 @@ class AccountControllerTest extends TestCase $this->session(['accounts.create.uri' => 'http://localhost']); $this->be($this->user()); $data = [ - 'name' => 'new account ' . rand(1000, 9999), + 'name' => 'new account ' . random_int(1000, 9999), 'what' => 'asset', 'create_another' => 1, ]; @@ -395,7 +402,7 @@ class AccountControllerTest extends TestCase $this->session(['accounts.edit.uri' => 'http://localhost/javascript/account']); $this->be($this->user()); $data = [ - 'name' => 'updated account ' . rand(1000, 9999), + 'name' => 'updated account ' . random_int(1000, 9999), 'active' => 1, 'what' => 'asset', ]; @@ -422,7 +429,7 @@ class AccountControllerTest extends TestCase $this->session(['accounts.edit.uri' => 'http://localhost']); $this->be($this->user()); $data = [ - 'name' => 'updated account ' . rand(1000, 9999), + 'name' => 'updated account ' . random_int(1000, 9999), 'active' => 1, 'what' => 'asset', 'return_to_edit' => '1', diff --git a/tests/Feature/Controllers/Admin/LinkControllerTest.php b/tests/Feature/Controllers/Admin/LinkControllerTest.php index feec43fe8b..46666f3c05 100644 --- a/tests/Feature/Controllers/Admin/LinkControllerTest.php +++ b/tests/Feature/Controllers/Admin/LinkControllerTest.php @@ -167,9 +167,9 @@ class LinkControllerTest extends TestCase { $repository = $this->mock(LinkTypeRepositoryInterface::class); $data = [ - 'name' => 'test ' . rand(1, 1000), - 'inward' => 'test inward' . rand(1, 1000), - 'outward' => 'test outward' . rand(1, 1000), + 'name' => 'test ' . random_int(1, 1000), + 'inward' => 'test inward' . random_int(1, 1000), + 'outward' => 'test outward' . random_int(1, 1000), ]; $repository->shouldReceive('store')->once()->andReturn(LinkType::first()); $repository->shouldReceive('find')->andReturn(LinkType::first()); @@ -189,9 +189,9 @@ class LinkControllerTest extends TestCase { $repository = $this->mock(LinkTypeRepositoryInterface::class); $data = [ - 'name' => 'test ' . rand(1, 1000), - 'inward' => 'test inward' . rand(1, 1000), - 'outward' => 'test outward' . rand(1, 1000), + 'name' => 'test ' . random_int(1, 1000), + 'inward' => 'test inward' . random_int(1, 1000), + 'outward' => 'test outward' . random_int(1, 1000), 'create_another' => '1', ]; $repository->shouldReceive('store')->once()->andReturn(new LinkType); @@ -215,9 +215,9 @@ class LinkControllerTest extends TestCase $repository->shouldReceive('update')->once()->andReturn(new $linkType); $data = [ - 'name' => 'test ' . rand(1, 1000), - 'inward' => 'test inward' . rand(1, 1000), - 'outward' => 'test outward' . rand(1, 1000), + 'name' => 'test ' . random_int(1, 1000), + 'inward' => 'test inward' . random_int(1, 1000), + 'outward' => 'test outward' . random_int(1, 1000), ]; $this->session(['link_types.edit.uri' => 'http://localhost']); $this->be($this->user()); @@ -236,9 +236,9 @@ class LinkControllerTest extends TestCase $linkType = LinkType::where('editable', 0)->first(); $data = [ - 'name' => 'test ' . rand(1, 1000), - 'inward' => 'test inward' . rand(1, 1000), - 'outward' => 'test outward' . rand(1, 1000), + 'name' => 'test ' . random_int(1, 1000), + 'inward' => 'test inward' . random_int(1, 1000), + 'outward' => 'test outward' . random_int(1, 1000), 'return_to_edit' => '1', ]; $this->session(['link_types.edit.uri' => 'http://localhost']); @@ -259,9 +259,9 @@ class LinkControllerTest extends TestCase $linkType = LinkType::create(['editable' => 1, 'inward' => 'healox', 'outward' => 'byaex', 'name' => 'Test tyapeX']); $data = [ - 'name' => 'test ' . rand(1, 1000), - 'inward' => 'test inward' . rand(1, 1000), - 'outward' => 'test outward' . rand(1, 1000), + 'name' => 'test ' . random_int(1, 1000), + 'inward' => 'test inward' . random_int(1, 1000), + 'outward' => 'test outward' . random_int(1, 1000), 'return_to_edit' => '1', ]; $repository->shouldReceive('update')->once()->andReturn(new $linkType); diff --git a/tests/Feature/Controllers/Admin/UpdateControllerTest.php b/tests/Feature/Controllers/Admin/UpdateControllerTest.php index db8f6883c7..42e123cdad 100644 --- a/tests/Feature/Controllers/Admin/UpdateControllerTest.php +++ b/tests/Feature/Controllers/Admin/UpdateControllerTest.php @@ -103,14 +103,15 @@ class UpdateControllerTest extends TestCase FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration); $version = config('firefly.version'); + $date = new Carbon; + $date->subDays(5); $releases = [ - new Release(['id' => 'x', 'title' => $version . '.1', 'content' => '', 'updated' => new Carbon]), + new Release(['id' => 'x', 'title' => $version . '.1', 'content' => '', 'updated' => $date]), ]; $updater = $this->mock(UpdateRequest::class); $updater->shouldReceive('call')->andReturnNull(); $updater->shouldReceive('getReleases')->andReturn($releases); - // expect a new release (because of .1) $this->be($this->user()); $response = $this->post(route('admin.update-check.manual')); $response->assertStatus(200); @@ -130,15 +131,16 @@ class UpdateControllerTest extends TestCase FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig); FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration); + $date = new Carbon; + $date->subDays(5); $version = config('firefly.version'); $releases = [ - new Release(['id' => 'x', 'title' => $version, 'content' => '', 'updated' => new Carbon]), + new Release(['id' => 'x', 'title' => $version, 'content' => '', 'updated' => $date]), ]; $updater = $this->mock(UpdateRequest::class); $updater->shouldReceive('call')->andReturnNull(); $updater->shouldReceive('getReleases')->andReturn($releases); - // expect a new release (because of .1) $this->be($this->user()); $response = $this->post(route('admin.update-check.manual')); $response->assertStatus(200); @@ -163,7 +165,6 @@ class UpdateControllerTest extends TestCase $updater->shouldReceive('call')->andThrow(FireflyException::class, 'Something broke.'); $updater->shouldReceive('getReleases')->andReturn($releases); - // expect a new release (because of .1) $this->be($this->user()); $response = $this->post(route('admin.update-check.manual')); $response->assertStatus(200); diff --git a/tests/Feature/Controllers/AttachmentControllerTest.php b/tests/Feature/Controllers/AttachmentControllerTest.php index 11653ed821..b1a0d40979 100644 --- a/tests/Feature/Controllers/AttachmentControllerTest.php +++ b/tests/Feature/Controllers/AttachmentControllerTest.php @@ -146,7 +146,7 @@ class AttachmentControllerTest extends TestCase $this->session(['attachments.edit.uri' => 'http://localhost']); $data = [ - 'title' => 'Some updated title ' . rand(1000, 9999), + 'title' => 'Some updated title ' . random_int(1000, 9999), 'notes' => 'A', 'description' => 'B', ]; diff --git a/tests/Feature/Controllers/BillControllerTest.php b/tests/Feature/Controllers/BillControllerTest.php index ff02b86b63..68aabe1da0 100644 --- a/tests/Feature/Controllers/BillControllerTest.php +++ b/tests/Feature/Controllers/BillControllerTest.php @@ -235,7 +235,7 @@ class BillControllerTest extends TestCase $attachHelper->shouldReceive('getMessages')->andReturn(new MessageBag); $data = [ - 'name' => 'New Bill ' . rand(1000, 9999), + 'name' => 'New Bill ' . random_int(1000, 9999), 'match' => 'some words', 'amount_min' => '100', 'amount_currency_id_amount_min' => 1, @@ -270,7 +270,7 @@ class BillControllerTest extends TestCase $data = [ 'id' => 1, - 'name' => 'Updated Bill ' . rand(1000, 9999), + 'name' => 'Updated Bill ' . random_int(1000, 9999), 'match' => 'some more words', 'amount_min' => '100', 'amount_currency_id_amount_min' => 1, diff --git a/tests/Feature/Controllers/BudgetControllerTest.php b/tests/Feature/Controllers/BudgetControllerTest.php index e5befa980b..1849152552 100644 --- a/tests/Feature/Controllers/BudgetControllerTest.php +++ b/tests/Feature/Controllers/BudgetControllerTest.php @@ -575,14 +575,14 @@ class BudgetControllerTest extends TestCase $repository = $this->mock(BudgetRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); - $repository->shouldReceive('find')->andReturn($budget); + $repository->shouldReceive('findNull')->andReturn($budget); $repository->shouldReceive('store')->andReturn($budget); $repository->shouldReceive('cleanupBudgets'); $this->session(['budgets.create.uri' => 'http://localhost']); $data = [ - 'name' => 'New Budget ' . rand(1000, 9999), + 'name' => 'New Budget ' . random_int(1000, 9999), ]; $this->be($this->user()); $response = $this->post(route('budgets.store'), $data); @@ -600,14 +600,14 @@ class BudgetControllerTest extends TestCase $repository = $this->mock(BudgetRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); - $repository->shouldReceive('find')->andReturn($budget); + $repository->shouldReceive('findNull')->andReturn($budget); $repository->shouldReceive('update'); $repository->shouldReceive('cleanupBudgets'); $this->session(['budgets.edit.uri' => 'http://localhost']); $data = [ - 'name' => 'Updated Budget ' . rand(1000, 9999), + 'name' => 'Updated Budget ' . random_int(1000, 9999), 'active' => 1, ]; $this->be($this->user()); diff --git a/tests/Feature/Controllers/CategoryControllerTest.php b/tests/Feature/Controllers/CategoryControllerTest.php index 862a9d6594..e344bed2ea 100644 --- a/tests/Feature/Controllers/CategoryControllerTest.php +++ b/tests/Feature/Controllers/CategoryControllerTest.php @@ -450,13 +450,13 @@ class CategoryControllerTest extends TestCase $repository = $this->mock(CategoryRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); - $repository->shouldReceive('find')->andReturn(new Category); + $repository->shouldReceive('findNull')->andReturn(new Category); $repository->shouldReceive('store')->andReturn(new Category); $this->session(['categories.create.uri' => 'http://localhost']); $data = [ - 'name' => 'New Category ' . rand(1000, 9999), + 'name' => 'New Category ' . random_int(1000, 9999), ]; $this->be($this->user()); $response = $this->post(route('categories.store'), $data); @@ -476,12 +476,12 @@ class CategoryControllerTest extends TestCase $accountRepos = $this->mock(AccountRepositoryInterface::class); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $repository->shouldReceive('update'); - $repository->shouldReceive('find')->andReturn($category); + $repository->shouldReceive('findNull')->andReturn($category); $this->session(['categories.edit.uri' => 'http://localhost']); $data = [ - 'name' => 'Updated Category ' . rand(1000, 9999), + 'name' => 'Updated Category ' . random_int(1000, 9999), 'active' => 1, ]; $this->be($this->user()); diff --git a/tests/Feature/Controllers/Chart/AccountControllerTest.php b/tests/Feature/Controllers/Chart/AccountControllerTest.php index 9b920120fc..9c8a8fae37 100644 --- a/tests/Feature/Controllers/Chart/AccountControllerTest.php +++ b/tests/Feature/Controllers/Chart/AccountControllerTest.php @@ -319,7 +319,7 @@ class AccountControllerTest extends TestCase $currencyRepos = $this->mock(CurrencyRepositoryInterface::class); $currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1)); $generator = $this->mock(GeneratorInterface::class); - $generator->shouldReceive('multiSet')->andreturn([]); + $generator->shouldReceive('multiSet')->andReturn([]); Steam::shouldReceive('balanceInRange')->andReturn(['2012-01-01' => '0']); $this->be($this->user()); diff --git a/tests/Feature/Controllers/JavascriptControllerTest.php b/tests/Feature/Controllers/JavascriptControllerTest.php index 15cef60f44..645b5a49c2 100644 --- a/tests/Feature/Controllers/JavascriptControllerTest.php +++ b/tests/Feature/Controllers/JavascriptControllerTest.php @@ -30,6 +30,7 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use Illuminate\Support\Collection; use Log; use Tests\TestCase; +use Mockery; /** * Class JavascriptControllerTest @@ -62,6 +63,7 @@ class JavascriptControllerTest extends TestCase $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$account])) ->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->once(); $currencyRepos->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn(new TransactionCurrency); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(),'currency_id'])->andReturn('1'); $this->be($this->user()); $response = $this->get(route('javascript.accounts')); @@ -77,6 +79,8 @@ class JavascriptControllerTest extends TestCase $currency = factory(TransactionCurrency::class)->make(); $repository->shouldReceive('get')->andReturn(new Collection([$currency])); + + $this->be($this->user()); $response = $this->get(route('javascript.currencies')); $response->assertStatus(200); @@ -96,6 +100,7 @@ class JavascriptControllerTest extends TestCase $currencyRepos = $this->mock(CurrencyRepositoryInterface::class); $accountRepos->shouldReceive('findNull')->andReturn(new Account); $currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1)); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(),'currency_id'])->andReturn('1'); $this->be($this->user()); $this->changeDateRange($this->user(), $range); $response = $this->get(route('javascript.variables')); @@ -116,6 +121,7 @@ class JavascriptControllerTest extends TestCase $currencyRepos = $this->mock(CurrencyRepositoryInterface::class); $accountRepos->shouldReceive('findNull')->andReturn(new Account); $currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1)); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(),'currency_id'])->andReturn('1'); $this->be($this->user()); $this->changeDateRange($this->user(), $range); diff --git a/tests/Feature/Controllers/Json/BoxControllerTest.php b/tests/Feature/Controllers/Json/BoxControllerTest.php index 27e3995c2d..977efbaeac 100644 --- a/tests/Feature/Controllers/Json/BoxControllerTest.php +++ b/tests/Feature/Controllers/Json/BoxControllerTest.php @@ -31,6 +31,7 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use Illuminate\Support\Collection; use Log; +use Mockery; use Tests\TestCase; /** @@ -112,6 +113,9 @@ class BoxControllerTest extends TestCase $currencyRepos = $this->mock(CurrencyRepositoryInterface::class); $accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()])); $currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1)); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1'); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset'); + $this->be($this->user()); $response = $this->get(route('json.box.net-worth')); $response->assertStatus(200); @@ -126,6 +130,8 @@ class BoxControllerTest extends TestCase $currencyRepos = $this->mock(CurrencyRepositoryInterface::class); $accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()])); $currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1)); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1'); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset'); $start = new Carbon; $start->addMonths(6)->startOfMonth(); diff --git a/tests/Feature/Controllers/PiggyBankControllerTest.php b/tests/Feature/Controllers/PiggyBankControllerTest.php index 31a8043c5c..bd78799224 100644 --- a/tests/Feature/Controllers/PiggyBankControllerTest.php +++ b/tests/Feature/Controllers/PiggyBankControllerTest.php @@ -366,7 +366,7 @@ class PiggyBankControllerTest extends TestCase $this->session(['piggy-banks.create.uri' => 'http://localhost']); $data = [ - 'name' => 'Piggy ' . rand(999, 10000), + 'name' => 'Piggy ' . random_int(999, 10000), 'targetamount' => '100.123', 'account_id' => 2, 'amount_currency_id_targetamount' => 1, @@ -393,7 +393,7 @@ class PiggyBankControllerTest extends TestCase $this->session(['piggy-banks.edit.uri' => 'http://localhost']); $data = [ 'id' => 3, - 'name' => 'Updated Piggy ' . rand(999, 10000), + 'name' => 'Updated Piggy ' . random_int(999, 10000), 'targetamount' => '100.123', 'account_id' => 2, 'amount_currency_id_targetamount' => 1, diff --git a/tests/Feature/Controllers/Popup/ReportControllerTest.php b/tests/Feature/Controllers/Popup/ReportControllerTest.php index 3f80005cfe..3fe609c251 100644 --- a/tests/Feature/Controllers/Popup/ReportControllerTest.php +++ b/tests/Feature/Controllers/Popup/ReportControllerTest.php @@ -115,8 +115,8 @@ class ReportControllerTest extends TestCase $account = factory(Account::class)->make(); $popupHelper->shouldReceive('balanceForNoBudget')->once()->andReturn(new Collection); - $budgetRepos->shouldReceive('find')->andReturn(new Budget)->once()->withArgs([0]); - $accountRepos->shouldReceive('find')->andReturn($account)->once()->withArgs([1]); + $budgetRepos->shouldReceive('findNull')->andReturn(new Budget)->once()->withArgs([0]); + $accountRepos->shouldReceive('findNull')->andReturn($account)->once()->withArgs([1]); $this->be($this->user()); @@ -151,8 +151,8 @@ class ReportControllerTest extends TestCase $budget = factory(Budget::class)->make(); $account = factory(Account::class)->make(); - $budgetRepos->shouldReceive('find')->andReturn($budget)->once()->withArgs([1]); - $accountRepos->shouldReceive('find')->andReturn($account)->once()->withArgs([1]); + $budgetRepos->shouldReceive('findNull')->andReturn($budget)->once()->withArgs([1]); + $accountRepos->shouldReceive('findNull')->andReturn($account)->once()->withArgs([1]); $popupHelper->shouldReceive('balanceForBudget')->once()->andReturn(new Collection); $this->be($this->user()); @@ -188,8 +188,8 @@ class ReportControllerTest extends TestCase $budget = factory(Budget::class)->make(); $account = factory(Account::class)->make(); - $budgetRepos->shouldReceive('find')->andReturn($budget)->once()->withArgs([1]); - $accountRepos->shouldReceive('find')->andReturn($account)->once()->withArgs([1]); + $budgetRepos->shouldReceive('findNull')->andReturn($budget)->once()->withArgs([1]); + $accountRepos->shouldReceive('findNull')->andReturn($account)->once()->withArgs([1]); $popupHelper->shouldReceive('balanceDifference')->once()->andReturn(new Collection); $this->be($this->user()); @@ -224,8 +224,8 @@ class ReportControllerTest extends TestCase $budget = factory(Budget::class)->make(); $account = factory(Account::class)->make(); - $budgetRepos->shouldReceive('find')->andReturn($budget)->once()->withArgs([1]); - $accountRepos->shouldReceive('find')->andReturn($account)->once()->withArgs([1]); + $budgetRepos->shouldReceive('findNull')->andReturn($budget)->once()->withArgs([1]); + $accountRepos->shouldReceive('findNull')->andReturn($account)->once()->withArgs([1]); $this->be($this->user()); $arguments = [ @@ -259,7 +259,7 @@ class ReportControllerTest extends TestCase $popupHelper = $this->mock(PopupReportInterface::class); $budget = factory(Budget::class)->make(); - $budgetRepos->shouldReceive('find')->andReturn($budget)->once()->withArgs([1]); + $budgetRepos->shouldReceive('findNull')->andReturn($budget)->once()->withArgs([1]); $popupHelper->shouldReceive('byBudget')->andReturn(new Collection); $this->be($this->user()); @@ -289,11 +289,10 @@ class ReportControllerTest extends TestCase $budgetRepos = $this->mock(BudgetRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class); $categoryRepos = $this->mock(CategoryRepositoryInterface::class); - $categoryRepos = $this->mock(CategoryRepositoryInterface::class); $popupHelper = $this->mock(PopupReportInterface::class); $category = factory(Category::class)->make(); - $categoryRepos->shouldReceive('find')->andReturn($category)->once()->withArgs([1]); + $categoryRepos->shouldReceive('findNull')->andReturn($category)->once()->withArgs([1]); $popupHelper->shouldReceive('byCategory')->andReturn(new Collection); $this->be($this->user()); @@ -327,7 +326,7 @@ class ReportControllerTest extends TestCase $accountRepos = $this->mock(AccountRepositoryInterface::class); $account = factory(Account::class)->make(); - $accountRepos->shouldReceive('find')->withArgs([1])->andReturn($account)->once(); + $accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($account)->once(); $popupHelper->shouldReceive('byExpenses')->andReturn(new Collection); $this->be($this->user()); @@ -361,7 +360,7 @@ class ReportControllerTest extends TestCase $accountRepos = $this->mock(AccountRepositoryInterface::class); $account = factory(Account::class)->make(); - $accountRepos->shouldReceive('find')->withArgs([1])->andReturn($account)->once(); + $accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($account)->once(); $popupHelper->shouldReceive('byIncome')->andReturn(new Collection); $this->be($this->user()); diff --git a/tests/Feature/Controllers/TagControllerTest.php b/tests/Feature/Controllers/TagControllerTest.php index 8d0b07287f..75d7001faf 100644 --- a/tests/Feature/Controllers/TagControllerTest.php +++ b/tests/Feature/Controllers/TagControllerTest.php @@ -267,7 +267,7 @@ class TagControllerTest extends TestCase $this->session(['tags.create.uri' => 'http://localhost']); $data = [ - 'tag' => 'Hello new tag' . rand(999, 10000), + 'tag' => 'Hello new tag' . random_int(999, 10000), 'tagMode' => 'nothing', 'tag_position_has_tag' => 'true', @@ -292,7 +292,7 @@ class TagControllerTest extends TestCase $this->session(['tags.edit.uri' => 'http://localhost']); $data = [ 'id' => 1, - 'tag' => 'Hello updated tag' . rand(999, 10000), + 'tag' => 'Hello updated tag' . random_int(999, 10000), 'tagMode' => 'nothing', ]; diff --git a/tests/Feature/Controllers/TransactionControllerTest.php b/tests/Feature/Controllers/TransactionControllerTest.php index 7e41431863..1e532ad5e1 100644 --- a/tests/Feature/Controllers/TransactionControllerTest.php +++ b/tests/Feature/Controllers/TransactionControllerTest.php @@ -61,14 +61,19 @@ class TransactionControllerTest extends TestCase */ public function testIndex() { + $date = new Carbon; + $this->session(['start' => $date, 'end' => clone $date]); + // mock stuff + $transfer = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 3)->first(); $repository = $this->mock(JournalRepositoryInterface::class); $collector = $this->mock(JournalCollectorInterface::class); - $repository->shouldReceive('first')->times(2)->andReturn(new TransactionJournal); + $repository->shouldReceive('first')->times(2)->andReturn($transfer); $collector->shouldReceive('setTypes')->andReturnSelf(); $collector->shouldReceive('setLimit')->andReturnSelf(); $collector->shouldReceive('setPage')->andReturnSelf(); + $collector->shouldReceive('addFilter')->andReturnSelf(); $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf(); $collector->shouldReceive('setRange')->andReturnSelf(); $collector->shouldReceive('withBudgetInformation')->andReturnSelf(); @@ -90,16 +95,21 @@ class TransactionControllerTest extends TestCase */ public function testIndexAll() { + $date = new Carbon; + $this->session(['start' => $date, 'end' => clone $date]); + // mock stuff + $transfer = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 3)->first(); $repository = $this->mock(JournalRepositoryInterface::class); $collector = $this->mock(JournalCollectorInterface::class); - $repository->shouldReceive('first')->twice()->andReturn(new TransactionJournal); + $repository->shouldReceive('first')->twice()->andReturn($transfer); $collector->shouldReceive('setTypes')->andReturnSelf(); $collector->shouldReceive('setLimit')->andReturnSelf(); $collector->shouldReceive('setPage')->andReturnSelf(); $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf(); $collector->shouldReceive('setRange')->andReturnSelf(); + $collector->shouldReceive('addFilter')->andReturnSelf(); $collector->shouldReceive('withBudgetInformation')->andReturnSelf(); $collector->shouldReceive('withCategoryInformation')->andReturnSelf(); $collector->shouldReceive('withOpposingAccount')->andReturnSelf(); @@ -108,7 +118,7 @@ class TransactionControllerTest extends TestCase $collector->shouldReceive('getJournals')->andReturn(new Collection); $this->be($this->user()); - $response = $this->get(route('transactions.index', ['transfer', 'all'])); + $response = $this->get(route('transactions.index.all', ['transfer'])); $response->assertStatus(200); // has bread crumb $response->assertSee('