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
- composer install
- php artisan env
# - mv -v .env.testing .env
# - touch tests/database/db.sqlite
# - php artisan migrate --seed
- mv -v .env.testing .env
script:
# - phpunit --debug
- phpunit --debug
after_script:
# - php vendor/bin/coveralls
- php vendor/bin/coveralls

View File

@ -26,7 +26,8 @@
"watson/validating": "~1.0",
"doctrine/dbal": "~2.5",
"illuminate/html": "~5.0",
"league/commonmark": "0.7.*"
"league/commonmark": "0.7.*",
"mockery/mockery": "0.9.*"
},
"require-dev": {
"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",
"This file is @generated automatically"
],
"hash": "b77b9f717b25e1e193bdc6edb18ad492",
"hash": "c59c73e25e4664d99252f9ea851ad57c",
"packages": [
{
"name": "classpreloader/classpreloader",
@ -1216,6 +1216,72 @@
],
"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",
"version": "1.13.1",

View File

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

View File

@ -140,9 +140,16 @@ class ChangesForV336 extends Migration
Schema::table(
'bills', function (Blueprint $table) {
// raw query:
try {
DB::insert('ALTER TABLE `bills` CHANGE `name` `name` 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('match_encrypted', false, true)->default(0);
$table->foreign('user_id', 'bill_user_id')->references('id')->on('users')->onDelete('cascade');
@ -188,7 +195,11 @@ class ChangesForV336 extends Migration
);
Schema::table(
'piggy_banks', function (Blueprint $table) {
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']);
// create index again:

View File

@ -113,7 +113,9 @@ class TestDataSeeder extends Seeder
*/
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' => 'thegrumpydictator@gmail.com', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]);
}
@ -238,7 +240,8 @@ class TestDataSeeder extends Seeder
public function createPiggyBanks()
{
// account
$savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
$savings = $this->findAccount('Savings account');
// some dates
$endDate = clone $this->_startOfMonth;
@ -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)
{
// get some objects from the database:
$checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();
$savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
$landLord = Account::whereName('Land lord')->orderBy('id', 'DESC')->first();
$utilities = Account::whereName('Utilities company')->orderBy('id', 'DESC')->first();
$television = Account::whereName('TV company')->orderBy('id', 'DESC')->first();
$phone = Account::whereName('Phone agency')->orderBy('id', 'DESC')->first();
$employer = Account::whereName('Employer')->orderBy('id', 'DESC')->first();
$bills = Budget::whereName('Bills')->orderBy('id', 'DESC')->first();
$house = Category::whereName('House')->orderBy('id', 'DESC')->first();
$checking = $this->findAccount('Checking account');
$savings = $this->findAccount('Savings account');
$landLord = $this->findAccount('Land lord');
$utilities = $this->findAccount('Utilities company');
$television = $this->findAccount('TV company');
$phone = $this->findAccount('Phone agency');
$employer = $this->findAccount('Employer');
$bills = $this->findBudget('Bills');
$house = $this->findCategory('House');
$withdrawal = TransactionType::whereType('Withdrawal')->first();
$deposit = TransactionType::whereType('Deposit')->first();
$transfer = TransactionType::whereType('Transfer')->first();
$euro = TransactionCurrency::whereCode('EUR')->first();
$rentBill = Bill::where('name', 'Rent')->first();
$rentBill = $this->findBill('Rent');
$cur = $date->format('Y-m-d');
$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
*/
public function createGroceries(Carbon $date)
{
// variables we need:
$checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();
$shopOne = Account::whereName('Groceries House')->orderBy('id', 'DESC')->first();
$shopTwo = Account::whereName('Super savers')->orderBy('id', 'DESC')->first();
$lunchHouse = Account::whereName('Lunch House')->orderBy('id', 'DESC')->first();
$lunch = Category::whereName('Lunch')->orderBy('id', 'DESC')->first();
$daily = Category::whereName('DailyGroceries')->orderBy('id', 'DESC')->first();
$checking = $this->findAccount('Checking account');
$shopOne = $this->findAccount('Groceries House');
$shopTwo = $this->findAccount('Super savers');
$lunchHouse = $this->findAccount('Lunch House');
$lunch = $this->findCategory('Lunch');
$daily = $this->findCategory('DailyGroceries');
$euro = TransactionCurrency::whereCode('EUR')->first();
$withdrawal = TransactionType::whereType('Withdrawal')->first();
$groceries = Budget::whereName('Groceries')->orderBy('id', 'DESC')->first();
$groceries = $this->findBudget('Groceries');
$shops = [$shopOne, $shopTwo];
@ -518,9 +601,9 @@ class TestDataSeeder extends Seeder
{
$date->addDays(12);
$dollar = TransactionCurrency::whereCode('USD')->first();
$checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();
$savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
$buyMore = Account::whereName('Buy More')->orderBy('id', 'DESC')->first();
$checking = $this->findAccount('Checking account');
$savings = $this->findAccount('Savings account');
$buyMore = $this->findAccount('Buy More');
$withdrawal = TransactionType::whereType('Withdrawal')->first();
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();

View File

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

View File

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