PHP Classes

How to Test Your Application Features in Practice During a PHP Version Upgrade - 4 minutes - Lately in PHP Podcast Episode 92 Part 6

Recommend this page to a friend!
  Blog PHP Classes blog   RSS 1.0 feed RSS 2.0 feed   Blog How to Test Your Appl...   Post a comment Post a comment   See comments See comments (0)   Trackbacks (0)  

Author:

Viewers: 189

Last month viewers: 1

Categories: PHP Tutorials, Lately in PHP Podcast

After you have planned all the steps of a PHP version upgrade process, it is time to execute the planned steps.

Read this article, watch a 4-minute video, or listen to part 6 of episode 92 of the Lately in PHP podcast to learn how to test your application features in practice during a PHP version upgrade using reliable testing tools.




Loaded Article

In this article you can learn:

How to Plan a PHP Version Upgrade Successfully

1. Previous Article: Why You Need to Choose the Right Moment to Upgrade to a New PHP Version

2. Previous Article: When Is the Right Time to Upgrade

3. Previous Article: How to Plan a PHP Version Upgrade Successfully

4. Previous Article: How to Setup a Development Environment Separate from the Production Environment

5. Previous Article: What Are Your App Features to Test First Before a PHP Version Upgrade

7. This Article: Test Crucial PHP and Environment Features Next

8. Next Article: What Is The Right Order to Make Changes in Your Environment During a PHP Version Upgrade

Contents


Listen or download the podcast, RSS feed and subscribe in iTunes

Click on the Play button to listen now.

Introduction music obtained with permission from: http://spoti.fi/NCS

View Podcast in iTunes

Listen on Spotify
Listen on Spotify


Sound effects obtained with permission from: https://www.zapsplat.com/

In iTunes, use the Subscribe to Podcast... item of the Advanced menu, and then enter the URL above to subscribe to this podcast.

Watch the podcast video

See the Lately in PHP podcast play list on YouTube and Subscribe to this channel there.

Episode 92 Part 6 Video

Play Video

What was said in the podcast

3. What Should You Do Upgrade Successfully

3.4 Test Crucial PHP and Environment Features Next

When you upgrade to a newer version of PHP, the operating system, the Web server, or the database server that you use, if your application stops working, you may lose even money if your revenue depends on these crucial environment tools.

So you need to have tests to evaluate if your application still works after an upgrade of these tools.

You should test the upgrades of these tools first in your development environment.

You can use any test suite tool to help you on this, like, for instance, PHPUnit.

I use the PHP Feature Test package for this purpose.

This package is simple. It has a core class and driver classes. The core class automates the process of calling the driver classes. The driver classes test specific features of PHP, PHP extensions, and even connections to databases.

This package is extensible. You can create your feature test driver classes to adapt them to the needs of your projects.

You need to develop a new driver class, add the details of that driver class to a feature test configuration file in JSON format, and eventually, options to configure specific aspects of your test driver class, like, for instance, database connection parameters.

Here is an example of a driver class for testing PHP SSL support:

class feature_test_ssl_client_class extends feature_test_driver_class
{
    public 
$required_options = array(
        
'ssl_url',
    );

    Function 
Process()
    {
        if(!
extension_loaded('openssl'))
        {
            
$this->results 'DISABLED: The OpenSSL extension is not available in this PHP installation as expected.';
        }
        else
        {
            
$url str_replace('{account}''mlemos'$this->options->ssl_url);
            
$context = array(
                
'ssl' => array(
                    
'verify_peer' => false,
                    
'verify_peer_name' => false
                
)
            );
            
$success file_get_contents($urlfalsestream_context_create($context));
            if(!
$success)
            {
                
$error error_get_last();
                
$this->results 'Accessing OpenID URL failed ('.$url.') with error: '.$error['message'];
            }
        }
        return 
true;
    }
};

Your application script to test environment features can be as simple as this:

    /*
     * Create the feature test main object
     */
    
$feature_test = new feature_test_class;

    
/*
     * Set the configuration file that defines all the supported tests
     * You can create a new configuration file to perform other tests that
     * are not yet implemented by the current feature test driver classes.
     */
    
$feature_test->configuration_file 'feature_test_configuration.json';

    
/*
     * Set the path of the feature test driver classes
     */
    
$feature_test->drivers_path 'drivers';

    
/*
     * Set the html variable to determine whether you want the test
     * results to be outputted in plain text or HTML.
     */
    
$feature_test->html defined('__HTML');

    
/*
     * Setup an options object with custom properties that will be used to
     * configure the driver classes.
     */
    
$options = new stdClass;
    
$options->database_type 'mysqli';
    
$options->database_user 'root';
    
$options->database_password 'mysql password';
    
$options->database_host 'localhost';
    
$options->database_name 'database name';
    
$options->database_options = array();
    
$options->cipher 'bf-ecb';
    
$options->ssl_url 'https://www.phpclasses.org/';
    
$options->upload_progress true;
    
$options->intl true;
    
$options->strftime false;

    
$feature_test->options $options;

    
/*
     * If you want to run this test script from the command line shell,
     * you can pass the names of the tests that you want to perform,
     * just in case you just to perform some of the available tests.
     */
    
if(IsSet($_SERVER['argv'])
    && 
GetType($_SERVER['argv']) == 'array'
    
&& Count($_SERVER['argv']) > 1)
    {
        
$feature_test->test_list $_SERVER['argv'];
        
array_shift($feature_test->test_list);
    }
    else
        
$feature_test->test_list = array();

    
/*
     * Call the class and output the results depending on whether the
     * tests failed or not.
     */
    
if(!$feature_test->Initialize()
    || !
$feature_test->Process()
    || !
$feature_test->Finalize())
        echo 
'Failed tests: '.$feature_test->error."\n";
    else
        echo 
$feature_test->Output();
Show notes



You need to be a registered user or login to post a comment

1,616,619 PHP developers registered to the PHP Classes site.
Be One of Us!

Login Immediately with your account on:



Comments:

No comments were submitted yet.



  Blog PHP Classes blog   RSS 1.0 feed RSS 2.0 feed   Blog How to Test Your Appl...   Post a comment Post a comment   See comments See comments (0)   Trackbacks (0)