AlphaPDFTest::testNumPagesWaterMark()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Royopa\AlphaPDF\Tests;
5
6
use Symfony\Component\Security\Core\User\User;
7
use PHPUnit\Framework\TestCase;
8
use Royopa\AlphaPDF\AlphaPDF;
9
use Royopa\AlphaPDF\WaterMark;
10
use Royopa\AlphaPDF\Fpdi;
11
use Symfony\Component\Filesystem\Filesystem;
12
13
class AlphaPDFTest extends TestCase
14
{
15
    protected $user;
16
    protected $sourceFile;
17
    protected $outputFile;
18
19
    public function testIsInstanceOfFpdi()
20
    {
21
        $alphaPdf = new AlphaPDF();
22
        $isInstance = false;
23
        if ($alphaPdf instanceof \setasign\Fpdi\Fpdi) {
0 ignored issues
show
introduced by
$alphaPdf is always a sub-type of setasign\Fpdi\Fpdi.
Loading history...
24
            $isInstance = true;
25
        }
26
        $this->assertTrue($isInstance);
27
28
        if ($alphaPdf instanceof \Royopa\AlphaPDF\Fpdi) {
0 ignored issues
show
introduced by
$alphaPdf is always a sub-type of Royopa\AlphaPDF\Fpdi.
Loading history...
29
            $isInstance = true;
30
        }
31
        $this->assertTrue($isInstance);
32
    }
33
34
    public function testNumPagesWaterMark()
35
    {
36
        $waterMark = new WaterMark($this->sourceFile, $this->user);
37
        $this->assertEquals(
38
            20,
39
            $waterMark->getPdf()->getNumPages()
40
        );
41
    }
42
43
    public function testUserWaterMark()
44
    {
45
        $waterMark = new WaterMark($this->sourceFile, $this->user);
46
47
        $waterMark
48
            ->doWaterMark()
49
            ->Output('F', $this->outputFile)
50
        ;
51
52
        $waterMarkOutput = new WaterMark($this->outputFile, $this->user);
53
54
        $this->assertEquals(
55
            $waterMark->getPdf()->getNumPages(),
56
            $waterMarkOutput->getPdf()->getNumPages()
57
        );
58
    }
59
60
    public function setUp()
61
    {
62
        $this->user = new User('royopa', '123456');
63
        $this->sourceFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'CVM-Guia-01-FII.pdf';
64
        $this->outputFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'CVM-Guia-01-FII.output.pdf';
65
    }
66
67
    public function tearDown()
68
    {
69
        $fs = new Filesystem();
70
        $fs->remove($this->outputFile);
71
    }
72
}