1--TEST--
2openssl_x509_export() tests
3--SKIPIF--
4<?php if (!extension_loaded("openssl")) print "skip"; ?>
5--FILE--
6<?php
7$cert_file = __DIR__ . "/cert.crt";
8
9$a = file_get_contents($cert_file);
10$b = "file://" . $cert_file;
11$c = "invalid cert";
12$d = openssl_x509_read($a);
13$e = array();
14
15var_dump(openssl_x509_export($a, $output));  // read cert as a binary string
16var_dump(openssl_x509_export($b, $output2)); // read cert from a filename string
17var_dump(openssl_x509_export($c, $output3)); // read an invalid cert, fails
18var_dump(openssl_x509_export($d, $output4)); // read cert from a resource
19
20try {
21    openssl_x509_export($e, $output5); // read an array, fails
22} catch (TypeError $exception) {
23    echo $exception->getMessage() . "\n";
24}
25
26if (PHP_EOL !== "\n") {
27    $a = str_replace(PHP_EOL, "\n", $a);
28}
29
30var_dump(strcmp($output, $a));
31var_dump(strcmp($output, $output2));
32var_dump(strcmp($output, $output3));
33var_dump(strcmp($output, $output4)); // different
34var_dump(strcmp($output, $output5)); // different
35?>
36--EXPECTF--
37bool(true)
38bool(true)
39
40Warning: openssl_x509_export(): X.509 Certificate cannot be retrieved in %s on line %d
41bool(false)
42bool(true)
43openssl_x509_export(): Argument #1 ($certificate) must be of type OpenSSLCertificate|string, array given
44int(0)
45int(0)
46int(%d)
47int(0)
48int(%d)
49