|
| 1 | +<?php |
| 2 | + |
| 3 | +class ExceptionEncoderTest extends PHPUnit_Framework_TestCase |
| 4 | +{ |
| 5 | + public function testExceptionObjectResult() |
| 6 | + { |
| 7 | + $code = 1234; |
| 8 | + $message = 'Test Message'; |
| 9 | + $exception = new \DomainException($message, $code); |
| 10 | + |
| 11 | + $encoder = new Understand\UnderstandLaravel\ExceptionEncoder(); |
| 12 | + $exceptionArray = $encoder->exceptionToArray($exception); |
| 13 | + $stackTraceArray = $encoder->stackTraceToArray($exception->getTrace()); |
| 14 | + |
| 15 | + $this->assertSame($message, $exceptionArray['message']); |
| 16 | + $this->assertSame('DomainException', $exceptionArray['class']); |
| 17 | + $this->assertSame($code, $exceptionArray['code']); |
| 18 | + $this->assertSame(__FILE__, $exceptionArray['file']); |
| 19 | + $this->assertSame(serialize($stackTraceArray), serialize($exceptionArray['stack'])); |
| 20 | + $this->assertNotEmpty($exceptionArray['line']); |
| 21 | + } |
| 22 | + |
| 23 | + public function testStackTraceResult() |
| 24 | + { |
| 25 | + $exception = new \DomainException; |
| 26 | + |
| 27 | + $encoder = new Understand\UnderstandLaravel\ExceptionEncoder(); |
| 28 | + $originalStackTrace = $exception->getTrace(); |
| 29 | + $stackTraceArray = $encoder->stackTraceToArray($originalStackTrace); |
| 30 | + |
| 31 | + $this->assertSame(count($originalStackTrace), count($stackTraceArray)); |
| 32 | + $this->assertSame($originalStackTrace[0]['function'], $stackTraceArray[0]['function']); |
| 33 | + $this->assertSame($originalStackTrace[0]['class'], $stackTraceArray[0]['class']); |
| 34 | + } |
| 35 | + |
| 36 | + public function testEmptyExceptionMessageCase() |
| 37 | + { |
| 38 | + $exception = new \DomainException; |
| 39 | + $encoder = new Understand\UnderstandLaravel\ExceptionEncoder(); |
| 40 | + $exceptionArray = $encoder->exceptionToArray($exception); |
| 41 | + |
| 42 | + $this->assertSame('DomainException', $exceptionArray['message']); |
| 43 | + } |
| 44 | + |
| 45 | +} |
0 commit comments