mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-19 02:45:58 +00:00
Mock previously unmocked calls.
This commit is contained in:
@@ -155,7 +155,7 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
* @param Account $account
|
* @param Account $account
|
||||||
* @param int $page
|
* @param int $page
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return LengthAwarePaginator
|
||||||
*/
|
*/
|
||||||
public function getJournals(Account $account, $page)
|
public function getJournals(Account $account, $page)
|
||||||
{
|
{
|
||||||
|
@@ -7,6 +7,7 @@ use FireflyIII\Models\Account;
|
|||||||
use FireflyIII\Models\Preference;
|
use FireflyIII\Models\Preference;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,7 +83,7 @@ interface AccountRepositoryInterface
|
|||||||
* @param Account $account
|
* @param Account $account
|
||||||
* @param string $range
|
* @param string $range
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return LengthAwarePaginator
|
||||||
*/
|
*/
|
||||||
public function getJournals(Account $account, $page);
|
public function getJournals(Account $account, $page);
|
||||||
|
|
||||||
|
@@ -4,6 +4,7 @@ use FireflyIII\Models\Account;
|
|||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\Preference;
|
use FireflyIII\Models\Preference;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use League\FactoryMuffin\Facade as FactoryMuffin;
|
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||||
|
|
||||||
@@ -95,12 +96,15 @@ class AccountControllerTest extends TestCase
|
|||||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||||
|
|
||||||
$this->be($account->user);
|
$this->be($account->user);
|
||||||
$this->assertCount(1, DB::table('accounts')->where('id', $account->id)->whereNull('deleted_at')->get());
|
|
||||||
|
// mock:
|
||||||
|
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
|
||||||
|
$repository->shouldReceive('destroy')->andReturn(true);
|
||||||
|
|
||||||
// post it!
|
// post it!
|
||||||
$this->call('POST', '/accounts/destroy/' . $account->id, ['_token' => 'replaceme']);
|
$this->call('POST', '/accounts/destroy/' . $account->id, ['_token' => 'replaceme']);
|
||||||
$this->assertSessionHas('success');
|
$this->assertSessionHas('success');
|
||||||
$this->assertCount(0, DB::table('accounts')->where('id', $account->id)->whereNull('deleted_at')->get());
|
$this->assertResponseStatus(302);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEdit()
|
public function testEdit()
|
||||||
@@ -167,7 +171,10 @@ class AccountControllerTest extends TestCase
|
|||||||
// an account:
|
// an account:
|
||||||
$this->be($this->account->user);
|
$this->be($this->account->user);
|
||||||
|
|
||||||
|
// mock!
|
||||||
Amount::shouldReceive('getCurrencyCode')->once()->andReturn('A');
|
Amount::shouldReceive('getCurrencyCode')->once()->andReturn('A');
|
||||||
|
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
|
||||||
|
$repository->shouldReceive('getJournals')->andReturn(new LengthAwarePaginator([],0,10));
|
||||||
|
|
||||||
// get edit page:
|
// get edit page:
|
||||||
$this->call('GET', '/accounts/show/' . $this->account->id);
|
$this->call('GET', '/accounts/show/' . $this->account->id);
|
||||||
|
@@ -93,6 +93,9 @@ class BillControllerTest extends TestCase
|
|||||||
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
|
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
|
||||||
$this->be($bill->user);
|
$this->be($bill->user);
|
||||||
|
|
||||||
|
$repository = $this->mock('FireflyIII\Repositories\Bill\BillRepositoryInterface');
|
||||||
|
$repository->shouldReceive('destroy')->andReturn(true);
|
||||||
|
|
||||||
|
|
||||||
$this->call('POST', '/bills/destroy/' . $bill->id, ['_token' => 'replaceMe']);
|
$this->call('POST', '/bills/destroy/' . $bill->id, ['_token' => 'replaceMe']);
|
||||||
$this->assertSessionHas('success', 'The bill was deleted.');
|
$this->assertSessionHas('success', 'The bill was deleted.');
|
||||||
|
@@ -78,12 +78,13 @@ class BudgetControllerTest extends TestCase
|
|||||||
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
|
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
|
||||||
$this->be($budget->user);
|
$this->be($budget->user);
|
||||||
|
|
||||||
$this->assertCount(1, DB::table('budgets')->where('id', $budget->id)->get());
|
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
||||||
|
$repository->shouldReceive('destroy')->andReturn(true);
|
||||||
|
|
||||||
$this->call('POST', '/budgets/destroy/' . $budget->id, ['_token' => 'replaceme']);
|
$this->call('POST', '/budgets/destroy/' . $budget->id, ['_token' => 'replaceme']);
|
||||||
|
|
||||||
$this->assertSessionHas('success', 'The budget "' . e($budget->name) . '" was deleted.');
|
$this->assertSessionHas('success', 'The budget "' . e($budget->name) . '" was deleted.');
|
||||||
$this->assertCount(0, DB::table('budgets')->wherenull('deleted_at')->where('id', $budget->id)->get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEdit()
|
public function testEdit()
|
||||||
|
@@ -146,12 +146,18 @@ class CategoryControllerTest extends TestCase
|
|||||||
|
|
||||||
public function testStore()
|
public function testStore()
|
||||||
{
|
{
|
||||||
$category = FactoryMuffin::create('FireflyIII\Models\Category');
|
// create
|
||||||
$repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
|
$category = FactoryMuffin::create('FireflyIII\Models\Category');
|
||||||
|
|
||||||
$repository->shouldReceive('store')->andReturn($category);
|
|
||||||
$this->be($category->user);
|
$this->be($category->user);
|
||||||
|
|
||||||
|
// mock
|
||||||
|
$repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
|
||||||
|
$request = $this->mock('FireflyIII\Http\Requests\CategoryFormRequest');
|
||||||
|
|
||||||
|
// expect
|
||||||
|
$repository->shouldReceive('store')->andReturn($category);
|
||||||
|
$request->shouldReceive('input')->andReturn('');
|
||||||
|
|
||||||
$this->call('POST', '/categories/store', ['_token' => 'replaceMe', 'name' => 'Bla bla #' . rand(1, 1000)]);
|
$this->call('POST', '/categories/store', ['_token' => 'replaceMe', 'name' => 'Bla bla #' . rand(1, 1000)]);
|
||||||
$this->assertResponseStatus(302);
|
$this->assertResponseStatus(302);
|
||||||
$this->assertSessionHas('success', 'New category "' . $category->name . '" stored!');
|
$this->assertSessionHas('success', 'New category "' . $category->name . '" stored!');
|
||||||
@@ -160,12 +166,19 @@ class CategoryControllerTest extends TestCase
|
|||||||
//
|
//
|
||||||
public function testStoreAndRedirect()
|
public function testStoreAndRedirect()
|
||||||
{
|
{
|
||||||
$category = FactoryMuffin::create('FireflyIII\Models\Category');
|
// create
|
||||||
$repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
|
$category = FactoryMuffin::create('FireflyIII\Models\Category');
|
||||||
|
|
||||||
$repository->shouldReceive('store')->andReturn($category);
|
|
||||||
$this->be($category->user);
|
$this->be($category->user);
|
||||||
|
|
||||||
|
// mock:
|
||||||
|
$repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
|
||||||
|
$request = $this->mock('FireflyIII\Http\Requests\CategoryFormRequest');
|
||||||
|
|
||||||
|
// fake:
|
||||||
|
$repository->shouldReceive('store')->andReturn($category);
|
||||||
|
$request->shouldReceive('input')->andReturn('');
|
||||||
|
|
||||||
|
|
||||||
$this->call('POST', '/categories/store', ['_token' => 'replaceMe', 'create_another' => 1, 'name' => 'Bla bla #' . rand(1, 1000)]);
|
$this->call('POST', '/categories/store', ['_token' => 'replaceMe', 'create_another' => 1, 'name' => 'Bla bla #' . rand(1, 1000)]);
|
||||||
$this->assertResponseStatus(302);
|
$this->assertResponseStatus(302);
|
||||||
$this->assertSessionHas('success', 'New category "' . $category->name . '" stored!');
|
$this->assertSessionHas('success', 'New category "' . $category->name . '" stored!');
|
||||||
@@ -173,12 +186,18 @@ class CategoryControllerTest extends TestCase
|
|||||||
|
|
||||||
public function testUpdate()
|
public function testUpdate()
|
||||||
{
|
{
|
||||||
$category = FactoryMuffin::create('FireflyIII\Models\Category');
|
// create
|
||||||
$repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
|
$category = FactoryMuffin::create('FireflyIII\Models\Category');
|
||||||
|
|
||||||
$repository->shouldReceive('update')->andReturn($category);
|
|
||||||
$this->be($category->user);
|
$this->be($category->user);
|
||||||
|
|
||||||
|
// mock
|
||||||
|
$repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
|
||||||
|
$request = $this->mock('FireflyIII\Http\Requests\CategoryFormRequest');
|
||||||
|
|
||||||
|
// expect
|
||||||
|
$repository->shouldReceive('update')->andReturn($category);
|
||||||
|
$request->shouldReceive('input')->andReturn('');
|
||||||
|
|
||||||
$this->call('POST', '/categories/update/' . $category->id, ['_token' => 'replaceMe', 'name' => 'Bla bla #' . rand(1, 1000)]);
|
$this->call('POST', '/categories/update/' . $category->id, ['_token' => 'replaceMe', 'name' => 'Bla bla #' . rand(1, 1000)]);
|
||||||
$this->assertResponseStatus(302);
|
$this->assertResponseStatus(302);
|
||||||
$this->assertSessionHas('success', 'Category "' . $category->name . '" updated.');
|
$this->assertSessionHas('success', 'Category "' . $category->name . '" updated.');
|
||||||
@@ -186,12 +205,19 @@ class CategoryControllerTest extends TestCase
|
|||||||
|
|
||||||
public function testUpdateAndRedirect()
|
public function testUpdateAndRedirect()
|
||||||
{
|
{
|
||||||
$category = FactoryMuffin::create('FireflyIII\Models\Category');
|
// create
|
||||||
$repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
|
$category = FactoryMuffin::create('FireflyIII\Models\Category');
|
||||||
|
|
||||||
$repository->shouldReceive('update')->andReturn($category);
|
|
||||||
$this->be($category->user);
|
$this->be($category->user);
|
||||||
|
|
||||||
|
// mock
|
||||||
|
$repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
|
||||||
|
$request = $this->mock('FireflyIII\Http\Requests\CategoryFormRequest');
|
||||||
|
|
||||||
|
// expect
|
||||||
|
$request->shouldReceive('input')->andReturn('');
|
||||||
|
$repository->shouldReceive('update')->andReturn($category);
|
||||||
|
|
||||||
|
|
||||||
$this->call('POST', '/categories/update/' . $category->id, ['_token' => 'replaceMe', 'return_to_edit' => 1, 'name' => 'Bla bla #' . rand(1, 1000)]);
|
$this->call('POST', '/categories/update/' . $category->id, ['_token' => 'replaceMe', 'return_to_edit' => 1, 'name' => 'Bla bla #' . rand(1, 1000)]);
|
||||||
$this->assertResponseStatus(302);
|
$this->assertResponseStatus(302);
|
||||||
$this->assertSessionHas('success', 'Category "' . $category->name . '" updated.');
|
$this->assertSessionHas('success', 'Category "' . $category->name . '" updated.');
|
||||||
|
@@ -177,7 +177,15 @@ FactoryMuffin::define(
|
|||||||
FactoryMuffin::define(
|
FactoryMuffin::define(
|
||||||
'FireflyIII\Models\TransactionType',
|
'FireflyIII\Models\TransactionType',
|
||||||
[
|
[
|
||||||
'type' => 'word',
|
'type' => function () {
|
||||||
|
$types = ['Withdrawal', 'Deposit', 'Transfer'];
|
||||||
|
$count = DB::table('transaction_types')->count();
|
||||||
|
if ($count < 3) {
|
||||||
|
return $types[$count];
|
||||||
|
} else {
|
||||||
|
return RandomString::generateRandomString(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user