Results 1 to 6 of 6

Thread: How to test license validation via REST API

  1. #1
    Join Date
    Sep 2006

    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 

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

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

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


    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. #2
    While I kind of get what you're trying to do, I have no clue what XML parser you are using as neither "new XML" or "XMLtoTree" ring any bells here... much less if it's a XML structure is a value like "is_valid" REALLY going to be in the top of the array version of that structure?

    I'd suggest using DOMDocument instead so you can walk it properly. A lot of people prefer simpleXML, but usually I find that a bit limited in what you can do.

    I'd have to see a sample of the XML file's content to tell you much more.

  3. #3
    Join Date
    Sep 2006
    I dont understand, what does the XML parser have to do with PHPUnit testing?

  4. #4
    I'm not sure I understand what you mean by "PHPUnit" - quick google search... oh, it's some goofy framework crap to avoid installing a testing server; my advice, pitch that in the trash just like every other blasted framework. Nothing like wasting time making more work for yourself and then being told it's less work and saves time. Frameworks... pah.

    Just run it as a normal script.

    That said, I'm just not seeing how what you have there would even do anything since I don't know what you are calling or what it's building since again, no clue what that XML class you are using actually does or outputs. I know in normal XML parsers like simpleXML or DOMDocument in MOST cases a return like ['is_valid'] would be deeply nested, NOT in the top of any array structure.

    ... and without seeing the XML structure you are trying to parse, anything we try to tell you is nothing more than a wild stab in the dark. Though again, it doesn't look like the code you presented should actually work, unless that unknown XML class is doing something really goofy or strange to that file.

  5. #5
    Join Date
    Sep 2006
    Not at all helpful

    Thanks anyways

  6. #6
    Join Date
    Aug 2014
    PHPLicengine is a php license management system. You can try their trial version to get an idea to implement your own.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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