1--TEST--
2openssl_csr_export() tests
3--EXTENSIONS--
4openssl
5--SKIPIF--
6<?php
7if (!defined("OPENSSL_KEYTYPE_DSA")) die("skip DSA disabled");
8?>
9--FILE--
10<?php
11$wrong = "wrong";
12$config = __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf';
13$config_arg = array('config' => $config);
14
15$dn = array(
16    "countryName" => "BR",
17    "stateOrProvinceName" => "Rio Grande do Sul",
18    "localityName" => "Porto Alegre",
19    "commonName" => "Henrique do N. Angelo",
20    "emailAddress" => "hnangelo@php.net"
21);
22
23$args = array(
24    "digest_alg" => "sha256",
25    "private_key_bits" => 2048,
26    "private_key_type" => OPENSSL_KEYTYPE_DSA,
27    "encrypt_key" => true,
28    "config" => $config,
29);
30
31$privkey = openssl_pkey_new($config_arg);
32$csr = openssl_csr_new($dn, $privkey, $args);
33var_dump(openssl_csr_export($csr, $output));
34try {
35    var_dump(openssl_csr_export($wrong, $output));
36} catch (TypeError $e) {
37    echo $e->getMessage(), "\n";
38}
39try {
40    var_dump(openssl_csr_export($privkey, $output));
41} catch (TypeError $e) {
42    echo $e->getMessage(), "\n";
43}
44var_dump(openssl_csr_export($csr, $output, false));
45?>
46--EXPECTF--
47bool(true)
48
49Warning: openssl_csr_export(): X.509 Certificate Signing Request cannot be retrieved in %s on line %d
50bool(false)
51openssl_csr_export(): Argument #1 ($csr) must be of type OpenSSLCertificateSigningRequest|string, OpenSSLAsymmetricKey given
52bool(true)
53