Completed
Push — master ( 73d93a...d5eebb )
by Ryuichi
02:49
created

FileTest::okFilePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 20 and the first side effect is on line 4.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
namespace WebStream\IO\Test;
3
4
require_once dirname(__FILE__) . '/../File.php';
5
require_once dirname(__FILE__) . '/../Writer/OutputStreamWriter.php';
6
require_once dirname(__FILE__) . '/../Writer/SimpleFileWriter.php';
7
require_once dirname(__FILE__) . '/../Test/Providers/FileProvider.php';
8
require_once dirname(__FILE__) . '/../Test/Modules/IOException.php';
9
10
use WebStream\IO\File;
11
use WebStream\IO\Writer\SimpleFileWriter;
12
use WebStream\IO\Test\Providers\FileProvider;
13
14
/**
15
 * FileTest
16
 * @author Ryuichi TANAKA.
17
 * @since 2016/08/19
18
 * @version 0.7
19
 */
20
class FileTest extends \PHPUnit_Framework_TestCase
21
{
22
    use FileProvider;
23
24
    /**
25
     * 正常系
26
     * ファイル名を取得できること
27
     * @test
28
     * @dataProvider fileProvider
29
     */
30
    public function okFileName($file)
31
    {
32
        $this->assertEquals($file->getFileName(), "file-test1.txt");
33
    }
34
35
    /**
36
     * 正常系
37
     * ファイル拡張子を取得できること
38
     * @test
39
     * @dataProvider fileProvider
40
     */
41
    public function okFileExtension($file)
42
    {
43
        $this->assertEquals($file->getFileExtension(), "txt");
44
    }
45
46
    /**
47
     * 正常系
48
     * ファイルパスを取得できること
49
     * @test
50
     * @dataProvider fileProvider
51
     */
52
    public function okFilePath($file)
53
    {
54
        $this->assertEquals($file->getFilePath(), dirname(__FILE__) . "/Providers/../Fixtures/" . $file->getFileName());
55
    }
56
57
    /**
58
     * 正常系
59
     * 絶対ファイルパスを取得できること
60
     * @dataProvider fileLinkProvider
61
     */
62
    public function okFileAbsolutePath($file, $linkPath)
63
    {
64
        symlink($file->getFilePath(), $linkPath);
65
        $linkFile = new File($linkPath);
66
        $this->assertEquals($file->getAbsoluteFilePath(), $linkFile->getAbsoluteFilePath());
67
        unlink($linkPath);
68
    }
69
70
    /**
71
     * 正常系
72
     * ファイルに読み込み権限をチェックできること
73
     * @test
74
     * @dataProvider fileProvider
75
     */
76
    public function okFileReadable($file)
77
    {
78
        chmod($file->getFilePath(), 0444);
79
        $this->assertTrue($file->isReadable());
80
    }
81
82
    /**
83
     * 正常系
84
     * ファイルに書き込み権限をチェックできること
85
     * @test
86
     * @dataProvider fileProvider
87
     */
88
    public function okFileWritable($file)
89
    {
90
        chmod($file->getFilePath(), 0666);
91
        $this->assertTrue($file->isWritable());
92
    }
93
94
    /**
95
     * 正常系
96
     * ファイルに実行権限をチェックできること
97
     * @test
98
     * @dataProvider fileProvider
99
     */
100
    public function okFileExecutable($file)
101
    {
102
        chmod($file->getFilePath(), 0555);
103
        $this->assertTrue($file->isExecutable());
104
    }
105
106
    /**
107
     * 正常系
108
     * ファイルであるかどうかチェックできること
109
     * @test
110
     * @dataProvider fileProvider
111
     */
112
    public function okFile($file)
113
    {
114
        $this->assertTrue($file->exists());
115
        $this->assertTrue($file->isFile());
116
    }
117
118
    /**
119
     * 正常系
120
     * ディレクトリであるかどうかチェックできること
121
     * @test
122
     * @dataProvider directoryProvider
123
     */
124
    public function okDirectory($file)
125
    {
126
        $this->assertTrue($file->exists());
127
        $this->assertTrue($file->isDirectory());
128
    }
129
130
    /**
131
     * 正常系
132
     * リンクであるかどうかチェックできること
133
     * @test
134
     * @dataProvider fileLinkProvider
135
     */
136
    public function okLink($file, $linkPath)
137
    {
138
        symlink($file->getFilePath(), $linkPath);
139
        $linkFile = new File($linkPath);
140
        $this->assertTrue($linkFile->exists());
141
        $this->assertTrue($linkFile->isLink());
142
        unlink($linkPath);
143
    }
144
145
    /**
146
     * 正常系
147
     * ファイルサイズを取得できること
148
     * @test
149
     * @dataProvider fileProvider
150
     */
151
    public function okFileSize($file)
152
    {
153
        $this->assertEquals($file->length(), 5);
154
    }
155
156
    /**
157
     * 正常系
158
     * ファイルを削除できること
159
     * @test
160
     * @dataProvider tmpFileProvider
161
     */
162
    public function okFileDelete($file)
163
    {
164
        $writer = new SimpleFileWriter($file->getFilePath());
165
        $writer->write("test");
166
        $this->assertTrue($file->delete());
167
    }
168
169
    /**
170
     * 正常系
171
     * ファイルサイズを取得できること
172
     * @test
173
     * @dataProvider tmpFileProvider
174
     */
175
    public function okFileRename($file)
176
    {
177
        $writer = new SimpleFileWriter($file->getFilePath());
178
        $writer->write("test");
179
        $this->assertTrue($file->renameTo("/tmp/file-test-rename.txt"));
180
181
        $renameFile = new File("/tmp/file-test-rename.txt");
182
        $renameFile->delete();
183
    }
184
185
    /**
186
     * 正常系
187
     * ファイル最終更新日時を取得できること
188
     * @test
189
     * @dataProvider fileProvider
190
     */
191
    public function okLastModified($file)
192
    {
193
        $this->assertEquals(gettype($file->lastModified()), "integer");
194
    }
195
}
196