Skip to content

Commit

Permalink
test: Add tests for ExceptionDataBag (#1358)
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric committed Sep 5, 2022
1 parent e4db1c4 commit dc599ef
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions tests/ExceptionDataBagTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

declare(strict_types=1);

namespace Sentry\Tests;

use PHPUnit\Framework\TestCase;
use Sentry\ExceptionDataBag;
use Sentry\ExceptionMechanism;
use Sentry\Frame;
use Sentry\Stacktrace;

final class ExceptionDataBagTest extends TestCase
{
/**
* @dataProvider constructorDataProvider
*/
public function testConstructor(array $constructorArgs, string $expectedType, string $expectedValue, ?Stacktrace $expectedStackTrace, ?ExceptionMechanism $expectedExceptionMechansim)
{
$exceptionDataBag = new ExceptionDataBag(...$constructorArgs);

$this->assertSame($expectedType, $exceptionDataBag->getType());
$this->assertSame($expectedValue, $exceptionDataBag->getValue());
$this->assertSame($expectedStackTrace, $exceptionDataBag->getStacktrace());
$this->assertSame($expectedExceptionMechansim, $exceptionDataBag->getMechanism());
}

public function constructorDataProvider(): \Generator
{
yield [
[
new \RuntimeException('foo bar'),
null,
null,
],
\RuntimeException::class,
'foo bar',
null,
null,
];

$strackTarce = new Stacktrace([
new Frame('test_function', '/path/to/file', 10, null, '/path/to/file'),
]);
$exceptionMechansim = new ExceptionMechanism(ExceptionMechanism::TYPE_GENERIC, false);

yield [
[
new \RuntimeException('foo bar'),
$strackTarce,
$exceptionMechansim,
],
\RuntimeException::class,
'foo bar',
$strackTarce,
$exceptionMechansim,
];
}

public function testSetType(): void
{
$exceptionDataBag = new ExceptionDataBag(new \RuntimeException());

$exceptionDataBag->setType('foo bar');

$this->assertSame('foo bar', $exceptionDataBag->getType());
}

public function testSetValue(): void
{
$exceptionDataBag = new ExceptionDataBag(new \RuntimeException());

$exceptionDataBag->setValue('foo bar');

$this->assertSame('foo bar', $exceptionDataBag->getValue());
}

public function testSetStacktrace(): void
{
$exceptionDataBag = new ExceptionDataBag(new \RuntimeException());

$stacktrace = new Stacktrace([
new Frame('test_function', '/path/to/file', 10, null, '/path/to/file'),
]);

$exceptionDataBag->setStacktrace($stacktrace);

$this->assertSame($stacktrace, $exceptionDataBag->getStacktrace());
}

public function testSetMechanism(): void
{
$exceptionDataBag = new ExceptionDataBag(new \RuntimeException());
$exceptionMechanism = new ExceptionMechanism(ExceptionMechanism::TYPE_GENERIC, false);

$exceptionDataBag->setMechanism($exceptionMechanism);

$this->assertSame($exceptionMechanism, $exceptionDataBag->getMechanism());
}
}

0 comments on commit dc599ef

Please sign in to comment.