Skip to content

Commit 629d380

Browse files
authored
[BUGFIX] Use safe file functions in ParserTest (#1378)
Part of #1168
1 parent 1b363fd commit 629d380

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

tests/ParserTest.php

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
use Sabberworm\CSS\Value\URL;
3131
use Sabberworm\CSS\Value\ValueList;
3232

33+
use function Safe\file_get_contents;
34+
use function Safe\opendir;
35+
3336
/**
3437
* @covers \Sabberworm\CSS\Parser
3538
*/
@@ -58,25 +61,26 @@ public function parseForOneDeclarationBlockReturnsDocumentWithOneDeclarationBloc
5861
public function files(): void
5962
{
6063
$directory = __DIR__ . '/fixtures';
61-
if ($directoryHandle = \opendir($directory)) {
62-
/* This is the correct way to loop over the directory. */
63-
while (false !== ($filename = \readdir($directoryHandle))) {
64-
if (\strpos($filename, '.') === 0) {
65-
continue;
66-
}
67-
if (\strrpos($filename, '.css') !== \strlen($filename) - \strlen('.css')) {
68-
continue;
69-
}
70-
if (\strpos($filename, '-') === 0) {
71-
// Either a file which SHOULD fail (at least in strict mode)
72-
// or a future test of an as-of-now missing feature
73-
continue;
74-
}
75-
$parser = new Parser(\file_get_contents($directory . '/' . $filename));
76-
self::assertNotSame('', $parser->parse()->render());
64+
$directoryHandle = opendir($directory);
65+
66+
/* This is the correct way to loop over the directory. */
67+
while (false !== ($filename = \readdir($directoryHandle))) {
68+
if (\strpos($filename, '.') === 0) {
69+
continue;
7770
}
78-
\closedir($directoryHandle);
71+
if (\strrpos($filename, '.css') !== \strlen($filename) - \strlen('.css')) {
72+
continue;
73+
}
74+
if (\strpos($filename, '-') === 0) {
75+
// Either a file which SHOULD fail (at least in strict mode)
76+
// or a future test of an as-of-now missing feature
77+
continue;
78+
}
79+
$parser = new Parser(file_get_contents($directory . '/' . $filename));
80+
self::assertNotSame('', $parser->parse()->render());
7981
}
82+
83+
\closedir($directoryHandle);
8084
}
8185

8286
/**
@@ -943,7 +947,7 @@ public function missingPropertyValueLenient(): void
943947
public static function parsedStructureForFile($filename, $settings = null): Document
944948
{
945949
$filename = __DIR__ . "/fixtures/$filename.css";
946-
$parser = new Parser(\file_get_contents($filename), $settings);
950+
$parser = new Parser(file_get_contents($filename), $settings);
947951
return $parser->parse();
948952
}
949953

0 commit comments

Comments
 (0)