35 $this->driver = M::mock(
'Fossology\\Lib\\Db\\Driver');
36 $this->driver->shouldReceive(
'booleanToDb')->with(
true)->andReturn(
't');
37 $this->driver->shouldReceive(
'booleanToDb')->with(
false)->andReturn(
'f');
38 $this->driver->shouldReceive(
'escapeString')->andReturnUsing(
function ($v){
39 return pg_escape_string($v);
42 $this->logger = M::mock(
'Monolog\\Logger');
43 $this->logger->shouldReceive(
'addDebug');
51 function testBeginTransaction()
53 $this->driver->shouldReceive(
"begin")->withNoArgs()->once();
57 function testBeginTransactionTwice()
59 $this->driver->shouldReceive(
"begin")->withNoArgs()->once();
69 $this->driver->shouldReceive(
"commit")->withNoArgs()->never();
73 function testBeginAndCommitTransaction()
75 $this->driver->shouldReceive(
"begin")->withNoArgs()->once();
77 $this->driver->shouldReceive(
"commit")->withNoArgs()->once();
81 abstract function testInsertTableRow();
83 function testFlushStats()
85 $this->driver->shouldReceive(
'prepare');
87 $this->
dbManager->prepare($sqlStmt,
'SELECT elephant FROM africa');
88 $this->logger->shouldReceive(
'addDebug')->with(M::pattern(
"/executing '$sqlStmt' took /"));
92 abstract function testCreateMap();
94 function testExistsDb_no()
96 $this->driver->shouldReceive(
'existsTable')->with(M::pattern(
'/dTable/'))->andReturn(FALSE);
97 $existsTable = $this->
dbManager->existsTable(
'badTable');
98 assertThat($existsTable, is(FALSE));
101 function testExistsDb_yes()
103 $this->driver->shouldReceive(
'existsTable')->with(M::pattern(
'/dTable/'))->andReturn(TRUE);
104 $existsTable = $this->
dbManager->existsTable(
'goodTable');
105 assertThat($existsTable, is(TRUE));
113 $this->
dbManager->existsTable(
"goodTable' OR 3<'4");
116 function testInsertTableRowReturning()
118 $this->driver->shouldReceive(
'query');
119 $this->driver->shouldReceive(
'prepare');
120 $this->driver->shouldReceive(
'execute')->with(
"logging.returning:id", array(
"mouse"))->andReturn();
121 $this->driver->shouldReceive(
'fetchArray')->withAnyArgs()->andReturn(array(
"id" => 23,
"animal" =>
"mouse"));
122 $this->driver->shouldReceive(
'freeResult')->withAnyArgs();
124 $returnId = $this->
dbManager->insertInto(
'europe',
'animal', array(
'mouse'), $log=
'logging',
'id');
125 assertThat($returnId,equalTo(23));
fo_dbManager * dbManager
fo_dbManager object