phpvms/tests/TestCase.php

62 lines
1.6 KiB
PHP
Raw Normal View History

2017-06-09 02:28:26 +08:00
<?php
2017-06-20 00:30:39 +08:00
use Carbon\Carbon;
2017-07-05 02:57:08 +08:00
use Illuminate\Support\Facades\Mail;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
2017-06-20 00:30:39 +08:00
2017-06-09 02:28:26 +08:00
abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
{
/**
* The base URL to use while testing the application.
*
* @var string
*/
2017-06-10 03:47:02 +08:00
protected $app;
2017-06-09 02:28:26 +08:00
protected $baseUrl = 'http://localhost';
protected $connectionsToTransact = ['testing'];
2017-06-09 02:28:26 +08:00
2017-06-10 03:47:02 +08:00
public function __construct($name = null, array $data = [], $dataName = '') {
parent::__construct($name, $data, $dataName);
}
2017-07-05 02:09:44 +08:00
protected function reset_db() {
Artisan::call('database:create', ['--reset' => true]);
Artisan::call('migrate:refresh', ['--env' => 'unittest']);
}
public function setUp() {
parent::setUp();
$this->reset_db();
2017-07-05 02:57:08 +08:00
Mail::fake();
}
2017-06-09 02:28:26 +08:00
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
//$app['config']->set('database.default','testing');
2017-06-09 02:28:26 +08:00
return $app;
}
2017-06-10 03:47:02 +08:00
public function createRepository($repo_name) {
$app = $this->createApplication();
return $app->make('App\Repositories\\' . $repo_name);
2017-06-10 03:47:02 +08:00
}
2017-06-20 00:30:39 +08:00
public function addData($file)
{
2017-07-05 02:57:08 +08:00
$svc = app('\App\Services\DatabaseService');
$file_path = base_path('tests/data/' . $file . '.yml');
$svc->seed_from_yaml_file($file_path);
2017-06-20 00:30:39 +08:00
}
2017-06-09 02:28:26 +08:00
}