DocumentDictionaryCacheTest::run()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 4
nop 0
dl 0
loc 16
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @file This file is part of the PdfParser library.
5
 *
6
 * @author  Konrad Abicht <[email protected]>
7
 *
8
 * @date    2020-06-01
9
 *
10
 * @author  Sébastien MALOT <[email protected]>
11
 *
12
 * @date    2017-01-03
13
 *
14
 * @license LGPLv3
15
 *
16
 * @url     <https://github.com/smalot/pdfparser>
17
 *
18
 *  PdfParser is a pdf library written in PHP, extraction oriented.
19
 *  Copyright (C) 2017 - Sébastien MALOT <[email protected]>
20
 *
21
 *  This program is free software: you can redistribute it and/or modify
22
 *  it under the terms of the GNU Lesser General Public License as published by
23
 *  the Free Software Foundation, either version 3 of the License, or
24
 *  (at your option) any later version.
25
 *
26
 *  This program is distributed in the hope that it will be useful,
27
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
28
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
 *  GNU Lesser General Public License for more details.
30
 *
31
 *  You should have received a copy of the GNU Lesser General Public License
32
 *  along with this program.
33
 *  If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
34
 */
35
36
namespace PerformanceTests\Test;
37
38
use PerformanceTests\AbstractPerformanceTest;
39
use Smalot\PdfParser\Parser;
40
41
/**
42
 * This test checks does a performance test with certain PDF files that extensively use
43
 * the getFirstFont() method of Document.php. If Document.php correctly uses a dictionary
44
 * to cache the objects inside the PDF file, then the parsing should be quick.
45
 * If it does not, the parsing can be extensively slow or even crash.
46
 */
47
class DocumentDictionaryCacheTest extends AbstractPerformanceTest
48
{
49
    /**
50
     * @var Parser
51
     */
52
    protected $parser;
53
    protected $data;
54
55
    public function init(): void
56
    {
57
        $this->parser = new Parser();
58
59
        // load PDF file content
60
        $this->data = file_get_contents(__DIR__.'/../../../samples/DocumentWithLotsOfObjects.pdf');
61
    }
62
63
    public function run(): void
64
    {
65
        // give PDF content to function and parse it
66
        $pdf = $this->parser->parseContent($this->data);
67
68
        $pages = $pdf->getPages();
69
70
        foreach ($pages as $i => $page) { /* @var $page Page */
71
            if ($i < 77) {
72
                continue;
73
            }
74
            if ($i > 78) {
75
                continue;
76
            }
77
78
            $page->getText(); // Test this method
79
        }
80
    }
81
82
    public function getMaxEstimatedTime(): int
83
    {
84
        return 20;
85
    }
86
}
87