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