N°3270 Notify on expiration not sending notification (trigger exception)

add boilerplate function and use it to intercept/enrich trigger exception loops
This commit is contained in:
odain
2020-08-21 18:10:48 +02:00
parent 94b9a9bb75
commit 4e0eed6e13
8 changed files with 173 additions and 13 deletions

View File

@@ -5,6 +5,7 @@ namespace Combodo\iTop\Test\UnitTest\Core;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
use ContextTag;
use MetaModel;
use PHPUnit\Exception;
use TriggerOnObjectCreate;
/**
@@ -14,10 +15,21 @@ use TriggerOnObjectCreate;
*
* @runTestsInSeparateProcesses
*/
//define('APPROOT', dirname(__FILE__).'/../../');
//define('APPCONF', APPROOT.'conf/');
class TriggerTest extends ItopDataTestCase
{
const USE_TRANSACTION = false;
protected function setUp()
{
//@include_once APPROOT . 'approot.inc.php';
parent::setUp();
}
public function testIsContextValid()
{
/** @var TriggerOnObjectCreate $oTrigger */
@@ -29,4 +41,65 @@ class TriggerTest extends ItopDataTestCase
ContextTag::AddContext(ContextTag::TAG_CRON);
$this->assertTrue($oTrigger->IsContextValid());
}
public function testEnrichRaisedException_Trigger()
{
$oTrigger = MetaModel::NewObject('TriggerOnObjectCreate');
$sStackTrace = "";
try
{
try
{
MetaModel::NewObject('Toto');
}
catch (\Exception $e)
{
$sStackTrace = $e->getTraceAsString();
\utils::EnrichRaisedException($oTrigger, $e);
}
$this->assertTrue(false, "An exception should have been thrown");
}
catch(\CoreException $e1)
{
$this->assertEquals('CoreException', get_class($e1));
$this->assertEquals('Unknown class \'Toto\' (<b title="Trigger">TriggerOnObjectCreate</b>::-1 ()<br/>)', $e1->getMessage());
$fullStackTraceAsString = $e1->getFullStackTraceAsString();
$this->assertContains("MetaModel::NewObject", $fullStackTraceAsString,"new enriched exception should contain root cause method: " . $fullStackTraceAsString);
}
}
public function NoEnrichmentProvider()
{
return [
[ null ],
[ new \PHPUnit\Runner\Exception() ],
] ;
}
/**
* @param $oCmdbAbstract
* @dataProvider NoEnrichmentProvider
*/
public function testEnrichRaisedException_NoEnrichment($oCmdbAbstract)
{
$sStackTrace = "";
try
{
try
{
MetaModel::NewObject('CoreException');
}
catch (\Exception $e)
{
$sStackTrace = $e->getTraceAsString();
\utils::EnrichRaisedException($oCmdbAbstract, $e);
}
$this->assertTrue(false, "An exception should have been thrown");
}
catch(\Exception $e1)
{
$this->assertEquals($e, $e1);
}
}
}