-
Notifications
You must be signed in to change notification settings - Fork 21
/
DatabaseTest.php
65 lines (58 loc) · 1.74 KB
/
DatabaseTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types = 1);
/*
* As a work of the United States government, this project is in the public domain within the United States.
*/
use Phinx\Console\PhinxApplication;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\NullOutput;
/**
* Helper class for seeding the database.
*
* The Phinx commands will use whatever phinx.yml is located in the
* directory that the PHPUnit command line argument is being run from.
*
* That is, if the tests are being run from LEAF_Nexus_Tests, it will
* use LEAF_Nexus_Tests/phinx.yml.
*/
class DatabaseTest extends TestCase
{
/**
* Populates the database with any default data from a fresh install.
* It does not tear down and rebuild the database, just inserts data.
*/
public function initialSeed() : void
{
$this->runPhinxCmd('seed:run -s InitialSeed');
}
/**
* Truncates all tables, seeds with initial data, seeds with base test data.
*/
public function resetDatabase() : void
{
$this->truncateTables();
$this->initialSeed();
$this->seedBaseTestData();
}
/**
* Seed the database with a base set of data to test against.
*/
public function seedBaseTestData() : void
{
$this->runPhinxCmd('seed:run -s BaseTestSeed');
}
/**
* Remove ALL data from ALL tables. Does not drop the tables or database.
*/
public function truncateTables() : void
{
$this->runPhinxCmd('seed:run -s TruncateTables');
}
private function runPhinxCmd($cmd) : void
{
$app = new PhinxApplication();
$app->setAutoExit(false);
$app->run(new StringInput($cmd), new NullOutput());
}
}