mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 18:54:58 +00:00 
			
		
		
		
	Various code coverage and test related fixes.
This commit is contained in:
		| @@ -233,7 +233,7 @@ class TagReportController extends Controller | ||||
|             } | ||||
|         } | ||||
|         if (count($newSet) === 0) { | ||||
|             $newSet = $chartData; | ||||
|             $newSet = $chartData; // @codeCoverageIgnore | ||||
|         } | ||||
|         $data = $this->generator->multiSet($newSet); | ||||
|         $cache->store($data); | ||||
|   | ||||
| @@ -14,7 +14,6 @@ namespace FireflyIII\Http\Controllers\Json; | ||||
|  | ||||
| use Carbon\Carbon; | ||||
| use FireflyIII\Http\Controllers\Controller; | ||||
| use FireflyIII\Models\CurrencyExchangeRate; | ||||
| use FireflyIII\Models\TransactionCurrency; | ||||
| use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; | ||||
| use FireflyIII\Services\Currency\ExchangeRateInterface; | ||||
|   | ||||
| @@ -269,8 +269,10 @@ class SingleController extends Controller | ||||
|         $foreignCurrencyId = intval($journal->getMeta('foreign_currency_id')); | ||||
|         if ($foreignCurrencyId > 0) { | ||||
|             // update some fields in pre-filled. | ||||
|             // @codeCoverageIgnoreStart | ||||
|             $preFilled['amount']   = $journal->getMeta('foreign_amount'); | ||||
|             $preFilled['currency'] = $this->currency->find(intval($journal->getMeta('foreign_currency_id'))); | ||||
|             // @codeCoverageIgnoreEnd | ||||
|         } | ||||
|  | ||||
|         if ($journal->isWithdrawal() && $destinationAccounts->first()->accountType->type == AccountType::CASH) { | ||||
|   | ||||
| @@ -185,9 +185,11 @@ class TransactionController extends Controller | ||||
|         $foreignCurrency = null; | ||||
|  | ||||
|         if ($journal->hasMeta('foreign_currency_id')) { | ||||
|             // @codeCoverageIgnoreStart | ||||
|             /** @var CurrencyRepositoryInterface $repository */ | ||||
|             $repository      = app(CurrencyRepositoryInterface::class); | ||||
|             $foreignCurrency = $repository->find(intval($journal->getMeta('foreign_currency_id'))); | ||||
|             // @codeCoverageIgnoreEnd | ||||
|         } | ||||
|  | ||||
|         return view('transactions.show', compact('journal', 'events', 'subTitle', 'what', 'transactions', 'foreignCurrency')); | ||||
|   | ||||
| @@ -36,11 +36,35 @@ $factory->define( | ||||
| } | ||||
| ); | ||||
|  | ||||
| $factory->define( | ||||
|     FireflyIII\Models\CurrencyExchangeRate::class, function (Faker\Generator $faker) { | ||||
|  | ||||
|     return [ | ||||
|         'user_id'          => 1, | ||||
|         'from_currency_id' => 1, | ||||
|         'to_currency_id'   => 2, | ||||
|         'date'             => '2017-01-01', | ||||
|         'rate'             => '1.5', | ||||
|         'user_rate'        => null, | ||||
|     ]; | ||||
| } | ||||
| ); | ||||
|  | ||||
| $factory->define( | ||||
|     FireflyIII\Models\TransactionCurrency::class, function (Faker\Generator $faker) { | ||||
|  | ||||
|     return [ | ||||
|         'name'   => $faker->words(1, true), | ||||
|         'code'   => 'ABC', | ||||
|         'symbol' => 'x', | ||||
|     ]; | ||||
| } | ||||
| ); | ||||
|  | ||||
| $factory->define( | ||||
|     FireflyIII\Models\ImportJob::class, function (Faker\Generator $faker) { | ||||
|     return [ | ||||
|         'id'              => $faker->numberBetween(1, 10), | ||||
|         'id'              => $faker->numberBetween(1, 100), | ||||
|         'user_id'         => 1, | ||||
|         'key'             => $faker->words(1, true), | ||||
|         'file_type'       => 'csv', | ||||
| @@ -101,7 +125,7 @@ $factory->define( | ||||
| $factory->define( | ||||
|     FireflyIII\Models\PiggyBank::class, function (Faker\Generator $faker) { | ||||
|     return [ | ||||
|         'id'            => $faker->numberBetween(1, 10), | ||||
|         'id'            => $faker->unique()->numberBetween(100, 10000), | ||||
|         'account_id'    => $faker->numberBetween(1, 10), | ||||
|         'name'          => $faker->words(3, true), | ||||
|         'target_amount' => '1000.00', | ||||
| @@ -116,7 +140,7 @@ $factory->define( | ||||
| $factory->define( | ||||
|     FireflyIII\Models\Tag::class, function (Faker\Generator $faker) { | ||||
|     return [ | ||||
|         'id'      => $faker->numberBetween(100, 150), | ||||
|         'id'      => $faker->unique()->numberBetween(200, 10000), | ||||
|         'user_id' => 1, | ||||
|         'tagMode' => 'nothing', | ||||
|         'tag'     => $faker->words(1, true), | ||||
|   | ||||
							
								
								
									
										51
									
								
								phpunit.coverage.specific.xml
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										51
									
								
								phpunit.coverage.specific.xml
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,51 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <!-- | ||||
|   ~ phpunit.coverage.specific.xml | ||||
|   ~ Copyright (c) 2017 thegrumpydictator@gmail.com | ||||
|   ~ 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. | ||||
|   --> | ||||
|  | ||||
| <phpunit backupGlobals="false" | ||||
|          backupStaticAttributes="false" | ||||
|          bootstrap="bootstrap/autoload.php" | ||||
|          colors="true" | ||||
|          convertErrorsToExceptions="true" | ||||
|          convertNoticesToExceptions="true" | ||||
|          convertWarningsToExceptions="true" | ||||
|          processIsolation="false" | ||||
|          beStrictAboutOutputDuringTests="true" | ||||
|          stopOnFailure="true"> | ||||
|     <testsuites> | ||||
|         <testsuite name="Feature Tests"> | ||||
|             <directory suffix="Test.php">./tests/Feature</directory> | ||||
|         </testsuite> | ||||
|  | ||||
|         <testsuite name="Unit Tests"> | ||||
|             <directory suffix="Test.php">./tests/Unit</directory> | ||||
|         </testsuite> | ||||
|     </testsuites> | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|     <filter> | ||||
|         <whitelist addUncoveredFilesFromWhitelist="true"> | ||||
|             <directory suffix=".php">./app</directory> | ||||
|         </whitelist> | ||||
|         <blacklist> | ||||
|             <directory>vendor/</directory> | ||||
|         </blacklist> | ||||
|     </filter> | ||||
|     <logging> | ||||
|         <log type="coverage-clover" target="./storage/build/clover-specific.xml" charset="UTF-8"/> | ||||
|     </logging> | ||||
|     <php> | ||||
|         <env name="APP_ENV" value="testing"/> | ||||
|         <env name="CACHE_DRIVER" value="array"/> | ||||
|         <env name="SESSION_DRIVER" value="array"/> | ||||
|         <env name="QUEUE_DRIVER" value="sync"/> | ||||
|     </php> | ||||
| </phpunit> | ||||
| @@ -32,7 +32,7 @@ | ||||
|         </blacklist> | ||||
|     </filter> | ||||
|     <logging> | ||||
|         <log type="coverage-clover" target="./storage/build/clover.xml" charset="UTF-8"/> | ||||
|         <log type="coverage-clover" target="./storage/build/clover-all.xml" charset="UTF-8"/> | ||||
|     </logging> | ||||
|     <php> | ||||
|         <env name="APP_ENV" value="testing"/> | ||||
|   | ||||
| @@ -7,7 +7,7 @@ | ||||
|  * See the LICENSE file for details. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types = 1); | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Tests\Feature\Controllers; | ||||
|  | ||||
| @@ -16,6 +16,7 @@ use FireflyIII\Helpers\Collector\JournalCollectorInterface; | ||||
| use FireflyIII\Models\Account; | ||||
| use FireflyIII\Models\AccountType; | ||||
| use FireflyIII\Models\Transaction; | ||||
| use FireflyIII\Models\TransactionCurrency; | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use FireflyIII\Repositories\Account\AccountTaskerInterface; | ||||
| @@ -105,6 +106,7 @@ class AccountControllerTest extends TestCase | ||||
|         $repository   = $this->mock(CurrencyRepositoryInterface::class); | ||||
|         $repository->shouldReceive('get')->andReturn(new Collection); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository->shouldReceive('find')->once()->andReturn(new TransactionCurrency()); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $account  = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first(); | ||||
| @@ -162,14 +164,16 @@ class AccountControllerTest extends TestCase | ||||
|  | ||||
|         $repository = $this->mock(AccountRepositoryInterface::class); | ||||
|         $repository->shouldReceive('oldestJournalDate')->andReturn(clone $date)->once(); | ||||
|         $repository->shouldReceive('getAccountsByType')->andReturn(new Collection)->once(); | ||||
|  | ||||
|         $transaction = factory(Transaction::class)->make(); | ||||
|         $collector   = $this->mock(JournalCollectorInterface::class); | ||||
|         $collector->shouldReceive('setAccounts')->andReturnSelf(); | ||||
|         $collector->shouldReceive('setRange')->andReturnSelf(); | ||||
|         $collector->shouldReceive('setLimit')->andReturnSelf(); | ||||
|         $collector->shouldReceive('withOpposingAccount')->andReturnSelf(); | ||||
|         $collector->shouldReceive('setPage')->andReturnSelf(); | ||||
|         $collector->shouldReceive('setTypes')->andReturnSelf(); | ||||
|         $collector->shouldReceive('getJournals')->andReturn(new Collection([$transaction])); | ||||
|         $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([$transaction], 0, 10)); | ||||
|  | ||||
|  | ||||
| @@ -198,6 +202,9 @@ class AccountControllerTest extends TestCase | ||||
|         $collector->shouldReceive('setRange')->andReturnSelf(); | ||||
|         $collector->shouldReceive('setLimit')->andReturnSelf(); | ||||
|         $collector->shouldReceive('setPage')->andReturnSelf(); | ||||
|  | ||||
|         $collector->shouldReceive('setTypes')->andReturnSelf(); | ||||
|  | ||||
|         $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([$transaction], 0, 10)); | ||||
|  | ||||
|  | ||||
| @@ -249,14 +256,14 @@ class AccountControllerTest extends TestCase | ||||
|         $collector->shouldReceive('setRange')->andReturnSelf(); | ||||
|         $collector->shouldReceive('setLimit')->andReturnSelf(); | ||||
|         $collector->shouldReceive('setPage')->andReturnSelf(); | ||||
|  | ||||
|         $collector->shouldReceive('setTypes')->andReturnSelf(); | ||||
|         $collector->shouldReceive('withOpposingAccount')->andReturnSelf(); | ||||
|         $collector->shouldReceive('getJournals')->andReturn(new Collection([$transaction])); | ||||
|         $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([$transaction], 0, 10)); | ||||
|  | ||||
|         $tasker     = $this->mock(AccountTaskerInterface::class); | ||||
|         $repository = $this->mock(AccountRepositoryInterface::class); | ||||
|         $repository->shouldReceive('oldestJournalDate')->andReturn(new Carbon)->once(); | ||||
|         $repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET, AccountType::DEFAULT]])->once()->andReturn(new Collection); | ||||
|         $tasker->shouldReceive('amountOutInPeriod')->withAnyArgs()->andReturn('-1'); | ||||
|         $tasker->shouldReceive('amountInInPeriod')->withAnyArgs()->andReturn('1'); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $this->changeDateRange($this->user(), $range); | ||||
| @@ -284,12 +291,12 @@ class AccountControllerTest extends TestCase | ||||
|         $collector->shouldReceive('setPage')->andReturnSelf(); | ||||
|         $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10)); | ||||
|  | ||||
|         $tasker     = $this->mock(AccountTaskerInterface::class); | ||||
|         $repository = $this->mock(AccountRepositoryInterface::class); | ||||
|         $repository->shouldReceive('oldestJournalDate')->andReturn(new Carbon); | ||||
|         $repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET, AccountType::DEFAULT]])->once()->andReturn(new Collection); | ||||
|         $tasker->shouldReceive('amountOutInPeriod')->withAnyArgs()->andReturn('-1'); | ||||
|         $tasker->shouldReceive('amountInInPeriod')->withAnyArgs()->andReturn('1'); | ||||
|  | ||||
|         $collector->shouldReceive('setTypes')->andReturnSelf(); | ||||
|         $collector->shouldReceive('withOpposingAccount')->andReturnSelf(); | ||||
|         $collector->shouldReceive('getJournals')->andReturn(new Collection); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $this->changeDateRange($this->user(), $range); | ||||
|   | ||||
| @@ -304,17 +304,6 @@ class AccountControllerTest extends TestCase | ||||
|         $response->assertStatus(200); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers                   \FireflyIII\Http\Controllers\Chart\AccountController::period | ||||
|      * @expectedExceptionMessage YYYY-MM-DD | ||||
|      */ | ||||
|     public function testPeriodBadDate() | ||||
|     { | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('chart.account.period', [1, 'bcdefed'])); | ||||
|         $response->assertStatus(500); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\Chart\AccountController::report | ||||
|      * @covers \FireflyIII\Http\Controllers\Chart\AccountController::accountBalanceChart | ||||
|   | ||||
| @@ -123,7 +123,7 @@ class CategoryReportControllerTest extends TestCase | ||||
|     { | ||||
|         $generator   = $this->mock(GeneratorInterface::class); | ||||
|         $collector   = $this->mock(JournalCollectorInterface::class); | ||||
|         $transaction = factory(Transaction::class)->make(); | ||||
|         $transactions = factory(Transaction::class, 10)->make(); | ||||
|  | ||||
|         $collector->shouldReceive('setAccounts')->andReturnSelf(); | ||||
|         $collector->shouldReceive('setRange')->andReturnSelf(); | ||||
| @@ -132,7 +132,7 @@ class CategoryReportControllerTest extends TestCase | ||||
|         $collector->shouldReceive('disableFilter')->andReturnSelf(); | ||||
|         $collector->shouldReceive('setCategories')->andReturnSelf(); | ||||
|         $collector->shouldReceive('withOpposingAccount')->andReturnSelf(); | ||||
|         $collector->shouldReceive('getJournals')->andReturn(new Collection([$transaction])); | ||||
|         $collector->shouldReceive('getJournals')->andReturn($transactions); | ||||
|         $generator->shouldReceive('multiSet')->andReturn([])->once(); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|   | ||||
| @@ -7,7 +7,7 @@ | ||||
|  * See the LICENSE file for details. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types = 1); | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Tests\Feature\Controllers\Chart; | ||||
|  | ||||
| @@ -33,6 +33,7 @@ class ReportControllerTest extends TestCase | ||||
|     public function testNetWorth() | ||||
|     { | ||||
|         $generator = $this->mock(GeneratorInterface::class); | ||||
|         $tasker    = $this->mock(AccountTaskerInterface::class); | ||||
|  | ||||
|         Steam::shouldReceive('balancesById')->andReturn(['5', '10']); | ||||
|         $generator->shouldReceive('singleSet')->andReturn([]); | ||||
| @@ -50,9 +51,10 @@ class ReportControllerTest extends TestCase | ||||
|     { | ||||
|         $generator = $this->mock(GeneratorInterface::class); | ||||
|         $tasker    = $this->mock(AccountTaskerInterface::class); | ||||
|  | ||||
|         $tasker->shouldReceive('amountOutInPeriod')->andReturn('-1'); | ||||
|         $tasker->shouldReceive('amountInInPeriod')->andReturn('1'); | ||||
|         $income    = [1 => ['sum' => '100']]; | ||||
|         $expense   = [2 => ['sum' => '-100']]; | ||||
|         $tasker->shouldReceive('getIncomeReport')->once()->andReturn($income); | ||||
|         $tasker->shouldReceive('getExpenseReport')->once()->andReturn($expense); | ||||
|         $generator->shouldReceive('multiSet')->andReturn([]); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
| @@ -69,8 +71,11 @@ class ReportControllerTest extends TestCase | ||||
|         $generator = $this->mock(GeneratorInterface::class); | ||||
|         $tasker    = $this->mock(AccountTaskerInterface::class); | ||||
|  | ||||
|         $tasker->shouldReceive('amountOutInPeriod')->andReturn('-1'); | ||||
|         $tasker->shouldReceive('amountInInPeriod')->andReturn('1'); | ||||
|         $income  = []; | ||||
|         $expense = []; | ||||
|         $tasker->shouldReceive('getIncomeReport')->andReturn($income)->times(1); | ||||
|         $tasker->shouldReceive('getExpenseReport')->andReturn($expense)->times(1); | ||||
|  | ||||
|         $generator->shouldReceive('multiSet')->andReturn([]); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|   | ||||
| @@ -122,11 +122,17 @@ class TagReportControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testMainChart() | ||||
|     { | ||||
|         $generator   = $this->mock(GeneratorInterface::class); | ||||
|         $collector   = $this->mock(JournalCollectorInterface::class); | ||||
|         $transaction = factory(Transaction::class)->make(); | ||||
|         $tag         = factory(Tag::class)->make(); | ||||
|         $transaction->transactionJournal->tags()->save($tag); | ||||
|         $generator = $this->mock(GeneratorInterface::class); | ||||
|         $collector = $this->mock(JournalCollectorInterface::class); | ||||
|         $set       = new Collection; | ||||
|         for ($i = 0; $i < 10; $i++) { | ||||
|  | ||||
|  | ||||
|             $transaction = factory(Transaction::class)->make(); | ||||
|             $tag         = factory(Tag::class)->make(); | ||||
|             $transaction->transactionJournal->tags()->save($tag); | ||||
|             $set->push($transaction); | ||||
|         } | ||||
|  | ||||
|  | ||||
|         $collector->shouldReceive('setAccounts')->andReturnSelf(); | ||||
| @@ -136,7 +142,7 @@ class TagReportControllerTest extends TestCase | ||||
|         $collector->shouldReceive('disableFilter')->andReturnSelf(); | ||||
|         $collector->shouldReceive('setTags')->andReturnSelf(); | ||||
|         $collector->shouldReceive('withOpposingAccount')->andReturnSelf(); | ||||
|         $collector->shouldReceive('getJournals')->andReturn(new Collection([$transaction])); | ||||
|         $collector->shouldReceive('getJournals')->andReturn($set); | ||||
|         $generator->shouldReceive('multiSet')->andReturn([])->once(); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|   | ||||
| @@ -26,6 +26,20 @@ use Tests\TestCase; | ||||
|  */ | ||||
| class JavascriptControllerTest extends TestCase | ||||
| { | ||||
|     /** | ||||
|      * @covers       \FireflyIII\Http\Controllers\JavascriptController::currencies | ||||
|      */ | ||||
|     public function testCurrencies() | ||||
|     { | ||||
|         $repository = $this->mock(CurrencyRepositoryInterface::class); | ||||
|         $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); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers       \FireflyIII\Http\Controllers\JavascriptController::accounts | ||||
|      */ | ||||
|   | ||||
							
								
								
									
										55
									
								
								tests/Feature/Controllers/Json/ExchangeControllerTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								tests/Feature/Controllers/Json/ExchangeControllerTest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,55 @@ | ||||
| <?php | ||||
| /** | ||||
|  * ExchangeControllerTest.php | ||||
|  * Copyright (c) 2017 thegrumpydictator@gmail.com | ||||
|  * 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\CurrencyExchangeRate; | ||||
| use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; | ||||
| use Tests\TestCase; | ||||
|  | ||||
| /** | ||||
|  * Class ExchangeControllerTest | ||||
|  * | ||||
|  * @package Tests\Feature\Controllers | ||||
|  */ | ||||
| class ExchangeControllerTest extends TestCase | ||||
| { | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\Json\ExchangeController::getRate | ||||
|      */ | ||||
|     public function testGetRate() | ||||
|     { | ||||
|         $repository = $this->mock(CurrencyRepositoryInterface::class); | ||||
|  | ||||
|         $rate = factory(CurrencyExchangeRate::class)->make(); | ||||
|         $repository->shouldReceive('getExchangeRate')->andReturn($rate); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('json.rate', ['EUR', 'USD', '20170101'])); | ||||
|         $response->assertStatus(200); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\Json\ExchangeController::getRate | ||||
|      */ | ||||
|     public function testGetRateAmount() | ||||
|     { | ||||
|         $repository = $this->mock(CurrencyRepositoryInterface::class); | ||||
|         $rate       = factory(CurrencyExchangeRate::class)->make(); | ||||
|         $repository->shouldReceive('getExchangeRate')->andReturn($rate); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('json.rate', ['EUR', 'USD', '20170101']) . '?amount=10'); | ||||
|         $response->assertStatus(200); | ||||
|     } | ||||
| } | ||||
| @@ -7,7 +7,7 @@ | ||||
|  * See the LICENSE file for details. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types = 1); | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Tests\Feature\Controllers; | ||||
|  | ||||
| @@ -17,7 +17,9 @@ use FireflyIII\Models\AccountType; | ||||
| use FireflyIII\Models\Budget; | ||||
| use FireflyIII\Models\Category; | ||||
| use FireflyIII\Models\Tag; | ||||
| use FireflyIII\Models\Transaction; | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
| use FireflyIII\Models\TransactionType; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use FireflyIII\Repositories\Account\AccountTaskerInterface; | ||||
| use FireflyIII\Repositories\Bill\BillRepositoryInterface; | ||||
| @@ -123,13 +125,18 @@ class JsonControllerTest extends TestCase | ||||
|         // mock stuff | ||||
|         $accountRepos = $this->mock(AccountRepositoryInterface::class); | ||||
|         $tasker       = $this->mock(AccountTaskerInterface::class); | ||||
|         $collector    = $this->mock(JournalCollectorInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $accountRepos->shouldReceive('getAccountsByType')->withArgs([([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH])])->once()->andReturn( | ||||
|             new Collection | ||||
|         ); | ||||
|         $accountRepos->shouldReceive('getAccountsByType')->withArgs([([AccountType::DEFAULT, AccountType::ASSET])])->once()->andReturn(new Collection); | ||||
|         $tasker->shouldReceive('amountInInPeriod')->andReturn('100'); | ||||
|         $transaction                     = factory(Transaction::class)->make(); | ||||
|         $transaction->transaction_amount = '100.00'; | ||||
|  | ||||
|         $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once(); | ||||
|         $collector->shouldReceive('setRange')->andReturnSelf()->once(); | ||||
|         $collector->shouldReceive('getJournals')->andReturn(new Collection([$transaction]))->once(); | ||||
|         $collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->andReturnSelf()->once(); | ||||
|         $collector->shouldReceive('withOpposingAccount')->andReturnSelf()->once(); | ||||
|  | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('json.box.in')); | ||||
| @@ -145,13 +152,17 @@ class JsonControllerTest extends TestCase | ||||
|         // mock stuff | ||||
|         $accountRepos = $this->mock(AccountRepositoryInterface::class); | ||||
|         $tasker       = $this->mock(AccountTaskerInterface::class); | ||||
|         $collector    = $this->mock(JournalCollectorInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $accountRepos->shouldReceive('getAccountsByType')->withArgs([([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH])])->once()->andReturn( | ||||
|             new Collection | ||||
|         ); | ||||
|         $accountRepos->shouldReceive('getAccountsByType')->withArgs([([AccountType::DEFAULT, AccountType::ASSET])])->once()->andReturn(new Collection); | ||||
|         $tasker->shouldReceive('amountOutInPeriod')->andReturn('100'); | ||||
|         $transaction                     = factory(Transaction::class)->make(); | ||||
|         $transaction->transaction_amount = '100.00'; | ||||
|  | ||||
|         $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once(); | ||||
|         $collector->shouldReceive('setRange')->andReturnSelf()->once(); | ||||
|         $collector->shouldReceive('getJournals')->andReturn(new Collection([$transaction]))->once(); | ||||
|         $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->once(); | ||||
|         $collector->shouldReceive('withOpposingAccount')->andReturnSelf()->once(); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('json.box.out')); | ||||
| @@ -165,7 +176,7 @@ class JsonControllerTest extends TestCase | ||||
|     public function testBudgets() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $budget = factory(Budget::class)->make(); | ||||
|         $budget        = factory(Budget::class)->make(); | ||||
|         $categoryRepos = $this->mock(BudgetRepositoryInterface::class); | ||||
|         $journalRepos  = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
| @@ -280,22 +291,6 @@ class JsonControllerTest extends TestCase | ||||
|         $response->assertStatus(200); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\JsonController::transactionTypes | ||||
|      */ | ||||
|     public function testTransactionTypes() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $journalRepos->shouldReceive('getTransactionTypes')->once()->andReturn(new Collection); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('json.transaction-types', ['deposit'])); | ||||
|         $response->assertStatus(200); | ||||
|         $response->assertExactJson([]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\JsonController::transactionJournals | ||||
|      */ | ||||
| @@ -316,6 +311,22 @@ class JsonControllerTest extends TestCase | ||||
|         $response->assertExactJson([]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\JsonController::transactionTypes | ||||
|      */ | ||||
|     public function testTransactionTypes() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $journalRepos->shouldReceive('getTransactionTypes')->once()->andReturn(new Collection); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('json.transaction-types', ['deposit'])); | ||||
|         $response->assertStatus(200); | ||||
|         $response->assertExactJson([]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\JsonController::trigger | ||||
|      */ | ||||
|   | ||||
| @@ -161,9 +161,11 @@ class PiggyBankControllerTest extends TestCase | ||||
|         // mock stuff | ||||
|         $repository   = $this->mock(PiggyBankRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $piggyBank    = factory(PiggyBank::class)->make(); | ||||
|         $one = factory(PiggyBank::class)->make(); | ||||
|         $two = factory(PiggyBank::class)->make(); | ||||
|         $two->account_id = $one->account_id; | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository->shouldReceive('getPiggyBanks')->andReturn(new Collection([$piggyBank])); | ||||
|         $repository->shouldReceive('getPiggyBanks')->andReturn(new Collection([$one, $two])); | ||||
|  | ||||
|         Steam::shouldReceive('balanceIgnoreVirtual')->twice()->andReturn('1'); | ||||
|  | ||||
|   | ||||
| @@ -26,8 +26,6 @@ class OperationsControllerTest extends TestCase | ||||
| { | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\Report\OperationsController::expenses | ||||
|      * @covers \FireflyIII\Http\Controllers\Report\OperationsController::getExpenseReport | ||||
|      * @covers \FireflyIII\Http\Controllers\Report\OperationsController::groupByOpposing | ||||
|      */ | ||||
|     public function testExpenses() | ||||
|     { | ||||
| @@ -49,7 +47,6 @@ class OperationsControllerTest extends TestCase | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\Report\OperationsController::income | ||||
|      * @covers \FireflyIII\Http\Controllers\Report\OperationsController::getIncomeReport | ||||
|      */ | ||||
|     public function testIncome() | ||||
|     { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user