diff --git a/app/Http/Controllers/BillController.php b/app/Http/Controllers/BillController.php index 2990b32e35..dd41c0304a 100644 --- a/app/Http/Controllers/BillController.php +++ b/app/Http/Controllers/BillController.php @@ -196,7 +196,11 @@ class BillController extends Controller $parameters = new ParameterBag(); $parameters->set('start', $start); $parameters->set('end', $end); - $transformer = new BillTransformer($parameters); + + /** @var BillTransformer $transformer */ + $transformer = app(BillTransformer::class); + $transformer->setParameters($parameters); + /** @var Collection $bills */ $bills = $paginator->getCollection()->map( function (Bill $bill) use ($transformer) { @@ -294,7 +298,12 @@ class BillController extends Controller $parameters = new ParameterBag(); $parameters->set('start', $start); $parameters->set('end', $end); - $resource = new Item($bill, new BillTransformer($parameters), 'bill'); + + /** @var BillTransformer $transformer */ + $transformer = app(BillTransformer::class); + $transformer->setParameters($parameters); + + $resource = new Item($bill, $transformer, 'bill'); $object = $manager->createData($resource)->toArray(); $object['data']['currency'] = $bill->transactionCurrency; diff --git a/app/Http/Controllers/PiggyBankController.php b/app/Http/Controllers/PiggyBankController.php index bc23632b74..fff7716d4a 100644 --- a/app/Http/Controllers/PiggyBankController.php +++ b/app/Http/Controllers/PiggyBankController.php @@ -244,9 +244,15 @@ class PiggyBankController extends Controller // transform piggies using the transformer: $parameters = new ParameterBag; $parameters->set('end', $end); - $transformed = new Collection; - $transformer = new PiggyBankTransformer(new ParameterBag); - $accountTransformer = new AccountTransformer($parameters); + $transformed = new Collection; + + /** @var PiggyBankTransformer $transformer */ + $transformer = app(PiggyBankTransformer::class); + $transformer->setParameters(new ParameterBag); + + /** @var AccountTransformer $accountTransformer */ + $accountTransformer = app(AccountTransformer::class); + $accountTransformer->setParameters($parameters); /** @var PiggyBank $piggy */ foreach ($collection as $piggy) { $array = $transformer->transform($piggy); @@ -435,7 +441,10 @@ class PiggyBankController extends Controller // transform piggies using the transformer: $parameters = new ParameterBag; $parameters->set('end', $end); - $transformer = new PiggyBankTransformer(new ParameterBag); + + /** @var PiggyBankTransformer $transformer */ + $transformer = app(PiggyBankTransformer::class); + $transformer->setParameters($parameters); $piggy = $transformer->transform($piggyBank); $events = $this->piggyRepos->getEvents($piggyBank); $subTitle = $piggyBank->name; diff --git a/app/Http/Controllers/Recurring/EditController.php b/app/Http/Controllers/Recurring/EditController.php index c77733b9c0..f9ee3f51cf 100644 --- a/app/Http/Controllers/Recurring/EditController.php +++ b/app/Http/Controllers/Recurring/EditController.php @@ -81,7 +81,10 @@ class EditController extends Controller */ public function edit(Request $request, Recurrence $recurrence) { - $transformer = new RecurrenceTransformer(new ParameterBag); + /** @var RecurrenceTransformer $transformer */ + $transformer = app(RecurrenceTransformer::class); + $transformer->setParameters(new ParameterBag); + $array = $transformer->transform($recurrence); $budgets = app('expandedform')->makeSelectListWithEmpty($this->budgets->getActiveBudgets()); diff --git a/app/Http/Controllers/Recurring/IndexController.php b/app/Http/Controllers/Recurring/IndexController.php index e26a5507fe..1c1f2719e1 100644 --- a/app/Http/Controllers/Recurring/IndexController.php +++ b/app/Http/Controllers/Recurring/IndexController.php @@ -86,7 +86,10 @@ class IndexController extends Controller /** @var Collection $recurrences */ $recurrences = $collection->slice(($page - 1) * $pageSize, $pageSize); - $transformer = new RecurrenceTransformer(new ParameterBag); + /** @var RecurrenceTransformer $transformer */ + $transformer = app(RecurrenceTransformer::class); + $transformer->setParameters(new ParameterBag); + $recurring = []; /** @var Recurrence $recurrence */ foreach ($recurrences as $recurrence) { @@ -114,7 +117,10 @@ class IndexController extends Controller */ public function show(Recurrence $recurrence) { - $transformer = new RecurrenceTransformer(new ParameterBag); + /** @var RecurrenceTransformer $transformer */ + $transformer = app(RecurrenceTransformer::class); + $transformer->setParameters(new ParameterBag); + $array = $transformer->transform($recurrence); $transactions = $this->recurring->getTransactions($recurrence); diff --git a/app/Http/Controllers/Transaction/MassController.php b/app/Http/Controllers/Transaction/MassController.php index f70652c4f8..e367da91d0 100644 --- a/app/Http/Controllers/Transaction/MassController.php +++ b/app/Http/Controllers/Transaction/MassController.php @@ -142,7 +142,10 @@ class MassController extends Controller $this->rememberPreviousUri('transactions.mass-edit.uri'); - $transformer = new TransactionTransformer(new ParameterBag); + /** @var TransactionTransformer $transformer */ + $transformer = app(TransactionTransformer::class); + $transformer->setParameters(new ParameterBag); + /** @var TransactionCollectorInterface $collector */ $collector = app(TransactionCollectorInterface::class); $collector->setUser($user); diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index 2cabef11f7..480a4e29ea 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -253,7 +253,11 @@ class TransactionController extends Controller $collector->setJournals(new Collection([$journal])); $set = $collector->getTransactions(); $transactions = []; - $transformer = new TransactionTransformer(new ParameterBag); + + /** @var TransactionTransformer $transformer */ + $transformer = app(TransactionTransformer::class); + $transformer->setParameters(new ParameterBag); + /** @var Transaction $transaction */ foreach ($set as $transaction) { $transactions[] = $transformer->transform($transaction); diff --git a/app/Http/Requests/SplitJournalFormRequest.php b/app/Http/Requests/SplitJournalFormRequest.php index 0ad4321f26..caed4c9d5f 100644 --- a/app/Http/Requests/SplitJournalFormRequest.php +++ b/app/Http/Requests/SplitJournalFormRequest.php @@ -95,7 +95,7 @@ class SplitJournalFormRequest extends Request 'foreign_currency_code' => null, 'reconciled' => false, 'identifier' => $index, - 'currency_id' => (int)$transaction['transaction_currency_id'], + 'currency_id' => (int)$transaction['currency_id'], 'currency_code' => null, 'description' => $transaction['transaction_description'] ?? '', 'amount' => $transaction['amount'] ?? '', diff --git a/app/Support/Http/Controllers/RequestInformation.php b/app/Support/Http/Controllers/RequestInformation.php index d44fcd1630..33fcdce409 100644 --- a/app/Support/Http/Controllers/RequestInformation.php +++ b/app/Support/Http/Controllers/RequestInformation.php @@ -230,7 +230,10 @@ trait RequestInformation $collector->setJournals(new Collection([$journal])); $set = $collector->getTransactions(); $transactions = []; - $transformer = new TransactionTransformer(new ParameterBag); + + /** @var TransactionTransformer $transformer */ + $transformer = app(TransactionTransformer::class); + $transformer->setParameters(new ParameterBag()); /** @var Transaction $transaction */ foreach ($set as $transaction) { $res = []; diff --git a/database/factories/AccountFactory.php b/database/factories/AccountFactory.php index da08fd82c2..055cb4cbb6 100644 --- a/database/factories/AccountFactory.php +++ b/database/factories/AccountFactory.php @@ -28,7 +28,7 @@ $factory->define( FireflyIII\Models\Account::class, function (Faker\Generator $faker) { return [ - //'id' => $faker->unique()->numberBetween(1000, 10000), + 'id' => $faker->unique()->numberBetween(1000, 10000), 'user_id' => 1, 'created_at' => new Carbon, 'updated_at' => new Carbon, diff --git a/resources/views/v1/transactions/split/edit.twig b/resources/views/v1/transactions/split/edit.twig index bb6e571644..c6a06fc0f5 100644 --- a/resources/views/v1/transactions/split/edit.twig +++ b/resources/views/v1/transactions/split/edit.twig @@ -56,7 +56,7 @@

- {{ formatAmountBySymbol(preFilled.journal_amount, preFilled.transactions[0].currency_symbol, preFilled.transactions[0].currency_dp) }} + {{ formatAmountBySymbol(preFilled.journal_amount|default("0"), preFilled.transactions[0].currency_symbol|default("x"), preFilled.transactions[0].currency_dp) }}

diff --git a/tests/Feature/Controllers/BillControllerTest.php b/tests/Feature/Controllers/BillControllerTest.php index 901e93519e..c4bb7799bc 100644 --- a/tests/Feature/Controllers/BillControllerTest.php +++ b/tests/Feature/Controllers/BillControllerTest.php @@ -34,6 +34,7 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface; use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\TransactionRules\TransactionMatcher; +use FireflyIII\Transformers\BillTransformer; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Collection; use Illuminate\Support\MessageBag; @@ -168,6 +169,12 @@ class BillControllerTest extends TestCase $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class); $userRepos = $this->mock(UserRepositoryInterface::class); $currencyRepos = $this->mock(CurrencyRepositoryInterface::class); + $transformer = $this->mock(BillTransformer::class); + + $transformer->shouldReceive('setParameters')->atLeast()->once(); + $transformer->shouldReceive('transform')->atLeast()->once()->andReturn( + ['id' => 5, 'active' => true, 'name' => 'x', 'next_expected_match' => '2018-01-01'] + ); $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once(); $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); @@ -175,7 +182,6 @@ class BillControllerTest extends TestCase $repository->shouldReceive('getPaginator')->andReturn(new LengthAwarePaginator($collection, 1, 50))->once(); $repository->shouldReceive('setUser'); $repository->shouldReceive('getNoteText')->andReturn('Hi there'); - $repository->shouldReceive('getPaidDatesInRange')->twice()->andReturn(new Collection([new Carbon, new Carbon, new Carbon])); $repository->shouldReceive('getRulesForBills')->andReturn([]); @@ -254,33 +260,42 @@ class BillControllerTest extends TestCase $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class); $userRepos = $this->mock(UserRepositoryInterface::class); $currencyRepos = $this->mock(CurrencyRepositoryInterface::class); + $transformer = $this->mock(BillTransformer::class); + + $transformer->shouldReceive('setParameters')->atLeast()->once(); + $transformer->shouldReceive('setCurrentScope')->atLeast()->once(); + $transformer->shouldReceive('getDefaultIncludes')->atLeast()->once(); + $transformer->shouldReceive('getAvailableIncludes')->atLeast()->once(); + $transformer->shouldReceive('transform')->atLeast()->once()->andReturn( + ['id' => 5, 'active' => true, 'name' => 'x', 'next_expected_match' => '2018-01-01', + 'currency_symbol' => 'x','amount_min' => '10','amount_max' => '15' + ] + ); + $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once(); $repository->shouldReceive('getYearAverage')->andReturn('0'); $repository->shouldReceive('getOverallAverage')->andReturn('0'); - $repository->shouldReceive('nextExpectedMatch')->andReturn(new Carbon); +// $repository->shouldReceive('nextExpectedMatch')->andReturn(new Carbon); $repository->shouldReceive('getRulesForBill')->andReturn(new Collection); - $repository->shouldReceive('getNoteText')->andReturn('Hi there'); +// $repository->shouldReceive('getNoteText')->andReturn('Hi there'); $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); - +// $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf(); $collector->shouldReceive('setBills')->andReturnSelf(); $collector->shouldReceive('setLimit')->andReturnSelf(); $collector->shouldReceive('setPage')->andReturnSelf(); - $collector->shouldReceive('withBudgetInformation')->andReturnSelf(); $collector->shouldReceive('withCategoryInformation')->andReturnSelf(); $collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10)); - $repository->shouldReceive('getPaidDatesInRange')->twice()->andReturn(new Collection([new Carbon, new Carbon, new Carbon])); - $repository->shouldReceive('setUser'); +// $repository->shouldReceive('getPaidDatesInRange')->twice()->andReturn(new Collection([new Carbon, new Carbon, new Carbon])); +// $repository->shouldReceive('setUser'); $this->be($this->user()); $response = $this->get(route('bills.show', [1])); $response->assertStatus(200); // has bread crumb $response->assertSee('