summaryrefslogtreecommitdiff
path: root/tests/unit/Testing/Data/Analysis/TDbStatementAnalysisTest.php
blob: 70437816f6c7482319dc97819b425170b38c8738 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
require_once dirname(__FILE__).'/../../../phpunit.php';

Prado::using('System.Testing.Data.Analysis.TDbStatementAnalysis');

/**
 * @package System.Testing.Data.Analysis
 */
class TDbStatementAnalysisTest extends PHPUnit_Framework_TestCase
{
	private $analyser;

	public function setUp()
	{
		$this->analyser = new TDbStatementAnalysis();
	}

	public function tearDown()
	{
		$this->analyser = null;
	}

	public function testStaticClassificationAnalysis()
	{
		$parameter = new TDbStatementAnalysisParameter();
		self::assertEquals(TDbStatementClassification::UNKNOWN, TDbStatementAnalysis::doClassificationAnalysis($parameter));

		$parameter = new TDbStatementAnalysisParameter('SELECT 1');
		self::assertEquals(TDbStatementClassification::UNKNOWN, TDbStatementAnalysis::doClassificationAnalysis($parameter));

		$parameter = new TDbStatementAnalysisParameter('SELECT 1', TDbStatementClassification::SQL);
		self::assertEquals(TDbStatementClassification::SQL, TDbStatementAnalysis::doClassificationAnalysis($parameter));
	}

	public function testDriverName()
	{
		self::assertNull($this->analyser->getDriverName());

		$this->analyser->setDriverName('mysql');
		self::assertEquals('mysql', $this->analyser->getDriverName());

		$this->analyser->setDriverName('mssql');
		self::assertEquals('mssql', $this->analyser->getDriverName());

		$this->analyser->setDriverName(null);
		self::assertNull($this->analyser->getDriverName());
	}

	public function testClassificationAnalysis()
	{
		$parameter = new TDbStatementAnalysisParameter();
		self::assertEquals(TDbStatementClassification::UNKNOWN, $this->analyser->getClassificationAnalysis($parameter));

		$parameter = new TDbStatementAnalysisParameter('SELECT 1');
		self::assertEquals(TDbStatementClassification::UNKNOWN, $this->analyser->getClassificationAnalysis($parameter));

		$parameter = new TDbStatementAnalysisParameter('SELECT 1', TDbStatementClassification::SQL);
		self::assertEquals(TDbStatementClassification::SQL, $this->analyser->getClassificationAnalysis($parameter));
	}

}
?>