Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    922
    Thanks
    302
    Thanked 3 Times in 3 Posts

    Question How to test license validation via REST API

    Please consider the following PHP code

    PHP Code:
    static public function IsLicenseValid($domain)
    {
        if (empty(
    $domain)) {
            throw new 
    Exception;
        }

        
    $licenseResponse Curl::Post(['hostname' => $domain]);

            
    $Xml     = new XML();
            
    $xmlTree $Xml->XMLToTree($licenseResponse);

            if (
    $xmlTree['is_valid'] == 'true') {
                return 
    true;
            }
        }

        return 
    false;

    I am writing test case using PHPUnit to check the above method. I am able to cover all cases except one case in which a domain license should return true in is_valid xml node.

    The REST API is so secured that it does not accept request from IPs that are not listed in their whitelist. And if someone is making a request from a non-whitelisted IP the API returns a false value for is_valid (and this is how I am covering the case for false)

    I know this can be done using a mock object but I am not really sure how to write a mock object that can cover the case where a domain name is valid. Can someone please help?

    Thanks in advance

  • #2
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHPLicengine is a php license management system. You can try their trial version to get an idea to implement your own.

  • #3
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    922
    Thanks
    302
    Thanked 3 Times in 3 Posts
    Please read my question before answering


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •