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