Passed
Push — develop ( 3bea6f...0f8f07 )
by Mark
36:13
created

XmlScannerTest::testInvalidXML()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Reader\Security;
4
5
use PhpOffice\PhpSpreadsheet\Reader\Security\XmlScanner;
6
use PHPUnit\Framework\TestCase;
7
8
class XmlScannerTest extends TestCase
9
{
10
    /**
11
     * @dataProvider providerValidXML
12
     *
13
     * @param mixed $filename
14
     * @param mixed $expectedResult
15
     */
16
    public function testValidXML($filename, $expectedResult)
17
    {
18
        $reader = new XmlScanner();
19
        $result = $reader->scanFile($filename);
20
        self::assertEquals($expectedResult, $result);
21
    }
22
23
    public function providerValidXML()
24
    {
25
        $tests = [];
26
        foreach (glob(__DIR__ . '/../../../data/Reader/Xml/XEETestValid*.xml') as $file) {
27
            $tests[basename($file)] = [realpath($file), file_get_contents($file)];
28
        }
29
30
        return $tests;
31
    }
32
33
    /**
34
     * @dataProvider providerInvalidXML
35
     *
36
     * @param mixed $filename
37
     */
38
    public function testInvalidXML($filename)
39
    {
40
        $this->expectException(\PhpOffice\PhpSpreadsheet\Reader\Exception::class);
41
42
        $reader = new XmlScanner();
43
        $expectedResult = 'FAILURE: Should throw an Exception rather than return a value';
44
        $result = $reader->scanFile($filename);
45
        self::assertEquals($expectedResult, $result);
46
    }
47
48
    public function providerInvalidXML()
49
    {
50
        $tests = [];
51
        foreach (glob(__DIR__ . '/../../../data/Reader/Xml/XEETestInvalidUTF*.xml') as $file) {
52
            $tests[basename($file)] = [realpath($file)];
53
        }
54
55
        return $tests;
56
    }
57
}
58