Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix the unit tests.
James Cole9b177151757f
diff --git a/app/Console/Commands/UpgradeDatabase.php b/app/Console/Commands/UpgradeDatabase.phpindex b70011a8d9..bf11fad82d 100644--- a/app/Console/Commands/UpgradeDatabase.php+++ b/app/Console/Commands/UpgradeDatabase.php@@ -71,6 +71,7 @@ class UpgradeDatabase extends Command$this->setTransactionIdentifier();$this->migrateRepetitions();$this->updateAccountCurrencies();+ $this->line('Updating currency information..');$this->updateTransferCurrencies();$this->updateOtherCurrencies();$this->info('Firefly III database is up to date.');@@ -218,16 +219,10 @@ class UpgradeDatabase extends Commandif (is_null($transaction->transaction_currency_id)) {$transaction->transaction_currency_id = $currency->id;$transaction->save();- $this->line(sprintf('Transaction #%d is set to %s', $transaction->id, $currency->code));}// when mismatch in transaction:if ($transaction->transaction_currency_id !== $currency->id) {- $this->line(- sprintf(- 'Transaction #%d is set to %s and foreign %s', $transaction->id, $currency->code, $transaction->transactionCurrency->code- )- );$transaction->foreign_currency_id = $transaction->transaction_currency_id;$transaction->foreign_amount = $transaction->amount;$transaction->transaction_currency_id = $currency->id;@@ -372,12 +367,10 @@ class UpgradeDatabase extends Commandif (is_null($transaction->transaction_currency_id)) {$transaction->transaction_currency_id = $currency->id;$transaction->save();- $this->line(sprintf('Transaction #%d is set to %s', $transaction->id, $currency->code));}// when mismatch in transaction:if ($transaction->transaction_currency_id !== $currency->id) {- $this->line(sprintf('Transaction #%d is set to %s and foreign %s', $transaction->id, $currency->code, $transaction->transactionCurrency->code));$transaction->foreign_currency_id = $transaction->transaction_currency_id;$transaction->foreign_amount = $transaction->amount;$transaction->transaction_currency_id = $currency->id;diff --git a/app/Http/Controllers/ExportController.php b/app/Http/Controllers/ExportController.phpindex 326ad87c77..0afaba639f 100644--- a/app/Http/Controllers/ExportController.php+++ b/app/Http/Controllers/ExportController.php@@ -152,12 +152,9 @@ class ExportController extends Controller$jobs->changeStatus($job, 'export_status_make_exporter');/** @var ProcessorInterface $processor */- $processor = app(ExpandedProcessor::class);+ $processor = app(ProcessorInterface::class);$processor->setSettings($settings);---/** Collect journals:*/diff --git a/app/Models/ExportJob.php b/app/Models/ExportJob.phpindex 89f2e4554b..6cf10bbb39 100644--- a/app/Models/ExportJob.php+++ b/app/Models/ExportJob.php@@ -13,12 +13,15 @@ declare(strict_types=1);namespace FireflyIII\Models;+use FireflyIII\User;use Illuminate\Database\Eloquent\Model;use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;/*** Class ExportJob*+ * @property User $user+ ** @package FireflyIII\Models*/class ExportJob extends Modeldiff --git a/app/Providers/FireflyServiceProvider.php b/app/Providers/FireflyServiceProvider.phpindex a2b6429f20..2323ba9340 100644--- a/app/Providers/FireflyServiceProvider.php+++ b/app/Providers/FireflyServiceProvider.php@@ -13,7 +13,7 @@ declare(strict_types=1);namespace FireflyIII\Providers;-use FireflyIII\Export\Processor;+use FireflyIII\Export\ExpandedProcessor;use FireflyIII\Export\ProcessorInterface;use FireflyIII\Generator\Chart\Basic\ChartJsGenerator;use FireflyIII\Generator\Chart\Basic\GeneratorInterface;@@ -138,7 +138,8 @@ class FireflyServiceProvider extends ServiceProvider);// other generators- $this->app->bind(ProcessorInterface::class, Processor::class);+ // export:+ $this->app->bind(ProcessorInterface::class, ExpandedProcessor::class);$this->app->bind(UserRepositoryInterface::class, UserRepository::class);$this->app->bind(AttachmentHelperInterface::class, AttachmentHelper::class);diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.phpindex c014cb7078..8669ccf1b3 100644--- a/database/factories/ModelFactory.php+++ b/database/factories/ModelFactory.php@@ -210,6 +210,7 @@ $factory->define('id' => $faker->unique()->numberBetween(1000, 10000),'name' => $faker->words(3, true),'account_type_id' => 1,+ 'active' => true,];});diff --git a/tests/Feature/Controllers/ExportControllerTest.php b/tests/Feature/Controllers/ExportControllerTest.phpindex 9f66e44c9c..6de839c908 100644--- a/tests/Feature/Controllers/ExportControllerTest.php+++ b/tests/Feature/Controllers/ExportControllerTest.php@@ -143,12 +143,15 @@ class ExportControllerTest extends TestCase$processor->shouldReceive('collectOldUploads')->once();$processor->shouldReceive('collectAttachments')->once();+ $job = new ExportJob;+ $job->user = $this->user();+$repository->shouldReceive('changeStatus')->andReturn(true);- $repository->shouldReceive('findByKey')->andReturn(new ExportJob);+ $repository->shouldReceive('findByKey')->andReturn($job);$this->be($this->user());- $response = $this->post(route('export.export'), $data);+ $response = $this->post(route('export.submit'), $data);$response->assertStatus(200);$response->assertSee('ok');}diff --git a/tests/Feature/Controllers/Json/AutoCompleteControllerTest.php b/tests/Feature/Controllers/Json/AutoCompleteControllerTest.phpnew file mode 100644index 0000000000..e00cfb2c13--- /dev/null+++ b/tests/Feature/Controllers/Json/AutoCompleteControllerTest.php@@ -0,0 +1,87 @@+<?php+/**+ * AutoCompleteControllerTest.php+ * Copyright (c) 2017 [email protected]+ * This software may be modified and distributed under the terms of the+ * Creative Commons Attribution-ShareAlike 4.0 International License.+ *+ * See the LICENSE file for details.+ */++declare(strict_types=1);++namespace Tests\Feature\Controllers\Json;+++use FireflyIII\Models\Account;+use FireflyIII\Models\AccountType;+use FireflyIII\Models\TransactionJournal;+use FireflyIII\Repositories\Account\AccountRepositoryInterface;+use FireflyIII\Repositories\Journal\JournalRepositoryInterface;+use Illuminate\Support\Collection;+use Tests\TestCase;++/**+ * Class AutoCompleteControllerTest+ *+ * @package Tests\Feature\Controllers\Json+ */+class AutoCompleteControllerTest extends TestCase+{++ /**+ * @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController::allAccounts+ */+ public function testAllAccounts()+ {+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $accountRepos->shouldReceive('getAccountsByType')+ ->withArgs([[AccountType::REVENUE, AccountType::EXPENSE, AccountType::BENEFICIARY, AccountType::DEFAULT, AccountType::ASSET]])+ ->andReturn(new Collection);++ $this->be($this->user());+ $response = $this->get(route('json.all-accounts'));+ $response->assertStatus(200);+ }++ /**+ * @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController::expenseAccounts+ */+ public function testExpenseAccounts()+ {+ // mock stuff+ $account = factory(Account::class)->make();+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $journalRepos = $this->mock(JournalRepositoryInterface::class);+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);+ $accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE, AccountType::BENEFICIARY]])->once()->andReturn(+ new Collection([$account])+ );++ $this->be($this->user());+ $response = $this->get(route('json.expense-accounts'));+ $response->assertStatus(200);+ $response->assertExactJson([$account->name]);+ }++ /**+ * @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController::revenueAccounts+ */+ public function testRevenueAccounts()+ {+ // mock stuff+ $account = factory(Account::class)->make();+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $journalRepos = $this->mock(JournalRepositoryInterface::class);+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);+ $accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::REVENUE]])->once()->andReturn(+ new Collection([$account])+ );++ $this->be($this->user());+ $response = $this->get(route('json.revenue-accounts'));+ $response->assertStatus(200);+ $response->assertExactJson([$account->name]);+ }++}\ No newline at end of filediff --git a/tests/Feature/Controllers/JsonControllerTest.php b/tests/Feature/Controllers/JsonControllerTest.phpindex 2afd48ca56..bef5b28839 100644--- a/tests/Feature/Controllers/JsonControllerTest.php+++ b/tests/Feature/Controllers/JsonControllerTest.php@@ -54,21 +54,6 @@ class JsonControllerTest extends TestCase$response->assertStatus(200);}- /**- * @covers \FireflyIII\Http\Controllers\JsonController::allAccounts- */- public function testAllAccounts()- {- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $accountRepos->shouldReceive('getAccountsByType')- ->withArgs([[AccountType::REVENUE, AccountType::EXPENSE, AccountType::BENEFICIARY, AccountType::DEFAULT, AccountType::ASSET]])- ->andReturn(new Collection);-- $this->be($this->user());- $response = $this->get(route('json.all-accounts'));- $response->assertStatus(200);- }-/*** @covers \FireflyIII\Http\Controllers\JsonController::allTransactionJournals()*/@@ -210,45 +195,6 @@ class JsonControllerTest extends TestCase$response->assertExactJson([$category->name]);}- /**- * @covers \FireflyIII\Http\Controllers\JsonController::expenseAccounts- */- public function testExpenseAccounts()- {- // mock stuff- $account = factory(Category::class)->make();- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $journalRepos = $this->mock(JournalRepositoryInterface::class);- $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);- $accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE, AccountType::BENEFICIARY]])->once()->andReturn(- new Collection([$account])- );-- $this->be($this->user());- $response = $this->get(route('json.expense-accounts'));- $response->assertStatus(200);- $response->assertExactJson([$account->name]);- }-- /**- * @covers \FireflyIII\Http\Controllers\JsonController::revenueAccounts- */- public function testRevenueAccounts()- {- // mock stuff- $account = factory(Category::class)->make();- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $journalRepos = $this->mock(JournalRepositoryInterface::class);- $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);- $accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::REVENUE]])->once()->andReturn(- new Collection([$account])- );-- $this->be($this->user());- $response = $this->get(route('json.revenue-accounts'));- $response->assertStatus(200);- $response->assertExactJson([$account->name]);- }/*** @covers \FireflyIII\Http\Controllers\JsonController::tags