Some new code for testing.

This commit is contained in:
James Cole 2016-01-16 09:15:24 +01:00
parent e834489206
commit deaebc373c
7 changed files with 1530 additions and 1411 deletions

1
.gitignore vendored
View File

@ -15,3 +15,4 @@ storage/
.project
.settings/
.env.local

View File

@ -48,7 +48,7 @@ return [
'sqlite' => [
'driver' => 'sqlite',
'database' => storage_path('database.sqlite'),
'database' => storage_path('database') . '/testing.db',
'prefix' => '',
],

View File

@ -22,9 +22,15 @@ class DatabaseSeeder extends Seeder
$this->call('TransactionTypeSeeder');
$this->call('PermissionSeeder');
if (App::environment() == 'testing' || App::environment() == 'homestead' || gethostname() == 'lightning') {
// set up basic test data (as little as possible):
if (App::environment() == 'testing') {
$this->call('TestDataSeeder');
}
// this one is reserved for more extensive testing.
//if (App::environment() == 'testing' || App::environment() == 'homestead' || gethostname() == 'lightning') {
//$this->call('VisualTestDataSeeder');
//}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

41
pu.sh Executable file
View File

@ -0,0 +1,41 @@
#!/bin/bash
# set testing environment
cp .env.testing .env
# test!
if [ -z "$1" ]
then
#phpunit --verbose
phpunit
fi
# directories to look in:
#dirs=("controllers" "database" "factories" "generators" "helpers" "models" "middleware" "repositories" "support")
#
#if [ ! -z "$1" ]
#then
# for i in "${dirs[@]}"
# do
# firstFile="./tests/$i/$1.php"
# secondFile="./tests/$i/$1Test.php"
# if [ -f "$firstFile" ]
# then
# # run it!
# phpunit --verbose $firstFile
# exit $?
# fi
# if [ -f "$secondFile" ]
# then
# # run it!
# phpunit --verbose $secondFile
# exit $?
# fi
#
#
# done
#
#fi
# restore .env file
cp .env.local .env

View File

@ -1,4 +1,5 @@
<?php
use Carbon\Carbon;
/**
* Class TestCase
@ -19,10 +20,61 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
*/
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app = require __DIR__ . '/../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
return $app;
}
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
parent::setUp();
// if the database copy does not exist, call migrate.
$copy = storage_path('database') . '/testing-copy.db';
$original = storage_path('database') . '/testing.db';
// move .env file over?
if (!file_exists($copy)) {
touch($original);
Artisan::call('migrate', ['--seed' => true]);
copy($original, $copy);
} else {
if (file_exists($copy)) {
copy($copy, $original);
}
}
// if the database copy does exists, copy back as original.
$this->session(
[
'start' => Carbon::now()->startOfMonth(),
'end' => Carbon::now()->endOfMonth(),
'first' => Carbon::now()->startOfYear(),
]
);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
public function tearDown()
{
parent::tearDown();
// delete copy original.
//$original = __DIR__.'/../storage/database/testing.db';
//unlink($original);
}
}