[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <[email protected]> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Symfony\Component\VarDumper\Test; 13 14 use Symfony\Component\VarDumper\Cloner\VarCloner; 15 use Symfony\Component\VarDumper\Dumper\CliDumper; 16 17 /** 18 * @author Nicolas Grekas <[email protected]> 19 */ 20 trait VarDumperTestTrait 21 { 22 /** 23 * @internal 24 */ 25 private $varDumperConfig = [ 26 'casters' => [], 27 'flags' => null, 28 ]; 29 30 protected function setUpVarDumper(array $casters, int $flags = null): void 31 { 32 $this->varDumperConfig['casters'] = $casters; 33 $this->varDumperConfig['flags'] = $flags; 34 } 35 36 /** 37 * @after 38 */ 39 protected function tearDownVarDumper(): void 40 { 41 $this->varDumperConfig['casters'] = []; 42 $this->varDumperConfig['flags'] = null; 43 } 44 45 public function assertDumpEquals($expected, $data, int $filter = 0, string $message = '') 46 { 47 $this->assertSame($this->prepareExpectation($expected, $filter), $this->getDump($data, null, $filter), $message); 48 } 49 50 public function assertDumpMatchesFormat($expected, $data, int $filter = 0, string $message = '') 51 { 52 $this->assertStringMatchesFormat($this->prepareExpectation($expected, $filter), $this->getDump($data, null, $filter), $message); 53 } 54 55 protected function getDump($data, $key = null, int $filter = 0): ?string 56 { 57 if (null === $flags = $this->varDumperConfig['flags']) { 58 $flags = getenv('DUMP_LIGHT_ARRAY') ? CliDumper::DUMP_LIGHT_ARRAY : 0; 59 $flags |= getenv('DUMP_STRING_LENGTH') ? CliDumper::DUMP_STRING_LENGTH : 0; 60 $flags |= getenv('DUMP_COMMA_SEPARATOR') ? CliDumper::DUMP_COMMA_SEPARATOR : 0; 61 } 62 63 $cloner = new VarCloner(); 64 $cloner->addCasters($this->varDumperConfig['casters']); 65 $cloner->setMaxItems(-1); 66 $dumper = new CliDumper(null, null, $flags); 67 $dumper->setColors(false); 68 $data = $cloner->cloneVar($data, $filter)->withRefHandles(false); 69 if (null !== $key && null === $data = $data->seek($key)) { 70 return null; 71 } 72 73 return rtrim($dumper->dump($data, true)); 74 } 75 76 private function prepareExpectation($expected, int $filter): string 77 { 78 if (!\is_string($expected)) { 79 $expected = $this->getDump($expected, null, $filter); 80 } 81 82 return rtrim($expected); 83 } 84 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |