librenms/tests/DBTestCase.php
Tony Murray 1b1907a09f Update database tests to prepare for more (#6500)
* Update database tests to prepare for more
Add test_db_name, test_db_user, test_db_pass to allow developers to have a dedicated testing database.
Extract DBTestCase to include common functionality for database based tests. Use transactions to isolate tests.
Enable STRICT_TRANS_TABLE, test for it's existence (only when we have a user that can set it)
Move the database cleanup to register_shutdown_function, this makes it happen every time at the end of tests.
If the was not empty, only truncate the tables (that aren't prepopulated) instead of drop the database.
Use our schema functions for schema tests.
Fix some missing array indexes so it doesn't clutter test output.

* Fix style
2017-04-26 07:56:00 -05:00

49 lines
1.3 KiB
PHP

<?php
/**
* DBTestCase.php
*
* Base Test Case for Database tests
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2017 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace LibreNMS\Tests;
class DBTestCase extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
parent::setUp();
if (getenv('DBTEST')) {
dbConnect();
dbBeginTransaction();
} else {
$this->markTestSkipped('Database tests not enabled. Set DBTEST=1 to enable.');
}
}
public function tearDown()
{
parent::tearDown();
if (getenv('DBTEST')) {
dbRollbackTransaction();
}
}
}