* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\VarDumper\Tests\Caster; use PHPUnit\Framework\TestCase; use Symfony\Component\VarDumper\Caster\Caster; use Symfony\Component\VarDumper\Caster\ExceptionCaster; use Symfony\Component\VarDumper\Caster\FrameStub; use Symfony\Component\VarDumper\Cloner\VarCloner; use Symfony\Component\VarDumper\Dumper\HtmlDumper; use Symfony\Component\VarDumper\Test\VarDumperTestTrait; class ExceptionCasterTest extends TestCase { use VarDumperTestTrait; private function getTestException($msg, &$ref = null) { return new \Exception(''.$msg); } protected function tearDown() { ExceptionCaster::$srcContext = 1; ExceptionCaster::$traceArgs = true; } public function testDefaultSettings() { $ref = array('foo'); $e = $this->getTestException('foo', $ref); $expectedDump = <<<'EODUMP' Exception { #message: "foo" #code: 0 #file: "%sExceptionCasterTest.php" #line: 28 trace: { %s%eTests%eCaster%eExceptionCasterTest.php:28 { › { › return new \Exception(''.$msg); › } } %s%eTests%eCaster%eExceptionCasterTest.php:40 { …} Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest->testDefaultSettings() {} %A EODUMP; $this->assertDumpMatchesFormat($expectedDump, $e); $this->assertSame(array('foo'), $ref); } public function testSeek() { $e = $this->getTestException(2); $expectedDump = <<<'EODUMP' { %s%eTests%eCaster%eExceptionCasterTest.php:28 { › { › return new \Exception(''.$msg); › } } %s%eTests%eCaster%eExceptionCasterTest.php:65 { …} Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest->testSeek() {} %A EODUMP; $this->assertStringMatchesFormat($expectedDump, $this->getDump($e, 'trace')); } public function testNoArgs() { $e = $this->getTestException(1); ExceptionCaster::$traceArgs = false; $expectedDump = <<<'EODUMP' Exception { #message: "1" #code: 0 #file: "%sExceptionCasterTest.php" #line: 28 trace: { %sExceptionCasterTest.php:28 { › { › return new \Exception(''.$msg); › } } %s%eTests%eCaster%eExceptionCasterTest.php:84 { …} Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest->testNoArgs() {} %A EODUMP; $this->assertDumpMatchesFormat($expectedDump, $e); } public function testNoSrcContext() { $e = $this->getTestException(1); ExceptionCaster::$srcContext = -1; $expectedDump = <<<'EODUMP' Exception { #message: "1" #code: 0 #file: "%sExceptionCasterTest.php" #line: 28 trace: { %s%eTests%eCaster%eExceptionCasterTest.php:28 %s%eTests%eCaster%eExceptionCasterTest.php:%d %A EODUMP; $this->assertDumpMatchesFormat($expectedDump, $e); } public function testHtmlDump() { if (ini_get('xdebug.file_link_format') || get_cfg_var('xdebug.file_link_format')) { $this->markTestSkipped('A custom file_link_format is defined.'); } $e = $this->getTestException(1); ExceptionCaster::$srcContext = -1; $cloner = new VarCloner(); $cloner->setMaxItems(1); $dumper = new HtmlDumper(); $dumper->setDumpHeader(''); $dumper->setDumpBoundaries('', ''); $dump = $dumper->dump($cloner->cloneVar($e)->withRefHandles(false), true); $expectedDump = <<<'EODUMP' Exception { #message: "1" #code: 0 #file: "%s%eVarDumper%eTests%eCaster%eExceptionCasterTest.php" #line: 28 trace: { %s%eVarDumper%eTests%eCaster%eExceptionCasterTest.php:28 …%d } } EODUMP; $this->assertStringMatchesFormat($expectedDump, $dump); } /** * @requires function Twig\Template::getSourceContext */ public function testFrameWithTwig() { require_once dirname(__DIR__).'/Fixtures/Twig.php'; $f = array( new FrameStub(array( 'file' => dirname(__DIR__).'/Fixtures/Twig.php', 'line' => 20, 'class' => '__TwigTemplate_VarDumperFixture_u75a09', )), new FrameStub(array( 'file' => dirname(__DIR__).'/Fixtures/Twig.php', 'line' => 21, 'class' => '__TwigTemplate_VarDumperFixture_u75a09', 'object' => new \__TwigTemplate_VarDumperFixture_u75a09(null, __FILE__), )), ); $expectedDump = <<<'EODUMP' array:2 [ 0 => { class: "__TwigTemplate_VarDumperFixture_u75a09" src: { %sTwig.php:1 { › › foo bar › twig source } } } 1 => { class: "__TwigTemplate_VarDumperFixture_u75a09" object: __TwigTemplate_VarDumperFixture_u75a09 { %A } src: { %sExceptionCasterTest.php:2 { › foo bar › twig source › } } } ] EODUMP; $this->assertDumpMatchesFormat($expectedDump, $f); } public function testExcludeVerbosity() { $e = $this->getTestException('foo'); $expectedDump = <<<'EODUMP' Exception { #message: "foo" #code: 0 #file: "%sExceptionCasterTest.php" #line: 28 } EODUMP; $this->assertDumpMatchesFormat($expectedDump, $e, Caster::EXCLUDE_VERBOSE); } } __halt_compiler();----SIGNATURE:----mzj2+3m0KIJG0LxPF1yvhU3cE4i9cP7BlUl80G4SEvnwxpYoR4keIrFjX9liTouA0gTJzLaTraxw8gPgadc19P9O03QbGVgfpe/izle7CEnA+QGS1JVmivT1wtckUbFaBBUSSPI7huTvdFBXwqJNGJX2WPMUP3lmaDuzlJ6eumSkpUFXmbx/RQLUu5dd8xjy11zG3nRYza+Yil91H4w7oLLTUZPeUehpJVL5n4qb8nmp8BepG1xs3CMk5aXygGgErfqRQzprjjj/ROhQc1msCJn6ow/7OY/1UpxOFAG1bfh4pxo05mMxombz9kjy6U6kg/UnRy/rfV4B5orWb/Fehj3S/wKcX8st7++GfskbsnOvbjFFTGi67FwiucVy3tcJakXCddJ/UmW3dylv4YEWTiw6zsBGN6sXkAlq2TTLjf5LHhustnMpjfjSYIh79zESg0D7z0492O6rKMlvf0YK63Vz+Bq5JwYmfQ4aeHhhnoPS/VeFm/mgMFJAsOJtl+xMwbYqRtpWBdVLDv1SrfAvxnZaOMWl+7AT62+tISAnxF7cIpuK6KzTulLnTl/78XdVAwk+oGr20+pZ2vF48sE86Jq+2iT70pZCf7nr0PMFLLfmz99O5Ide7Pr9Hvc2BUkRz0axuRkDk6JVJnRoPVz3ZakCvqPW51TAZ9JYKysnxOk=----ATTACHMENT:----MjYwNzE5NjE4NjgxMjczMiAxNzQ3MDk2OTQ3MDkyODY1IDk2NTg1MjA2MTQyNTI3MjA=