diff options
| author | Greg Roach <fisharebest@webtrees.net> | 2018-12-30 21:05:53 +0000 |
|---|---|---|
| committer | Greg Roach <fisharebest@webtrees.net> | 2018-12-30 21:05:53 +0000 |
| commit | 061b43d78e753dc0c2b6d7c1767d279b5f5aeee9 (patch) | |
| tree | 51366298751ffdffc2438a90988e1d9852ae2a50 /tests/TestCase.php | |
| parent | 01461f8661111b35c96e8f511f9f4a2267c68123 (diff) | |
| download | webtrees-061b43d78e753dc0c2b6d7c1767d279b5f5aeee9.tar.gz webtrees-061b43d78e753dc0c2b6d7c1767d279b5f5aeee9.tar.bz2 webtrees-061b43d78e753dc0c2b6d7c1767d279b5f5aeee9.zip | |
Use illuminate/database for trees/users and add tests using sqlite
Diffstat (limited to 'tests/TestCase.php')
| -rw-r--r-- | tests/TestCase.php | 72 |
1 files changed, 61 insertions, 11 deletions
diff --git a/tests/TestCase.php b/tests/TestCase.php index ebdd34c3e0..12bc86e3c0 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -17,9 +17,9 @@ declare(strict_types=1); namespace Fisharebest\Webtrees; -use function basename; use Fisharebest\Webtrees\Schema\SeedDatabase; use Illuminate\Database\Capsule\Manager as DB; +use function basename; use function file_get_contents; /** @@ -27,20 +27,69 @@ use function file_get_contents; */ class TestCase extends \PHPUnit\Framework\TestCase { + protected static $uses_database = false; + + protected static $uses_transactions = false; + + /** + * Things to run once, before all the tests. + */ + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + + defined('WT_BASE_URL') || define('WT_BASE_URL', 'http://localhost/'); + defined('WT_ROOT') || define('WT_ROOT', dirname(__DIR__) . '/'); + defined('WT_DATA_DIR') || define('WT_DATA_DIR', WT_ROOT . 'data/'); + + if (static::$uses_database) { + static::createTestDatabase(); + } + } + + /** + * Things to run once, AFTER all the tests. + */ + public static function tearDownAfterClass() + { + if (static::$uses_database) { + $pdo = DB::connection()->getPdo(); + $pdo = null; + } + + parent::tearDownAfterClass(); + } + + /** + * Things to run before every test. + */ protected function setUp() { parent::setUp(); defined('WT_BASE_URL') || define('WT_BASE_URL', 'http://localhost/'); - defined('WT_DATA_DIR') || define('WT_DATA_DIR', 'data/'); - defined('WT_ROOT') || define('WT_ROOT', ''); - I18N::init('en-US'); + defined('WT_ROOT') || define('WT_ROOT', dirname(__DIR__) . '/'); + defined('WT_DATA_DIR') || define('WT_DATA_DIR', WT_ROOT . 'data/'); + defined('WT_LOCALE') || define('WT_LOCALE', I18N::init('en-US')); + + if (static::$uses_database) { + DB::connection()->beginTransaction(); + } + } + + /** + * Things to run after every test + */ + protected function tearDown() { + if (static::$uses_database && static::$uses_transactions) { + DB::connection()->rollBack(); + } } /** * Create an SQLite in-memory database for testing */ - protected function createTestDatabase(): void + protected static function createTestDatabase(): void { $capsule = new DB(); $capsule->addConnection([ @@ -60,17 +109,18 @@ class TestCase extends \PHPUnit\Framework\TestCase * Import a GEDCOM file into the test database. * * @param string $gedcom_file + * + * @return Tree */ - protected function importTree(string $gedcom_file): void + protected function importTree(string $gedcom_file): Tree { - $x = DB::table('gedcom')->insert([ - 'gedcom_name' => basename($gedcom_file), - ]); - - var_dump($x);exit; + $tree = Tree::create(basename($gedcom_file), basename($gedcom_file)); DB::table('gedcom_chunk')->insert([ + 'gedcom_id' => $tree->id(), 'chunk_data' => file_get_contents($gedcom_file), ]); + + return $tree; } } |
