PHP Classes

File: tests/Parser/Wsdl/TagInputTest.php

Recommend this page to a friend!
  Classes of WsdlToPhp   PHP SOAP Package Generator   tests/Parser/Wsdl/TagInputTest.php   Download  
File: tests/Parser/Wsdl/TagInputTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: PHP SOAP Package Generator
Generate package to call SOAP services using WSDL
Author: By
Last change: issue-31 - #31: add unit test for Input tags parser
Date: 8 years ago
Size: 3,472 bytes
 

Contents

Class file image Download
<?php

namespace WsdlToPhp\PackageGenerator\Tests\Parser\Wsdl;

use
WsdlToPhp\PackageGenerator\Parser\Wsdl\TagInput;

class
TagInputTest extends WsdlParser
{
   
/**
     * @return \WsdlToPhp\PackageGenerator\Parser\Wsdl\TagInput
     */
   
public static function myBoardPackInstance()
    {
        return new
TagInput(self::generatorInstance(self::wsdlMyBoardPackPath()));
    }
   
/**
     * @return \WsdlToPhp\PackageGenerator\Parser\Wsdl\TagInput
     */
   
public static function lnpInstance()
    {
        return new
TagInput(self::generatorInstance(self::wsdlLnpPath()));
    }
   
/**
     * @return \SoapClient
     */
   
public static function myBoardPackSoapClient()
    {
        return new \
SoapClient(self::wsdlMyBoardPackPath());
    }
   
/**
     * @return \SoapClient
     */
   
public static function lnpSoapClient()
    {
        return new \
SoapClient(self::wsdlLnpPath());
    }
   
/**
     *
     */
   
public function testParseMyBoardpack()
    {
       
$tagInputParser = self::myBoardPackInstance();
       
$soapClient = self::myBoardPackSoapClient();

       
$tagInputParser->parse();

       
$count = 0;
       
$soapFunctions = $soapClient->__getFunctions();
        foreach (
$soapFunctions as $soapFunction) {
           
$methodData = self::getMethodDataFromSoapFunction($soapFunction);
           
$method = $tagInputParser->getGenerator()->getServiceMethod($methodData['name']);
            if (
strtolower($methodData['parameter']) === TagInput::UNKNOWN) {
               
$this->assertNotSame(TagInput::UNKNOWN, strtolower($method->getParameterType()));
               
$count++;
            }
        }
       
$this->assertSame(128, $count);
    }
   
/**
     *
     */
   
public function testParseLnp()
    {
       
$tagInputParser = self::lnpInstance();
       
$soapClient = self::lnpSoapClient();

       
$tagInputParser->parse();

       
$count = 0;
       
$soapFunctions = $soapClient->__getFunctions();
        foreach (
$soapFunctions as $soapFunction) {
           
$methodData = self::getMethodDataFromSoapFunction($soapFunction);
           
$method = $tagInputParser->getGenerator()->getServiceMethod($methodData['name']);
            if (
strtolower($methodData['parameter']) === TagInput::UNKNOWN) {
                if (
is_array($method->getParameterType())) {
                    foreach (
$method->getParameterType() as $methodParameterType) {
                       
$this->assertNotSame(TagInput::UNKNOWN, strtolower($methodParameterType));
                    }
                } else {
                   
$this->assertNotSame(TagInput::UNKNOWN, strtolower($method->getParameterType()));
                }
               
$count++;
            }
        }
       
$this->assertSame(7, $count);
    }
   
/**
     * @param string $soapFunction
     * @return string[]
     */
   
public static function getMethodDataFromSoapFunction($soapFunction)
    {
        if (
stripos($soapFunction, TagInput::UNKNOWN) !== false) {
           
$parameterType = TagInput::UNKNOWN;
        } else {
           
$parameterType = '[a-zA-Z_]*';
        }
       
$matches = array();
       
preg_match(sprintf('/[a-zA-Z_]*\s([a-zA-Z_]*)\(.*(%s)\s/i', $parameterType), $soapFunction, $matches);
       
$name = isset($matches[1]) ? $matches[1] : '';
       
$parameter = isset($matches[2]) ? $matches[2] : '';
        return array(
           
'name' => $name,
           
'parameter' => $parameter,
        );
    }
}