Fixed tests.

This commit is contained in:
James Cole 2015-03-31 17:49:47 +02:00
parent 3a49450461
commit f8a5fb4225
8 changed files with 207 additions and 47 deletions

View File

@ -14,12 +14,10 @@ install:
- rm composer.lock - rm composer.lock
- composer install - composer install
- php artisan env - php artisan env
# - mv -v .env.testing .env - mv -v .env.testing .env
# - touch tests/database/db.sqlite
# - php artisan migrate --seed
script: script:
# - phpunit --debug - phpunit --debug
after_script: after_script:
# - php vendor/bin/coveralls - php vendor/bin/coveralls

View File

@ -26,7 +26,8 @@
"watson/validating": "~1.0", "watson/validating": "~1.0",
"doctrine/dbal": "~2.5", "doctrine/dbal": "~2.5",
"illuminate/html": "~5.0", "illuminate/html": "~5.0",
"league/commonmark": "0.7.*" "league/commonmark": "0.7.*",
"mockery/mockery": "0.9.*"
}, },
"require-dev": { "require-dev": {
"barryvdh/laravel-debugbar": "@stable", "barryvdh/laravel-debugbar": "@stable",

68
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "b77b9f717b25e1e193bdc6edb18ad492", "hash": "c59c73e25e4664d99252f9ea851ad57c",
"packages": [ "packages": [
{ {
"name": "classpreloader/classpreloader", "name": "classpreloader/classpreloader",
@ -1216,6 +1216,72 @@
], ],
"time": "2015-03-29 14:01:43" "time": "2015-03-29 14:01:43"
}, },
{
"name": "mockery/mockery",
"version": "0.9.3",
"source": {
"type": "git",
"url": "https://github.com/padraic/mockery.git",
"reference": "686f85fa5b3b079cc0157d7cd3e9adb97f0b41e1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/padraic/mockery/zipball/686f85fa5b3b079cc0157d7cd3e9adb97f0b41e1",
"reference": "686f85fa5b3b079cc0157d7cd3e9adb97f0b41e1",
"shasum": ""
},
"require": {
"lib-pcre": ">=7.0",
"php": ">=5.3.2"
},
"require-dev": {
"hamcrest/hamcrest-php": "~1.1",
"phpunit/phpunit": "~4.0",
"satooshi/php-coveralls": "~0.7@dev"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "0.9.x-dev"
}
},
"autoload": {
"psr-0": {
"Mockery": "library/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Pádraic Brady",
"email": "padraic.brady@gmail.com",
"homepage": "http://blog.astrumfutura.com"
},
{
"name": "Dave Marshall",
"email": "dave.marshall@atstsolutions.co.uk",
"homepage": "http://davedevelopment.co.uk"
}
],
"description": "Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succint API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL). Designed as a drop in alternative to PHPUnit's phpunit-mock-objects library, Mockery is easy to integrate with PHPUnit and can operate alongside phpunit-mock-objects without the World ending.",
"homepage": "http://github.com/padraic/mockery",
"keywords": [
"BDD",
"TDD",
"library",
"mock",
"mock objects",
"mockery",
"stub",
"test",
"test double",
"testing"
],
"time": "2014-12-22 10:06:19"
},
{ {
"name": "monolog/monolog", "name": "monolog/monolog",
"version": "1.13.1", "version": "1.13.1",

View File

@ -48,7 +48,7 @@ return [
'sqlite' => [ 'sqlite' => [
'driver' => 'sqlite', 'driver' => 'sqlite',
'database' => realpath(__DIR__ . '/../tests/database/db.sqlite'), 'database' => ':memory:',
'prefix' => '', 'prefix' => '',
], ],

View File

@ -55,7 +55,7 @@ class ChangesForV336 extends Migration
$table->dropUnique('bill_user_id'); $table->dropUnique('bill_user_id');
} }
); );
// //
Schema::table( Schema::table(
'bills', function (Blueprint $table) { 'bills', function (Blueprint $table) {
// raw query: // raw query:
@ -140,9 +140,16 @@ class ChangesForV336 extends Migration
Schema::table( Schema::table(
'bills', function (Blueprint $table) { 'bills', function (Blueprint $table) {
// raw query: // raw query:
try {
DB::insert('ALTER TABLE `bills` CHANGE `name` `name` TEXT NOT NULL'); DB::insert('ALTER TABLE `bills` CHANGE `name` `name` TEXT NOT NULL');
DB::insert('ALTER TABLE `bills` CHANGE `match` `match` TEXT NOT NULL'); } catch (PDOException $e) {
// don't care.
}
try {
DB::insert('ALTER TABLE `bills` CHANGE `match` `match` TEXT NOT NULL');
} catch (PDOException $e) {
// don't care.
}
$table->smallInteger('name_encrypted', false, true)->default(0); $table->smallInteger('name_encrypted', false, true)->default(0);
$table->smallInteger('match_encrypted', false, true)->default(0); $table->smallInteger('match_encrypted', false, true)->default(0);
$table->foreign('user_id', 'bill_user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('user_id', 'bill_user_id')->references('id')->on('users')->onDelete('cascade');
@ -188,7 +195,11 @@ class ChangesForV336 extends Migration
); );
Schema::table( Schema::table(
'piggy_banks', function (Blueprint $table) { 'piggy_banks', function (Blueprint $table) {
DB::insert('ALTER TABLE `piggy_banks` CHANGE `name` `name` TEXT NOT NULL'); try {
DB::insert('ALTER TABLE `piggy_banks` CHANGE `name` `name` TEXT NOT NULL');
} catch (PDOException $e) {
// don't care.
}
$table->dropColumn(['repeats', 'rep_length', 'rep_every', 'rep_times']); $table->dropColumn(['repeats', 'rep_length', 'rep_every', 'rep_times']);
// create index again: // create index again:

View File

@ -113,7 +113,9 @@ class TestDataSeeder extends Seeder
*/ */
public function createUsers() public function createUsers()
{ {
User::create(['email' => 'reset@example.com', 'password' => bcrypt('functional'), 'reset' => 'okokokokokokokokokokokokokokokok', 'remember_token' => null]); User::create(
['email' => 'reset@example.com', 'password' => bcrypt('functional'), 'reset' => 'okokokokokokokokokokokokokokokok', 'remember_token' => null]
);
User::create(['email' => 'functional@example.com', 'password' => bcrypt('functional'), 'reset' => null, 'remember_token' => null]); User::create(['email' => 'functional@example.com', 'password' => bcrypt('functional'), 'reset' => null, 'remember_token' => null]);
User::create(['email' => 'thegrumpydictator@gmail.com', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]); User::create(['email' => 'thegrumpydictator@gmail.com', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]);
} }
@ -238,7 +240,8 @@ class TestDataSeeder extends Seeder
public function createPiggyBanks() public function createPiggyBanks()
{ {
// account // account
$savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first(); $savings = $this->findAccount('Savings account');
// some dates // some dates
$endDate = clone $this->_startOfMonth; $endDate = clone $this->_startOfMonth;
@ -247,7 +250,7 @@ class TestDataSeeder extends Seeder
$endDate->addMonths(4); $endDate->addMonths(4);
$nextYear->addYear()->subDay(); $nextYear->addYear()->subDay();
$end = $endDate->format('Y-m-d'); $end = $endDate->format('Y-m-d');
// piggy bank // piggy bank
$newCamera = PiggyBank::create( $newCamera = PiggyBank::create(
@ -287,15 +290,15 @@ class TestDataSeeder extends Seeder
* New: create no less than eight piggy banks that * New: create no less than eight piggy banks that
* create all sorts of reminders * create all sorts of reminders
*/ */
$list = ['week','quarter','month','year']; $list = ['week', 'quarter', 'month', 'year'];
$nextYear = clone $this->_startOfMonth; $nextYear = clone $this->_startOfMonth;
$nextYear->addYear(); $nextYear->addYear();
foreach($list as $entry) { foreach ($list as $entry) {
PiggyBank::create( PiggyBank::create(
[ [
'account_id' => $savings->id, 'account_id' => $savings->id,
'name' => $entry.' piggy bank with target date.', 'name' => $entry . ' piggy bank with target date.',
'targetamount' => 1000, 'targetamount' => 1000,
'startdate' => $this->som, 'startdate' => $this->som,
'targetdate' => $nextYear, 'targetdate' => $nextYear,
@ -308,7 +311,7 @@ class TestDataSeeder extends Seeder
PiggyBank::create( PiggyBank::create(
[ [
'account_id' => $savings->id, 'account_id' => $savings->id,
'name' => $entry.' piggy bank without target date.', 'name' => $entry . ' piggy bank without target date.',
'targetamount' => 1000, 'targetamount' => 1000,
'startdate' => $this->som, 'startdate' => $this->som,
'targetdate' => null, 'targetdate' => null,
@ -321,6 +324,26 @@ class TestDataSeeder extends Seeder
} }
} }
/**
* @param $name
*
* @return Account|null
*/
protected function findAccount($name)
{
// account
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
/** @var Account $account */
foreach (Account::get() as $account) {
if ($account->name == $name && $user->id == $account->user_id) {
return $account;
break;
}
}
return null;
}
/** /**
* *
*/ */
@ -415,20 +438,20 @@ class TestDataSeeder extends Seeder
public function createMonthlyExpenses(Carbon $date) public function createMonthlyExpenses(Carbon $date)
{ {
// get some objects from the database: // get some objects from the database:
$checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first(); $checking = $this->findAccount('Checking account');
$savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first(); $savings = $this->findAccount('Savings account');
$landLord = Account::whereName('Land lord')->orderBy('id', 'DESC')->first(); $landLord = $this->findAccount('Land lord');
$utilities = Account::whereName('Utilities company')->orderBy('id', 'DESC')->first(); $utilities = $this->findAccount('Utilities company');
$television = Account::whereName('TV company')->orderBy('id', 'DESC')->first(); $television = $this->findAccount('TV company');
$phone = Account::whereName('Phone agency')->orderBy('id', 'DESC')->first(); $phone = $this->findAccount('Phone agency');
$employer = Account::whereName('Employer')->orderBy('id', 'DESC')->first(); $employer = $this->findAccount('Employer');
$bills = Budget::whereName('Bills')->orderBy('id', 'DESC')->first(); $bills = $this->findBudget('Bills');
$house = Category::whereName('House')->orderBy('id', 'DESC')->first(); $house = $this->findCategory('House');
$withdrawal = TransactionType::whereType('Withdrawal')->first(); $withdrawal = TransactionType::whereType('Withdrawal')->first();
$deposit = TransactionType::whereType('Deposit')->first(); $deposit = TransactionType::whereType('Deposit')->first();
$transfer = TransactionType::whereType('Transfer')->first(); $transfer = TransactionType::whereType('Transfer')->first();
$euro = TransactionCurrency::whereCode('EUR')->first(); $euro = TransactionCurrency::whereCode('EUR')->first();
$rentBill = Bill::where('name', 'Rent')->first(); $rentBill = $this->findBill('Rent');
$cur = $date->format('Y-m-d'); $cur = $date->format('Y-m-d');
$formatted = $date->format('F Y'); $formatted = $date->format('F Y');
@ -471,21 +494,81 @@ class TestDataSeeder extends Seeder
} }
/**
* @param $name
*
* @return Budget|null
*/
protected function findBudget($name)
{
// account
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
/** @var Budget $budget */
foreach (Budget::get() as $budget) {
if ($budget->name == $name && $user->id == $budget->user_id) {
return $budget;
break;
}
}
return null;
}
/**
* @param $name
*
* @return Category|null
*/
protected function findCategory($name)
{
// account
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
/** @var Category $category */
foreach (Category::get() as $category) {
if ($category->name == $name && $user->id == $category->user_id) {
return $category;
break;
}
}
return null;
}
/**
* @param $name
*
* @return Bill|null
*/
protected function findBill($name)
{
// account
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
/** @var Bill $bill */
foreach (Bill::get() as $bill) {
if ($bill->name == $name && $user->id == $bill->user_id) {
return $bill;
break;
}
}
return null;
}
/** /**
* @param Carbon $date * @param Carbon $date
*/ */
public function createGroceries(Carbon $date) public function createGroceries(Carbon $date)
{ {
// variables we need: // variables we need:
$checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first(); $checking = $this->findAccount('Checking account');
$shopOne = Account::whereName('Groceries House')->orderBy('id', 'DESC')->first(); $shopOne = $this->findAccount('Groceries House');
$shopTwo = Account::whereName('Super savers')->orderBy('id', 'DESC')->first(); $shopTwo = $this->findAccount('Super savers');
$lunchHouse = Account::whereName('Lunch House')->orderBy('id', 'DESC')->first(); $lunchHouse = $this->findAccount('Lunch House');
$lunch = Category::whereName('Lunch')->orderBy('id', 'DESC')->first(); $lunch = $this->findCategory('Lunch');
$daily = Category::whereName('DailyGroceries')->orderBy('id', 'DESC')->first(); $daily = $this->findCategory('DailyGroceries');
$euro = TransactionCurrency::whereCode('EUR')->first(); $euro = TransactionCurrency::whereCode('EUR')->first();
$withdrawal = TransactionType::whereType('Withdrawal')->first(); $withdrawal = TransactionType::whereType('Withdrawal')->first();
$groceries = Budget::whereName('Groceries')->orderBy('id', 'DESC')->first(); $groceries = $this->findBudget('Groceries');
$shops = [$shopOne, $shopTwo]; $shops = [$shopOne, $shopTwo];
@ -518,9 +601,9 @@ class TestDataSeeder extends Seeder
{ {
$date->addDays(12); $date->addDays(12);
$dollar = TransactionCurrency::whereCode('USD')->first(); $dollar = TransactionCurrency::whereCode('USD')->first();
$checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first(); $checking = $this->findAccount('Checking account');
$savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first(); $savings = $this->findAccount('Savings account');
$buyMore = Account::whereName('Buy More')->orderBy('id', 'DESC')->first(); $buyMore = $this->findAccount('Buy More');
$withdrawal = TransactionType::whereType('Withdrawal')->first(); $withdrawal = TransactionType::whereType('Withdrawal')->first();
$user = User::whereEmail('thegrumpydictator@gmail.com')->first(); $user = User::whereEmail('thegrumpydictator@gmail.com')->first();

View File

@ -13,7 +13,6 @@ class AccountControllerTest extends TestCase
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$this->be(FireflyIII\User::whereEmail('thegrumpydictator@gmail.com')->first());
} }
@ -30,6 +29,7 @@ class AccountControllerTest extends TestCase
public function testCreate() public function testCreate()
{ {
$this->be(new FireflyIII\User);
$response = $this->call('GET', '/accounts/create/asset'); $response = $this->call('GET', '/accounts/create/asset');
$this->assertResponseOk(); $this->assertResponseOk();
$this->assertViewHas('subTitle', 'Create a new asset account'); $this->assertViewHas('subTitle', 'Create a new asset account');

View File

@ -13,8 +13,7 @@ class HomeControllerTest extends TestCase
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
Artisan::call('migrate');
} }
/** /**
@ -33,8 +32,7 @@ class HomeControllerTest extends TestCase
{ {
$start = '2014-03-01'; $start = '2014-03-01';
$end = '2015-03-31'; $end = '2015-03-31';
$this->be(new FireflyIII\User);
$this->be(FireflyIII\User::whereEmail('thegrumpydictator@gmail.com')->first());
$this->call('POST', '/daterange', ['end' => $end, 'start' => $start,'_token' => 'replaceme']); $this->call('POST', '/daterange', ['end' => $end, 'start' => $start,'_token' => 'replaceme']);
$this->assertResponseOk(); $this->assertResponseOk();
@ -51,8 +49,9 @@ class HomeControllerTest extends TestCase
{ {
$start = '2015-03-01'; $start = '2015-03-01';
$end = '2015-03-31'; $end = '2015-03-31';
$this->be(new FireflyIII\User);
$this->be(FireflyIII\User::whereEmail('thegrumpydictator@gmail.com')->first());
$this->call('POST', '/daterange', ['end' => $end, 'start' => $start,'_token' => 'replaceme']); $this->call('POST', '/daterange', ['end' => $end, 'start' => $start,'_token' => 'replaceme']);
$this->assertResponseOk(); $this->assertResponseOk();
@ -66,7 +65,9 @@ class HomeControllerTest extends TestCase
*/ */
public function testIndexLoggedIn() public function testIndexLoggedIn()
{ {
$this->be(FireflyIII\User::whereEmail('thegrumpydictator@gmail.com')->first()); $this->be(new FireflyIII\User);
Amount::shouldReceive('getCurrencyCode')->andReturn('EUR');
$response = $this->call('GET', '/'); $response = $this->call('GET', '/');
$this->assertResponseOk(); $this->assertResponseOk();