Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\VarDumper\Test; Chris@0: Chris@0: use Symfony\Component\VarDumper\Cloner\VarCloner; Chris@0: use Symfony\Component\VarDumper\Dumper\CliDumper; Chris@0: Chris@0: /** Chris@0: * @author Nicolas Grekas
Chris@0: */ Chris@0: trait VarDumperTestTrait Chris@0: { Chris@12: public function assertDumpEquals($dump, $data, $filter = 0, $message = '') Chris@0: { Chris@17: if (\is_string($filter)) { Chris@17: @trigger_error(sprintf('The $message argument of the "%s()" method at the 3rd position is deprecated since Symfony 3.4 and will be moved at the 4th position in 4.0.', __METHOD__), E_USER_DEPRECATED); Chris@12: $message = $filter; Chris@12: $filter = 0; Chris@12: } Chris@12: Chris@12: $this->assertSame(rtrim($dump), $this->getDump($data, null, $filter), $message); Chris@0: } Chris@0: Chris@12: public function assertDumpMatchesFormat($dump, $data, $filter = 0, $message = '') Chris@0: { Chris@17: if (\is_string($filter)) { Chris@17: @trigger_error(sprintf('The $message argument of the "%s()" method at the 3rd position is deprecated since Symfony 3.4 and will be moved at the 4th position in 4.0.', __METHOD__), E_USER_DEPRECATED); Chris@12: $message = $filter; Chris@12: $filter = 0; Chris@12: } Chris@12: Chris@12: $this->assertStringMatchesFormat(rtrim($dump), $this->getDump($data, null, $filter), $message); Chris@0: } Chris@0: Chris@12: protected function getDump($data, $key = null, $filter = 0) Chris@0: { Chris@0: $flags = getenv('DUMP_LIGHT_ARRAY') ? CliDumper::DUMP_LIGHT_ARRAY : 0; Chris@0: $flags |= getenv('DUMP_STRING_LENGTH') ? CliDumper::DUMP_STRING_LENGTH : 0; Chris@0: Chris@0: $cloner = new VarCloner(); Chris@0: $cloner->setMaxItems(-1); Chris@0: $dumper = new CliDumper(null, null, $flags); Chris@0: $dumper->setColors(false); Chris@12: $data = $cloner->cloneVar($data, $filter)->withRefHandles(false); Chris@0: if (null !== $key && null === $data = $data->seek($key)) { Chris@0: return; Chris@0: } Chris@0: Chris@0: return rtrim($dumper->dump($data, true)); Chris@0: } Chris@0: }