27 $this->
dbManager->setDriver($this->driver);
35 function testInsertTableRow()
38 $assocParams = array(
'cola'=>1,
'colb'=>2);
40 $this->driver->shouldReceive(
'query')->once();
41 $this->driver->shouldReceive(
'freeResult');
42 $this->
dbManager->insertTableRow($tableName,$assocParams,$sqlLog);
45 function testCreateMap()
51 $preSql =
"/ $keyColumn, *$valueColumn /";
52 $this->driver->shouldReceive(
'query')->andReturn(
'fakeRes');
53 $this->driver->shouldReceive(
'fetchArray')->andReturn(
54 array($keyColumn=>
'k0',$valueColumn=>
'v0'),
55 array($keyColumn=>
'k1',$valueColumn=>
'v1'),
58 $this->driver->shouldReceive(
'freeResult');
59 $map = $this->
dbManager->createMap($tableName,$keyColumn,$valueColumn,$sqlLog);
60 assertThat($map,hasKey(
'k0'));
61 assertThat($map,EqualTo(array(
'k0'=>
'v0',
'k1'=>
'v1')));
64 function testEvaluateStatement()
66 $this->driver->shouldReceive(
'query');
67 $sqlStmt =
'SELECT pet FROM africa WHERE cervical=$1 AND class=$2 AND $3';
68 $this->
dbManager->prepare($stmt=
'statement',$sqlStmt);
70 $reflection = new \ReflectionClass(get_class($this->
dbManager));
71 $method = $reflection->getMethod(
'evaluateStatement');
72 $method->setAccessible(
true);
74 $params = array(7,
'Mammalia',
true);
75 $sql = $method->invoke($this->
dbManager,$stmt,$params);
76 assertThat($sql, is(
'SELECT pet FROM africa WHERE cervical=7 AND class=\'Mammalia\' AND t') );
78 $params = array(7,
'Mammalia\'; SELECT * FROM passwords WHERE user like \'%',
true);
79 $sql = $method->invoke($this->
dbManager,$stmt,$params);
80 assertThat($sql, is(
'SELECT pet FROM africa WHERE cervical=7 AND class=\'Mammalia\'\'; SELECT * FROM passwords WHERE user like \'\'%\' AND t') );
83 function testEvaluateStatement_exception()
85 $sqlStmt =
'SELECT pet FROM africa WHERE cervical=$1 AND class=$2';
86 $this->
dbManager->prepare($stmt=
'statement',$sqlStmt);
88 $reflection = new \ReflectionClass(get_class($this->
dbManager));
89 $method = $reflection->getMethod(
'evaluateStatement');
90 $method->setAccessible(
true);
92 $exceptionMsg =
false;
93 $params = array(7,
'Mammalia',
'non-used parameter');
95 $method->invoke($this->
dbManager,$stmt,$params);
98 $exceptionMsg = $e->getMessage();
100 assertThat($exceptionMsg, is(
'$3 not found in prepared statement'));
fo_dbManager * dbManager
fo_dbManager object