e5f6bf5b98e7e23ce69d0f86d47e7c46e9edb02e
[yaffs-website] / vendor / symfony / var-dumper / Test / VarDumperTestTrait.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
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 <p@tchwork.com>
19  */
20 trait VarDumperTestTrait
21 {
22     public function assertDumpEquals($dump, $data, $message = '')
23     {
24         $this->assertSame(rtrim($dump), $this->getDump($data), $message);
25     }
26
27     public function assertDumpMatchesFormat($dump, $data, $message = '')
28     {
29         $this->assertStringMatchesFormat(rtrim($dump), $this->getDump($data), $message);
30     }
31
32     protected function getDump($data)
33     {
34         $h = fopen('php://memory', 'r+b');
35         $cloner = new VarCloner();
36         $cloner->setMaxItems(-1);
37         $dumper = new CliDumper($h);
38         $dumper->setColors(false);
39         $dumper->dump($cloner->cloneVar($data)->withRefHandles(false));
40         $data = stream_get_contents($h, -1, 0);
41         fclose($h);
42
43         return rtrim($data);
44     }
45 }