diff --git a/.travis.yml b/.travis.yml index 3253115..ffa7656 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,9 @@ language: php dist: trusty php: + - "7.4" + - "7.3" + - "7.2" - "7.1" - "7.0" - "5.6" diff --git a/composer.json b/composer.json index 569c0c3..fc97ae1 100644 --- a/composer.json +++ b/composer.json @@ -15,9 +15,17 @@ "mikehaertl/php-shellcommand": "^1.5.0", "mikehaertl/php-tmpfile": "^1.1.0" }, + "require-dev": { + "phpunit/phpunit": ">4.0 <8" + }, "autoload": { "psr-4": { "mikehaertl\\pdftk\\": "src/" } + }, + "autoload-dev": { + "psr-4": { + "tests\\": "tests" + } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3a31f11..d4a86b0 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,7 +8,6 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" bootstrap="./tests/bootstrap.php" > diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 413f7b9..5ebedc9 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -1,7 +1,10 @@ assertTrue($command->execute($file)); $this->assertFileExists($file); - $this->assertEquals("pdftk A='$document1' B='$document2' input_pw B='complex'\''\"password' output '$file'", (string) $command); + $this->assertEquals("pdftk 'A'='$document1' 'B'='$document2' 'input_pw' 'B'='complex'\''\"password' 'output' '$file'", (string) $command); } public function testCanAddOptions() @@ -42,7 +45,7 @@ public function testCanAddOptions() $this->assertTrue($command->execute($file)); $this->assertFileExists($file); - $this->assertEquals("pdftk A='$document1' output '$file' encrypt_40bit allow Printing owner_pw 'complex'\''\"password'", (string) $command); + $this->assertEquals("pdftk 'A'='$document1' 'output' '$file' 'encrypt_40bit' allow Printing 'owner_pw' 'complex'\''\"password'", (string) $command); } public function testCanSetAndGetOperationAndArgument() @@ -59,7 +62,7 @@ public function testCanSetAndGetOperationAndArgument() $this->assertEquals('cat', $command->getOperation()); $this->assertEquals('A', $command->getOperationArgument()); - $this->assertEquals("pdftk A='$document1' cat A output '$file'", (string) $command); + $this->assertEquals("pdftk 'A'='$document1' cat A 'output' '$file'", (string) $command); } public function testCanAddPageRanges() @@ -86,7 +89,7 @@ public function testCanAddPageRanges() $this->assertTrue($command->execute($file)); $this->assertFileExists($file); - $this->assertEquals("pdftk A='$document1' cat 1 A1 1-3 1-3even 1-3evennorth 1-3north A1-3 A1-3even A1-3oddeast A1-3east 1-3east 1 3 A1 A3 output '$file'", (string) $command); + $this->assertEquals("pdftk 'A'='$document1' cat 1 A1 1-3 1-3even 1-3evennorth 1-3north A1-3 A1-3even A1-3oddeast A1-3east 1-3east 1 3 A1 A3 'output' '$file'", (string) $command); } protected function getDocument1() diff --git a/tests/DataFieldsTest.php b/tests/DataFieldsTest.php index 4cd60d8..810eb1c 100644 --- a/tests/DataFieldsTest.php +++ b/tests/DataFieldsTest.php @@ -1,7 +1,10 @@ assertFileExists($file); $tmpFile = (string) $pdf->getTmpFile(); - $this->assertEquals("pdftk A='$document' output '$tmpFile'", (string) $pdf->getCommand()); + $this->assertEquals("pdftk 'A'='$document' 'output' '$tmpFile'", (string) $pdf->getCommand()); } public function testCanPassPdfInstanceToConstructor() { @@ -45,7 +48,7 @@ public function testCanPassPdfInstanceToConstructor() $this->assertFileExists($file); $tmpFile = (string) $pdf2->getTmpFile(); - $this->assertEquals("pdftk A='$outFile1' output '$tmpFile'", (string) $pdf2->getCommand()); + $this->assertEquals("pdftk 'A'='$outFile1' 'output' '$tmpFile'", (string) $pdf2->getCommand()); } public function testCanPassDocumentsToConstructor() { @@ -61,7 +64,7 @@ public function testCanPassDocumentsToConstructor() $this->assertFileExists($file); $tmpFile = (string) $pdf->getTmpFile(); - $this->assertEquals("pdftk A='$document1' B='$document2' output '$tmpFile'", (string) $pdf->getCommand()); + $this->assertEquals("pdftk 'A'='$document1' 'B'='$document2' 'output' '$tmpFile'", (string) $pdf->getCommand()); } public function testCanPassPdfInstancesToConstructor() { @@ -91,7 +94,7 @@ public function testCanPassPdfInstancesToConstructor() $this->assertFileExists($file); $tmpFile = (string) $pdf->getTmpFile(); - $this->assertEquals("pdftk A='$outFile1' B='$outFile2' output '$tmpFile'", (string) $pdf->getCommand()); + $this->assertEquals("pdftk 'A'='$outFile1' 'B'='$outFile2' 'output' '$tmpFile'", (string) $pdf->getCommand()); } public function testCanPassDocumentsWithPasswordToConstructor() { @@ -108,7 +111,7 @@ public function testCanPassDocumentsWithPasswordToConstructor() $tmpFile = (string) $pdf->getTmpFile(); $this->assertEquals( - "pdftk A='$document1' B='$document2' input_pw A='complex'\''\"password' output '$tmpFile'", + "pdftk 'A'='$document1' 'B'='$document2' 'input_pw' 'A'='complex'\''\"password' 'output' '$tmpFile'", (string) $pdf->getCommand() ); } @@ -126,7 +129,7 @@ public function testCanAddFiles() $tmpFile = (string) $pdf->getTmpFile(); $this->assertEquals( - "pdftk A='$document1' D='$document2' input_pw A='complex'\''\"password' output '$tmpFile'", + "pdftk 'A'='$document1' 'D'='$document2' 'input_pw' 'A'='complex'\''\"password' 'output' '$tmpFile'", (string) $pdf->getCommand() ); } @@ -143,7 +146,7 @@ public function testCanPerformEmptyOperation() $tmpFile = (string) $pdf->getTmpFile(); $this->assertEquals( - "pdftk A='$document1' input_pw A='complex'\''\"password' output '$tmpFile'", + "pdftk 'A'='$document1' 'input_pw' 'A'='complex'\''\"password' 'output' '$tmpFile'", (string) $pdf->getCommand() ); } @@ -165,7 +168,7 @@ public function testCanCatFile() $tmpFile = (string) $pdf->getTmpFile(); $this->assertEquals( - "pdftk A='$document' cat 1-5 2 3 4 end-2even 3-5east 4-8eveneast 1south output '$tmpFile'", + "pdftk 'A'='$document' cat 1-5 2 3 4 end-2even 3-5east 4-8eveneast 1south 'output' '$tmpFile'", (string) $pdf->getCommand() ); } @@ -191,7 +194,7 @@ public function testCanCatFiles() $tmpFile = (string) $pdf->getTmpFile(); $this->assertEquals( - "pdftk A='$document1' B='$document2' cat A1-5 2 3 4 Bend-2even A3-5east B4-8eveneast A1south output '$tmpFile'", + "pdftk 'A'='$document1' 'B'='$document2' cat A1-5 2 3 4 Bend-2even A3-5east B4-8eveneast A1south 'output' '$tmpFile'", (string) $pdf->getCommand() ); } @@ -217,7 +220,7 @@ public function testCanShuffleFiles() $tmpFile = (string) $pdf->getTmpFile(); $this->assertEquals( - "pdftk A='$document1' B='$document2' shuffle A1-5 2 3 4 Bend-2even A3-5east B4-8eveneast A1south output '$tmpFile'", + "pdftk 'A'='$document1' 'B'='$document2' shuffle A1-5 2 3 4 Bend-2even A3-5east B4-8eveneast A1south 'output' '$tmpFile'", (string) $pdf->getCommand() ); } @@ -287,7 +290,7 @@ public function testCanFillFormFromData() $tmpFile = (string) $pdf->getTmpFile(); $this->assertRegExp( - "#pdftk A='$form' fill_form '/tmp/[^ ]+\.xfdf' output '$tmpFile' drop_xfa need_appearances#", + "#pdftk 'A'='$form' 'fill_form' '/tmp/[^ ]+\.xfdf' 'output' '$tmpFile' 'drop_xfa' 'need_appearances'#", (string) $pdf->getCommand() ); } @@ -307,7 +310,7 @@ public function testCanFillFormFromFile() $tmpFile = (string) $pdf->getTmpFile(); $this->assertRegExp( - "#pdftk A='$form' fill_form '$fdf' output '$tmpFile' drop_xfa need_appearances#", + "#pdftk 'A'='$form' 'fill_form' '$fdf' 'output' '$tmpFile' 'drop_xfa' 'need_appearances'#", (string) $pdf->getCommand() ); } @@ -316,15 +319,15 @@ public function testCanUpdateInfo() { $document1 = $this->getDocument1(); $file = $this->getOutFile(); - + $pdf = new Pdf($document1); $this->assertInstanceOf('mikehaertl\pdftk\Pdf', $pdf->updateInfo([ 'Creator' => 'php-pdftk' ])); $this->assertTrue($pdf->saveAs($file)); - + $this->assertFileExists($file); - + $tmpFile = (string) $pdf->getTmpFile(); $pdf = new Pdf($file); $data = $pdf->getData(); @@ -343,7 +346,7 @@ public function testCanSetBackground() $this->assertFileExists($file); $tmpFile = (string) $pdf->getTmpFile(); - $this->assertEquals("pdftk A='$document1' background '$document2' output '$tmpFile'", (string) $pdf->getCommand()); + $this->assertEquals("pdftk 'A'='$document1' 'background' '$document2' 'output' '$tmpFile'", (string) $pdf->getCommand()); } public function testCanSetMultiBackground() @@ -358,7 +361,7 @@ public function testCanSetMultiBackground() $this->assertFileExists($file); $tmpFile = (string) $pdf->getTmpFile(); - $this->assertEquals("pdftk A='$document1' multibackground '$document2' output '$tmpFile'", (string) $pdf->getCommand()); + $this->assertEquals("pdftk 'A'='$document1' 'multibackground' '$document2' 'output' '$tmpFile'", (string) $pdf->getCommand()); } public function testCanStamp() @@ -373,7 +376,7 @@ public function testCanStamp() $this->assertFileExists($file); $tmpFile = (string) $pdf->getTmpFile(); - $this->assertEquals("pdftk A='$document1' stamp '$document2' output '$tmpFile'", (string) $pdf->getCommand()); + $this->assertEquals("pdftk 'A'='$document1' 'stamp' '$document2' 'output' '$tmpFile'", (string) $pdf->getCommand()); } public function testCanMultiStamp() @@ -388,7 +391,7 @@ public function testCanMultiStamp() $this->assertFileExists($file); $tmpFile = (string) $pdf->getTmpFile(); - $this->assertEquals("pdftk A='$document1' multistamp '$document2' output '$tmpFile'", (string) $pdf->getCommand()); + $this->assertEquals("pdftk 'A'='$document1' 'multistamp' '$document2' 'output' '$tmpFile'", (string) $pdf->getCommand()); } public function testCanRemovePermissions() @@ -402,7 +405,7 @@ public function testCanRemovePermissions() $this->assertFileExists($file); $tmpFile = (string) $pdf->getTmpFile(); - $this->assertEquals("pdftk A='$document' output '$tmpFile' allow", (string) $pdf->getCommand()); + $this->assertEquals("pdftk 'A'='$document' 'output' '$tmpFile' 'allow'", (string) $pdf->getCommand()); } public function testCanSetPermissions() @@ -416,7 +419,7 @@ public function testCanSetPermissions() $this->assertFileExists($file); $tmpFile = (string) $pdf->getTmpFile(); - $this->assertEquals("pdftk A='$document' output '$tmpFile' allow Assembly CopyContents", (string) $pdf->getCommand()); + $this->assertEquals("pdftk 'A'='$document' 'output' '$tmpFile' allow Assembly CopyContents", (string) $pdf->getCommand()); } public function testCanFlatten() @@ -430,7 +433,7 @@ public function testCanFlatten() $this->assertFileExists($file); $tmpFile = (string) $pdf->getTmpFile(); - $this->assertEquals("pdftk A='$document' output '$tmpFile' flatten", (string) $pdf->getCommand()); + $this->assertEquals("pdftk 'A'='$document' 'output' '$tmpFile' 'flatten'", (string) $pdf->getCommand()); } public function testCanCompress() @@ -444,7 +447,7 @@ public function testCanCompress() $this->assertFileExists($file); $tmpFile = (string) $pdf->getTmpFile(); - $this->assertEquals("pdftk A='$document' output '$tmpFile' compress", (string) $pdf->getCommand()); + $this->assertEquals("pdftk 'A'='$document' 'output' '$tmpFile' 'compress'", (string) $pdf->getCommand()); } public function testCanUncompress() @@ -458,7 +461,7 @@ public function testCanUncompress() $this->assertFileExists($file); $tmpFile = (string) $pdf->getTmpFile(); - $this->assertEquals("pdftk A='$document' output '$tmpFile' uncompress", (string) $pdf->getCommand()); + $this->assertEquals("pdftk 'A'='$document' 'output' '$tmpFile' 'uncompress'", (string) $pdf->getCommand()); } public function testCanKeepFirstId() @@ -472,7 +475,7 @@ public function testCanKeepFirstId() $this->assertFileExists($file); $tmpFile = (string) $pdf->getTmpFile(); - $this->assertEquals("pdftk A='$document' output '$tmpFile' keep_first_id", (string) $pdf->getCommand()); + $this->assertEquals("pdftk 'A'='$document' 'output' '$tmpFile' 'keep_first_id'", (string) $pdf->getCommand()); } public function testCanKeepFinalId() @@ -486,7 +489,7 @@ public function testCanKeepFinalId() $this->assertFileExists($file); $tmpFile = (string) $pdf->getTmpFile(); - $this->assertEquals("pdftk A='$document' output '$tmpFile' keep_final_id", (string) $pdf->getCommand()); + $this->assertEquals("pdftk 'A'='$document' 'output' '$tmpFile' 'keep_final_id'", (string) $pdf->getCommand()); } public function testCanDropXfa() @@ -500,7 +503,7 @@ public function testCanDropXfa() $this->assertFileExists($file); $tmpFile = (string) $pdf->getTmpFile(); - $this->assertEquals("pdftk A='$document' output '$tmpFile' drop_xfa", (string) $pdf->getCommand()); + $this->assertEquals("pdftk 'A'='$document' 'output' '$tmpFile' 'drop_xfa'", (string) $pdf->getCommand()); } public function testCanSetPasswords() @@ -515,7 +518,7 @@ public function testCanSetPasswords() $this->assertFileExists($file); $tmpFile = (string) $pdf->getTmpFile(); - $this->assertEquals("pdftk A='$document' output '$tmpFile' owner_pw '\"'\''**' user_pw '**\"'\'''", (string) $pdf->getCommand()); + $this->assertEquals("pdftk 'A'='$document' 'output' '$tmpFile' 'owner_pw' '\"'\''**' 'user_pw' '**\"'\'''", (string) $pdf->getCommand()); } public function testSet128BitEncryption() @@ -529,7 +532,7 @@ public function testSet128BitEncryption() $this->assertFileExists($file); $tmpFile = (string) $pdf->getTmpFile(); - $this->assertEquals("pdftk A='$document' output '$tmpFile' encrypt_128bit", (string) $pdf->getCommand()); + $this->assertEquals("pdftk 'A'='$document' 'output' '$tmpFile' 'encrypt_128bit'", (string) $pdf->getCommand()); } public function testSet40BitEncryption() @@ -543,7 +546,7 @@ public function testSet40BitEncryption() $this->assertFileExists($file); $tmpFile = (string) $pdf->getTmpFile(); - $this->assertEquals("pdftk A='$document' output '$tmpFile' encrypt_40bit", (string) $pdf->getCommand()); + $this->assertEquals("pdftk 'A'='$document' 'output' '$tmpFile' 'encrypt_40bit'", (string) $pdf->getCommand()); } @@ -653,7 +656,7 @@ protected function getOutFile() PageMediaRect: 0 0 595 842 PageMediaDimensions: 595 842 EOD; - + protected $formDataArray = array( "Info" => array( "CreationDate" => "D:20140709121536+02'00'", @@ -695,7 +698,7 @@ protected function getOutFile() "Dimensions" => "595 842" ), ) - + ); protected $formDataFields = <<