Passed
Push — feature/switch-to-phpunit ( 82614e )
by Konrad
03:39
created

ParserTest::testParseFile()   B

Complexity

Conditions 8
Paths 16

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 24
rs 8.4444
cc 8
nc 16
nop 0
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-01
8
 *
9
 * @license LGPLv3
10
 * @url     <https://github.com/smalot/pdfparser>
11
 *
12
 *  PdfParser is a pdf library written in PHP, extraction oriented.
13
 *  Copyright (C) 2017 - Sébastien MALOT <[email protected]>
14
 *
15
 *  This program is free software: you can redistribute it and/or modify
16
 *  it under the terms of the GNU Lesser General Public License as published by
17
 *  the Free Software Foundation, either version 3 of the License, or
18
 *  (at your option) any later version.
19
 *
20
 *  This program is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU Lesser General Public License for more details.
24
 *
25
 *  You should have received a copy of the GNU Lesser General Public License
26
 *  along with this program.
27
 *  If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
28
 */
29
30
namespace Tests\Smalot\PdfParser\Integration;
31
32
use Exception;
33
use Smalot\PdfParser\Parser;
34
use Smalot\PdfParser\Test\TestCase;
35
36
class ParserTest extends TestCase
37
{
38
    public function setUp()
39
    {
40
        parent::setUp();
41
42
        $this->fixture = new Parser();
43
    }
44
45
    public function testParseFile()
46
    {
47
        $directory = $this->rootDir.'/samples/bugs';
48
49
        if (is_dir($directory)) {
50
            $files = scandir($directory);
51
52
            foreach ($files as $file) {
53
                if (preg_match('/^.*\.pdf$/i', $file)) {
54
                    try {
55
                        $document = $this->fixture->parseFile($directory.'/'.$file);
56
                        $pages = $document->getPages();
57
                        $this->assertTrue(0 < \count($pages));
58
59
                        foreach ($pages as $page) {
60
                            $content = $page->getText();
61
                            $this->assert->string($content);
0 ignored issues
show
Bug Best Practice introduced by
The property assert does not exist on Tests\Smalot\PdfParser\Integration\ParserTest. Did you maybe forget to declare it?
Loading history...
62
                        }
63
                    } catch (Exception $e) {
64
                        if (
65
                            'Secured pdf file are currently not supported.' !== $e->getMessage()
66
                            && 0 != strpos($e->getMessage(), 'TCPDF_PARSER')
67
                        ) {
68
                            throw $e;
69
                        }
70
                    }
71
                }
72
            }
73
        }
74
    }
75
}
76