From 254c4cfefc90b0f473ba06d4de9e4d75ec46fce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20H=C3=A4rtl?= Date: Tue, 7 Jan 2020 09:11:11 +0100 Subject: [PATCH 1/2] Test against newer PHP versions and use require/autoload-dev --- .travis.yml | 3 +++ composer.json | 8 ++++++++ tests/CommandTest.php | 5 ++++- tests/DataFieldsTest.php | 5 ++++- tests/FdfFileTest.php | 5 ++++- tests/InfoFieldsTest.php | 5 ++++- tests/InfoFileTest.php | 5 ++++- tests/PdfTest.php | 5 ++++- tests/XfdfFileTest.php | 5 ++++- 9 files changed, 39 insertions(+), 7 deletions(-) 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/tests/CommandTest.php b/tests/CommandTest.php index 413f7b9..e0c2ad4 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -1,7 +1,10 @@ Date: Tue, 7 Jan 2020 11:05:40 +0100 Subject: [PATCH 2/2] Fix tests for updated php-shellcommand --- phpunit.xml.dist | 1 - tests/CommandTest.php | 8 +++--- tests/PdfTest.php | 64 +++++++++++++++++++++---------------------- 3 files changed, 36 insertions(+), 37 deletions(-) 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 e0c2ad4..5ebedc9 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -29,7 +29,7 @@ public function testCanAddFiles() $this->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() @@ -45,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() @@ -62,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() @@ -89,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/PdfTest.php b/tests/PdfTest.php index 4882362..29f77f2 100644 --- a/tests/PdfTest.php +++ b/tests/PdfTest.php @@ -28,7 +28,7 @@ public function testCanPassDocumentToConstructor() $this->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() { @@ -48,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() { @@ -64,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() { @@ -94,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() { @@ -111,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() ); } @@ -129,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() ); } @@ -146,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() ); } @@ -168,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() ); } @@ -194,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() ); } @@ -220,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() ); } @@ -290,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() ); } @@ -310,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() ); } @@ -319,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(); @@ -346,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() @@ -361,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() @@ -376,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() @@ -391,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() @@ -405,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() @@ -419,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() @@ -433,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() @@ -447,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() @@ -461,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() @@ -475,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() @@ -489,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() @@ -503,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() @@ -518,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() @@ -532,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() @@ -546,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()); } @@ -656,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'", @@ -698,7 +698,7 @@ protected function getOutFile() "Dimensions" => "595 842" ), ) - + ); protected $formDataFields = <<