2017-12-20 08:36:49 -06:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace LibreNMS\Tests;
|
|
|
|
|
|
2019-10-13 13:40:38 +00:00
|
|
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
2018-05-09 06:53:45 -05:00
|
|
|
|
2019-10-13 13:40:38 +00:00
|
|
|
abstract class TestCase extends BaseTestCase
|
2017-12-20 08:36:49 -06:00
|
|
|
{
|
2019-10-13 13:40:38 +00:00
|
|
|
use CreatesApplication;
|
2018-11-28 16:49:18 -06:00
|
|
|
use SnmpsimHelpers;
|
|
|
|
|
|
2018-05-09 06:53:45 -05:00
|
|
|
public function __construct($name = null, $data = [], $dataName = '')
|
|
|
|
|
{
|
|
|
|
|
parent::__construct($name, $data, $dataName);
|
|
|
|
|
// grab global $snmpsim from bootstrap and make it accessible
|
2019-10-13 13:40:38 +00:00
|
|
|
$this->getSnmpsim();
|
2019-03-12 23:59:03 -05:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 08:36:49 -06:00
|
|
|
public function dbSetUp()
|
|
|
|
|
{
|
|
|
|
|
if (getenv('DBTEST')) {
|
2018-08-17 15:29:20 -05:00
|
|
|
\LibreNMS\DB\Eloquent::DB()->beginTransaction();
|
2017-12-20 08:36:49 -06:00
|
|
|
} else {
|
|
|
|
|
$this->markTestSkipped('Database tests not enabled. Set DBTEST=1 to enable.');
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-21 14:54:51 +02:00
|
|
|
|
2017-12-20 08:36:49 -06:00
|
|
|
public function dbTearDown()
|
|
|
|
|
{
|
|
|
|
|
if (getenv('DBTEST')) {
|
2019-10-13 13:40:38 +00:00
|
|
|
try {
|
|
|
|
|
\LibreNMS\DB\Eloquent::DB()->rollBack();
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
$this->fail("Exception when rolling back transaction.\n" . $e->getTraceAsString());
|
|
|
|
|
}
|
2017-12-20 08:36:49 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|