Set('context', ContextTag::TAG_PORTAL.', '.ContextTag::TAG_CRON);
$this->assertFalse($oTrigger->IsContextValid());
ContextTag::AddContext(ContextTag::TAG_SETUP);
$this->assertFalse($oTrigger->IsContextValid());
ContextTag::AddContext(ContextTag::TAG_CRON);
$this->assertTrue($oTrigger->IsContextValid());
}
public function testEnrichRaisedException_Trigger()
{
$oTrigger = MetaModel::NewObject('TriggerOnObjectCreate');
try
{
try
{
MetaModel::NewObject('Toto');
}
catch (\Exception $e)
{
\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\' (TriggerOnObjectCreate::-1 ()
)', $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 NonCmdbAbstractObject() ],
] ;
}
/**
* @param $oCmdbAbstract
* @dataProvider NoEnrichmentProvider
*/
public function testEnrichRaisedException_NoEnrichment($oCmdbAbstract)
{
try
{
try
{
MetaModel::NewObject('CoreException');
}
catch (\Exception $e)
{
\utils::EnrichRaisedException($oCmdbAbstract, $e);
}
$this->assertTrue(false, "An exception should have been thrown");
}
catch(\Exception $e1)
{
$this->assertEquals($e, $e1);
}
}
}
class NonCmdbAbstractObject{
}