1<?php
2
3/**
4 * Hoa
5 *
6 *
7 * @license
8 *
9 * New BSD License
10 *
11 * Copyright © 2007-2017, Hoa community. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions are met:
15 *     * Redistributions of source code must retain the above copyright
16 *       notice, this list of conditions and the following disclaimer.
17 *     * Redistributions in binary form must reproduce the above copyright
18 *       notice, this list of conditions and the following disclaimer in the
19 *       documentation and/or other materials provided with the distribution.
20 *     * Neither the name of the Hoa nor the names of its contributors may be
21 *       used to endorse or promote products derived from this software without
22 *       specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37namespace Hoa\Iterator\Test\Unit;
38
39use Hoa\Iterator as LUT;
40use Hoa\Test;
41
42/**
43 * Class \Hoa\Iterator\Test\Unit\SplFileInfo.
44 *
45 * Test suite of the SplFileInfo class.
46 *
47 * @copyright  Copyright © 2007-2017 Hoa community
48 * @license    New BSD License
49 */
50class SplFileInfo extends Test\Unit\Suite
51{
52    public function case_file()
53    {
54        $this
55            ->given($pathname = 'hoa://Test/Vfs/Foo.bar?type=file')
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 . '?type=file', $relativePath))
85            ->then
86                ->boolean($result->isFile())
87                    ->isTrue()
88                ->string($result->getBasename())
89                    ->isEqualTo('Foo.bar?type=file')
90                ->string($result->getExtension())
91                    ->isEqualTo('bar?type=file')
92                ->string($result->getRelativePath())
93                    ->isEqualTo($relativePath)
94                ->string($result->getRelativePathname())
95                    ->isEqualTo($relativePathname . '?type=file')
96                ->string($result->getPath())
97                    ->isEqualTo('hoa://Test/Vfs/A/B/C')
98                ->string($result->getPathname())
99                    ->isEqualTo($pathname . '?type=file');
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 =
114                    'hoa://Test/Vfs/Foo.bar?' .
115                    http_build_query([
116                        'type'  => 'file',
117                        'atime' => $atime,
118                        'ctime' => $ctime,
119                        'mtime' => $mtime
120                    ])
121            )
122            ->when($result = new LUT\SplFileInfo($pathname))
123            ->then
124                ->integer($result->getATime())
125                    ->isEqualTo($atime)
126                ->integer($result->getCTime())
127                    ->isEqualTo($ctime)
128                ->integer($result->getMTime())
129                    ->isEqualTo($mtime);
130    }
131
132    public function case_permissions()
133    {
134        $this
135            ->given($pathname = 'hoa://Test/Vfs/Fo.bar?type=file&permissions=0744')
136            ->when($result = new LUT\SplFileInfo($pathname))
137            ->then
138                ->boolean($result->isReadable())
139                    ->isTrue()
140                ->boolean($result->isWritable())
141                    ->isTrue()
142                ->boolean($result->isExecutable())
143                    ->isTrue()
144
145            ->given($pathname = 'hoa://Test/Vfs/Foo.bar?type=file&permissions=0644')
146            ->when($result = new LUT\SplFileInfo($pathname))
147            ->then
148                ->boolean($result->isReadable())
149                    ->isTrue()
150                ->boolean($result->isWritable())
151                    ->isTrue()
152                ->boolean($result->isExecutable())
153                    ->isFalse()
154
155            ->given($pathname = 'hoa://Test/Vfs/Fooo.bar?type=file&permissions=0444')
156            ->when($result = new LUT\SplFileInfo($pathname))
157            ->then
158                ->boolean($result->isReadable())
159                    ->isTrue()
160                ->boolean($result->isWritable())
161                    ->isFalse()
162                ->boolean($result->isExecutable())
163                    ->isFalse()
164
165            ->given($pathname = 'hoa://Test/Vfs/Foooo.bar?type=file&permissions=0044')
166            ->when($result = new LUT\SplFileInfo($pathname))
167            ->then
168                ->boolean($result->isReadable())
169                    ->isFalse()
170                ->boolean($result->isWritable())
171                    ->isFalse()
172                ->boolean($result->isExecutable())
173                    ->isFalse();
174    }
175}
176