Dealing with conditionals

From: Date: Wed, 06 Jun 2012 14:36:50 +0000
Subject: Dealing with conditionals
Groups: php.qa 
Request: Send a blank email to php-qa+get-66636@lists.php.net to get a copy of this message
Hello, New to the list, trying to obtain some information about writing solid test cases for new functions. Depending on the extensions linked dependency version (in this case OpenSSL), I would like to change the EXPECT based on this conditional. Here is an example test case I have written... --TEST-- Testing openssl_spki_new() --SKIPIF-- <?php if (!extension_loaded("openssl")) die("skip"); if (!@openssl_pkey_new()) die("skip cannot create private key"); ?> --FILE-- <?php /* private key creation */ echo "Creating private key..."; $pkey = openssl_pkey_new(); echo ($pkey !== false) ? "ok!\n\n" : "error creating private key\n\n"; /* testing all signing algorithms */ /* first check openssl's version to ensure we have all signing algos */ if(OPENSSL_VERSION_NUMBER <= 0x0090708f) {
        $algos = array('MD5'=>OPENSSL_ALGO_MD5,
                       'SHA1'=>OPENSSL_ALGO_SHA1,
                       'SHA256'=>OPENSSL_ALGO_SHA256,
                       'SHA512'=>OPENSSL_ALGO_SHA512);
} else {
        $algos = array('MD5'=>OPENSSL_ALGO_MD5,
                       'SHA1'=>OPENSSL_ALGO_SHA1);
} /* loop to create and verify results */ foreach($algos as $key => $value){ echo "Creating new SPKAC with ".$key."..."; $spki = openssl_spki_new($pkey, "sample_challenge_string", $value); if ((!empty($spki)) && (preg_match('/SPKAC=[a-zA-Z0-9\/\+]/', $spki))) echo "ok!\n"; } openssl_free_key($pkey); ?> --EXPECT-- Creating private key...ok! Creating new SPKAC with MD5...ok! Creating new SPKAC with SHA1...ok! Creating new SPKAC with SHA256...ok! Creating new SPKAC with SHA512...ok! As you can see it currently expects all signing algorithms to be present which would not be the case if PHP was compiled against an earlier version of the OpenSSL libraries. In this case > 0x0090708f or 0.9.7. How can I accomplish this, any feedback is also appreciated.

« previous php.qa (#66636) next »