Lib_Test_TestAbstract

TODO Add logging of original xml's (request and response).

Defined (1)

The class is defined in the following location(s).

/lib/Force.com-Toolkit-for-PHP/unit_test/Lib/Test/TestAbstract.php  
  1. abstract class Lib_Test_TestAbstract 
  2. protected $_wsdl; 
  3.  
  4. protected $_userName = 'hunter@barefootsolutions.com'; 
  5. //protected $_password = 'qwqDbM3q'+token; 
  6. protected $_password = 'qwqDbM3qD26eh0xIZhFmf7poWeYcTvrHq'; 
  7. protected $_token = 'D26eh0xIZhFmf7poWeYcTvrHq'; 
  8.  
  9. protected $_portalId = NULL; 
  10.  
  11. protected $_mySforceConnection; 
  12. protected $_mylogin; 
  13. protected $_mySoapClient; 
  14.  
  15. protected $_logger; 
  16. protected $_soapDir; 
  17. protected $_phpVersion; 
  18.  
  19. protected $_medaDataWsdlName = 'metadata'; 
  20.  
  21. public function __construct($soapDir) 
  22. $this->_soapDir = $soapDir; 
  23. $this->_logger = new Lib_Utils_FileLogger( 
  24. $this->getLogName(),  
  25. 'w'); 
  26.  
  27. $this->_phpVersion = phpversion(); 
  28. header('Content-Type: text/plain'); 
  29.  
  30. /** 
  31. * @param Lib_Utils_FileLogger $metaInfoLogger 
  32. * @return void 
  33. */ 
  34. public function run(Lib_Utils_FileLogger $metaInfoLogger) 
  35. try { 
  36. ob_start(); 
  37. $start_time = microtime(TRUE); 
  38.  
  39. try { 
  40. $this->_run(); 
  41. } catch (SoapFault $fault) { 
  42. $end_time = microtime(TRUE); 
  43. // some time SoapFaul is sign of positive test result 
  44. $resultStr = ob_get_clean(); 
  45. $this->_logger->write($resultStr); 
  46. print '<pre>' . $resultStr . '</pre>'; 
  47.  
  48. $this->_logger->write($fault->faultstring); 
  49. print '<pre>SoapFault:</pre>'; 
  50. print '<pre>' . $fault->faultstring . '</pre>'; 
  51.  
  52. try { 
  53. // $this->_validateSoapFault($resultStr . $fault->faultstring); 
  54. $this->_validateSoapFault($fault->faultstring); 
  55. $metaInfoLogger->write(basename($this->getLogName()) . ' - test is ok!'); 
  56. } catch (Lib_Exception_InvalidResponse $e) { 
  57. $metaInfoLogger->write(basename($this->getLogName()) . ' - test failed!'); 
  58.  
  59. return; 
  60. }  
  61.  
  62. $end_time = microtime(TRUE); 
  63. $resultStr = ob_get_clean(); 
  64. $this->_logger->write($resultStr); 
  65. print $resultStr; 
  66.  
  67. try { 
  68. $this->_validate($resultStr); 
  69. $metaInfoLogger->write(basename($this->getLogName()) . ' - test is ok!'); 
  70. } catch (Lib_Exception_InvalidResponse $e) { 
  71. $metaInfoLogger->write(basename($this->getLogName()) . ' - test failed!'); 
  72.  
  73. $metaInfoLogger->write('Total time: '. ($end_time - $start_time)); 
  74. $metaInfoLogger->write('Max allocated memory: '. memory_get_peak_usage(TRUE));  
  75. } catch (Exception $e) { 
  76. $this->_logger->write($this->_mySforceConnection->getLastRequest()); 
  77. ob_start(); 
  78. print_r($e); 
  79. $eStr = ob_get_clean(); 
  80. $this->_logger->write($eStr); 
  81.  
  82. print $this->_mySforceConnection->getLastRequest(); 
  83. echo "\n\n\n"; 
  84. print $eStr; 
  85.  
  86. $metaInfoLogger->write('Test failed!'); 
  87.  
  88. public function getLogName() 
  89. return $this->_soapDir . '/results/' . $this->getTestName() . '_' . $this->getWSDLName() . '_' .  
  90. $this->getWSDLVersion() . '_' . phpversion(); 
  91.  
  92. protected function _getMetaDataWSDL() 
  93. return $this->_soapDir . '/' . $this->_medaDataWsdlName . '.wsdl.xml'; 
  94.  
  95. /** 
  96. * @return void 
  97. * @throws SoapFault 
  98. */ 
  99. abstract protected function _run(); 
  100.  
  101. /** 
  102. * NOTE: implement in sub-classes. 
  103. *  
  104. * @param string $rs 
  105. * @return void 
  106. * @throws Lib_Exception_InvalidResponse 
  107. */ 
  108. protected function _validate($rs) 
  109. // generic check 
  110. if(strpos($rs, 'errors') !== FALSE) { 
  111. throw new Lib_Exception_InvalidResponse(); 
  112.  
  113. /** 
  114. * NOTE: implement in sub-classes. 
  115. *  
  116. * @param string $rs 
  117. * @return void 
  118. * @throws Lib_Exception_InvalidResponse 
  119. */ 
  120. protected function _validateSoapFault($rs) 
  121. throw new Lib_Exception_InvalidResponse(); 
  122.  
  123. /** 
  124. *  
  125. * @return string location of local wsdl file 
  126. */ 
  127. abstract public function getWSDL(); 
  128.  
  129. abstract public function getWSDLName(); 
  130.  
  131. abstract public function getWSDLVersion(); 
  132.  
  133. abstract public function getTestName();