@@ -44,26 +44,15 @@ private function getNewCert($password)
4444 $ csrNames = ['commonName ' => 'Jhon Doe ' ];
4545
4646 $ csr = openssl_csr_new ($ csrNames , $ privateKey , ['digest_alg ' => 'sha256 ' ]);
47- $ x509 = openssl_csr_sign ($ csr , null , $ privateKey , $ days = 365 , [ ' digest_alg ' => ' sha256 ' ] );
47+ $ x509 = openssl_csr_sign ($ csr , null , $ privateKey , 365 );
4848
49- openssl_x509_export ($ x509 , $ rootCertificate );
50- openssl_pkey_export ($ privateKey , $ rootPrivateKey );
51-
52- $ privateKey = openssl_pkey_new ([
53- 'private_key_bits ' => 2048 ,
54- 'private_key_type ' => OPENSSL_KEYTYPE_RSA ,
55- ]);
56- $ temporaryFile = tempnam (sys_get_temp_dir (), 'cfg ' );
57- $ csr = openssl_csr_new ($ csrNames , $ privateKey );
58- $ x509 = openssl_csr_sign ($ csr , $ rootCertificate , $ rootPrivateKey , 365 );
59- $ certContent = null ;
6049 openssl_pkcs12_export (
6150 $ x509 ,
62- $ certContent ,
51+ $ pfxCertificateContent ,
6352 $ privateKey ,
6453 $ password ,
6554 );
66- return $ certContent ;
55+ return $ pfxCertificateContent ;
6756 }
6857
6958 public function testSignSuccess ()
@@ -92,17 +81,24 @@ public function testSignSuccess()
9281 public function testSignUsingDifferentPasswords (string $ password ): void
9382 {
9483 global $ mockExec ;
95- if (!class_exists ('JSignPDF\JSignPDFBin\JavaCommandService ' )) {
96- $ this ->markTestSkipped ('Install jsignpdf/jsignpdf-bin ' );
97- }
84+ $ mockExec = ['Finished: Signature succesfully created. ' ];
9885 $ params = JSignParamBuilder::instance ()->withDefault ();
86+ vfsStream::setup ('download ' );
87+ mkdir ('vfs://download/jvava/bin ' , 0755 , true );
88+ touch ('vfs://download/jvava/bin/java ' );
89+ chmod ('vfs://download/jvava/bin/java ' , 0755 );
90+ $ params ->setJavaPath ('vfs://download/jvava/bin/java ' );
91+ $ params ->setJavaDownloadUrl ('' );
92+ mkdir ('vfs://download/jsignpdf ' , 0755 , true );
93+ $ params ->setjSignPdfJarPath ('vfs://download/jsignpdf ' );
94+ $ params ->setJSignPdfDownloadUrl ('' );
9995 $ params ->setCertificate ($ this ->getNewCert ($ password ));
10096 $ params ->setPassword ($ password );
101- $ mockExec = ' Finished: Signature succesfully created. ' ;
102- $ path = $ params ->getTempPdfSignedPath ();
103- file_put_contents ($ path , 'dummy ' );
104- $ fileSigned = $ this ->service ->sign ($ params );
105- $ this ->assertNotNull ( $ fileSigned );
97+ $ params -> setPathPdfSigned ( ' vfs://download/temp ' ) ;
98+ $ signedFilePath = $ params ->getTempPdfSignedPath ();
99+ file_put_contents ($ signedFilePath , 'signed file content ' );
100+ $ fileSignedContent = $ this ->service ->sign ($ params );
101+ $ this ->assertEquals ( ' signed file content ' , $ fileSignedContent );
106102 }
107103
108104 public static function providerSignUsingDifferentPasswords (): array
0 commit comments