Version 1
[yaffs-website] / vendor / symfony / var-dumper / Tests / Caster / SplCasterTest.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\Tests\Caster;
13
14 use Symfony\Component\VarDumper\Test\VarDumperTestCase;
15
16 /**
17  * @author Grégoire Pineau <lyrixx@lyrixx.info>
18  */
19 class SplCasterTest extends VarDumperTestCase
20 {
21     public function getCastFileInfoTests()
22     {
23         return array(
24             array(__FILE__, <<<'EOTXT'
25 SplFileInfo {
26 %Apath: "%sCaster"
27   filename: "SplCasterTest.php"
28   basename: "SplCasterTest.php"
29   pathname: "%sSplCasterTest.php"
30   extension: "php"
31   realPath: "%sSplCasterTest.php"
32   aTime: %s-%s-%d %d:%d:%d
33   mTime: %s-%s-%d %d:%d:%d
34   cTime: %s-%s-%d %d:%d:%d
35   inode: %d
36   size: %d
37   perms: 0%d
38   owner: %d
39   group: %d
40   type: "file"
41   writable: true
42   readable: true
43   executable: false
44   file: true
45   dir: false
46   link: false
47 %A}
48 EOTXT
49             ),
50             array('https://google.com/about', <<<'EOTXT'
51 SplFileInfo {
52 %Apath: "https://google.com"
53   filename: "about"
54   basename: "about"
55   pathname: "https://google.com/about"
56   extension: ""
57   realPath: false
58 %A}
59 EOTXT
60             ),
61         );
62     }
63
64     /** @dataProvider getCastFileInfoTests */
65     public function testCastFileInfo($file, $dump)
66     {
67         $this->assertDumpMatchesFormat($dump, new \SplFileInfo($file));
68     }
69
70     public function testCastFileObject()
71     {
72         $var = new \SplFileObject(__FILE__);
73         $var->setFlags(\SplFileObject::DROP_NEW_LINE | \SplFileObject::SKIP_EMPTY);
74         $dump = <<<'EOTXT'
75 SplFileObject {
76 %Apath: "%sCaster"
77   filename: "SplCasterTest.php"
78   basename: "SplCasterTest.php"
79   pathname: "%sSplCasterTest.php"
80   extension: "php"
81   realPath: "%sSplCasterTest.php"
82   aTime: %s-%s-%d %d:%d:%d
83   mTime: %s-%s-%d %d:%d:%d
84   cTime: %s-%s-%d %d:%d:%d
85   inode: %d
86   size: %d
87   perms: 0%d
88   owner: %d
89   group: %d
90   type: "file"
91   writable: true
92   readable: true
93   executable: false
94   file: true
95   dir: false
96   link: false
97 %AcsvControl: array:%d [
98     0 => ","
99     1 => """
100 %A]
101   flags: DROP_NEW_LINE|SKIP_EMPTY
102   maxLineLen: 0
103   fstat: array:26 [
104     "dev" => %d
105     "ino" => %d
106     "nlink" => %d
107     "rdev" => 0
108     "blksize" => %i
109     "blocks" => %i
110      …20
111   ]
112   eof: false
113   key: 0
114 }
115 EOTXT;
116         $this->assertDumpMatchesFormat($dump, $var);
117     }
118
119     /**
120      * @dataProvider provideCastSplDoublyLinkedList
121      */
122     public function testCastSplDoublyLinkedList($modeValue, $modeDump)
123     {
124         $var = new \SplDoublyLinkedList();
125         $var->setIteratorMode($modeValue);
126         $dump = <<<EOTXT
127 SplDoublyLinkedList {
128 %Amode: $modeDump
129   dllist: []
130 }
131 EOTXT;
132         $this->assertDumpMatchesFormat($dump, $var);
133     }
134
135     public function provideCastSplDoublyLinkedList()
136     {
137         return array(
138             array(\SplDoublyLinkedList::IT_MODE_FIFO, 'IT_MODE_FIFO | IT_MODE_KEEP'),
139             array(\SplDoublyLinkedList::IT_MODE_LIFO, 'IT_MODE_LIFO | IT_MODE_KEEP'),
140             array(\SplDoublyLinkedList::IT_MODE_FIFO | \SplDoublyLinkedList::IT_MODE_DELETE, 'IT_MODE_FIFO | IT_MODE_DELETE'),
141             array(\SplDoublyLinkedList::IT_MODE_LIFO | \SplDoublyLinkedList::IT_MODE_DELETE, 'IT_MODE_LIFO | IT_MODE_DELETE'),
142         );
143     }
144 }