1--TEST--
2openssl_x509_export_to_file() tests
3--SKIPIF--
4<?php if (!extension_loaded("openssl")) print "skip"; ?>
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
20var_dump(openssl_x509_export_to_file($e, $outfilename)); // read an array, fails
21echo "---\n";
22var_dump($exists = file_exists($outfilename));
23?>
24--CLEAN--
25<?php
26$outfilename = __DIR__ . "/openssl_x509_export_to_file__outfilename.tmp";
27if (file_exists($outfilename)) {
28    unlink($outfilename);
29}
30?>
31--EXPECTF--
32bool(true)
33bool(true)
34
35Warning: openssl_x509_export_to_file(): cannot get cert from parameter 1 in %s on line %d
36bool(false)
37bool(true)
38
39Warning: openssl_x509_export_to_file(): cannot get cert from parameter 1 in %s on line %d
40bool(false)
41---
42bool(true)
43