Code cleanup.

This commit is contained in:
James Cole 2017-03-05 11:19:06 +01:00
parent e5a2e1a8c7
commit 879f74e521
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
15 changed files with 111 additions and 113 deletions

View File

@ -15,6 +15,7 @@ namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use Tests\TestCase; use Tests\TestCase;
class BudgetControllerTest extends TestCase class BudgetControllerTest extends TestCase
{ {

View File

@ -13,8 +13,8 @@ namespace Tests\Feature\Controllers;
use FireflyIII\Import\ImportProcedureInterface; use FireflyIII\Import\ImportProcedureInterface;
use FireflyIII\Import\Setup\CsvSetup; use FireflyIII\Import\Setup\CsvSetup;
use Tests\TestCase;
use Illuminate\Http\UploadedFile; use Illuminate\Http\UploadedFile;
use Tests\TestCase;
class ImportControllerTest extends TestCase class ImportControllerTest extends TestCase
{ {

View File

@ -18,7 +18,6 @@ use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Support\Twig\Transaction;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag; use Illuminate\Support\MessageBag;
use Tests\TestCase; use Tests\TestCase;

View File

@ -90,7 +90,7 @@ class MassControllerTest extends TestCase
/** /**
* @covers \FireflyIII\Http\Controllers\Transaction\MassController::edit * @covers \FireflyIII\Http\Controllers\Transaction\MassController::edit
*/ */
public function testEditMultipleNothingLeft() public function testEditMultiple()
{ {
Log::debug('Edit multiple.'); Log::debug('Edit multiple.');
// mock stuff: // mock stuff:
@ -98,7 +98,19 @@ class MassControllerTest extends TestCase
$repository->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection); $repository->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);
// default transactions // default transactions
$collection = new Collection; $collection = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->take(2)->get();
// add deposit (with multiple sources)
$collection->push(
TransactionJournal::where('transaction_type_id', 2)
->whereNull('transaction_journals.deleted_at')
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->groupBy('transaction_journals.id')
->orderBy('ct', 'DESC')
->where('user_id', $this->user()->id)->first(['transaction_journals.id', DB::raw('count(transactions.`id`) as ct')])
);
// add withdrawal (with multiple destinations)
$collection->push( $collection->push(
TransactionJournal::where('transaction_type_id', 1) TransactionJournal::where('transaction_type_id', 1)
->whereNull('transaction_journals.deleted_at') ->whereNull('transaction_journals.deleted_at')
@ -121,7 +133,7 @@ class MassControllerTest extends TestCase
/** /**
* @covers \FireflyIII\Http\Controllers\Transaction\MassController::edit * @covers \FireflyIII\Http\Controllers\Transaction\MassController::edit
*/ */
public function testEditMultiple() public function testEditMultipleNothingLeft()
{ {
Log::debug('Edit multiple.'); Log::debug('Edit multiple.');
// mock stuff: // mock stuff:
@ -129,19 +141,7 @@ class MassControllerTest extends TestCase
$repository->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection); $repository->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);
// default transactions // default transactions
$collection = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->take(2)->get(); $collection = new Collection;
// add deposit (with multiple sources)
$collection->push(
TransactionJournal::where('transaction_type_id', 2)
->whereNull('transaction_journals.deleted_at')
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->groupBy('transaction_journals.id')
->orderBy('ct', 'DESC')
->where('user_id', $this->user()->id)->first(['transaction_journals.id', DB::raw('count(transactions.`id`) as ct')])
);
// add withdrawal (with multiple destinations)
$collection->push( $collection->push(
TransactionJournal::where('transaction_type_id', 1) TransactionJournal::where('transaction_type_id', 1)
->whereNull('transaction_journals.deleted_at') ->whereNull('transaction_journals.deleted_at')

View File

@ -185,6 +185,34 @@ class SingleControllerTest extends TestCase
$response->assertStatus(302); $response->assertStatus(302);
} }
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::store
*/
public function testStoreError()
{
// mock results:
$repository = $this->mock(JournalRepositoryInterface::class);
$journal = new TransactionJournal();
$journal->description = 'New journal';
$repository->shouldReceive('store')->andReturn($journal);
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->session(['transactions.create.url' => 'http://localhost']);
$this->be($this->user());
$data = [
'what' => 'withdrawal',
'amount' => '10',
'amount_currency_id_amount' => 1,
'source_account_id' => 1,
'destination_account_name' => 'Some destination',
'date' => '2016-01-01',
'description' => 'Test descr',
];
$response = $this->post(route('transactions.store', ['withdrawal']), $data);
$response->assertStatus(302);
$response->assertSessionHas('error');
}
/** /**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::store * @covers \FireflyIII\Http\Controllers\Transaction\SingleController::store
*/ */
@ -212,8 +240,6 @@ class SingleControllerTest extends TestCase
$attachmentRepo->shouldReceive('getMessages')->andReturn($messages); $attachmentRepo->shouldReceive('getMessages')->andReturn($messages);
$this->session(['transactions.create.url' => 'http://localhost']); $this->session(['transactions.create.url' => 'http://localhost']);
$this->be($this->user()); $this->be($this->user());
@ -233,34 +259,6 @@ class SingleControllerTest extends TestCase
$response->assertSessionHas('info'); $response->assertSessionHas('info');
} }
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::store
*/
public function testStoreError()
{
// mock results:
$repository = $this->mock(JournalRepositoryInterface::class);
$journal = new TransactionJournal();
$journal->description = 'New journal';
$repository->shouldReceive('store')->andReturn($journal);
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->session(['transactions.create.url' => 'http://localhost']);
$this->be($this->user());
$data = [
'what' => 'withdrawal',
'amount' => '10',
'amount_currency_id_amount' => 1,
'source_account_id' => 1,
'destination_account_name' => 'Some destination',
'date' => '2016-01-01',
'description' => 'Test descr',
];
$response = $this->post(route('transactions.store', ['withdrawal']), $data);
$response->assertStatus(302);
$response->assertSessionHas('error');
}
/** /**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::update * @covers \FireflyIII\Http\Controllers\Transaction\SingleController::update
*/ */

View File

@ -67,6 +67,17 @@ class TransactionControllerTest extends TestCase
$response->assertStatus(200); $response->assertStatus(200);
} }
/**
* @covers \FireflyIII\Http\Controllers\TransactionController::show
*/
public function testShow()
{
$this->be($this->user());
$response = $this->get(route('transactions.show', [1]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/** /**
* @covers \FireflyIII\Http\Controllers\Controller::redirectToAccount * @covers \FireflyIII\Http\Controllers\Controller::redirectToAccount
* @covers \FireflyIII\Http\Controllers\TransactionController::show * @covers \FireflyIII\Http\Controllers\TransactionController::show
@ -79,15 +90,4 @@ class TransactionControllerTest extends TestCase
$response->assertStatus(302); $response->assertStatus(302);
} }
/**
* @covers \FireflyIII\Http\Controllers\TransactionController::show
*/
public function testShow()
{
$this->be($this->user());
$response = $this->get(route('transactions.show', [1]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
} }

View File

@ -19,11 +19,11 @@ class ExampleTest extends TestCase
* *
* @return void * @return void
*/ */
public function testBasicTest() public function testAnotherBasicTest()
{ {
$response = $this->get('/login'); $response = $this->get('/');
$response->assertStatus(200); $response->assertStatus(302);
} }
/** /**
@ -31,10 +31,10 @@ class ExampleTest extends TestCase
* *
* @return void * @return void
*/ */
public function testAnotherBasicTest() public function testBasicTest()
{ {
$response = $this->get('/'); $response = $this->get('/login');
$response->assertStatus(302); $response->assertStatus(200);
} }
} }