2017-02-12 12:00:11 +01:00
< ? php
/**
* BillControllerTest . php
* Copyright ( c ) 2017 thegrumpydictator @ gmail . com
*
2017-10-21 08:40:00 +02:00
* This file is part of Firefly III .
*
* Firefly III is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* Firefly III is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2017-12-17 14:42:21 +01:00
* along with Firefly III . If not , see < http :// www . gnu . org / licenses />.
2017-02-12 12:00:11 +01:00
*/
2017-07-08 06:28:44 +02:00
declare ( strict_types = 1 );
2017-02-12 12:00:11 +01:00
namespace Tests\Feature\Controllers ;
2017-03-05 11:18:34 +01:00
use Carbon\Carbon ;
2018-02-28 15:50:00 +01:00
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface ;
2017-03-05 11:18:34 +01:00
use FireflyIII\Helpers\Collector\JournalCollectorInterface ;
use FireflyIII\Models\Bill ;
2018-06-01 22:04:52 +02:00
use FireflyIII\Models\Rule ;
use FireflyIII\Models\RuleGroup ;
2017-03-05 11:18:34 +01:00
use FireflyIII\Models\TransactionJournal ;
2017-02-12 12:21:44 +01:00
use FireflyIII\Repositories\Bill\BillRepositoryInterface ;
2017-03-05 11:18:34 +01:00
use FireflyIII\Repositories\Journal\JournalRepositoryInterface ;
2018-06-01 22:04:52 +02:00
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface ;
use FireflyIII\TransactionRules\TransactionMatcher ;
2017-03-05 11:18:34 +01:00
use Illuminate\Pagination\LengthAwarePaginator ;
2017-02-12 12:21:44 +01:00
use Illuminate\Support\Collection ;
2018-02-28 15:50:00 +01:00
use Illuminate\Support\MessageBag ;
2018-03-24 06:08:50 +01:00
use Log ;
2018-06-01 22:04:52 +02:00
use Mockery ;
2017-02-12 12:00:11 +01:00
use Tests\TestCase ;
2017-08-12 10:27:45 +02:00
/**
* Class BillControllerTest
*
* @ SuppressWarnings ( PHPMD . TooManyPublicMethods )
* @ SuppressWarnings ( PHPMD . ExcessiveMethodLength )
* @ SuppressWarnings ( PHPMD . CouplingBetweenObjects )
*/
2017-02-12 12:00:11 +01:00
class BillControllerTest extends TestCase
{
2018-03-24 06:08:50 +01:00
/**
*
*/
public function setUp ()
{
parent :: setUp ();
2018-04-28 10:27:33 +02:00
Log :: debug ( sprintf ( 'Now in %s.' , \get_class ( $this )));
2018-03-24 06:08:50 +01:00
}
2017-02-12 12:21:44 +01:00
/**
* @ covers \FireflyIII\Http\Controllers\BillController :: create
*/
2018-05-11 19:58:10 +02:00
public function testCreate () : void
2017-02-12 12:21:44 +01:00
{
2017-03-05 11:18:34 +01:00
// mock stuff
2018-02-28 15:50:00 +01:00
$attachHelper = $this -> mock ( AttachmentHelperInterface :: class );
2017-03-05 11:18:34 +01:00
$journalRepos = $this -> mock ( JournalRepositoryInterface :: class );
2018-06-01 22:04:52 +02:00
$ruleGroupRepos = $this -> mock ( RuleGroupRepositoryInterface :: class );
2018-04-28 10:27:33 +02:00
$journalRepos -> shouldReceive ( 'firstNull' ) -> once () -> andReturn ( new TransactionJournal );
2017-03-05 11:18:34 +01:00
2017-02-12 12:21:44 +01:00
$this -> be ( $this -> user ());
$response = $this -> get ( route ( 'bills.create' ));
$response -> assertStatus ( 200 );
// has bread crumb
$response -> assertSee ( '<ol class="breadcrumb">' );
}
/**
* @ covers \FireflyIII\Http\Controllers\BillController :: delete
*/
2018-05-11 19:58:10 +02:00
public function testDelete () : void
2017-02-12 12:21:44 +01:00
{
2017-03-05 11:18:34 +01:00
// mock stuff
2018-02-28 15:50:00 +01:00
$attachHelper = $this -> mock ( AttachmentHelperInterface :: class );
2017-03-05 11:18:34 +01:00
$journalRepos = $this -> mock ( JournalRepositoryInterface :: class );
2018-06-01 22:04:52 +02:00
$ruleGroupRepos = $this -> mock ( RuleGroupRepositoryInterface :: class );
2018-04-28 10:27:33 +02:00
$journalRepos -> shouldReceive ( 'firstNull' ) -> once () -> andReturn ( new TransactionJournal );
2017-03-05 11:18:34 +01:00
2017-02-12 12:21:44 +01:00
$this -> be ( $this -> user ());
$response = $this -> get ( route ( 'bills.delete' , [ 1 ]));
$response -> assertStatus ( 200 );
// has bread crumb
$response -> assertSee ( '<ol class="breadcrumb">' );
}
/**
* @ covers \FireflyIII\Http\Controllers\BillController :: destroy
*/
2018-05-11 19:58:10 +02:00
public function testDestroy () : void
2017-02-12 12:21:44 +01:00
{
2017-03-05 11:18:34 +01:00
// mock stuff
2018-02-28 15:50:00 +01:00
$attachHelper = $this -> mock ( AttachmentHelperInterface :: class );
2017-03-05 11:18:34 +01:00
$journalRepos = $this -> mock ( JournalRepositoryInterface :: class );
$repository = $this -> mock ( BillRepositoryInterface :: class );
2018-06-01 22:04:52 +02:00
$ruleGroupRepos = $this -> mock ( RuleGroupRepositoryInterface :: class );
2017-02-12 12:21:44 +01:00
$repository -> shouldReceive ( 'destroy' ) -> andReturn ( true );
2018-04-28 10:27:33 +02:00
$journalRepos -> shouldReceive ( 'firstNull' ) -> once () -> andReturn ( new TransactionJournal );
2017-02-12 12:21:44 +01:00
2017-03-18 20:53:44 +01:00
$this -> session ([ 'bills.delete.uri' => 'http://localhost' ]);
2017-02-12 12:21:44 +01:00
$this -> be ( $this -> user ());
$response = $this -> post ( route ( 'bills.destroy' , [ 1 ]));
$response -> assertStatus ( 302 );
$response -> assertSessionHas ( 'success' );
}
/**
* @ covers \FireflyIII\Http\Controllers\BillController :: edit
*/
2018-05-11 19:58:10 +02:00
public function testEdit () : void
2017-02-12 12:21:44 +01:00
{
2017-03-05 11:18:34 +01:00
// mock stuff
2018-02-28 15:50:00 +01:00
$attachHelper = $this -> mock ( AttachmentHelperInterface :: class );
2017-03-05 11:18:34 +01:00
$journalRepos = $this -> mock ( JournalRepositoryInterface :: class );
2018-06-01 22:04:52 +02:00
$ruleGroupRepos = $this -> mock ( RuleGroupRepositoryInterface :: class );
2018-04-28 10:27:33 +02:00
$journalRepos -> shouldReceive ( 'firstNull' ) -> once () -> andReturn ( new TransactionJournal );
2017-03-05 11:18:34 +01:00
2017-02-12 12:21:44 +01:00
$this -> be ( $this -> user ());
$response = $this -> get ( route ( 'bills.edit' , [ 1 ]));
$response -> assertStatus ( 200 );
// has bread crumb
$response -> assertSee ( '<ol class="breadcrumb">' );
}
/**
* @ covers \FireflyIII\Http\Controllers\BillController :: index
2017-02-17 20:14:38 +01:00
* @ covers \FireflyIII\Http\Controllers\BillController :: __construct
2017-02-12 12:21:44 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testIndex () : void
2017-02-12 12:21:44 +01:00
{
2017-03-05 11:18:34 +01:00
// mock stuff
2018-02-28 15:50:00 +01:00
$attachHelper = $this -> mock ( AttachmentHelperInterface :: class );
2017-03-18 11:02:02 +01:00
$bill = factory ( Bill :: class ) -> make ();
2017-03-05 11:18:34 +01:00
$journalRepos = $this -> mock ( JournalRepositoryInterface :: class );
$repository = $this -> mock ( BillRepositoryInterface :: class );
2018-06-01 22:04:52 +02:00
$ruleGroupRepos = $this -> mock ( RuleGroupRepositoryInterface :: class );
2018-04-28 10:27:33 +02:00
$journalRepos -> shouldReceive ( 'firstNull' ) -> once () -> andReturn ( new TransactionJournal );
2018-02-07 16:49:11 +01:00
$collection = new Collection ([ $bill ]);
$repository -> shouldReceive ( 'getPaginator' ) -> andReturn ( new LengthAwarePaginator ( $collection , 1 , 50 )) -> once ();
$repository -> shouldReceive ( 'setUser' );
2017-12-06 19:41:51 +01:00
$repository -> shouldReceive ( 'getPaidDatesInRange' ) -> twice () -> andReturn ( new Collection ([ new Carbon , new Carbon , new Carbon ]));
2018-04-14 21:21:20 +02:00
$repository -> shouldReceive ( 'getRulesForBills' ) -> andReturn ([]);
2018-02-07 16:49:11 +01:00
2017-02-12 12:21:44 +01:00
$this -> be ( $this -> user ());
$response = $this -> get ( route ( 'bills.index' ));
$response -> assertStatus ( 200 );
// has bread crumb
$response -> assertSee ( '<ol class="breadcrumb">' );
}
/**
* @ covers \FireflyIII\Http\Controllers\BillController :: rescan
*/
2018-05-11 19:58:10 +02:00
public function testRescan () : void
2017-02-12 12:21:44 +01:00
{
2017-03-05 11:18:34 +01:00
// mock stuff
2018-06-01 22:04:52 +02:00
$rule = Rule :: first ();
2018-02-28 15:50:00 +01:00
$attachHelper = $this -> mock ( AttachmentHelperInterface :: class );
2017-03-18 11:02:02 +01:00
$journal = factory ( TransactionJournal :: class ) -> make ();
2017-03-05 11:18:34 +01:00
$journalRepos = $this -> mock ( JournalRepositoryInterface :: class );
$repository = $this -> mock ( BillRepositoryInterface :: class );
2018-06-01 22:04:52 +02:00
$ruleGroupRepos = $this -> mock ( RuleGroupRepositoryInterface :: class );
2018-04-28 10:27:33 +02:00
$journalRepos -> shouldReceive ( 'firstNull' ) -> once () -> andReturn ( new TransactionJournal );
2018-06-01 22:04:52 +02:00
$repository -> shouldReceive ( 'getRulesForBill' ) -> andReturn ( new Collection ([ $rule ]));
//calls for transaction matcher:
$matcher = $this -> mock ( TransactionMatcher :: class );
$matcher -> shouldReceive ( 'setLimit' ) -> once () -> withArgs ([ 100000 ]);
$matcher -> shouldReceive ( 'setRange' ) -> once () -> withArgs ([ 100000 ]);
$matcher -> shouldReceive ( 'setRule' ) -> once () -> withArgs ([ Mockery :: any ()]);
$matcher -> shouldReceive ( 'findTransactionsByRule' ) -> once () -> andReturn ( new Collection );
$repository -> shouldReceive ( 'linkCollectionToBill' ) -> once ();
2017-02-12 12:21:44 +01:00
$this -> be ( $this -> user ());
$response = $this -> get ( route ( 'bills.rescan' , [ 1 ]));
$response -> assertStatus ( 302 );
$response -> assertSessionHas ( 'success' );
}
2017-03-18 11:02:02 +01:00
/**
* @ covers \FireflyIII\Http\Controllers\BillController :: rescan
*/
2018-05-11 19:58:10 +02:00
public function testRescanInactive () : void
2017-03-18 11:02:02 +01:00
{
// mock stuff
2018-02-28 15:50:00 +01:00
$attachHelper = $this -> mock ( AttachmentHelperInterface :: class );
2017-03-18 11:02:02 +01:00
$journalRepos = $this -> mock ( JournalRepositoryInterface :: class );
2018-02-28 15:50:00 +01:00
$repository = $this -> mock ( BillRepositoryInterface :: class );
2018-06-01 22:04:52 +02:00
$ruleGroupRepos = $this -> mock ( RuleGroupRepositoryInterface :: class );
2018-04-28 10:27:33 +02:00
$journalRepos -> shouldReceive ( 'firstNull' ) -> once () -> andReturn ( new TransactionJournal );
2017-03-18 11:02:02 +01:00
$this -> be ( $this -> user ());
$response = $this -> get ( route ( 'bills.rescan' , [ 3 ]));
$response -> assertStatus ( 302 );
$response -> assertSessionHas ( 'warning' );
}
2017-02-12 12:21:44 +01:00
/**
* @ covers \FireflyIII\Http\Controllers\BillController :: show
*/
2018-05-11 19:58:10 +02:00
public function testShow () : void
2017-02-12 12:21:44 +01:00
{
2017-03-05 11:18:34 +01:00
// mock stuff
2018-02-28 15:50:00 +01:00
$attachHelper = $this -> mock ( AttachmentHelperInterface :: class );
2017-03-05 11:18:34 +01:00
$journalRepos = $this -> mock ( JournalRepositoryInterface :: class );
$collector = $this -> mock ( JournalCollectorInterface :: class );
$repository = $this -> mock ( BillRepositoryInterface :: class );
2018-06-01 22:04:52 +02:00
$ruleGroupRepos = $this -> mock ( RuleGroupRepositoryInterface :: class );
2017-03-05 11:18:34 +01:00
$repository -> shouldReceive ( 'getYearAverage' ) -> andReturn ( '0' );
$repository -> shouldReceive ( 'getOverallAverage' ) -> andReturn ( '0' );
$repository -> shouldReceive ( 'nextExpectedMatch' ) -> andReturn ( new Carbon );
2018-04-14 21:21:20 +02:00
$repository -> shouldReceive ( 'getRulesForBill' ) -> andReturn ( new Collection );
2018-04-28 10:27:33 +02:00
$journalRepos -> shouldReceive ( 'firstNull' ) -> once () -> andReturn ( new TransactionJournal );
2017-03-05 11:18:34 +01:00
$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 ( 'getPaginatedJournals' ) -> andReturn ( new LengthAwarePaginator ([], 0 , 10 ));
2017-12-06 19:41:51 +01:00
$repository -> shouldReceive ( 'getPaidDatesInRange' ) -> twice () -> andReturn ( new Collection ([ new Carbon , new Carbon , new Carbon ]));
2018-02-07 16:49:11 +01:00
$repository -> shouldReceive ( 'setUser' );
2017-03-05 11:18:34 +01:00
2017-02-12 12:21:44 +01:00
$this -> be ( $this -> user ());
$response = $this -> get ( route ( 'bills.show' , [ 1 ]));
$response -> assertStatus ( 200 );
// has bread crumb
$response -> assertSee ( '<ol class="breadcrumb">' );
}
/**
2018-07-12 21:32:58 +02:00
* @ covers \FireflyIII\Http\Controllers\BillController
2018-03-03 17:16:47 +01:00
* @ covers \FireflyIII\Http\Requests\BillFormRequest
* @ covers \FireflyIII\Http\Requests\Request
2017-02-12 12:21:44 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testStore () : void
2017-02-12 12:21:44 +01:00
{
2018-07-12 21:32:58 +02:00
$this -> be ( $this -> user ());
$bill = $this -> user () -> bills () -> first ();
2017-03-05 11:18:34 +01:00
// mock stuff
2018-02-28 15:50:00 +01:00
$attachHelper = $this -> mock ( AttachmentHelperInterface :: class );
2017-03-05 11:18:34 +01:00
$journalRepos = $this -> mock ( JournalRepositoryInterface :: class );
$repository = $this -> mock ( BillRepositoryInterface :: class );
2018-06-01 22:04:52 +02:00
$ruleGroupRepos = $this -> mock ( RuleGroupRepositoryInterface :: class );
$journalRepos -> shouldReceive ( 'firstNull' ) -> once () -> andReturn ( new TransactionJournal );
2018-07-12 21:32:58 +02:00
$repository -> shouldReceive ( 'store' ) -> andReturn ( $bill );
2018-06-01 22:04:52 +02:00
$attachHelper -> shouldReceive ( 'saveAttachmentsForModel' );
$attachHelper -> shouldReceive ( 'getMessages' ) -> andReturn ( new MessageBag );
$ruleGroupRepos -> shouldReceive ( 'count' ) -> andReturn ( 1 );
$ruleGroupRepos -> shouldReceive ( 'getActiveGroups' ) -> andReturn ( new Collection ([ RuleGroup :: first ()])) -> once ();
$data = [
'name' => 'New Bill ' . random_int ( 1000 , 9999 ),
'amount_min' => '100' ,
'transaction_currency_id' => 1 ,
'skip' => 0 ,
'strict' => 1 ,
'amount_max' => '100' ,
'date' => '2016-01-01' ,
'repeat_freq' => 'monthly' ,
];
$this -> session ([ 'bills.create.uri' => 'http://localhost' ]);
2018-07-12 21:32:58 +02:00
2018-06-01 22:04:52 +02:00
$response = $this -> post ( route ( 'bills.store' ), $data );
$response -> assertStatus ( 302 );
$response -> assertSessionHas ( 'success' );
}
/**
* @ covers \FireflyIII\Http\Controllers\BillController :: store
* @ covers \FireflyIII\Http\Requests\BillFormRequest
* @ covers \FireflyIII\Http\Requests\Request
*/
public function testStoreCreateAnother () : void
{
// mock stuff
$attachHelper = $this -> mock ( AttachmentHelperInterface :: class );
$journalRepos = $this -> mock ( JournalRepositoryInterface :: class );
$repository = $this -> mock ( BillRepositoryInterface :: class );
$ruleGroupRepos = $this -> mock ( RuleGroupRepositoryInterface :: class );
2018-07-12 21:32:58 +02:00
$bill = $this -> user () -> bills () -> first ();
2018-04-28 10:27:33 +02:00
$journalRepos -> shouldReceive ( 'firstNull' ) -> once () -> andReturn ( new TransactionJournal );
2018-07-12 21:32:58 +02:00
$repository -> shouldReceive ( 'store' ) -> andReturn ( $bill );
2018-02-28 15:50:00 +01:00
$attachHelper -> shouldReceive ( 'saveAttachmentsForModel' );
$attachHelper -> shouldReceive ( 'getMessages' ) -> andReturn ( new MessageBag );
2018-06-01 22:04:52 +02:00
$ruleGroupRepos -> shouldReceive ( 'count' ) -> andReturn ( 1 );
$ruleGroupRepos -> shouldReceive ( 'getActiveGroups' ) -> andReturn ( new Collection ([ RuleGroup :: first ()])) -> once ();
2017-03-05 11:18:34 +01:00
2017-02-12 12:21:44 +01:00
$data = [
2018-04-14 21:21:20 +02:00
'name' => 'New Bill ' . random_int ( 1000 , 9999 ),
'amount_min' => '100' ,
'transaction_currency_id' => 1 ,
'skip' => 0 ,
2018-06-01 22:04:52 +02:00
'create_another' => '1' ,
2018-04-14 21:21:20 +02:00
'strict' => 1 ,
'amount_max' => '100' ,
'date' => '2016-01-01' ,
'repeat_freq' => 'monthly' ,
2017-02-12 12:21:44 +01:00
];
2017-03-18 20:53:44 +01:00
$this -> session ([ 'bills.create.uri' => 'http://localhost' ]);
2017-02-12 12:21:44 +01:00
$this -> be ( $this -> user ());
$response = $this -> post ( route ( 'bills.store' ), $data );
$response -> assertStatus ( 302 );
$response -> assertSessionHas ( 'success' );
}
2018-06-01 22:04:52 +02:00
/**
* @ covers \FireflyIII\Http\Controllers\BillController :: store
* @ covers \FireflyIII\Http\Requests\BillFormRequest
* @ covers \FireflyIII\Http\Requests\Request
*/
public function testStoreNoGroup () : void
{
// mock stuff
$attachHelper = $this -> mock ( AttachmentHelperInterface :: class );
$journalRepos = $this -> mock ( JournalRepositoryInterface :: class );
$repository = $this -> mock ( BillRepositoryInterface :: class );
$ruleGroupRepos = $this -> mock ( RuleGroupRepositoryInterface :: class );
$journalRepos -> shouldReceive ( 'firstNull' ) -> once () -> andReturn ( new TransactionJournal );
$repository -> shouldReceive ( 'store' ) -> andReturn ( new Bill );
$attachHelper -> shouldReceive ( 'saveAttachmentsForModel' );
$attachHelper -> shouldReceive ( 'getMessages' ) -> andReturn ( new MessageBag );
$ruleGroupRepos -> shouldReceive ( 'count' ) -> andReturn ( 0 );
$ruleGroupRepos -> shouldReceive ( 'store' ) -> once () -> withArgs ([[ 'title' => 'Rule group for bills' , 'description' => 'A special rule group for all the rules that involve bills.' ]]) -> andReturn ( RuleGroup :: first ());
$data = [
'name' => 'New Bill ' . random_int ( 1000 , 9999 ),
'amount_min' => '100' ,
'transaction_currency_id' => 1 ,
'skip' => 0 ,
'create_another' => '1' ,
'strict' => 1 ,
'amount_max' => '100' ,
'date' => '2016-01-01' ,
'repeat_freq' => 'monthly' ,
];
$this -> session ([ 'bills.create.uri' => 'http://localhost' ]);
$this -> be ( $this -> user ());
$response = $this -> post ( route ( 'bills.store' ), $data );
$response -> assertStatus ( 302 );
$response -> assertSessionHas ( 'success' );
}
/**
* @ covers \FireflyIII\Http\Controllers\BillController :: store
* @ covers \FireflyIII\Http\Requests\BillFormRequest
* @ covers \FireflyIII\Http\Requests\Request
*/
public function testStoreError () : void
{
// mock stuff
$attachHelper = $this -> mock ( AttachmentHelperInterface :: class );
$journalRepos = $this -> mock ( JournalRepositoryInterface :: class );
$repository = $this -> mock ( BillRepositoryInterface :: class );
$ruleGroupRepos = $this -> mock ( RuleGroupRepositoryInterface :: class );
$journalRepos -> shouldReceive ( 'firstNull' ) -> once () -> andReturn ( new TransactionJournal );
$repository -> shouldReceive ( 'store' ) -> andReturn ( null );
$data = [
'name' => 'New Bill ' . random_int ( 1000 , 9999 ),
'amount_min' => '100' ,
'transaction_currency_id' => 1 ,
'skip' => 0 ,
'strict' => 1 ,
'amount_max' => '100' ,
'date' => '2016-01-01' ,
'repeat_freq' => 'monthly' ,
];
$this -> be ( $this -> user ());
$response = $this -> post ( route ( 'bills.store' ), $data );
$response -> assertStatus ( 302 );
$response -> assertSessionHas ( 'error' );
$response -> assertRedirect ( route ( 'bills.create' ));
}
2017-02-12 12:21:44 +01:00
/**
* @ covers \FireflyIII\Http\Controllers\BillController :: update
2018-03-03 17:16:47 +01:00
* @ covers \FireflyIII\Http\Requests\BillFormRequest
* @ covers \FireflyIII\Http\Requests\Request
2017-02-12 12:21:44 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testUpdate () : void
2017-02-12 12:21:44 +01:00
{
2017-03-05 11:18:34 +01:00
// mock stuff
2018-02-28 15:50:00 +01:00
$attachHelper = $this -> mock ( AttachmentHelperInterface :: class );
2017-03-05 11:18:34 +01:00
$journalRepos = $this -> mock ( JournalRepositoryInterface :: class );
$repository = $this -> mock ( BillRepositoryInterface :: class );
2018-06-01 22:04:52 +02:00
$ruleGroupRepos = $this -> mock ( RuleGroupRepositoryInterface :: class );
2018-04-28 10:27:33 +02:00
$journalRepos -> shouldReceive ( 'firstNull' ) -> once () -> andReturn ( new TransactionJournal );
2017-03-05 11:18:34 +01:00
$repository -> shouldReceive ( 'update' ) -> andReturn ( new Bill );
2018-02-28 15:50:00 +01:00
$attachHelper -> shouldReceive ( 'saveAttachmentsForModel' );
$attachHelper -> shouldReceive ( 'getMessages' ) -> andReturn ( new MessageBag );
2017-03-05 11:18:34 +01:00
2017-02-12 12:21:44 +01:00
$data = [
2018-06-01 22:04:52 +02:00
'id' => 1 ,
'name' => 'Updated Bill ' . random_int ( 1000 , 9999 ),
'amount_min' => '100' ,
2018-04-14 21:21:20 +02:00
'transaction_currency_id' => 1 ,
2018-06-01 22:04:52 +02:00
'skip' => 0 ,
'amount_max' => '100' ,
'date' => '2016-01-01' ,
'repeat_freq' => 'monthly' ,
2017-02-12 12:21:44 +01:00
];
2017-03-18 20:53:44 +01:00
$this -> session ([ 'bills.edit.uri' => 'http://localhost' ]);
2017-02-12 12:21:44 +01:00
$this -> be ( $this -> user ());
$response = $this -> post ( route ( 'bills.update' , [ 1 ]), $data );
$response -> assertStatus ( 302 );
$response -> assertSessionHas ( 'success' );
}
2017-02-16 22:33:32 +01:00
}