New unit tests to cover missed methods.

This commit is contained in:
James Cole
2015-01-01 12:06:42 +01:00
parent 3386c8b455
commit 8e892e7ea5
20 changed files with 276 additions and 105 deletions

View File

@@ -1,21 +1,9 @@
<?php
$db = realpath(__DIR__ . '/_data') . '/db.sqlite';
if(!file_exists($db)) {
exec('touch '.$db);
exec('php artisan migrate --seed --env=testing');
exec('sqlite3 tests/_data/db.sqlite .dump > tests/_data/dump.sql');
$db = realpath(__DIR__ . '/_data') . '/db.sqlite';
$dump = realpath(__DIR__ . '/_data') . '/dump.sql';
if (!file_exists($db)) {
$out = [];
exec('touch ' . $db);
exec('php artisan migrate --seed --env=testing', $out);
exec('sqlite3 tests/_data/db.sqlite .dump > tests/_data/dump.sql', $out);
}
/**
* Class resetToClean
*/
class resetToClean
{
/**
*
*/
static public function clean()
{
//exec('cp ' . realpath(__DIR__ . '/_data') . '/clean.sqlite ' . realpath(__DIR__ . '/_data') . '/testing.sqlite');
}
}

View File

@@ -11,6 +11,10 @@ modules:
Db:
populate: false
cleanup: true
dsn: 'sqlite:tests/_data/db.sqlite'
user: ''
password: ''
dump: tests/_data/dump.sql
Laravel4:
environment: 'testing'
filters: false

View File

@@ -55,7 +55,6 @@ class AccountControllerCest
$I->see('Delete account "Delete me"');
$I->submitForm('#destroy', []);
$I->dontSeeRecord('accounts', ['id' => 3, 'deleted_at' => null]);
resetToClean::clean();
}
/**
@@ -113,7 +112,6 @@ class AccountControllerCest
$I->see('Create a new asset account');
$I->submitForm('#store', ['name' => 'New through tests.', 'what' => 'asset', 'account_role' => 'defaultExpense', 'post_submit_action' => 'store']);
$I->seeRecord('accounts', ['name' => 'New through tests.']);
resetToClean::clean();
}
/**
@@ -128,7 +126,6 @@ class AccountControllerCest
'#store', ['name' => 'New through tests.', 'what' => 'asset', 'account_role' => 'defaultExpense', 'post_submit_action' => 'create_another']
);
$I->seeRecord('accounts', ['name' => 'New through tests.']);
resetToClean::clean();
}
/**
@@ -141,7 +138,6 @@ class AccountControllerCest
$I->see('Create a new asset account');
$I->submitForm('#store', ['name' => null, 'what' => 'asset', 'account_role' => 'defaultExpense', 'post_submit_action' => 'validate_only']);
$I->dontSeeRecord('accounts', ['name' => 'New through tests.']);
resetToClean::clean();
}
/**
@@ -156,7 +152,6 @@ class AccountControllerCest
'#store', ['name' => 'New through tests.', 'what' => 'asset', 'account_role' => 'defaultExpense', 'post_submit_action' => 'validate_only']
);
$I->dontSeeRecord('accounts', ['name' => 'New through tests.']);
resetToClean::clean();
}
/**
@@ -169,7 +164,6 @@ class AccountControllerCest
$I->see('Edit asset account "Delete me"');
$I->submitForm('#update', ['name' => 'Update me', 'what' => 'asset', 'account_role' => 'defaultExpense', 'post_submit_action' => 'update']);
$I->seeRecord('accounts', ['name' => 'Update me']);
resetToClean::clean();
}
@@ -185,7 +179,6 @@ class AccountControllerCest
'#update', ['name' => 'Savings accountXX', 'what' => 'asset', 'account_role' => 'defaultExpense', 'post_submit_action' => 'return_to_edit']
);
$I->seeRecord('accounts', ['name' => 'Savings accountXX']);
resetToClean::clean();
}

View File

@@ -148,7 +148,6 @@ class BudgetControllerCest
$I->see('Create a new budget');
$I->submitForm('#store', ['name' => 'New budget.', 'post_submit_action' => 'store']);
$I->seeRecord('budgets', ['name' => 'New budget.']);
resetToClean::clean();
}
/**
@@ -197,7 +196,6 @@ class BudgetControllerCest
$I->see('Edit budget "Delete me"');
$I->submitForm('#update', ['name' => 'Update me', 'post_submit_action' => 'update']);
$I->seeRecord('budgets', ['name' => 'Update me']);
resetToClean::clean();
}

View File

@@ -107,7 +107,6 @@ class CategoryControllerCest
$I->see('Create a new category');
$I->submitForm('#store', ['name' => 'New category.', 'post_submit_action' => 'store']);
$I->seeRecord('categories', ['name' => 'New category.']);
resetToClean::clean();
}
/**
@@ -120,7 +119,6 @@ class CategoryControllerCest
$I->see('Create a new category');
$I->submitForm('#store', ['name' => 'New category.', 'post_submit_action' => 'create_another']);
$I->seeRecord('categories', ['name' => 'New category.']);
resetToClean::clean();
}
/**
@@ -133,7 +131,6 @@ class CategoryControllerCest
$I->see('Create a new category');
$I->submitForm('#store', ['name' => null, 'post_submit_action' => 'validate_only']);
$I->dontSeeRecord('categories', ['name' => 'New category.']);
resetToClean::clean();
}
/**
@@ -146,7 +143,6 @@ class CategoryControllerCest
$I->see('Create a new category');
$I->submitForm('#store', ['name' => 'New category.', 'post_submit_action' => 'validate_only']);
$I->dontSeeRecord('categories', ['name' => 'New category.']);
resetToClean::clean();
}
/**
@@ -159,7 +155,6 @@ class CategoryControllerCest
$I->see('Edit category "Delete me"');
$I->submitForm('#update', ['name' => 'Update me', 'post_submit_action' => 'update']);
$I->seeRecord('categories', ['name' => 'Update me']);
resetToClean::clean();
}

View File

@@ -168,7 +168,6 @@ class CurrencyControllerCest
$I->see('Edit currency "US Dollar"');
$I->submitForm('#update', ['name' => 'Successful update', 'symbol' => '$', 'code' => 'USD', 'post_submit_action' => 'update']);
$I->seeRecord('transaction_currencies', ['name' => 'Successful update']);
resetToClean::clean();
}

View File

@@ -46,7 +46,10 @@ class TransactionControllerCest
public function destroyTransfer(FunctionalTester $I)
{
$I->wantTo('destroy a transfer');
$I->amOnPage('/transaction/delete/406');
$journal = TransactionJournal::whereDescription('Money for new PC')->first();
$I->amOnPage('/transaction/delete/' . $journal->id);
$I->submitForm('#destroy', []);
$I->see('Transaction &quot;Money for new PC&quot; destroyed.');
@@ -63,8 +66,9 @@ class TransactionControllerCest
public function edit(FunctionalTester $I)
{
$journal = TransactionJournal::whereDescription('Money for piggy')->first();
$I->wantTo('edit a transaction');
$I->amOnPage('/transaction/edit/408');
$I->amOnPage('/transaction/edit/' . $journal->id);
$I->see('Edit transfer &quot;Money for piggy&quot;');
}
@@ -91,8 +95,10 @@ class TransactionControllerCest
public function show(FunctionalTester $I)
{
$journal = TransactionJournal::whereDescription('Money for new PC')->first();
$I->wantTo('see a transaction');
$I->amOnPage('/transaction/show/406');
$I->amOnPage('/transaction/show/' . $journal->id);
$I->see('Transfer "Money for new PC"');
$I->see('1.259');
}
@@ -117,27 +123,6 @@ class TransactionControllerCest
$I->see('Transaction &quot;Test&quot; stored.');
}
public function storeAndReturn(FunctionalTester $I)
{
$I->wantTo('store a transaction');
$I->amOnPage('/transactions/create/withdrawal');
$I->submitForm(
'#store', [
'reminder' => '',
'description' => 'Test',
'account_id' => 1,
'expense_account' => 'Zomaar',
'amount' => 100,
'date' => '2014-12-30',
'budget_id' => 3,
'category' => 'Categorrr',
'post_submit_action' => 'create_another'
]
);
$I->see('Transaction &quot;Test&quot; stored.');
}
public function storeAndFail(FunctionalTester $I)
{
$I->wantTo('store a transaction and fail');
@@ -158,6 +143,26 @@ class TransactionControllerCest
$I->see('Could not store transaction: The description field is required.');
}
public function storeAndReturn(FunctionalTester $I)
{
$I->wantTo('store a transaction');
$I->amOnPage('/transactions/create/withdrawal');
$I->submitForm(
'#store', [
'reminder' => '',
'description' => 'Test',
'account_id' => 1,
'expense_account' => 'Zomaar',
'amount' => 100,
'date' => '2014-12-30',
'budget_id' => 3,
'category' => 'Categorrr',
'post_submit_action' => 'create_another'
]
);
$I->see('Transaction &quot;Test&quot; stored.');
}
public function update(FunctionalTester $I)
{
$I->wantTo('update a transaction');

View File

@@ -1,2 +1,8 @@
<?php
// Here you can initialize variables that will be available to your tests
$db = realpath(__DIR__ . '/../_data') . '/db.sqlite';
if (!file_exists($db)) {
$out = [];
exec('touch ' . $db);
exec('php artisan migrate --seed --env=testing', $out);
exec('sqlite3 tests/_data/db.sqlite .dump > tests/_data/dump.sql', $out);
}

View File

@@ -0,0 +1,40 @@
<?php
use League\FactoryMuffin\Facade as f;
/**
* Class AccountTest
*/
class AccountTest extends TestCase
{
public function setUp()
{
parent::setUp();
}
public function tearDown()
{
parent::tearDown();
}
// tests
public function testAccountMeta()
{
$account = f::create('Account');
$newMeta = $account->updateMeta('field', 'value');
$this->assertInstanceOf('AccountMeta', $newMeta);
$secondMeta = $account->updateMeta('field', 'newValue');
$this->assertEquals($newMeta->id, $secondMeta->id);
$this->assertEquals($newMeta->data, 'value');
$this->assertEquals($secondMeta->data, 'newValue');
}
public function testAccountUser()
{
$account = f::create('Account');
$this->assertInstanceOf('Account', $account);
$this->assertInstanceOf('User', $account->user);
}
}

View File

@@ -0,0 +1,18 @@
<?php
class ExamplATest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
}
protected function tearDown()
{
}
// tests
public function testMe()
{
}
}