-
-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathSpecialCasesTest.php
55 lines (45 loc) · 1.66 KB
/
SpecialCasesTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use Safe\Exceptions\FilesystemException;
use Safe\Exceptions\PcreException;
class SpecialCasesTest extends TestCase
{
public function testPregReplace(): void
{
$this->expectException(PcreException::class);
$this->expectExceptionMessage('PREG_BAD_UTF8_ERROR: Invalid UTF8 character');
\Safe\preg_replace("/([\s,]+)/u", "foo", "\xc3\x28");
}
public function testFgetcsvWithTrailingNewline(): void
{
if (($handle = \fopen(__DIR__."/csv/test.csv", "r")) === false) {
throw new \RuntimeException('Test file could not be opened.');
}
while (($data = \Safe\fgetcsv($handle, 1000, ",")) !== false) {
$this->assertEquals(['test', 'test'], $data);
}
\fclose($handle);
}
public function testFgetcsvReturnFalseonEndOfFile(): void
{
if (($handle = \fopen(__DIR__."/csv/test2.csv", "r")) === false) {
throw new \RuntimeException('Test file could not be opened.');
}
while (($data = \Safe\fgetcsv($handle, 1000, ",")) !== false) {
$this->assertEquals(['test', 'test'], $data);
}
$this->assertEquals(false, $data);
\fclose($handle);
}
/*public function testFgetcsvThrowsOnError()
{
if (($handle = \fopen(__DIR__."/csv/test3.csv", "r")) === false) {
throw new \RuntimeException('Test file could not be opened.');
}
$this->expectException(FilesystemException::class);
while (($data = \Safe\fgetcsv($handle, 1000, ",")) !== false) {
echo var_export($data, true);
}
}*/
}