33namespace Jeidison \JSignPDF \Sign ;
44
55function exec (string $ command , array &$ output = null , int &$ return_var = null ) {
6- global $ mockExec ;
7- if ($ mockExec ) {
8- $ output = $ mockExec ;
9- return $ output ;
10- }
11- return \exec ($ command , $ output , $ return_var );
6+ global $ mockExec ;
7+ if ($ mockExec ) {
8+ $ output = $ mockExec ;
9+ return $ output ;
10+ }
11+ return \exec ($ command , $ output , $ return_var );
1212}
1313
1414namespace Jeidison \JSignPDF \Tests ;
@@ -27,8 +27,8 @@ class JSignPDFTest extends TestCase
2727
2828 protected function setUp (): void
2929 {
30- global $ mockExec ;
31- $ mockExec = null ;
30+ global $ mockExec ;
31+ $ mockExec = null ;
3232 $ this ->service = new JSignService ();
3333 }
3434
@@ -54,7 +54,14 @@ private function getNewCert($password)
5454 $ temporaryFile = tempnam (sys_get_temp_dir (), 'cfg ' );
5555 $ csr = openssl_csr_new ($ csrNames , $ privateKey );
5656 $ x509 = openssl_csr_sign ($ csr , $ rootCertificate , $ rootPrivateKey , 365 );
57- return $ this ->service ->exportToPkcs12 ($ x509 , $ privateKey , $ password );
57+ $ certContent = null ;
58+ openssl_pkcs12_export (
59+ $ x509 ,
60+ $ certContent ,
61+ $ privateKey ,
62+ $ password ,
63+ );
64+ return $ certContent ;
5865 }
5966
6067 public function testSignSuccess ()
@@ -73,16 +80,16 @@ public function testSignSuccess()
7380 */
7481 public function testSignUsingDifferentPasswords (string $ password )
7582 {
76- global $ mockExec ;
83+ global $ mockExec ;
7784 if (!class_exists ('JSignPDF\JSignPDFBin\JavaCommandService ' )) {
7885 $ this ->markTestSkipped ('Install jsignpdf/jsignpdf-bin ' );
7986 }
8087 $ params = JSignParamBuilder::instance ()->withDefault ();
8188 $ params ->setCertificate ($ this ->getNewCert ($ password ));
8289 $ params ->setPassword ($ password );
83- $ mockExec = 'Finished: Signature succesfully created. ' ;
84- $ path = $ params ->getTempPdfSignedPath ();
85- file_put_contents ($ path , 'dummy ' );
90+ $ mockExec = 'Finished: Signature succesfully created. ' ;
91+ $ path = $ params ->getTempPdfSignedPath ();
92+ file_put_contents ($ path , 'dummy ' );
8693 $ fileSigned = $ this ->service ->sign ($ params );
8794 $ this ->assertNotNull ($ fileSigned );
8895 }
0 commit comments