Fixed tests, added migration stuff, added default user.

This commit is contained in:
James Cole
2014-07-04 07:22:16 +02:00
parent 1836249407
commit abbbba219a
6 changed files with 180 additions and 1 deletions

View File

@@ -1,7 +1,94 @@
<?php
use Firefly\Helper\Migration\MigrationHelperInterface as MHI;
class MigrationController extends BaseController
{
protected $migration;
public function __construct(MHI $migration)
{
$this->migration = $migration;
}
public function index()
{
return View::make('migrate.index');
}
public function postIndex()
{
if (Input::hasFile('exportFile')) {
// get content:
$file = Input::file('exportFile');
$path = $file->getRealPath();
$this->migration->loadFile($path);
if (!$this->migration->validFile()) {
return View::make('error')->with('message', 'Invalid JSON content.');
}
}
// then, start migrating!
//
//
// // map old and new id's.
// $map = [
// 'accounts' => [],
// 'beneficiaries' => [],
// ];
//
// // get the account types we need
// $beneficiaryAT = AccountType::where('description', 'Beneficiary account')->first();
//
// // save all accounts:
// foreach ($JSON->accounts as $entry) {
// // create account:
// if ($entry->openingbalance == 0) {
// $account = $this->accounts->store(['name' => $entry->name]);
// } else {
// $account = $this->accounts->storeWithInitialBalance(
// ['name' => $entry->name],
// new Carbon($entry->openingbalancedate),
// floatval($entry->openingbalance)
// );
// }
// $map['accounts'][$entry->id] = $account->id;
// }
// unset($entry);
//
// // save all components:
// foreach ($JSON->components as $entry) {
// switch ($entry->type->type) {
// case 'beneficiary':
// // create new account for beneficiary:
// $account = $this->accounts->store(['name' => $entry->name]);
// $map['beneficiaries'][$entry->id] = $account;
// break;
// case 'category':
// // create new component for category:
//// $account = $this->accounts->store(['name' => $entry->name]);
//// $map['beneficiaries'][$entry->id] = $account;
// break;
// }
// }
// unset($JSON->accounts);
//
//
// var_dump($JSON);
// var_dump($map);
//
// exit;
// }
//
return View::make('error')->with('message', 'No file found.');
}
/*
public function index()
{

View File

@@ -16,6 +16,7 @@ class DatabaseSeeder extends Seeder
$this->call('TransactionCurrencySeeder');
$this->call('TransactionTypeSeeder');
$this->call('ComponentTypeSeeder');
$this->call('DefaultUserSeeder');
}
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* Created by PhpStorm.
* User: sander
* Date: 03/07/14
* Time: 21:06
*/
class DefaultUserSeeder extends Seeder
{
public function run()
{
DB::table('users')->delete();
User::create(
[
'email' => 's@nder.be',
'password' => Hash::make('sander'),
'verification' => null,
'reset' => null,
'remember_token' => null,
'migrated' => false
]
);
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* Created by PhpStorm.
* User: sander
* Date: 03/07/14
* Time: 21:34
*/
namespace Firefly\Helper\Migration;
class MigrationHelper implements MigrationHelperInterface
{
protected $path;
protected $JSON;
public function loadFile($path)
{
$this->path = $path;
}
public function validFile()
{
// file does not exist:
if(!file_exists($this->path)) {
return false;
}
// load the content:
$content = file_get_contents($this->path);
if($content === false) {
return false;
}
// parse the content
$this->JSON = json_decode($content);
if(is_null($this->JSON)) {
return false;
}
}
}

View File

@@ -0,0 +1,18 @@
<?php
/**
* Created by PhpStorm.
* User: sander
* Date: 03/07/14
* Time: 21:33
*/
namespace Firefly\Helper\Migration;
interface MigrationHelperInterface
{
public function loadFile($path);
public function validFile();
}

View File

@@ -10,8 +10,13 @@ class HomeControllerTest extends TestCase
public function testIndex()
{
// mock:
View::shouldReceive('make')->with('index');
View::shouldReceive('make')->with('index')->once()->andReturn(\Mockery::self())
->shouldReceive('with')->once() // Pass a 'with' parameter
->with('count', 0)
;
Auth::shouldReceive('check')->andReturn(true);
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('count')->andReturn(0);
// call
$this->call('GET', '/');