Skip to content

Commit

Permalink
Move model tracking to base test class
Browse files Browse the repository at this point in the history
  • Loading branch information
allejo committed Feb 6, 2018
1 parent 443746d commit 6e44652
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
21 changes: 0 additions & 21 deletions tests/ModelTests/MatchEloTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,6 @@ class MatchEloTest extends TestCase
const TEAM_WIN = 1;
const TEAM_DRAW = 2;

/** @var \Faker\Generator */
private $faker;
private $createdModels = [];

protected function setUp()
{
$this->connectToDatabase();

$this->faker = Faker\Factory::create();
}

public function tearDown()
{
foreach ($this->createdModels as $model)
{
$this->wipe($model);
}

parent::tearDown();
}

//
// Yes, we need to test our own helper function in our tests
//
Expand Down
15 changes: 15 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

abstract class TestCase extends \PHPUnit_Framework_TestCase
{
/** @var \Faker\Generator */
protected $faker;
protected $createdModels = [];

/**
* The BZID of the last player created, used to prevent conflicts when creating new players
* @var int
Expand Down Expand Up @@ -200,11 +204,22 @@ protected function reset()
}
}

protected function setUp()
{
self::connectToDatabase();

$this->faker = Faker\Factory::create();
}

/**
* Clean-up all the database entries added during the test
*/
public function tearDown()
{
foreach ($this->createdModels as $model) {
$this->wipe($model);
}

foreach ($this->playersCreated as $id) {
self::wipe(Player::get($id));
}
Expand Down

0 comments on commit 6e44652

Please sign in to comment.