librenms/tests/TestCase.php
Tony Murray 63442e8b4a
Refactor tests (#10625)
* Refactor tests
Boot Laravel for all tests.
Config use private static property for storage instead of global

* Backup/restore modules

* disable snmpsim log

* Fixing DBTestCase

* Fix macros loading to the wrong place

* trap and other tests should check if db is available

* don't include snmp.inc.php if mock.snmp.inc.php is already included...

* fix migration

* if we don't reset the db, run migrations at least.

* set vars for migrate too

* Fix style

* ignore issues with undefined indexes in legacy code
2019-10-13 13:40:38 +00:00

38 lines
1005 B
PHP

<?php
namespace LibreNMS\Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
use SnmpsimHelpers;
public function __construct($name = null, $data = [], $dataName = '')
{
parent::__construct($name, $data, $dataName);
// grab global $snmpsim from bootstrap and make it accessible
$this->getSnmpsim();
}
public function dbSetUp()
{
if (getenv('DBTEST')) {
\LibreNMS\DB\Eloquent::DB()->beginTransaction();
} else {
$this->markTestSkipped('Database tests not enabled. Set DBTEST=1 to enable.');
}
}
public function dbTearDown()
{
if (getenv('DBTEST')) {
try {
\LibreNMS\DB\Eloquent::DB()->rollBack();
} catch (\Exception $e) {
$this->fail("Exception when rolling back transaction.\n" . $e->getTraceAsString());
}
}
}
}