diff --git a/tests/ExceptionDataBagTest.php b/tests/ExceptionDataBagTest.php new file mode 100644 index 000000000..c7ce0eca2 --- /dev/null +++ b/tests/ExceptionDataBagTest.php @@ -0,0 +1,100 @@ +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()); + } +}