. */ declare(strict_types=1); namespace Tests\Feature\Controllers; use Carbon\Carbon; use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Models\Budget; use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Collection; use Log; use Tests\TestCase; /** * Class BudgetControllerTest * * @SuppressWarnings(PHPMD.TooManyPublicMethods) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class BudgetControllerTest extends TestCase { /** * */ public function setUp() { parent::setUp(); Log::debug(sprintf('Now in %s.', \get_class($this))); } /** * @covers \FireflyIII\Http\Controllers\BudgetController::amount */ public function testAmount(): void { Log::debug('Now in testAmount()'); // mock stuff $repository = $this->mock(BudgetRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); $repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit); $repository->shouldReceive('spentInPeriod')->andReturn('0'); $repository->shouldReceive('budgetedPerDay')->andReturn('10'); $data = ['amount' => 200, 'start' => '2017-01-01', 'end' => '2017-01-31']; $this->be($this->user()); $response = $this->post(route('budgets.amount', [1]), $data); $response->assertStatus(200); } /** * @covers \FireflyIII\Http\Controllers\BudgetController::amount */ public function testAmountLargeDiff(): void { Log::debug('Now in testAmount()'); // mock stuff $repository = $this->mock(BudgetRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); $repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit); $repository->shouldReceive('spentInPeriod')->andReturn('0'); $repository->shouldReceive('budgetedPerDay')->andReturn('10'); $data = ['amount' => 20000, 'start' => '2017-01-01', 'end' => '2017-01-31']; $this->be($this->user()); $response = $this->post(route('budgets.amount', [1]), $data); $response->assertStatus(200); $response->assertSee('Normally you budget about \u20ac10.00 per day.'); } /** * @covers \FireflyIII\Http\Controllers\BudgetController::amount */ public function testAmountZero(): void { Log::debug('Now in testAmountZero()'); // mock stuff $repository = $this->mock(BudgetRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); $repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit); $repository->shouldReceive('spentInPeriod')->andReturn('0'); $repository->shouldReceive('budgetedPerDay')->andReturn('10'); $data = ['amount' => 0, 'start' => '2017-01-01', 'end' => '2017-01-31']; $this->be($this->user()); $response = $this->post(route('budgets.amount', [1]), $data); $response->assertStatus(200); } /** * @covers \FireflyIII\Http\Controllers\BudgetController::amount */ public function testAmountOutOfRange(): void { Log::debug('Now in testAmountOutOfRange()'); // mock stuff $repository = $this->mock(BudgetRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); $repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit); $repository->shouldReceive('spentInPeriod')->andReturn('0'); $repository->shouldReceive('budgetedPerDay')->andReturn('10'); $today = new Carbon; $start = $today->startOfMonth()->format('Y-m-d'); $end = $today->endOfMonth()->format('Y-m-d'); $data = ['amount' => 200, 'start' => $start, 'end' => $end]; $this->be($this->user()); $response = $this->post(route('budgets.amount', [1]), $data); $response->assertStatus(200); } /** * @covers \FireflyIII\Http\Controllers\BudgetController::create */ public function testCreate(): void { Log::debug('Now in testCreate()'); // mock stuff $repository = $this->mock(BudgetRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); $this->be($this->user()); $response = $this->get(route('budgets.create')); $response->assertStatus(200); // has bread crumb $response->assertSee('