Hoa central
SplFileInfo.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Iterator\Test\Unit;
38 
39 use Hoa\Iterator as LUT;
40 use Hoa\Test;
41 
51 {
52  public function case_file()
53  {
54  $this
55  ->given($pathname = 'hoa://Test/Vfs/Foo.bar')
56  ->when($result = new LUT\SplFileInfo($pathname))
57  ->then
58  ->boolean($result->isFile())
59  ->isTrue()
60  ->string($result->getType())
61  ->isEqualTo('file');
62  }
63 
64  public function case_directory()
65  {
66  $this
67  ->given($pathname = 'hoa://Test/Vfs/Foo?type=directory')
68  ->when($result = new LUT\SplFileInfo($pathname))
69  ->then
70  ->boolean($result->isDir())
71  ->isTrue()
72  ->string($result->getType())
73  ->isEqualTo('dir');
74  }
75 
76  public function case_path_informations()
77  {
78  $this
79  ->given(
80  $relativePath = 'hoa://Test/Vfs/A/B/',
81  $relativePathname = 'C/Foo.bar',
82  $pathname = $relativePath . $relativePathname
83  )
84  ->when($result = new LUT\SplFileInfo($pathname, $relativePath))
85  ->then
86  ->boolean($result->isFile())
87  ->isTrue()
88  ->string($result->getBasename())
89  ->isEqualTo('Foo.bar')
90  ->string($result->getExtension())
91  ->isEqualTo('bar')
92  ->string($result->getRelativePath())
93  ->isEqualTo($relativePath)
94  ->string($result->getRelativePathname())
95  ->isEqualTo($relativePathname)
96  ->string($result->getPath())
97  ->isEqualTo('hoa://Test/Vfs/A/B/C')
98  ->string($result->getPathname())
99  ->isEqualTo($pathname);
100  }
101 
102  public function case_times()
103  {
104  $this
105  ->given(
106  $timestamp = $this->realdom->boundinteger(
107  $this->realdom->timestamp('yesterday'),
108  $this->realdom->timestamp('tomorrow')
109  ),
110  $atime = $this->sample($timestamp),
111  $ctime = $this->sample($timestamp),
112  $mtime = $this->sample($timestamp),
113  $pathname = 'hoa://Test/Vfs/Foo.bar?' .
114  http_build_query([
115  'atime' => $atime,
116  'ctime' => $ctime,
117  'mtime' => $mtime
118  ])
119  )
120  ->when($result = new LUT\SplFileInfo($pathname))
121  ->then
122  ->integer($result->getATime())
123  ->isEqualTo($atime)
124  ->integer($result->getCTime())
125  ->isEqualTo($ctime)
126  ->integer($result->getMTime())
127  ->isEqualTo($mtime);
128  }
129 
130  public function case_permissions()
131  {
132  $this
133  ->given($pathname = 'hoa://Test/Vfs/Fo.bar?permissions=0744')
134  ->when($result = new LUT\SplFileInfo($pathname))
135  ->then
136  ->boolean($result->isReadable())
137  ->isTrue()
138  ->boolean($result->isWritable())
139  ->isTrue()
140  ->boolean($result->isExecutable())
141  ->isTrue()
142 
143  ->given($pathname = 'hoa://Test/Vfs/Foo.bar?permissions=0644')
144  ->when($result = new LUT\SplFileInfo($pathname))
145  ->then
146  ->boolean($result->isReadable())
147  ->isTrue()
148  ->boolean($result->isWritable())
149  ->isTrue()
150  ->boolean($result->isExecutable())
151  ->isFalse()
152 
153  ->given($pathname = 'hoa://Test/Vfs/Fooo.bar?permissions=0444')
154  ->when($result = new LUT\SplFileInfo($pathname))
155  ->then
156  ->boolean($result->isReadable())
157  ->isTrue()
158  ->boolean($result->isWritable())
159  ->isFalse()
160  ->boolean($result->isExecutable())
161  ->isFalse()
162 
163  ->given($pathname = 'hoa://Test/Vfs/Foooo.bar?permissions=0044')
164  ->when($result = new LUT\SplFileInfo($pathname))
165  ->then
166  ->boolean($result->isReadable())
167  ->isFalse()
168  ->boolean($result->isWritable())
169  ->isFalse()
170  ->boolean($result->isExecutable())
171  ->isFalse();
172  }
173 }