Passed
Push — master ( a90ece...2f3895 )
by Jeremy
01:27 queued 11s
created

ElementStructTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 38
c 0
b 0
f 0
dl 0
loc 52
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A testParse() 0 50 1
1
<?php
2
3
/**
4
 * @file This file is part of the PdfParser library.
5
 *
6
 * @author  Konrad Abicht <[email protected]>
7
 * @date    2020-06-02
8
 *
9
 * @author  Sébastien MALOT <[email protected]>
10
 * @date    2017-01-03
11
 *
12
 * @license LGPLv3
13
 * @url     <https://github.com/smalot/pdfparser>
14
 *
15
 *  PdfParser is a pdf library written in PHP, extraction oriented.
16
 *  Copyright (C) 2017 - Sébastien MALOT <[email protected]>
17
 *
18
 *  This program is free software: you can redistribute it and/or modify
19
 *  it under the terms of the GNU Lesser General Public License as published by
20
 *  the Free Software Foundation, either version 3 of the License, or
21
 *  (at your option) any later version.
22
 *
23
 *  This program is distributed in the hope that it will be useful,
24
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
 *  GNU Lesser General Public License for more details.
27
 *
28
 *  You should have received a copy of the GNU Lesser General Public License
29
 *  along with this program.
30
 *  If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
31
 */
32
33
namespace Tests\Smalot\PdfParser\Integration\Element;
34
35
use Smalot\PdfParser\Element\ElementStruct;
36
use Smalot\PdfParser\Header;
37
use Test\Smalot\PdfParser\TestCase;
38
39
class ElementStructTest extends TestCase
40
{
41
    public function testParse()
42
    {
43
        $document = $this->getDocumentInstance();
44
45
        // Skipped.
46
        $offset = 0;
47
        $element = ElementStruct::parse('ABC', $document, $offset);
48
        $this->assertFalse($element);
0 ignored issues
show
Bug introduced by
It seems like $element can also be of type Smalot\PdfParser\Header; however, parameter $condition of PHPUnit\Framework\Assert::assertFalse() does only seem to accept boolean, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

48
        $this->assertFalse(/** @scrutinizer ignore-type */ $element);
Loading history...
49
        $this->assertEquals(0, $offset);
50
51
        $offset = 0;
52
        $element = ElementStruct::parse(' [ << /Filter /FlateDecode >> ]', $document, $offset);
53
        $this->assertFalse($element);
54
        $this->assertEquals(0, $offset);
55
56
        $offset = 0;
57
        $element = ElementStruct::parse(' / << /Filter /FlateDecode >> ', $document, $offset);
58
        $this->assertFalse($element);
59
        $this->assertEquals(0, $offset);
60
61
        $offset = 0;
62
        $element = ElementStruct::parse(' 0 << /Filter /FlateDecode >> ', $document, $offset);
63
        $this->assertFalse($element);
64
        $this->assertEquals(0, $offset);
65
66
        $offset = 0;
67
        $element = ElementStruct::parse(" 0 \n << /Filter /FlateDecode >> ", $document, $offset);
68
        $this->assertFalse($element);
69
        $this->assertEquals(0, $offset);
70
71
        // Valid.
72
        $offset = 0;
73
        $element = ElementStruct::parse(' << /Filter /FlateDecode >> ', $document, $offset);
74
        $this->assertTrue($element instanceof Header);
75
        $this->assertEquals(27, $offset);
76
77
        $offset = 0;
78
        $element = ElementStruct::parse(' << /Filter /FlateDecode >>', $document, $offset);
79
        $this->assertTrue($element instanceof Header);
80
        $this->assertEquals(27, $offset);
81
82
        $offset = 0;
83
        $element = ElementStruct::parse('<< /Filter /FlateDecode >>', $document, $offset);
84
        $this->assertTrue($element instanceof Header);
85
        $this->assertEquals(26, $offset);
86
87
        $offset = 0;
88
        $element = ElementStruct::parse(" \n << /Filter /FlateDecode >> ", $document, $offset);
89
        $this->assertTrue($element instanceof Header);
90
        $this->assertEquals(29, $offset);
91
    }
92
}
93