How to use AtLeast class

Best Phake code snippet using AtLeast

TransactionJournalFactoryTest.php

Source:TransactionJournalFactoryTest.php Github

copy

Full Screen

1<?php2/**3 * TransactionJournalFactoryTest.php4 * Copyright (c) 2019 james@firefly-iii.org5 *6 * This file is part of Firefly III (https://github.com/firefly-iii).7 *8 * This program is free software: you can redistribute it and/or modify9 * it under the terms of the GNU Affero General Public License as10 * published by the Free Software Foundation, either version 3 of the11 * License, or (at your option) any later version.12 *13 * This program is distributed in the hope that it will be useful,14 * but WITHOUT ANY WARRANTY; without even the implied warranty of15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the16 * GNU Affero General Public License for more details.17 *18 * You should have received a copy of the GNU Affero General Public License19 * along with this program. If not, see <https://www.gnu.org/licenses/>.20 */21declare(strict_types=1);22namespace Tests\Unit\Factory;23use Amount;24use FireflyIII\Exceptions\FireflyException;25use FireflyIII\Factory\AccountFactory;26use FireflyIII\Factory\PiggyBankEventFactory;27use FireflyIII\Factory\TagFactory;28use FireflyIII\Factory\TransactionCurrencyFactory;29use FireflyIII\Factory\TransactionFactory;30use FireflyIII\Factory\TransactionJournalFactory;31use FireflyIII\Factory\TransactionJournalMetaFactory;32use FireflyIII\Models\PiggyBankEvent;33use FireflyIII\Models\Transaction;34use FireflyIII\Models\TransactionJournal;35use FireflyIII\Models\TransactionType;36use FireflyIII\Repositories\Account\AccountRepositoryInterface;37use FireflyIII\Repositories\Bill\BillRepositoryInterface;38use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;39use FireflyIII\Repositories\Category\CategoryRepositoryInterface;40use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;41use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;42use FireflyIII\Repositories\TransactionType\TransactionTypeRepositoryInterface;43use FireflyIII\Validation\AccountValidator;44use Log;45use Tests\TestCase;46/**47 * Class TransactionJournalFactoryTest48 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)49 * @SuppressWarnings(PHPMD.ExcessiveMethodLength)50 * @SuppressWarnings(PHPMD.TooManyPublicMethods)51 */52class TransactionJournalFactoryTest extends TestCase53{54 /**55 *56 */57 public function setUp(): void58 {59 parent::setUp();60 Log::info(sprintf('Now in %s.', get_class($this)));61 }62 /**63 * Submit empty array.64 *65 * @covers \FireflyIII\Factory\TransactionJournalFactory66 * @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait67 */68 public function testCreate(): void69 {70 $billRepos = $this->mock(BillRepositoryInterface::class);71 $budgetRepos = $this->mock(BudgetRepositoryInterface::class);72 $catRepos = $this->mock(CategoryRepositoryInterface::class);73 $curRepos = $this->mock(CurrencyRepositoryInterface::class);74 $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);75 $tagFactory = $this->mock(TagFactory::class);76 $transactionFactory = $this->mock(TransactionFactory::class);77 $accountRepos = $this->mock(AccountRepositoryInterface::class);78 $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class);79 $eventFactory = $this->mock(PiggyBankEventFactory::class);80 $accountFactory = $this->mock(AccountFactory::class);81 $currencyFactory = $this->mock(TransactionCurrencyFactory::class);82 $metaFactory = $this->mock(TransactionJournalMetaFactory::class);83 $validator = $this->mock(AccountValidator::class);84 $submission = [];85 // mock calls to all repositories86 $curRepos->shouldReceive('setUser')->atLeast()->once();87 $billRepos->shouldReceive('setUser')->atLeast()->once();88 $budgetRepos->shouldReceive('setUser')->atLeast()->once();89 $catRepos->shouldReceive('setUser')->atLeast()->once();90 $piggyRepos->shouldReceive('setUser')->atLeast()->once();91 $accountRepos->shouldReceive('setUser')->atLeast()->once();92 $tagFactory->shouldReceive('setUser')->atLeast()->once();93 $transactionFactory->shouldReceive('setUser')->atLeast()->once();94 /** @var TransactionJournalFactory $factory */95 $factory = app(TransactionJournalFactory::class);96 $factory->setUser($this->user());97 Log::warning('The following error is part of a test.');98 try {99 $collection = $factory->create($submission);100 } catch (FireflyException $e) {101 $this->assertTrue(false, $e->getMessage());102 return;103 }104 $this->assertCount(0, $collection);105 }106 /**107 * Submit minimal array for a withdrawal.108 * @covers \FireflyIII\Factory\TransactionJournalFactory109 * @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait110 */111 public function testCreateWithdrawal(): void112 {113 $billRepos = $this->mock(BillRepositoryInterface::class);114 $budgetRepos = $this->mock(BudgetRepositoryInterface::class);115 $catRepos = $this->mock(CategoryRepositoryInterface::class);116 $curRepos = $this->mock(CurrencyRepositoryInterface::class);117 $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);118 $tagFactory = $this->mock(TagFactory::class);119 $accountRepos = $this->mock(AccountRepositoryInterface::class);120 $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class);121 $eventFactory = $this->mock(PiggyBankEventFactory::class);122 $accountFactory = $this->mock(AccountFactory::class);123 $currencyFactory = $this->mock(TransactionCurrencyFactory::class);124 $metaFactory = $this->mock(TransactionJournalMetaFactory::class);125 $transactionFactory = $this->mock(TransactionFactory::class);126 $validator = $this->mock(AccountValidator::class);127 $validator->shouldReceive('setUser')->atLeast()->once();128 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);129 $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue();130 $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue();131 // data132 $withdrawal = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();133 $asset = $this->getRandomAsset();134 $expense = $this->getRandomExpense();135 $euro = $this->getEuro();136 $submission = [137 'transactions' => [138 [139 'type' => 'withdrawal',140 'amount' => '10',141 'description' => sprintf('I am a test #%d', $this->randomInt()),142 'source_id' => $asset->id,143 'destination_id' => $expense->id,144 ],145 ],146 ];147 // mock calls to all repositories148 $curRepos->shouldReceive('setUser')->atLeast()->once();149 $billRepos->shouldReceive('setUser')->atLeast()->once();150 $budgetRepos->shouldReceive('setUser')->atLeast()->once();151 $catRepos->shouldReceive('setUser')->atLeast()->once();152 $piggyRepos->shouldReceive('setUser')->atLeast()->once();153 $accountRepos->shouldReceive('setUser')->atLeast()->once();154 $tagFactory->shouldReceive('setUser')->atLeast()->once();155 $transactionFactory->shouldReceive('setUser')->atLeast()->once();156 $transactionFactory->shouldReceive('setJournal')->atLeast()->once();157 $transactionFactory->shouldReceive('setAccount')->atLeast()->once();158 $transactionFactory->shouldReceive('setCurrency')->atLeast()->once();159 $transactionFactory->shouldReceive('setForeignCurrency')->atLeast()->once();160 $transactionFactory->shouldReceive('setReconciled')->atLeast()->once();161 $transactionFactory->shouldReceive('createNegative')->atLeast()->once()->andReturn(new Transaction);162 $transactionFactory->shouldReceive('createPositive')->atLeast()->once()->andReturn(new Transaction);163 $typeRepos->shouldReceive('findTransactionType')->withArgs([null, 'withdrawal'])->atLeast()->once()->andReturn($withdrawal);164 $curRepos->shouldReceive('findCurrency')->atLeast()->once()->withArgs([0, null])->andReturn($euro);165 $curRepos->shouldReceive('findCurrencyNull')->atLeast()->once()->withArgs([0, null])->andReturn($euro);166 $billRepos->shouldReceive('findBill')->withArgs([0, null])->atLeast()->once()->andReturnNull();167 $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->atLeast()->once()->andReturn($asset);168 $accountRepos->shouldReceive('findNull')->withArgs([$expense->id])->atLeast()->once()->andReturn($expense);169 $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);170 $budgetRepos->shouldReceive('findBudget')->withArgs([0, null])->atLeast()->once()->andReturnNull();171 $catRepos->shouldReceive('findCategory')->withArgs([0, null])->atLeast()->once()->andReturnNull();172 $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once();173 /** @var TransactionJournalFactory $factory */174 $factory = app(TransactionJournalFactory::class);175 $factory->setUser($this->user());176 try {177 $collection = $factory->create($submission);178 } catch (FireflyException $e) {179 $this->assertTrue(false, $e->getMessage());180 return;181 }182 $this->assertCount(1, $collection);183 /** @var TransactionJournal $first */184 $first = $collection->first();185 $this->assertEquals($first->description, $submission['transactions'][0]['description']);186 $first->forceDelete();187 }188 /**189 * Submit minimal array for a deposit.190 * @covers \FireflyIII\Factory\TransactionJournalFactory191 * @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait192 */193 public function testCreateDeposit(): void194 {195 $billRepos = $this->mock(BillRepositoryInterface::class);196 $budgetRepos = $this->mock(BudgetRepositoryInterface::class);197 $catRepos = $this->mock(CategoryRepositoryInterface::class);198 $curRepos = $this->mock(CurrencyRepositoryInterface::class);199 $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);200 $tagFactory = $this->mock(TagFactory::class);201 $accountRepos = $this->mock(AccountRepositoryInterface::class);202 $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class);203 $eventFactory = $this->mock(PiggyBankEventFactory::class);204 $accountFactory = $this->mock(AccountFactory::class);205 $currencyFactory = $this->mock(TransactionCurrencyFactory::class);206 $metaFactory = $this->mock(TransactionJournalMetaFactory::class);207 $transactionFactory = $this->mock(TransactionFactory::class);208 $validator = $this->mock(AccountValidator::class);209 $validator->shouldReceive('setUser')->atLeast()->once();210 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['deposit']);211 $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue();212 $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue();213 // data214 $deposit = TransactionType::where('type', TransactionType::DEPOSIT)->first();215 $asset = $this->getRandomAsset();216 $revenue = $this->getRandomRevenue();217 $euro = $this->getEuro();218 $submission = [219 'transactions' => [220 [221 'type' => 'deposit',222 'amount' => '10',223 'description' => sprintf('I am a test #%d', $this->randomInt()),224 'source_id' => $revenue->id,225 'destination_id' => $asset->id,226 ],227 ],228 ];229 // mock calls to all repositories230 $curRepos->shouldReceive('setUser')->atLeast()->once();231 $billRepos->shouldReceive('setUser')->atLeast()->once();232 $budgetRepos->shouldReceive('setUser')->atLeast()->once();233 $catRepos->shouldReceive('setUser')->atLeast()->once();234 $piggyRepos->shouldReceive('setUser')->atLeast()->once();235 $accountRepos->shouldReceive('setUser')->atLeast()->once();236 $tagFactory->shouldReceive('setUser')->atLeast()->once();237 $transactionFactory->shouldReceive('setUser')->atLeast()->once();238 $transactionFactory->shouldReceive('setJournal')->atLeast()->once();239 $transactionFactory->shouldReceive('setAccount')->atLeast()->once();240 $transactionFactory->shouldReceive('setCurrency')->atLeast()->once();241 $transactionFactory->shouldReceive('setForeignCurrency')->atLeast()->once();242 $transactionFactory->shouldReceive('setReconciled')->atLeast()->once();243 $transactionFactory->shouldReceive('createNegative')->atLeast()->once()->andReturn(new Transaction);244 $transactionFactory->shouldReceive('createPositive')->atLeast()->once()->andReturn(new Transaction);245 $typeRepos->shouldReceive('findTransactionType')->withArgs([null, 'deposit'])->atLeast()->once()->andReturn($deposit);246 $curRepos->shouldReceive('findCurrency')->atLeast()->once()->withArgs([0, null])->andReturn($euro);247 $curRepos->shouldReceive('findCurrencyNull')->atLeast()->once()->withArgs([0, null])->andReturn($euro);248 $billRepos->shouldReceive('findBill')->withArgs([0, null])->atLeast()->once()->andReturnNull();249 $accountRepos->shouldReceive('findNull')->withArgs([$revenue->id])->atLeast()->once()->andReturn($revenue);250 $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->atLeast()->once()->andReturn($asset);251 $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);252 $catRepos->shouldReceive('findCategory')->withArgs([0, null])->atLeast()->once()->andReturnNull();253 $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once();254 /** @var TransactionJournalFactory $factory */255 $factory = app(TransactionJournalFactory::class);256 $factory->setUser($this->user());257 try {258 $collection = $factory->create($submission);259 } catch (FireflyException $e) {260 $this->assertTrue(false, $e->getMessage());261 return;262 }263 $this->assertCount(1, $collection);264 /** @var TransactionJournal $first */265 $first = $collection->first();266 $this->assertEquals($first->description, $submission['transactions'][0]['description']);267 $first->forceDelete();268 }269 /**270 * Submit array for a withdrawal. Include tag info.271 *272 * @covers \FireflyIII\Factory\TransactionJournalFactory273 * @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait274 */275 public function testCreateWithdrawalTags(): void276 {277 $billRepos = $this->mock(BillRepositoryInterface::class);278 $budgetRepos = $this->mock(BudgetRepositoryInterface::class);279 $catRepos = $this->mock(CategoryRepositoryInterface::class);280 $curRepos = $this->mock(CurrencyRepositoryInterface::class);281 $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);282 $tagFactory = $this->mock(TagFactory::class);283 $accountRepos = $this->mock(AccountRepositoryInterface::class);284 $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class);285 $eventFactory = $this->mock(PiggyBankEventFactory::class);286 $accountFactory = $this->mock(AccountFactory::class);287 $currencyFactory = $this->mock(TransactionCurrencyFactory::class);288 $metaFactory = $this->mock(TransactionJournalMetaFactory::class);289 $transactionFactory = $this->mock(TransactionFactory::class);290 $validator = $this->mock(AccountValidator::class);291 $validator->shouldReceive('setUser')->atLeast()->once();292 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);293 $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue();294 $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue();295 // data296 $withdrawal = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();297 $asset = $this->getRandomAsset();298 $tag = $this->user()->tags()->inRandomOrder()->first();299 $expense = $this->getRandomExpense();300 $euro = $this->getEuro();301 $submission = [302 'transactions' => [303 [304 'type' => 'withdrawal',305 'amount' => '10',306 'description' => sprintf('I am a test #%d', $this->randomInt()),307 'source_id' => $asset->id,308 'destination_id' => $expense->id,309 'tags' => ['a'],310 ],311 ],312 ];313 // mock calls to all repositories314 $curRepos->shouldReceive('setUser')->atLeast()->once();315 $billRepos->shouldReceive('setUser')->atLeast()->once();316 $budgetRepos->shouldReceive('setUser')->atLeast()->once();317 $catRepos->shouldReceive('setUser')->atLeast()->once();318 $piggyRepos->shouldReceive('setUser')->atLeast()->once();319 $accountRepos->shouldReceive('setUser')->atLeast()->once();320 $tagFactory->shouldReceive('setUser')->atLeast()->once();321 $transactionFactory->shouldReceive('setUser')->atLeast()->once();322 $transactionFactory->shouldReceive('setJournal')->atLeast()->once();323 $transactionFactory->shouldReceive('setAccount')->atLeast()->once();324 $transactionFactory->shouldReceive('setCurrency')->atLeast()->once();325 $transactionFactory->shouldReceive('setForeignCurrency')->atLeast()->once();326 $transactionFactory->shouldReceive('setReconciled')->atLeast()->once();327 $transactionFactory->shouldReceive('createNegative')->atLeast()->once()->andReturn(new Transaction);328 $transactionFactory->shouldReceive('createPositive')->atLeast()->once()->andReturn(new Transaction);329 $typeRepos->shouldReceive('findTransactionType')->withArgs([null, 'withdrawal'])->atLeast()->once()->andReturn($withdrawal);330 $curRepos->shouldReceive('findCurrency')->atLeast()->once()->withArgs([0, null])->andReturn($euro);331 $curRepos->shouldReceive('findCurrencyNull')->atLeast()->once()->withArgs([0, null])->andReturn($euro);332 $billRepos->shouldReceive('findBill')->withArgs([0, null])->atLeast()->once()->andReturnNull();333 $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->atLeast()->once()->andReturn($asset);334 $accountRepos->shouldReceive('findNull')->withArgs([$expense->id])->atLeast()->once()->andReturn($expense);335 $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);336 $budgetRepos->shouldReceive('findBudget')->withArgs([0, null])->atLeast()->once()->andReturnNull();337 $catRepos->shouldReceive('findCategory')->withArgs([0, null])->atLeast()->once()->andReturnNull();338 $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once();339 $tagFactory->shouldReceive('findOrCreate')->atLeast()->once()->andReturn($tag);340 /** @var TransactionJournalFactory $factory */341 $factory = app(TransactionJournalFactory::class);342 $factory->setUser($this->user());343 try {344 $collection = $factory->create($submission);345 } catch (FireflyException $e) {346 $this->assertTrue(false, $e->getMessage());347 return;348 }349 $this->assertCount(1, $collection);350 /** @var TransactionJournal $first */351 $first = $collection->first();352 $this->assertEquals($first->description, $submission['transactions'][0]['description']);353 $first->forceDelete();354 }355 /**356 * Submit minimal array for a withdrawal.357 * @covers \FireflyIII\Factory\TransactionJournalFactory358 * @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait359 */360 public function testCreateWithdrawalNote(): void361 {362 $billRepos = $this->mock(BillRepositoryInterface::class);363 $budgetRepos = $this->mock(BudgetRepositoryInterface::class);364 $catRepos = $this->mock(CategoryRepositoryInterface::class);365 $curRepos = $this->mock(CurrencyRepositoryInterface::class);366 $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);367 $tagFactory = $this->mock(TagFactory::class);368 $accountRepos = $this->mock(AccountRepositoryInterface::class);369 $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class);370 $eventFactory = $this->mock(PiggyBankEventFactory::class);371 $accountFactory = $this->mock(AccountFactory::class);372 $currencyFactory = $this->mock(TransactionCurrencyFactory::class);373 $metaFactory = $this->mock(TransactionJournalMetaFactory::class);374 $transactionFactory = $this->mock(TransactionFactory::class);375 $validator = $this->mock(AccountValidator::class);376 $validator->shouldReceive('setUser')->atLeast()->once();377 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);378 $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue();379 $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue();380 // data381 $withdrawal = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();382 $asset = $this->getRandomAsset();383 $expense = $this->getRandomExpense();384 $euro = $this->getEuro();385 $submission = [386 'transactions' => [387 [388 'type' => 'withdrawal',389 'amount' => '10',390 'description' => sprintf('I am a test #%d', $this->randomInt()),391 'source_id' => $asset->id,392 'destination_id' => $expense->id,393 'notes' => 'I am a note',394 ],395 ],396 ];397 // mock calls to all repositories398 $curRepos->shouldReceive('setUser')->atLeast()->once();399 $billRepos->shouldReceive('setUser')->atLeast()->once();400 $budgetRepos->shouldReceive('setUser')->atLeast()->once();401 $catRepos->shouldReceive('setUser')->atLeast()->once();402 $piggyRepos->shouldReceive('setUser')->atLeast()->once();403 $accountRepos->shouldReceive('setUser')->atLeast()->once();404 $tagFactory->shouldReceive('setUser')->atLeast()->once();405 $transactionFactory->shouldReceive('setUser')->atLeast()->once();406 $transactionFactory->shouldReceive('setJournal')->atLeast()->once();407 $transactionFactory->shouldReceive('setAccount')->atLeast()->once();408 $transactionFactory->shouldReceive('setCurrency')->atLeast()->once();409 $transactionFactory->shouldReceive('setForeignCurrency')->atLeast()->once();410 $transactionFactory->shouldReceive('setReconciled')->atLeast()->once();411 $transactionFactory->shouldReceive('createNegative')->atLeast()->once()->andReturn(new Transaction);412 $transactionFactory->shouldReceive('createPositive')->atLeast()->once()->andReturn(new Transaction);413 $typeRepos->shouldReceive('findTransactionType')->withArgs([null, 'withdrawal'])->atLeast()->once()->andReturn($withdrawal);414 $curRepos->shouldReceive('findCurrency')->atLeast()->once()->withArgs([0, null])->andReturn($euro);415 $curRepos->shouldReceive('findCurrencyNull')->atLeast()->once()->withArgs([0, null])->andReturn($euro);416 $billRepos->shouldReceive('findBill')->withArgs([0, null])->atLeast()->once()->andReturnNull();417 $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->atLeast()->once()->andReturn($asset);418 $accountRepos->shouldReceive('findNull')->withArgs([$expense->id])->atLeast()->once()->andReturn($expense);419 $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);420 $budgetRepos->shouldReceive('findBudget')->withArgs([0, null])->atLeast()->once()->andReturnNull();421 $catRepos->shouldReceive('findCategory')->withArgs([0, null])->atLeast()->once()->andReturnNull();422 $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once();423 /** @var TransactionJournalFactory $factory */424 $factory = app(TransactionJournalFactory::class);425 $factory->setUser($this->user());426 try {427 $collection = $factory->create($submission);428 } catch (FireflyException $e) {429 $this->assertTrue(false, $e->getMessage());430 return;431 }432 $this->assertCount(1, $collection);433 /** @var TransactionJournal $first */434 $first = $collection->first();435 $this->assertEquals($first->description, $submission['transactions'][0]['description']);436 $this->assertCount(1, $first->notes()->get());437 $first->forceDelete();438 }439 /**440 * Submit array for a withdrawal.441 *442 * Include budget, category.443 *444 * @covers \FireflyIII\Factory\TransactionJournalFactory445 * @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait446 */447 public function testCreateWithdrawalMeta(): void448 {449 $billRepos = $this->mock(BillRepositoryInterface::class);450 $budgetRepos = $this->mock(BudgetRepositoryInterface::class);451 $catRepos = $this->mock(CategoryRepositoryInterface::class);452 $curRepos = $this->mock(CurrencyRepositoryInterface::class);453 $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);454 $tagFactory = $this->mock(TagFactory::class);455 $accountRepos = $this->mock(AccountRepositoryInterface::class);456 $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class);457 $eventFactory = $this->mock(PiggyBankEventFactory::class);458 $accountFactory = $this->mock(AccountFactory::class);459 $currencyFactory = $this->mock(TransactionCurrencyFactory::class);460 $metaFactory = $this->mock(TransactionJournalMetaFactory::class);461 $transactionFactory = $this->mock(TransactionFactory::class);462 $validator = $this->mock(AccountValidator::class);463 $validator->shouldReceive('setUser')->atLeast()->once();464 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);465 $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue();466 $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue();467 // data468 $withdrawal = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();469 $asset = $this->getRandomAsset();470 $expense = $this->getRandomExpense();471 $budget = $this->user()->budgets()->inRandomOrder()->first();472 $category = $this->user()->categories()->inRandomOrder()->first();473 $euro = $this->getEuro();474 $submission = [475 'transactions' => [476 [477 'type' => 'withdrawal',478 'amount' => '10',479 'description' => sprintf('I am a test #%d', $this->randomInt()),480 'source_id' => $asset->id,481 'budget_id' => $budget->id,482 'category_id' => $category->id,483 'destination_id' => $expense->id,484 ],485 ],486 ];487 // mock calls to all repositories488 $curRepos->shouldReceive('setUser')->atLeast()->once();489 $billRepos->shouldReceive('setUser')->atLeast()->once();490 $budgetRepos->shouldReceive('setUser')->atLeast()->once();491 $catRepos->shouldReceive('setUser')->atLeast()->once();492 $piggyRepos->shouldReceive('setUser')->atLeast()->once();493 $accountRepos->shouldReceive('setUser')->atLeast()->once();494 $tagFactory->shouldReceive('setUser')->atLeast()->once();495 $transactionFactory->shouldReceive('setUser')->atLeast()->once();496 $transactionFactory->shouldReceive('setJournal')->atLeast()->once();497 $transactionFactory->shouldReceive('setAccount')->atLeast()->once();498 $transactionFactory->shouldReceive('setCurrency')->atLeast()->once();499 $transactionFactory->shouldReceive('setForeignCurrency')->atLeast()->once();500 $transactionFactory->shouldReceive('setReconciled')->atLeast()->once();501 $transactionFactory->shouldReceive('createNegative')->atLeast()->once()->andReturn(new Transaction);502 $transactionFactory->shouldReceive('createPositive')->atLeast()->once()->andReturn(new Transaction);503 $typeRepos->shouldReceive('findTransactionType')->withArgs([null, 'withdrawal'])->atLeast()->once()->andReturn($withdrawal);504 $curRepos->shouldReceive('findCurrency')->atLeast()->once()->withArgs([0, null])->andReturn($euro);505 $curRepos->shouldReceive('findCurrencyNull')->atLeast()->once()->withArgs([0, null])->andReturn($euro);506 $billRepos->shouldReceive('findBill')->withArgs([0, null])->atLeast()->once()->andReturnNull();507 $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->atLeast()->once()->andReturn($asset);508 $accountRepos->shouldReceive('findNull')->withArgs([$expense->id])->atLeast()->once()->andReturn($expense);509 $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);510 $budgetRepos->shouldReceive('findBudget')->withArgs([$budget->id, null])->atLeast()->once()->andReturn($budget);511 $catRepos->shouldReceive('findCategory')->withArgs([$category->id, null])->atLeast()->once()->andReturn($category);512 $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once();513 /** @var TransactionJournalFactory $factory */514 $factory = app(TransactionJournalFactory::class);515 $factory->setUser($this->user());516 try {517 $collection = $factory->create($submission);518 } catch (FireflyException $e) {519 $this->assertTrue(false, $e->getMessage());520 return;521 }522 $this->assertCount(1, $collection);523 /** @var TransactionJournal $first */524 $first = $collection->first();525 $this->assertEquals($first->description, $submission['transactions'][0]['description']);526 $first->forceDelete();527 }528 /**529 * Submit minimal array for a withdrawal.530 * Includes piggy bank data, but the piggy bank is invalid.531 *532 * @covers \FireflyIII\Factory\TransactionJournalFactory533 * @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait534 */535 public function testCreateTransferInvalidPiggie(): void536 {537 $billRepos = $this->mock(BillRepositoryInterface::class);538 $budgetRepos = $this->mock(BudgetRepositoryInterface::class);539 $catRepos = $this->mock(CategoryRepositoryInterface::class);540 $curRepos = $this->mock(CurrencyRepositoryInterface::class);541 $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);542 $tagFactory = $this->mock(TagFactory::class);543 $accountRepos = $this->mock(AccountRepositoryInterface::class);544 $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class);545 $eventFactory = $this->mock(PiggyBankEventFactory::class);546 $accountFactory = $this->mock(AccountFactory::class);547 $currencyFactory = $this->mock(TransactionCurrencyFactory::class);548 $metaFactory = $this->mock(TransactionJournalMetaFactory::class);549 $transactionFactory = $this->mock(TransactionFactory::class);550 $validator = $this->mock(AccountValidator::class);551 $validator->shouldReceive('setUser')->atLeast()->once();552 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['transfer']);553 $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue();554 $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue();555 // data556 $transfer = TransactionType::where('type', TransactionType::TRANSFER)->first();557 $asset = $this->getRandomAsset();558 $otherAsset = $this->getRandomAsset($asset->id);559 $euro = $this->getEuro();560 $piggy = $this->user()->piggyBanks()->inRandomOrder()->first();561 $submission = [562 'transactions' => [563 [564 'type' => 'transfer',565 'amount' => '10',566 'description' => sprintf('I am a test #%d', $this->randomInt()),567 'source_id' => $asset->id,568 'destination_id' => $otherAsset->id,569 'piggy_bank_id' => $piggy->id,570 ],571 ],572 ];573 // mock calls to all repositories574 $curRepos->shouldReceive('setUser')->atLeast()->once();575 $billRepos->shouldReceive('setUser')->atLeast()->once();576 $budgetRepos->shouldReceive('setUser')->atLeast()->once();577 $catRepos->shouldReceive('setUser')->atLeast()->once();578 $piggyRepos->shouldReceive('setUser')->atLeast()->once();579 $accountRepos->shouldReceive('setUser')->atLeast()->once();580 $tagFactory->shouldReceive('setUser')->atLeast()->once();581 $transactionFactory->shouldReceive('setUser')->atLeast()->once();582 $transactionFactory->shouldReceive('setJournal')->atLeast()->once();583 $transactionFactory->shouldReceive('setAccount')->atLeast()->once();584 $transactionFactory->shouldReceive('setCurrency')->atLeast()->once();585 $transactionFactory->shouldReceive('setForeignCurrency')->atLeast()->once();586 $transactionFactory->shouldReceive('setReconciled')->atLeast()->once();587 $transactionFactory->shouldReceive('createNegative')->atLeast()->once()->andReturn(new Transaction);588 $transactionFactory->shouldReceive('createPositive')->atLeast()->once()->andReturn(new Transaction);589 $typeRepos->shouldReceive('findTransactionType')->withArgs([null, 'transfer'])->atLeast()->once()->andReturn($transfer);590 $curRepos->shouldReceive('findCurrency')->atLeast()->once()->withArgs([0, null])->andReturn($euro);591 $curRepos->shouldReceive('findCurrencyNull')->atLeast()->once()->withArgs([0, null])->andReturn($euro);592 $billRepos->shouldReceive('findBill')->withArgs([0, null])->atLeast()->once()->andReturnNull();593 $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->atLeast()->once()->andReturn($asset);594 $accountRepos->shouldReceive('findNull')->withArgs([$otherAsset->id])->atLeast()->once()->andReturn($otherAsset);595 $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);596 $catRepos->shouldReceive('findCategory')->withArgs([0, null])->atLeast()->once()->andReturnNull();597 $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once();598 $piggyRepos->shouldReceive('findPiggyBank')->withArgs([$piggy->id, null])->atLeast()->once()->andReturn(null);599 /** @var TransactionJournalFactory $factory */600 $factory = app(TransactionJournalFactory::class);601 $factory->setUser($this->user());602 try {603 $collection = $factory->create($submission);604 } catch (FireflyException $e) {605 $this->assertTrue(false, $e->getMessage());606 return;607 }608 $this->assertCount(1, $collection);609 /** @var TransactionJournal $first */610 $first = $collection->first();611 $this->assertEquals($first->description, $submission['transactions'][0]['description']);612 $first->forceDelete();613 }614 /**615 * Submit minimal array for a withdrawal.616 * Includes piggy bank data.617 *618 * @covers \FireflyIII\Factory\TransactionJournalFactory619 * @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait620 */621 public function testCreateTransfer(): void622 {623 $billRepos = $this->mock(BillRepositoryInterface::class);624 $budgetRepos = $this->mock(BudgetRepositoryInterface::class);625 $catRepos = $this->mock(CategoryRepositoryInterface::class);626 $curRepos = $this->mock(CurrencyRepositoryInterface::class);627 $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);628 $tagFactory = $this->mock(TagFactory::class);629 $accountRepos = $this->mock(AccountRepositoryInterface::class);630 $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class);631 $eventFactory = $this->mock(PiggyBankEventFactory::class);632 $accountFactory = $this->mock(AccountFactory::class);633 $currencyFactory = $this->mock(TransactionCurrencyFactory::class);634 $metaFactory = $this->mock(TransactionJournalMetaFactory::class);635 $transactionFactory = $this->mock(TransactionFactory::class);636 $validator = $this->mock(AccountValidator::class);637 $validator->shouldReceive('setUser')->atLeast()->once();638 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['transfer']);639 $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue();640 $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue();641 // data642 $transfer = TransactionType::where('type', TransactionType::TRANSFER)->first();643 $asset = $this->getRandomAsset();644 $otherAsset = $this->getRandomAsset($asset->id);645 $euro = $this->getEuro();646 $piggy = $this->user()->piggyBanks()->inRandomOrder()->first();647 $submission = [648 'transactions' => [649 [650 'type' => 'transfer',651 'amount' => '10',652 'description' => sprintf('I am a test #%d', $this->randomInt()),653 'source_id' => $asset->id,654 'destination_id' => $otherAsset->id,655 'piggy_bank_id' => $piggy->id,656 ],657 ],658 ];659 // mock calls to all repositories660 $curRepos->shouldReceive('setUser')->atLeast()->once();661 $billRepos->shouldReceive('setUser')->atLeast()->once();662 $budgetRepos->shouldReceive('setUser')->atLeast()->once();663 $catRepos->shouldReceive('setUser')->atLeast()->once();664 $piggyRepos->shouldReceive('setUser')->atLeast()->once();665 $accountRepos->shouldReceive('setUser')->atLeast()->once();666 $tagFactory->shouldReceive('setUser')->atLeast()->once();667 $transactionFactory->shouldReceive('setUser')->atLeast()->once();668 $transactionFactory->shouldReceive('setJournal')->atLeast()->once();669 $transactionFactory->shouldReceive('setAccount')->atLeast()->once();670 $transactionFactory->shouldReceive('setCurrency')->atLeast()->once();671 $transactionFactory->shouldReceive('setForeignCurrency')->atLeast()->once();672 $transactionFactory->shouldReceive('setReconciled')->atLeast()->once();673 $transactionFactory->shouldReceive('createNegative')->atLeast()->once()->andReturn(new Transaction);674 $transactionFactory->shouldReceive('createPositive')->atLeast()->once()->andReturn(new Transaction);675 $typeRepos->shouldReceive('findTransactionType')->withArgs([null, 'transfer'])->atLeast()->once()->andReturn($transfer);676 $curRepos->shouldReceive('findCurrency')->atLeast()->once()->withArgs([0, null])->andReturn($euro);677 $curRepos->shouldReceive('findCurrencyNull')->atLeast()->once()->withArgs([0, null])->andReturn($euro);678 $billRepos->shouldReceive('findBill')->withArgs([0, null])->atLeast()->once()->andReturnNull();679 $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->atLeast()->once()->andReturn($asset);680 $accountRepos->shouldReceive('findNull')->withArgs([$otherAsset->id])->atLeast()->once()->andReturn($otherAsset);681 $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);682 $catRepos->shouldReceive('findCategory')->withArgs([0, null])->atLeast()->once()->andReturnNull();683 $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once();684 $piggyRepos->shouldReceive('findPiggyBank')->withArgs([$piggy->id, null])->atLeast()->once()->andReturn($piggy);685 $eventFactory->shouldReceive('create')->atLeast()->once()->andReturn(new PiggyBankEvent);686 /** @var TransactionJournalFactory $factory */687 $factory = app(TransactionJournalFactory::class);688 $factory->setUser($this->user());689 try {690 $collection = $factory->create($submission);691 } catch (FireflyException $e) {692 $this->assertTrue(false, $e->getMessage());693 return;694 }695 $this->assertCount(1, $collection);696 /** @var TransactionJournal $first */697 $first = $collection->first();698 $this->assertEquals($first->description, $submission['transactions'][0]['description']);699 $first->forceDelete();700 }701 /**702 * Submit minimal array for a withdrawal.703 * Includes piggy bank data.704 * Includes foreign amounts but foreign currency is missing or invalid.705 * Will be solved by getting users default currency.706 *707 * @covers \FireflyIII\Factory\TransactionJournalFactory708 * @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait709 */710 public function testCreateTransferForeign(): void711 {712 $billRepos = $this->mock(BillRepositoryInterface::class);713 $budgetRepos = $this->mock(BudgetRepositoryInterface::class);714 $catRepos = $this->mock(CategoryRepositoryInterface::class);715 $curRepos = $this->mock(CurrencyRepositoryInterface::class);716 $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);717 $tagFactory = $this->mock(TagFactory::class);718 $accountRepos = $this->mock(AccountRepositoryInterface::class);719 $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class);720 $eventFactory = $this->mock(PiggyBankEventFactory::class);721 $accountFactory = $this->mock(AccountFactory::class);722 $currencyFactory = $this->mock(TransactionCurrencyFactory::class);723 $metaFactory = $this->mock(TransactionJournalMetaFactory::class);724 $transactionFactory = $this->mock(TransactionFactory::class);725 $validator = $this->mock(AccountValidator::class);726 $validator->shouldReceive('setUser')->atLeast()->once();727 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['transfer']);728 $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue();729 $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue();730 // data731 $transfer = TransactionType::where('type', TransactionType::TRANSFER)->first();732 $asset = $this->getRandomAsset();733 $otherAsset = $this->getRandomAsset($asset->id);734 $euro = $this->getEuro();735 $piggy = $this->user()->piggyBanks()->inRandomOrder()->first();736 $submission = [737 'transactions' => [738 [739 'type' => 'transfer',740 'amount' => '10',741 'foreign_amount' => '10',742 'description' => sprintf('I am a test #%d', $this->randomInt()),743 'source_id' => $asset->id,744 'destination_id' => $otherAsset->id,745 'piggy_bank_id' => $piggy->id,746 ],747 ],748 ];749 // mock calls to all repositories750 $curRepos->shouldReceive('setUser')->atLeast()->once();751 $billRepos->shouldReceive('setUser')->atLeast()->once();752 $budgetRepos->shouldReceive('setUser')->atLeast()->once();753 $catRepos->shouldReceive('setUser')->atLeast()->once();754 $piggyRepos->shouldReceive('setUser')->atLeast()->once();755 $accountRepos->shouldReceive('setUser')->atLeast()->once();756 $tagFactory->shouldReceive('setUser')->atLeast()->once();757 $transactionFactory->shouldReceive('setUser')->atLeast()->once();758 Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn($euro);759 $transactionFactory->shouldReceive('setJournal')->atLeast()->once();760 $transactionFactory->shouldReceive('setAccount')->atLeast()->once();761 $transactionFactory->shouldReceive('setCurrency')->atLeast()->once();762 $transactionFactory->shouldReceive('setForeignCurrency')->atLeast()->once();763 $transactionFactory->shouldReceive('setReconciled')->atLeast()->once();764 $transactionFactory->shouldReceive('createNegative')->atLeast()->once()->andReturn(new Transaction);765 $transactionFactory->shouldReceive('createPositive')->atLeast()->once()->andReturn(new Transaction);766 $typeRepos->shouldReceive('findTransactionType')->withArgs([null, 'transfer'])->atLeast()->once()->andReturn($transfer);767 $curRepos->shouldReceive('findCurrency')->atLeast()->once()->withArgs([0, null])->andReturn($euro);768 $curRepos->shouldReceive('findCurrencyNull')->atLeast()->once()->withArgs([0, null])->andReturnNull();769 $billRepos->shouldReceive('findBill')->withArgs([0, null])->atLeast()->once()->andReturnNull();770 $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->atLeast()->once()->andReturn($asset);771 $accountRepos->shouldReceive('findNull')->withArgs([$otherAsset->id])->atLeast()->once()->andReturn($otherAsset);772 $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro, null);773 $catRepos->shouldReceive('findCategory')->withArgs([0, null])->atLeast()->once()->andReturnNull();774 $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once();775 $piggyRepos->shouldReceive('findPiggyBank')->withArgs([$piggy->id, null])->atLeast()->once()->andReturn($piggy);776 $eventFactory->shouldReceive('create')->atLeast()->once()->andReturn(new PiggyBankEvent);777 /** @var TransactionJournalFactory $factory */778 $factory = app(TransactionJournalFactory::class);779 $factory->setUser($this->user());780 try {781 $collection = $factory->create($submission);782 } catch (FireflyException $e) {783 $this->assertTrue(false, $e->getMessage());784 return;785 }786 $this->assertCount(1, $collection);787 /** @var TransactionJournal $first */788 $first = $collection->first();789 $this->assertEquals($first->description, $submission['transactions'][0]['description']);790 $first->forceDelete();791 }792}...

Full Screen

Full Screen

ApplyRulesTest.php

Source:ApplyRulesTest.php Github

copy

Full Screen

1<?php2/**3 * ApplyRulesTest.php4 * Copyright (c) 2019 james@firefly-iii.org5 *6 * This file is part of Firefly III (https://github.com/firefly-iii).7 *8 * This program is free software: you can redistribute it and/or modify9 * it under the terms of the GNU Affero General Public License as10 * published by the Free Software Foundation, either version 3 of the11 * License, or (at your option) any later version.12 *13 * This program is distributed in the hope that it will be useful,14 * but WITHOUT ANY WARRANTY; without even the implied warranty of15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the16 * GNU Affero General Public License for more details.17 *18 * You should have received a copy of the GNU Affero General Public License19 * along with this program. If not, see <https://www.gnu.org/licenses/>.20 */21declare(strict_types=1);22namespace Tests\Unit\Console\Commands\Tools;23use FireflyIII\Helpers\Collector\GroupCollectorInterface;24use FireflyIII\Models\Preference;25use FireflyIII\Repositories\Account\AccountRepositoryInterface;26use FireflyIII\Repositories\Journal\JournalRepositoryInterface;27use FireflyIII\Repositories\Rule\RuleRepositoryInterface;28use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;29use FireflyIII\Repositories\User\UserRepositoryInterface;30use FireflyIII\TransactionRules\Engine\RuleEngine;31use Illuminate\Support\Collection;32use Log;33use Mockery;34use Preferences;35use Tests\TestCase;36/**37 * Class ApplyRulesTest38 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)39 * @SuppressWarnings(PHPMD.ExcessiveMethodLength)40 * @SuppressWarnings(PHPMD.TooManyPublicMethods)41 */42class ApplyRulesTest extends TestCase43{44 /**45 *46 */47 public function setUp(): void48 {49 parent::setUp();50 Log::info(sprintf('Now in %s.', get_class($this)));51 }52 /**53 * Basic call with everything perfect (and ALL rules).54 *55 * @covers \FireflyIII\Console\Commands\Tools\ApplyRules56 */57 public function testHandle(): void58 {59 $ruleRepos = $this->mock(RuleRepositoryInterface::class);60 $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);61 $journalRepos = $this->mock(JournalRepositoryInterface::class);62 $collector = $this->mock(GroupCollectorInterface::class);63 $accountRepos = $this->mock(AccountRepositoryInterface::class);64 $ruleEngine = $this->mock(RuleEngine::class);65 $userRepos = $this->mock(UserRepositoryInterface::class);66 // data67 $asset = $this->getRandomAsset();68 $journal = $this->getRandomWithdrawal();69 $group = $this->user()->ruleGroups()->first();70 $rule = $this->user()->rules()->first();71 $groups = new Collection([$group]);72 $rules = new Collection([$rule]);73 // expected calls:74 $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());75 $ruleRepos->shouldReceive('setUser')->atLeast()->once();76 $ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();77 $accountRepos->shouldReceive('setUser')->atLeast()->once();78 $journalRepos->shouldReceive('setUser')->atLeast()->once();79 $accountRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([1])->andReturn($asset);80 $journalRepos->shouldReceive('firstNull')->atLeast()->once()->andReturn($journal);81 $ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn($groups);82 $ruleGroupRepos->shouldReceive('getActiveStoreRules')->atLeast()->once()->andReturn($rules);83 $collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();84 $collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();85 $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();86 $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([[], [], []]);87 $ruleEngine->shouldReceive('setUser')->atLeast()->once();88 $ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();89 $ruleEngine->shouldReceive('processJournalArray')->times(3);90 $ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once()->withArgs([RuleEngine::TRIGGER_STORE]);91 $parameters = [92 '--user=1',93 '--token=token',94 '--accounts=1',95 '--all_rules',96 ];97 // mock Preferences Facade:98 $pref = new Preference;99 $pref->data = 'token';100 Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);101 $this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))102 ->expectsOutput('Will apply 1 rule(s) to 3 transaction(s).')103 ->expectsOutput('Done!')104 ->assertExitCode(0);105 // this method changes no objects so there is nothing to verify.106 }107 /**108 * Basic call with everything perfect (and ALL rules), but no rules will be selected.109 *110 * @covers \FireflyIII\Console\Commands\Tools\ApplyRules111 */112 public function testHandEmpty(): void113 {114 $ruleRepos = $this->mock(RuleRepositoryInterface::class);115 $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);116 $journalRepos = $this->mock(JournalRepositoryInterface::class);117 $collector = $this->mock(GroupCollectorInterface::class);118 $accountRepos = $this->mock(AccountRepositoryInterface::class);119 $ruleEngine = $this->mock(RuleEngine::class);120 $userRepos = $this->mock(UserRepositoryInterface::class);121 // data122 $asset = $this->getRandomAsset();123 $journal = $this->getRandomWithdrawal();124 $group = $this->user()->ruleGroups()->first();125 $groups = new Collection([$group]);126 // expected calls:127 $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());128 $ruleRepos->shouldReceive('setUser')->atLeast()->once();129 $ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();130 $accountRepos->shouldReceive('setUser')->atLeast()->once();131 $journalRepos->shouldReceive('setUser')->atLeast()->once();132 $accountRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([1])->andReturn($asset);133 $journalRepos->shouldReceive('firstNull')->atLeast()->once()->andReturn($journal);134 $ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn($groups);135 $ruleGroupRepos->shouldReceive('getActiveStoreRules')->atLeast()->once()->andReturn(new Collection);136 $collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();137 $collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();138 $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();139 $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([[], [], []]);140 $ruleEngine->shouldReceive('setUser')->atLeast()->once();141 $ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();142 $ruleEngine->shouldReceive('processJournalArray')->times(3);143 $ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once()->withArgs([RuleEngine::TRIGGER_STORE]);144 $parameters = [145 '--user=1',146 '--token=token',147 '--accounts=1',148 '--all_rules',149 ];150 // mock Preferences Facade:151 $pref = new Preference;152 $pref->data = 'token';153 Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);154 $this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))155 ->expectsOutput('No rules or rule groups have been included.')156 ->expectsOutput('Done!')157 ->assertExitCode(0);158 }159 /**160 * Basic call with everything perfect (and ALL rules) and dates.161 *162 * @covers \FireflyIII\Console\Commands\Tools\ApplyRules163 */164 public function testHandleDate(): void165 {166 $ruleRepos = $this->mock(RuleRepositoryInterface::class);167 $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);168 $this->mock(JournalRepositoryInterface::class);169 $collector = $this->mock(GroupCollectorInterface::class);170 $accountRepos = $this->mock(AccountRepositoryInterface::class);171 $ruleEngine = $this->mock(RuleEngine::class);172 $userRepos = $this->mock(UserRepositoryInterface::class);173 // data174 $asset = $this->getRandomAsset();175 $group = $this->user()->ruleGroups()->first();176 $rule = $this->user()->rules()->first();177 $groups = new Collection([$group]);178 $rules = new Collection([$rule]);179 // expected calls:180 $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());181 $ruleRepos->shouldReceive('setUser')->atLeast()->once();182 $ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();183 $accountRepos->shouldReceive('setUser')->atLeast()->once();184 $accountRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([1])->andReturn($asset);185 $ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn($groups);186 $ruleGroupRepos->shouldReceive('getActiveStoreRules')->atLeast()->once()->andReturn($rules);187 $collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();188 $collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();189 $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();190 $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([[], [], []]);191 $ruleEngine->shouldReceive('setUser')->atLeast()->once();192 $ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();193 $ruleEngine->shouldReceive('processJournalArray')->times(3);194 $ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once()->withArgs([RuleEngine::TRIGGER_STORE]);195 $parameters = [196 '--user=1',197 '--token=token',198 '--accounts=1',199 '--all_rules',200 '--start_date=2019-01-31',201 '--end_date=2019-01-01',202 ];203 // mock Preferences Facade:204 $pref = new Preference;205 $pref->data = 'token';206 Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);207 $this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))208 ->expectsOutput('Will apply 1 rule(s) to 3 transaction(s).')209 ->expectsOutput('Done!')210 ->assertExitCode(0);211 }212 /**213 * Will submit some rules to apply.214 *215 * @covers \FireflyIII\Console\Commands\Tools\ApplyRules216 */217 public function testHandleRules(): void218 {219 $ruleRepos = $this->mock(RuleRepositoryInterface::class);220 $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);221 $journalRepos = $this->mock(JournalRepositoryInterface::class);222 $collector = $this->mock(GroupCollectorInterface::class);223 $accountRepos = $this->mock(AccountRepositoryInterface::class);224 $ruleEngine = $this->mock(RuleEngine::class);225 $userRepos = $this->mock(UserRepositoryInterface::class);226 // data227 $asset = $this->getRandomAsset();228 $journal = $this->getRandomWithdrawal();229 $group = $this->user()->ruleGroups()->first();230 $groups = new Collection([$group]);231 $activeRule = $this->user()->rules()->where('active', 1)->inRandomOrder()->first();232 $inactiveRule = $this->user()->rules()->where('active', 0)->inRandomOrder()->first();233 $rules = new Collection([$activeRule]);234 // expected calls:235 $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());236 $ruleRepos->shouldReceive('setUser')->atLeast()->once();237 $ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();238 $accountRepos->shouldReceive('setUser')->atLeast()->once();239 $journalRepos->shouldReceive('setUser')->atLeast()->once();240 $accountRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([1])->andReturn($asset);241 $journalRepos->shouldReceive('firstNull')->atLeast()->once()->andReturn($journal);242 $ruleRepos->shouldReceive('find')->atLeast()->once()->withArgs([$activeRule->id])->andReturn($activeRule);243 $ruleRepos->shouldReceive('find')->atLeast()->once()->withArgs([$inactiveRule->id])->andReturn($inactiveRule);244 $ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn($groups);245 $ruleGroupRepos->shouldReceive('getActiveStoreRules')->atLeast()->once()->andReturn($rules);246 $collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();247 $collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();248 $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();249 $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([[], [], []]);250 $ruleEngine->shouldReceive('setUser')->atLeast()->once();251 $ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();252 $ruleEngine->shouldReceive('processJournalArray')->times(3);253 $ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once()->withArgs([RuleEngine::TRIGGER_STORE]);254 $parameters = [255 '--user=1',256 '--token=token',257 '--accounts=1',258 sprintf('--rules=%d,%d', $activeRule->id, $inactiveRule->id),259 ];260 // mock Preferences Facade:261 $pref = new Preference;262 $pref->data = 'token';263 Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);264 $this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))265 ->expectsOutput('Will apply 1 rule(s) to 3 transaction(s).')266 ->expectsOutput('Done!')267 ->assertExitCode(0);268 }269 /**270 * Basic call with two rule groups. One active, one inactive.271 *272 * @covers \FireflyIII\Console\Commands\Tools\ApplyRules273 */274 public function testHandleRuleGroups(): void275 {276 $ruleRepos = $this->mock(RuleRepositoryInterface::class);277 $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);278 $journalRepos = $this->mock(JournalRepositoryInterface::class);279 $collector = $this->mock(GroupCollectorInterface::class);280 $accountRepos = $this->mock(AccountRepositoryInterface::class);281 $ruleEngine = $this->mock(RuleEngine::class);282 $userRepos = $this->mock(UserRepositoryInterface::class);283 $activeGroup = $this->user()->ruleGroups()->where('active', 1)->inRandomOrder()->first();284 $inactiveGroup = $this->user()->ruleGroups()->where('active', 0)->inRandomOrder()->first();285 // data286 $asset = $this->getRandomAsset();287 $journal = $this->getRandomWithdrawal();288 $rule = $this->user()->rules()->first();289 $groups = new Collection([$activeGroup]);290 $rules = new Collection([$rule]);291 // expected calls:292 $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());293 $ruleRepos->shouldReceive('setUser')->atLeast()->once();294 $ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();295 $accountRepos->shouldReceive('setUser')->atLeast()->once();296 $journalRepos->shouldReceive('setUser')->atLeast()->once();297 $accountRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([1])->andReturn($asset);298 $journalRepos->shouldReceive('firstNull')->atLeast()->once()->andReturn($journal);299 $ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn($groups);300 $ruleGroupRepos->shouldReceive('getActiveStoreRules')->atLeast()->once()->andReturn($rules);301 $ruleGroupRepos->shouldReceive('find')->atLeast()->once()->withArgs([$activeGroup->id])->andReturn($activeGroup);302 $ruleGroupRepos->shouldReceive('find')->atLeast()->once()->withArgs([$inactiveGroup->id])->andReturn($inactiveGroup);303 $collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();304 $collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();305 $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();306 $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([[], [], []]);307 $ruleEngine->shouldReceive('setUser')->atLeast()->once();308 $ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();309 $ruleEngine->shouldReceive('processJournalArray')->times(3);310 $ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once()->withArgs([RuleEngine::TRIGGER_STORE]);311 $parameters = [312 '--user=1',313 '--token=token',314 '--accounts=1',315 sprintf('--rule_groups=%d,%d', $activeGroup->id, $inactiveGroup->id),316 ];317 // mock Preferences Facade:318 $pref = new Preference;319 $pref->data = 'token';320 Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);321 $this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))322 ->expectsOutput(sprintf('Will ignore inactive rule group #%d ("%s")', $inactiveGroup->id, $inactiveGroup->title))323 // one rule out of 2 groups:324 ->expectsOutput('Will apply 1 rule(s) to 3 transaction(s).')325 ->expectsOutput('Done!')326 ->assertExitCode(0);327 }328 /**329 * Basic call but no accounts submitted.330 *331 * @covers \FireflyIII\Console\Commands\Tools\ApplyRules332 */333 public function testHandleNoAccounts(): void334 {335 $ruleRepos = $this->mock(RuleRepositoryInterface::class);336 $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);337 $this->mock(JournalRepositoryInterface::class);338 $this->mock(GroupCollectorInterface::class);339 $this->mock(AccountRepositoryInterface::class);340 $this->mock(RuleEngine::class);341 $userRepos = $this->mock(UserRepositoryInterface::class);342 // expected calls:343 $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());344 $ruleRepos->shouldReceive('setUser')->atLeast()->once();345 $ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();346 $parameters = [347 '--user=1',348 '--token=token',349 '--accounts=',350 '--all_rules',351 ];352 // mock Preferences Facade:353 $pref = new Preference;354 $pref->data = 'token';355 Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);356 $this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))357 ->expectsOutput('Please use the --accounts option to indicate the accounts to apply rules to.')358 ->assertExitCode(1);359 }360 /**361 * Basic call but only one expense account submitted362 *363 * @covers \FireflyIII\Console\Commands\Tools\ApplyRules364 */365 public function testHandleExpenseAccounts(): void366 {367 $ruleRepos = $this->mock(RuleRepositoryInterface::class);368 $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);369 $accountRepos = $this->mock(AccountRepositoryInterface::class);370 $userRepos = $this->mock(UserRepositoryInterface::class);371 $this->mock(RuleEngine::class);372 $this->mock(JournalRepositoryInterface::class);373 $this->mock(GroupCollectorInterface::class);374 // data375 $expense = $this->getRandomExpense();376 // expected calls:377 $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());378 $ruleRepos->shouldReceive('setUser')->atLeast()->once();379 $ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();380 $accountRepos->shouldReceive('setUser')->atLeast()->once();381 $accountRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([$expense->id])->andReturn($expense);382 $parameters = [383 '--user=1',384 '--token=token',385 '--accounts=' . $expense->id,386 '--all_rules',387 ];388 // mock Preferences Facade:389 $pref = new Preference;390 $pref->data = 'token';391 Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);392 $this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))393 ->expectsOutput('Please make sure all accounts in --accounts are asset accounts or liabilities.')394 ->assertExitCode(1);395 }396}...

Full Screen

Full Screen

IndexControllerTest.php

Source:IndexControllerTest.php Github

copy

Full Screen

1<?php2/**3 * IndexControllerTest.php4 * Copyright (c) 2019 james@firefly-iii.org5 *6 * This file is part of Firefly III (https://github.com/firefly-iii).7 *8 * This program is free software: you can redistribute it and/or modify9 * it under the terms of the GNU Affero General Public License as10 * published by the Free Software Foundation, either version 3 of the11 * License, or (at your option) any later version.12 *13 * This program is distributed in the hope that it will be useful,14 * but WITHOUT ANY WARRANTY; without even the implied warranty of15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the16 * GNU Affero General Public License for more details.17 *18 * You should have received a copy of the GNU Affero General Public License19 * along with this program. If not, see <https://www.gnu.org/licenses/>.20 */21declare(strict_types=1);22namespace Tests\Feature\Controllers\Transaction;23use Amount;24use FireflyIII\Helpers\Collector\GroupCollectorInterface;25use FireflyIII\Models\Preference;26use FireflyIII\Repositories\User\UserRepositoryInterface;27use Illuminate\Pagination\LengthAwarePaginator;28use Log;29use Mockery;30use Preferences;31use Tests\TestCase;32/**33 * Class IndexControllerTest34 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)35 * @SuppressWarnings(PHPMD.ExcessiveMethodLength)36 * @SuppressWarnings(PHPMD.TooManyPublicMethods)37 */38class IndexControllerTest extends TestCase39{40 /**41 *42 */43 public function setUp(): void44 {45 parent::setUp();46 Log::info(sprintf('Now in %s.', get_class($this)));47 }48 /**49 * @covers \FireflyIII\Http\Controllers\Transaction\IndexController50 */51 public function testIndex(): void52 {53 $this->mockDefaultSession();54 $group = $this->getRandomWithdrawalGroup();55 $userRepos = $this->mock(UserRepositoryInterface::class);56 $collector = $this->mock(GroupCollectorInterface::class);57 // generic set for the info blocks:58 $groupArray = [59 $this->getRandomWithdrawalAsArray(),60 $this->getRandomDepositAsArray(),61 $this->getRandomTransferAsArray(),62 ];63 // role?64 $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true);65 // make paginator.66 $paginator = new LengthAwarePaginator([$group], 1, 40, 1);67 Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('10');68 $collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf();69 $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();70 $collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();71 $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();72 $collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();73 $collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();74 $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();75 $collector->shouldReceive('getPaginatedGroups')->atLeast()->once()->andReturn($paginator);76 $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn($groupArray);77 $pref = new Preference;78 $pref->data = 50;79 Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);80 Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');81 $this->be($this->user());82 $response = $this->get(route('transactions.index', ['withdrawal']));83 $response->assertStatus(200);84 }85 /**86 * @covers \FireflyIII\Http\Controllers\Transaction\IndexController87 */88 public function testIndexDeposit(): void89 {90 $this->mockDefaultSession();91 $group = $this->getRandomWithdrawalGroup();92 $userRepos = $this->mock(UserRepositoryInterface::class);93 $collector = $this->mock(GroupCollectorInterface::class);94 // generic set for the info blocks:95 $groupArray = [96 $this->getRandomWithdrawalAsArray(),97 $this->getRandomDepositAsArray(),98 $this->getRandomTransferAsArray(),99 ];100 // role?101 $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true);102 // make paginator.103 $paginator = new LengthAwarePaginator([$group], 1, 40, 1);104 Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('10');105 $collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf();106 $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();107 $collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();108 $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();109 $collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();110 $collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();111 $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();112 $collector->shouldReceive('getPaginatedGroups')->atLeast()->once()->andReturn($paginator);113 $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn($groupArray);114 $pref = new Preference;115 $pref->data = 50;116 Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);117 Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');118 $this->be($this->user());119 $response = $this->get(route('transactions.index', ['deposit']));120 $response->assertStatus(200);121 }122 /**123 * @covers \FireflyIII\Http\Controllers\Transaction\IndexController124 */125 public function testIndexTransfers(): void126 {127 $this->mockDefaultSession();128 $group = $this->getRandomWithdrawalGroup();129 $userRepos = $this->mock(UserRepositoryInterface::class);130 $collector = $this->mock(GroupCollectorInterface::class);131 // generic set for the info blocks:132 $groupArray = [133 $this->getRandomWithdrawalAsArray(),134 $this->getRandomDepositAsArray(),135 $this->getRandomTransferAsArray(),136 ];137 // role?138 $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true);139 // make paginator.140 $paginator = new LengthAwarePaginator([$group], 1, 40, 1);141 Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('10');142 $collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf();143 $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();144 $collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();145 $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();146 $collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();147 $collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();148 $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();149 $collector->shouldReceive('getPaginatedGroups')->atLeast()->once()->andReturn($paginator);150 $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn($groupArray);151 $pref = new Preference;152 $pref->data = 50;153 Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);154 Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');155 $this->be($this->user());156 $response = $this->get(route('transactions.index', ['transfers']));157 $response->assertStatus(200);158 }159 /**160 * @covers \FireflyIII\Http\Controllers\Transaction\IndexController161 */162 public function testIndexAll(): void163 {164 $this->mockDefaultSession();165 $group = $this->getRandomWithdrawalGroup();166 $userRepos = $this->mock(UserRepositoryInterface::class);167 $collector = $this->mock(GroupCollectorInterface::class);168 // role?169 $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true);170 // make paginator.171 $paginator = new LengthAwarePaginator([$group], 1, 40, 1);172 $collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf();173 $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();174 $collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();175 $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();176 $collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();177 $collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();178 $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();179 $collector->shouldReceive('getPaginatedGroups')->atLeast()->once()->andReturn($paginator);180 $pref = new Preference;181 $pref->data = 50;182 Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);183 $this->be($this->user());184 $response = $this->get(route('transactions.index.all', ['withdrawal']));185 $response->assertStatus(200);186 }187}...

Full Screen

Full Screen

PhingVersion.php

Source:PhingVersion.php Github

copy

Full Screen

...83 /**84 * Get the atleast attribute.85 * @return string the atleast attribute.86 */87 public function getAtLeast()88 {89 return $this->atLeast;90 }91 /**92 * Set the atleast attribute.93 * This is of the form major.minor.point.94 * For example 1.7.0.95 * @param string $atLeast the version to check against.96 */97 public function setAtLeast($atLeast)98 {99 $this->atLeast = $atLeast;100 }101 /**102 * Get the exactly attribute.103 * @return string the exactly attribute.104 */105 public function getExactly()106 {107 return $this->exactly;108 }109 /**110 * Set the exactly attribute.111 * This is of the form major.minor.point....

Full Screen

Full Screen

AtLeast

Using AI Code Generation

copy

Full Screen

1$atLeast = Phake::atLeast(2);2Phake::verify($mock, $atLeast)->foo('bar');3$atMost = Phake::atMost(2);4Phake::verify($mock, $atMost)->foo('bar');5$between = Phake::between(1, 2);6Phake::verify($mock, $between)->foo('bar');7$exactly = Phake::exactly(2);8Phake::verify($mock, $exactly)->foo('bar');9$never = Phake::never();10Phake::verify($mock, $never)->foo('bar');11$once = Phake::once();12Phake::verify($mock, $once)->foo('bar');13$anyParameters = Phake::anyParameters();14Phake::verify($mock, $anyParameters)->foo('bar');15$ignoreRemaining = Phake::ignoreRemaining();16Phake::verify($mock, $ignoreRemaining)->foo('bar');17$anyParameters = Phake::anyParameters();18Phake::verify($mock, $anyParameters)->foo('bar');19$ignoreRemaining = Phake::ignoreRemaining();20Phake::verify($mock, $ignoreRemaining)->foo('bar');21$anyParameters = Phake::anyParameters();22Phake::verify($mock, $anyParameters)->foo('bar');23$ignoreRemaining = Phake::ignoreRemaining();24Phake::verify($mock, $ignoreRemaining)->foo('bar');25$anyParameters = Phake::anyParameters();26Phake::verify($mock, $anyParameters)->foo('bar');

Full Screen

Full Screen

AtLeast

Using AI Code Generation

copy

Full Screen

1$mock = Phake::mock('AtLeast');2Phake::when($mock)->getSomething()->thenReturn('something');3Phake::when($mock)->getSomethingElse()->thenReturn('something else');4$mock = Phake::mock('AtLeast');5Phake::when($mock)->getSomething()->thenReturn('something');6Phake::when($mock)->getSomethingElse()->thenReturn('something else');7$mock = Phake::mock('AtLeast');8Phake::when($mock)->getSomething()->thenReturn('something');9Phake::when($mock)->getSomethingElse()->thenReturn('something else');10$mock = Phake::mock('AtLeast');11Phake::when($mock)->getSomething()->thenReturn('something');12Phake::when($mock)->getSomethingElse()->thenReturn('something else');13$mock = Phake::mock('AtLeast');14Phake::when($mock)->getSomething()->thenReturn('something');15Phake::when($mock)->getSomethingElse()->thenReturn('something else');16$mock = Phake::mock('AtLeast');17Phake::when($mock)->getSomething()->thenReturn('something');18Phake::when($mock)->getSomethingElse()->thenReturn('something else');19$mock = Phake::mock('AtLeast');20Phake::when($mock)->getSomething()->thenReturn('something');21Phake::when($mock)->getSomethingElse()->thenReturn('something else');22$mock = Phake::mock('AtLeast');23Phake::when($mock)->getSomething()->thenReturn('something');24Phake::when($mock)->getSomethingElse()->thenReturn('something else');25$mock = Phake::mock('AtLeast');26Phake::when($mock)->getSomething()->thenReturn('something');

Full Screen

Full Screen

AtLeast

Using AI Code Generation

copy

Full Screen

1require_once 'PHPUnit/Autoload.php';2require_once 'Phake.php';3$atLeast = Phake::mock('Phake_Matchers_AtLeast');4Phake::when($atLeast)->matches(Phake::anyParameters())->thenReturn(true);5require_once 'PHPUnit/Autoload.php';6require_once 'Phake.php';7$atMost = Phake::mock('Phake_Matchers_AtMost');8Phake::when($atMost)->matches(Phake::anyParameters())->thenReturn(true);9require_once 'PHPUnit/Autoload.php';10require_once 'Phake.php';11$between = Phake::mock('Phake_Matchers_Between');12Phake::when($between)->matches(Phake::anyParameters())->thenReturn(true);13require_once 'PHPUnit/Autoload.php';14require_once 'Phake.php';15$contains = Phake::mock('Phake_Matchers_Contains');16Phake::when($contains)->matches(Phake::anyParameters())->thenReturn(true);17require_once 'PHPUnit/Autoload.php';18require_once 'Phake.php';19$equals = Phake::mock('Phake_Matchers_Equals');20Phake::when($equals)->matches(Phake::anyParameters())->thenReturn(true);21require_once 'PHPUnit/Autoload.php';22require_once 'Phake.php';23$identical = Phake::mock('Phake_Matchers_Identical');24Phake::when($identical)->matches(Phake::anyParameters())->thenReturn(true);25require_once 'PHPUnit/Autoload.php';26require_once 'Phake.php';27$isNull = Phake::mock('Phake_Matchers_IsNull');28Phake::when($isNull)->matches(Phake::anyParameters())->thenReturn(true);29require_once 'PHPUnit/Autoload.php';30require_once 'Phake.php';31$isTrue = Phake::mock('Phake_Matchers_IsTrue');32Phake::when($isTrue)->matches(Phake::anyParameters())->thenReturn(true);

Full Screen

Full Screen

AtLeast

Using AI Code Generation

copy

Full Screen

1$mock = Phake::mock('AtLeast');2Phake::when($mock)->foo('bar')->thenReturn('baz');3$mock = Phake::mock('AtLeast');4Phake::when($mock)->foo('bar')->thenReturn('baz');5$mock = Phake::mock('AtLeast');6Phake::when($mock)->foo('bar')->thenReturn('baz');7$mock = Phake::mock('AtLeast');8Phake::when($mock)->foo('bar')->thenReturn('baz');9$mock = Phake::mock('AtLeast');10Phake::when($mock)->foo('bar')->thenReturn('baz');11$mock = Phake::mock('AtLeast');12Phake::when($mock)->foo('bar')->thenReturn('baz');13$mock = Phake::mock('AtLeast');14Phake::when($mock)->foo('bar')->thenReturn('baz');15$mock = Phake::mock('AtLeast');16Phake::when($mock)->foo('bar')->thenReturn('baz');17$mock = Phake::mock('AtLeast');18Phake::when($mock)->foo('bar')->thenReturn('baz');19$mock = Phake::mock('AtLeast');20Phake::when($mock)->foo('bar')->thenReturn('baz');21$mock = Phake::mock('AtLeast');22Phake::when($mock)->foo('bar')->thenReturn('baz');23$mock = Phake::mock('AtLeast');24Phake::when($mock)->foo('bar')->thenReturn('baz');25$mock = Phake::mock('AtLeast');

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Phake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in AtLeast

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful