This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * This file is part of graze/data-file |
||
4 | * |
||
5 | * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com> |
||
6 | * |
||
7 | * For the full copyright and license information, please view the LICENSE |
||
8 | * file that was distributed with this source code. |
||
9 | * |
||
10 | * @license https://github.com/graze/data-file/blob/master/LICENSE.md |
||
11 | * @link https://github.com/graze/data-file |
||
12 | */ |
||
13 | |||
14 | namespace Graze\DataFile\Test\Integration\Node; |
||
15 | |||
16 | use Graze\DataFile\Modify\Compress\Gzip; |
||
17 | use Graze\DataFile\Node\FileNodeInterface; |
||
18 | use Graze\DataFile\Node\LocalFile; |
||
19 | use Graze\DataFile\Test\AbstractFileTestCase; |
||
20 | |||
21 | class LocalFileTest extends AbstractFileTestCase |
||
22 | { |
||
23 | public function testInstanceOf() |
||
24 | { |
||
25 | $file = new LocalFile('/broken/path/to/nowhere'); |
||
26 | static::assertInstanceOf(FileNodeInterface::class, $file); |
||
27 | } |
||
28 | |||
29 | View Code Duplication | public function testGetFilePathReturnsFullyQualifiedPath() |
|
0 ignored issues
–
show
|
|||
30 | { |
||
31 | $file = new LocalFile(static::$dir . 'file_path.test'); |
||
32 | $file->put('random'); |
||
33 | |||
34 | $expected = static::$dir . 'file_path.test'; |
||
35 | |||
36 | static::assertEquals($expected, $file->getPath()); |
||
37 | } |
||
38 | |||
39 | public function testGetFilenameJustReturnsTheFilename() |
||
40 | { |
||
41 | $file = new LocalFile(static::$dir . 'file_name.test'); |
||
42 | |||
43 | static::assertEquals('file_name.test', $file->getFilename()); |
||
44 | } |
||
45 | |||
46 | public function testFileExists() |
||
47 | { |
||
48 | $file = new LocalFile(static::$dir . 'file_exists.test'); |
||
49 | |||
50 | static::assertFalse($file->exists()); |
||
51 | |||
52 | $file->put('random'); |
||
53 | |||
54 | static::assertTrue($file->exists()); |
||
55 | } |
||
56 | |||
57 | public function testFileGetContents() |
||
58 | { |
||
59 | $file = new LocalFile(static::$dir . 'file_get_contents.test'); |
||
60 | |||
61 | $file->put('content stuff'); |
||
62 | |||
63 | static::assertEquals(['content stuff'], $file->getContents()); |
||
64 | } |
||
65 | |||
66 | public function testFileGetContentsReturnsEmptyArrayIfFileDoesNotExist() |
||
67 | { |
||
68 | $file = new LocalFile(static::$dir . 'file_get_contents_empty.test'); |
||
69 | static::assertEquals([], $file->getContents()); |
||
70 | } |
||
71 | |||
72 | public function testCompression() |
||
73 | { |
||
74 | $file = (new LocalFile(static::$dir . 'file_compression.test')) |
||
75 | ->setCompression(Gzip::NAME); |
||
76 | static::assertEquals('gzip', $file->getCompression()); |
||
77 | } |
||
78 | |||
79 | public function testEncoding() |
||
80 | { |
||
81 | $file = (new LocalFile(static::$dir . 'file_encoding.test')) |
||
82 | ->setEncoding('UTF-8'); |
||
83 | static::assertEquals('UTF-8', $file->getEncoding()); |
||
84 | } |
||
85 | |||
86 | public function testToString() |
||
87 | { |
||
88 | $file = new LocalFile(static::$dir . 'to_string.test'); |
||
89 | static::assertEquals($file->getPath(), $file); |
||
90 | } |
||
91 | |||
92 | public function testGetContentsForCompressedFile() |
||
93 | { |
||
94 | $file = new LocalFile(static::$dir . 'file_uncompressed.test'); |
||
95 | $file->put('uncompressed contents'); |
||
96 | |||
97 | $gzip = new Gzip(); |
||
98 | $compressed = $gzip->compress($file, ['keepOldFile' => true]); |
||
99 | |||
100 | static::assertEquals(['uncompressed contents'], $compressed->getContents()); |
||
101 | } |
||
102 | |||
103 | public function testGetContentsForCompressedFileDeletesTheUncompressedFileAfterwards() |
||
104 | { |
||
105 | $file = new LocalFile(static::$dir . 'file_uncompressed_todelete.test'); |
||
106 | $file->put('uncompressed contents'); |
||
107 | |||
108 | $gzip = new Gzip(); |
||
109 | $compressed = $gzip->compress($file, ['keepOldFile' => true]); |
||
110 | |||
111 | $compressed->getContents(); |
||
112 | |||
113 | static::assertFalse( |
||
114 | file_exists(static::$dir . 'file_uncompressed_todelete'), |
||
115 | "The uncompressed file should be deleted" |
||
116 | ); |
||
117 | } |
||
118 | |||
119 | public function testSetEncodingModifiesTheEncoding() |
||
120 | { |
||
121 | $file = new LocalFile(static::$dir . 'file_set_encoding.test'); |
||
122 | $file->put('uncompressed contents'); |
||
123 | |||
124 | $file->setEncoding('us-ascii'); |
||
125 | |||
126 | static::assertEquals('us-ascii', $file->getEncoding()); |
||
127 | } |
||
128 | |||
129 | View Code Duplication | public function testSetEncodingReturnsIsFluent() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
130 | { |
||
131 | $file = new LocalFile(static::$dir . 'file_set_encoding2.test'); |
||
132 | $file->put('uncompressed contents'); |
||
133 | |||
134 | $newFile = $file->setEncoding('us-ascii'); |
||
135 | |||
136 | static::assertNotNull($newFile); |
||
137 | static::assertSame($file, $newFile); |
||
138 | } |
||
139 | |||
140 | View Code Duplication | public function testSetCompressionModifiesTheEncoding() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
141 | { |
||
142 | $file = new LocalFile(static::$dir . 'file_set_compression.test'); |
||
143 | $file->put('uncompressed contents'); |
||
144 | |||
145 | $file->setCompression(Gzip::NAME); |
||
146 | |||
147 | static::assertEquals(Gzip::NAME, $file->getCompression()); |
||
148 | } |
||
149 | |||
150 | View Code Duplication | public function testSetCompressionReturnsIsFluent() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
151 | { |
||
152 | $file = new LocalFile(static::$dir . 'file_set_compression2.test'); |
||
153 | $file->put('uncompressed contents'); |
||
154 | |||
155 | $newFile = $file->setCompression(Gzip::NAME); |
||
156 | |||
157 | static::assertNotNull($newFile); |
||
158 | static::assertSame($file, $newFile); |
||
159 | } |
||
160 | |||
161 | public function testGetDirectoryReturnsJustTheDirectory() |
||
162 | { |
||
163 | $file = new LocalFile(static::$dir . 'file_dont_care.test'); |
||
164 | |||
165 | static::assertEquals(static::$dir, $file->getDirectory()); |
||
166 | } |
||
167 | |||
168 | public function testGetStream() |
||
169 | { |
||
170 | $file = new LocalFile(static::$dir . 'file_get_stream.test'); |
||
171 | |||
172 | $stream = $file->getStream(); |
||
173 | |||
174 | static::assertInternalType('resource', $stream); |
||
175 | |||
176 | fwrite($stream, 'some text'); |
||
177 | fclose($stream); |
||
178 | |||
179 | static::assertEquals('some text', $file->read()); |
||
180 | } |
||
181 | } |
||
182 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.