2015-02-05 21:39:52 -06:00
|
|
|
<?php
|
2015-04-03 01:37:53 -05:00
|
|
|
|
2015-05-02 12:44:12 -05:00
|
|
|
use Carbon\Carbon;
|
|
|
|
use FireflyIII\Models\TransactionCurrency;
|
2015-04-03 01:37:53 -05:00
|
|
|
use League\FactoryMuffin\Facade as FactoryMuffin;
|
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
|
|
|
* Class TestCase
|
|
|
|
*/
|
|
|
|
class TestCase extends Illuminate\Foundation\Testing\TestCase
|
|
|
|
{
|
2015-02-05 21:39:52 -06:00
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
|
|
|
* Creates the application.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Foundation\Application
|
|
|
|
*/
|
|
|
|
public function createApplication()
|
|
|
|
{
|
2015-03-13 02:44:07 -05:00
|
|
|
$app = require __DIR__ . '/../bootstrap/app.php';
|
2015-02-05 21:39:52 -06:00
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();
|
2015-02-05 21:39:52 -06:00
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
return $app;
|
|
|
|
}
|
2015-02-05 21:39:52 -06:00
|
|
|
|
2015-04-03 01:37:53 -05:00
|
|
|
/**
|
|
|
|
* Sets up the fixture, for example, opens a network connection.
|
|
|
|
* This method is called before a test is executed.
|
|
|
|
*/
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2015-04-20 14:57:20 -05:00
|
|
|
|
|
|
|
// if the database copy does not exist, call migrate.
|
2015-05-02 12:44:12 -05:00
|
|
|
$copy = __DIR__ . '/../storage/database/testing-copy.db';
|
|
|
|
$original = __DIR__ . '/../storage/database/testing.db';
|
|
|
|
|
|
|
|
FactoryMuffin::loadFactories(__DIR__ . '/factories');
|
|
|
|
|
2015-04-20 15:08:24 -05:00
|
|
|
if (!file_exists($copy)) {
|
|
|
|
Log::debug('Created new database.');
|
|
|
|
touch($original);
|
|
|
|
Artisan::call('migrate');
|
|
|
|
copy($original, $copy);
|
2015-05-02 12:44:12 -05:00
|
|
|
|
|
|
|
// create EUR currency
|
|
|
|
/** @var TransactionCurrency $currency */
|
|
|
|
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
|
|
|
|
$currency->code = 'EUR';
|
|
|
|
$currency->save();
|
|
|
|
Log::debug('Created new EUR currency.');
|
2015-04-20 15:08:24 -05:00
|
|
|
} else {
|
|
|
|
if (file_exists($copy)) {
|
|
|
|
copy($copy, $original);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if the database copy does exists, copy back as original.
|
2015-04-20 14:57:20 -05:00
|
|
|
|
2015-05-02 12:44:12 -05:00
|
|
|
$this->session(
|
|
|
|
[
|
|
|
|
'start' => Carbon::now()->startOfMonth(),
|
|
|
|
'end' => Carbon::now()->endOfMonth(),
|
|
|
|
'first' => Carbon::now()->startOfYear()
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-03 01:37:53 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:52:15 -05:00
|
|
|
/**
|
|
|
|
* This method is called before the first test of this test class is run.
|
|
|
|
*
|
|
|
|
* @since Method available since Release 3.4.0
|
|
|
|
*/
|
|
|
|
public static function setUpBeforeClass()
|
|
|
|
{
|
|
|
|
parent::setUpBeforeClass();
|
|
|
|
}
|
2015-04-02 15:51:00 -05:00
|
|
|
|
2015-04-20 14:57:20 -05:00
|
|
|
/**
|
|
|
|
* Tears down the fixture, for example, closes a network connection.
|
|
|
|
* This method is called after a test is executed.
|
|
|
|
*/
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
parent::tearDown();
|
|
|
|
|
2015-04-20 15:08:24 -05:00
|
|
|
// delete copy original.
|
|
|
|
//$original = __DIR__.'/../storage/database/testing.db';
|
|
|
|
//unlink($original);
|
|
|
|
|
2015-04-20 14:57:20 -05:00
|
|
|
}
|
|
|
|
|
2015-03-31 12:21:49 -05:00
|
|
|
/**
|
|
|
|
* @param string $class
|
|
|
|
*
|
2015-04-20 14:57:20 -05:00
|
|
|
* @return Mockery\MockInterface
|
2015-03-31 12:21:49 -05:00
|
|
|
*/
|
|
|
|
public function mock($class)
|
|
|
|
{
|
|
|
|
$mock = Mockery::mock($class);
|
|
|
|
|
|
|
|
$this->app->instance($class, $mock);
|
|
|
|
|
|
|
|
return $mock;
|
|
|
|
}
|
|
|
|
|
2015-04-02 15:51:00 -05:00
|
|
|
|
2015-02-05 21:39:52 -06:00
|
|
|
}
|