PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/Tests/MySQLConnector/MySQLConnectorTest.php

http://odatamysqlphpconnect.codeplex.com
PHP | 148 lines | 110 code | 20 blank | 18 comment | 0 complexity | 2fd1529006118cfdf91fd7a2bc306dba MD5 | raw file
  1. <?php
  2. require_once 'PHPUnit\Framework\Assert.php';
  3. require_once 'PHPUnit\Framework\Test.php';
  4. require_once 'PHPUnit\Framework\SelfDescribing.php';
  5. require_once 'PHPUnit\Framework\TestCase.php';
  6. require_once 'PHPUnit\Framework\TestSuite.php';
  7. require_once 'Tests\CustomMySQLConnector.php';
  8. define('OUT_DIR', '../OutputFiles');
  9. define('XSL_DIR', '../../ODataConnectorForMySQL/ProvidersGenerator');
  10. define('CONFIG_FILE', '../../ODataConnectorForMySQL/service.config.xml');
  11. Class TestMySQLConnector extends PHPUnit_Framework_TestCase {
  12. public $cmdArgv;
  13. protected $db;
  14. protected $host;
  15. protected $user;
  16. protected $pw;
  17. protected $srvc;
  18. protected function setUp()
  19. {
  20. $this->db = 'northwind';
  21. $this->host = 'localhost';
  22. $this->user = 'root';
  23. $this->pw = '';
  24. $this->srvc = "Northwind";
  25. $this->cmdArgv = array (
  26. "MySQLConnector.php",
  27. "/db=".$this->db,
  28. "/u=".$this->user,
  29. "/pw=".$this->pw,
  30. "/h=".$this->host,
  31. "/srvc=".$this->srvc
  32. );
  33. }
  34. /*
  35. * Generate providers.
  36. */
  37. function generateSrvc() {
  38. try
  39. {
  40. $util = new MySQLConnector($this->cmdArgv);
  41. $options = $util->getOptions();
  42. $stage = $util->_validateAndBuidOptions();
  43. $currentDir = str_replace("\\", "/", dirname(__FILE__));
  44. $serviceOutDir = $currentDir."/".OUT_DIR."/".$util->_options['serviceName'];
  45. $serviceXslDir = $currentDir."/".XSL_DIR;
  46. $configFileName = $currentDir."/".CONFIG_FILE;
  47. $stage = 2;
  48. $util->generateProviders($serviceOutDir, $serviceXslDir, $configFileName, $stage);
  49. }
  50. catch (\Exception $e)
  51. {
  52. $this->fail('An unexpected Exception has been raised . ' . $e->getMessage());
  53. }
  54. }
  55. /*
  56. * Test the generated file exist or not.
  57. */
  58. function testGeneratedFilesExists() {
  59. $this->generateSrvc();
  60. $this->assertFileExists(dirname(__FILE__)."/../OutputFiles/".$this->srvc."/".$this->srvc.'EDMX.xml');
  61. $this->assertFileExists(dirname(__FILE__)."/../OutputFiles/".$this->srvc."/".$this->srvc.'QueryProvider.php');
  62. $this->assertFileExists(dirname(__FILE__)."/../OutputFiles/".$this->srvc."/".$this->srvc.'Metadata.php');
  63. $this->assertFileExists(dirname(__FILE__)."/../OutputFiles/".$this->srvc."/".$this->srvc.'DSExpressionProvider.php');
  64. $this->assertFileExists(dirname(__FILE__)."/../OutputFiles/".$this->srvc."/".$this->srvc.'DataService.php');
  65. }
  66. /*
  67. * Test the QueryProvider class contains all the required APIs.
  68. */
  69. function testQueryProviderApiExists() {
  70. require_once "/Tests/OutputFiles/".$this->srvc."/".$this->srvc."QueryProvider.php";
  71. $className = $this->srvc."QueryProvider";
  72. $this->assertTrue(class_exists($className));
  73. $classObj = new $className();
  74. $this->assertTrue(method_exists($classObj, "__construct"));
  75. $this->assertTrue(method_exists($classObj, "getResourceSet"));
  76. $this->assertTrue(method_exists($classObj, "getResourceFromResourceSet"));
  77. $this->assertTrue(method_exists($classObj, "getResourceFromRelatedResourceSet"));
  78. $this->assertTrue(method_exists($classObj, "getRelatedResourceSet"));
  79. $this->assertTrue(method_exists($classObj, "getRelatedResourceReference"));
  80. $this->assertTrue(method_exists($classObj, "_serializeshipper"));
  81. $this->assertTrue(method_exists($classObj, "_serializeproduct"));
  82. $this->assertTrue(method_exists($classObj, "__destruct"));
  83. }
  84. /*
  85. * Test the DataService class contains all the required APIs.
  86. */
  87. function testMetadataApiExists() {
  88. require_once "Tests/OutputFiles/".$this->srvc."/".$this->srvc."DataService.php";
  89. $className = "Create".$this->srvc."Metadata";
  90. $this->assertTrue(class_exists($className));
  91. $classObj = new $className();
  92. $this->assertTrue(method_exists($classObj, "create"));
  93. }
  94. /*
  95. * Test the DSExpressionProvider class contains all the required APIs.
  96. */
  97. function testDSExpressionProviderApiExists() {
  98. require_once "Tests/OutputFiles/".$this->srvc."/".$this->srvc."DSExpressionProvider.php";
  99. $className = $this->srvc."DSExpressionProvider";
  100. $this->assertTrue(class_exists($className));
  101. $classObj = new $className();
  102. $this->assertTrue(method_exists($classObj, "getIteratorName"));
  103. $this->assertTrue(method_exists($classObj, "onLogicalExpression"));
  104. $this->assertTrue(method_exists($classObj, "onArithmeticExpression"));
  105. $this->assertTrue(method_exists($classObj, "onRelationalExpression"));
  106. $this->assertTrue(method_exists($classObj, "onUnaryExpression"));
  107. $this->assertTrue(method_exists($classObj, "onConstantExpression"));
  108. $this->assertTrue(method_exists($classObj, "onPropertyAccessExpression"));
  109. $this->assertTrue(method_exists($classObj, "onFunctionCallExpression"));
  110. $this->assertTrue(method_exists($classObj, "_prepareBinaryExpression"));
  111. $this->assertTrue(method_exists($classObj, "_prepareUnaryExpression"));
  112. }
  113. /*
  114. * Test the DSExpressionProvider class contains all the required APIs.
  115. */
  116. function testDDataServiceApiExists() {
  117. require_once "Tests/OutputFiles/".$this->srvc."/".$this->srvc."DataService.php";
  118. $className = $this->srvc."DataService";
  119. $this->assertTrue(class_exists($className));
  120. $classObj = new $className();
  121. $this->assertTrue(method_exists($classObj, "initializeService"));
  122. $this->assertTrue(method_exists($classObj, "getService"));
  123. $this->assertTrue(method_exists($classObj, "getExpressionProvider"));
  124. }
  125. protected function tearDown()
  126. {
  127. }
  128. }