Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix tests.
James Cole62b68c6a21dc
diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.phpindex ddc7e0b358..49e8a68e84 100644--- a/app/Repositories/Bill/BillRepository.php+++ b/app/Repositories/Bill/BillRepository.php@@ -344,29 +344,6 @@ class BillRepository implements BillRepositoryInterfacereturn $set;}- /**- * @param Bill $bill- *- * @return Collection- */- public function getPossiblyRelatedJournals(Bill $bill): Collection- {- $set = new Collection(- DB::table('transactions')->where('amount', '>', 0)->where('amount', '>=', $bill->amount_min)->where('amount', '<=', $bill->amount_max)- ->get(['transaction_journal_id'])- );- $ids = $set->pluck('transaction_journal_id')->toArray();-- $journals = new Collection;- if (count($ids) > 0) {- $journals = $this->user->transactionJournals()->transactionTypes([TransactionType::WITHDRAWAL])->whereIn('transaction_journals.id', $ids)->get(- ['transaction_journals.*']- );- }-- return $journals;- }-/*** Return all rules for one bill*diff --git a/app/Repositories/Bill/BillRepositoryInterface.php b/app/Repositories/Bill/BillRepositoryInterface.phpindex bdf1f6f29a..c53c8aa6e3 100644--- a/app/Repositories/Bill/BillRepositoryInterface.php+++ b/app/Repositories/Bill/BillRepositoryInterface.php@@ -133,13 +133,6 @@ interface BillRepositoryInterface*/public function getPayDatesInRange(Bill $bill, Carbon $start, Carbon $end): Collection;- /**- * @param Bill $bill- *- * @return Collection- */- public function getPossiblyRelatedJournals(Bill $bill): Collection;-/*** Return all rules for one bill*diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.phpindex 5a1e9ee90d..e37bd22338 100644--- a/database/factories/ModelFactory.php+++ b/database/factories/ModelFactory.php@@ -118,17 +118,18 @@ $factory->define(FireflyIII\Models\Bill::class,function (Faker\Generator $faker) {return [- 'created_at' => new Carbon,- 'updated_at' => new Carbon,- 'user_id' => 1,- 'name' => $faker->words(3, true),- 'match' => $faker->words(3, true),- 'amount_min' => '100.00',- 'amount_max' => '100.00',- 'date' => '2017-01-01',- 'repeat_freq' => 'monthly',- 'skip' => 0,- 'automatch' => 1,+ 'created_at' => new Carbon,+ 'updated_at' => new Carbon,+ 'user_id' => 1,+ 'transaction_currency_id' => 1,+ 'name' => $faker->words(3, true),+ 'match' => $faker->words(3, true),+ 'amount_min' => '100.00',+ 'amount_max' => '100.00',+ 'date' => '2017-01-01',+ 'repeat_freq' => 'monthly',+ 'skip' => 0,+ 'automatch' => 1,];});diff --git a/tests/Feature/Controllers/BillControllerTest.php b/tests/Feature/Controllers/BillControllerTest.phpindex 68aabe1da0..7da8478c81 100644--- a/tests/Feature/Controllers/BillControllerTest.php+++ b/tests/Feature/Controllers/BillControllerTest.php@@ -140,6 +140,7 @@ class BillControllerTest extends TestCase$repository->shouldReceive('getPaginator')->andReturn(new LengthAwarePaginator($collection, 1, 50))->once();$repository->shouldReceive('setUser');$repository->shouldReceive('getPaidDatesInRange')->twice()->andReturn(new Collection([new Carbon, new Carbon, new Carbon]));+ $repository->shouldReceive('getRulesForBills')->andReturn([]);$this->be($this->user());@@ -159,10 +160,8 @@ class BillControllerTest extends TestCase$journal = factory(TransactionJournal::class)->make();$journalRepos = $this->mock(JournalRepositoryInterface::class);$repository = $this->mock(BillRepositoryInterface::class);- $repository->shouldReceive('getPossiblyRelatedJournals')->once()->andReturn(new Collection([$journal]));- $repository->shouldReceive('scan')->once();$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);-+ $repository->shouldReceive('getRulesForBill')->andReturn(new Collection);$this->be($this->user());$response = $this->get(route('bills.rescan', [1]));$response->assertStatus(302);@@ -199,6 +198,7 @@ class BillControllerTest extends TestCase$repository->shouldReceive('getYearAverage')->andReturn('0');$repository->shouldReceive('getOverallAverage')->andReturn('0');$repository->shouldReceive('nextExpectedMatch')->andReturn(new Carbon);+ $repository->shouldReceive('getRulesForBill')->andReturn(new Collection);$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();@@ -235,15 +235,14 @@ class BillControllerTest extends TestCase$attachHelper->shouldReceive('getMessages')->andReturn(new MessageBag);$data = [- 'name' => 'New Bill ' . random_int(1000, 9999),- 'match' => 'some words',- 'amount_min' => '100',- 'amount_currency_id_amount_min' => 1,- 'amount_currency_id_amount_max' => 1,- 'skip' => 0,- 'amount_max' => '100',- 'date' => '2016-01-01',- 'repeat_freq' => 'monthly',+ 'name' => 'New Bill ' . random_int(1000, 9999),+ 'amount_min' => '100',+ 'transaction_currency_id' => 1,+ 'skip' => 0,+ 'strict' => 1,+ 'amount_max' => '100',+ 'date' => '2016-01-01',+ 'repeat_freq' => 'monthly',];$this->session(['bills.create.uri' => 'http://localhost']);$this->be($this->user());@@ -271,10 +270,8 @@ class BillControllerTest extends TestCase$data = ['id' => 1,'name' => 'Updated Bill ' . random_int(1000, 9999),- 'match' => 'some more words','amount_min' => '100',- 'amount_currency_id_amount_min' => 1,- 'amount_currency_id_amount_max' => 1,+ 'transaction_currency_id' => 1,'skip' => 0,'amount_max' => '100','date' => '2016-01-01',diff --git a/tests/Unit/Factory/BillFactoryTest.php b/tests/Unit/Factory/BillFactoryTest.phpindex 7b8bf5f07e..7f4d83b1b3 100644--- a/tests/Unit/Factory/BillFactoryTest.php+++ b/tests/Unit/Factory/BillFactoryTest.php@@ -42,16 +42,16 @@ class BillFactoryTest extends TestCasepublic function testCreateBasic(){$data = [- 'name' => 'Some new bill #' . random_int(1, 1000),- 'match' => 'i,am,word' . random_int(1, 1000),- 'amount_min' => '5',- 'amount_max' => '10',- 'date' => '2018-01-01',- 'repeat_freq' => 'monthly',- 'skip' => 0,- 'automatch' => true,- 'active' => true,- 'notes' => 'Hello!',+ 'name' => 'Some new bill #' . random_int(1, 1000),+ 'amount_min' => '5',+ 'transaction_currency_id' => 1,+ 'amount_max' => '10',+ 'date' => '2018-01-01',+ 'repeat_freq' => 'monthly',+ 'skip' => 0,+ 'automatch' => true,+ 'active' => true,+ 'notes' => 'Hello!',];/** @var BillFactory $factory */@@ -60,7 +60,6 @@ class BillFactoryTest extends TestCase$bill = $factory->create($data);$this->assertEquals($data['name'], $bill->name);- $this->assertEquals($data['match'], $bill->match);$this->assertEquals($data['amount_min'], $bill->amount_min);$this->assertEquals($data['repeat_freq'], $bill->repeat_freq);$note = $bill->notes()->first();@@ -77,16 +76,16 @@ class BillFactoryTest extends TestCasepublic function testCreateEmptyNotes(){$data = [- 'name' => 'Some new bill #' . random_int(1, 1000),- 'match' => 'i,am,word' . random_int(1, 1000),- 'amount_min' => '5',- 'amount_max' => '10',- 'date' => '2018-01-01',- 'repeat_freq' => 'monthly',- 'skip' => 0,- 'automatch' => true,- 'active' => true,- 'notes' => '',+ 'name' => 'Some new bill #' . random_int(1, 1000),+ 'amount_min' => '5',+ 'amount_max' => '10',+ 'date' => '2018-01-01',+ 'repeat_freq' => 'monthly',+ 'transaction_currency_id' => 1,+ 'skip' => 0,+ 'automatch' => true,+ 'active' => true,+ 'notes' => '',];/** @var BillFactory $factory */@@ -95,7 +94,6 @@ class BillFactoryTest extends TestCase$bill = $factory->create($data);$this->assertEquals($data['name'], $bill->name);- $this->assertEquals($data['match'], $bill->match);$this->assertEquals($data['amount_min'], $bill->amount_min);$this->assertEquals($data['repeat_freq'], $bill->repeat_freq);$this->assertEquals(0, $bill->notes()->count());diff --git a/tests/Unit/Transformers/BillTransformerTest.php b/tests/Unit/Transformers/BillTransformerTest.phpindex 75cee9e995..a7a0c714d8 100644--- a/tests/Unit/Transformers/BillTransformerTest.php+++ b/tests/Unit/Transformers/BillTransformerTest.php@@ -49,15 +49,16 @@ class BillTransformerTest extends TestCase$bill = Bill::create([- 'user_id' => $this->user()->id,- 'name' => 'Some bill ' . random_int(1, 10000),- 'match' => 'word,' . random_int(1, 10000),- 'amount_min' => 12.34,- 'amount_max' => 45.67,- 'date' => '2018-01-02',- 'repeat_freq' => 'weekly',- 'skip' => 0,- 'active' => 1,+ 'user_id' => $this->user()->id,+ 'name' => 'Some bill ' . random_int(1, 10000),+ 'match' => 'word,' . random_int(1, 10000),+ 'amount_min' => 12.34,+ 'amount_max' => 45.67,+ 'transaction_currency_id' => 1,+ 'date' => '2018-01-02',+ 'repeat_freq' => 'weekly',+ 'skip' => 0,+ 'active' => 1,]);$transformer = new BillTransformer(new ParameterBag);@@ -77,15 +78,16 @@ class BillTransformerTest extends TestCase$bill = Bill::create([- 'user_id' => $this->user()->id,- 'name' => 'Some bill ' . random_int(1, 10000),- 'match' => 'word,' . random_int(1, 10000),- 'amount_min' => 12.34,- 'amount_max' => 45.67,- 'date' => '2018-01-02',- 'repeat_freq' => 'weekly',- 'skip' => 0,- 'active' => 1,+ 'user_id' => $this->user()->id,+ 'name' => 'Some bill ' . random_int(1, 10000),+ 'match' => 'word,' . random_int(1, 10000),+ 'amount_min' => 12.34,+ 'amount_max' => 45.67,+ 'date' => '2018-01-02',+ 'transaction_currency_id' => 1,+ 'repeat_freq' => 'weekly',+ 'skip' => 0,+ 'active' => 1,]);$noteText = 'I are a note ' . random_int(1, 10000);@@ -121,15 +123,16 @@ class BillTransformerTest extends TestCase$repository->shouldReceive('getPaidDatesInRange')->andReturn(new Collection([new Carbon('2018-01-02')]));$bill = Bill::create([- 'user_id' => $this->user()->id,- 'name' => 'Some bill ' . random_int(1, 10000),- 'match' => 'word,' . random_int(1, 10000),- 'amount_min' => 12.34,- 'amount_max' => 45.67,- 'date' => '2018-01-02',- 'repeat_freq' => 'monthly',- 'skip' => 0,- 'active' => 1,+ 'user_id' => $this->user()->id,+ 'name' => 'Some bill ' . random_int(1, 10000),+ 'match' => 'word,' . random_int(1, 10000),+ 'amount_min' => 12.34,+ 'amount_max' => 45.67,+ 'date' => '2018-01-02',+ 'transaction_currency_id' => 1,+ 'repeat_freq' => 'monthly',+ 'skip' => 0,+ 'active' => 1,]);$parameters = new ParameterBag();