FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
ModernDbManagerTest.php
1 <?php
2 /*
3 Copyright (C) 2014, Siemens AG
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 namespace Fossology\Lib\Db;
20 
21 
23 {
24 
25  function setUp()
26  {
27  parent::setUp();
28  $this->dbManager = new ModernDbManager($this->logger);
29  $this->dbManager->setDriver($this->driver);
30  }
31 
32  function tearDown()
33  {
34  parent::tearDown();
35  }
36 
37  function testInsertTableRow()
38  {
39  $tableName = 'foo';
40  $assocParams = array('cola'=>1,'colb'=>2);
41  $sqlLog = 'bar';
42  $preSql = "INSERT INTO $tableName (cola,colb) VALUES ($1,$2)";
43  $this->driver->shouldReceive('prepare')->with($sqlLog,$preSql)->once();
44  $this->driver->shouldReceive('execute')->with($sqlLog,array_values($assocParams))->once();
45  $this->driver->shouldReceive('freeResult');
46  $this->dbManager->insertTableRow($tableName,$assocParams,$sqlLog);
47  }
48 
49  function testCreateMap()
50  {
51  $keyColumn = 'yek';
52  $valueColumn = 'lav';
53  $tableName = 'foo';
54  $sqlLog = 'bar';
55  $preSql = "/ $keyColumn, *$valueColumn /";
56  $this->driver->shouldReceive('prepare')->with($sqlLog,\Mockery::pattern($preSql))->once();
57  $this->driver->shouldReceive('execute')->andReturn('fakeRes');
58  $this->driver->shouldReceive('fetchArray')->andReturn(
59  array($keyColumn=>'k0',$valueColumn=>'v0'),
60  array($keyColumn=>'k1',$valueColumn=>'v1'),
61  false
62  );
63  $this->driver->shouldReceive('freeResult');
64  $map = $this->dbManager->createMap($tableName,$keyColumn,$valueColumn,$sqlLog);
65  assertThat($map,hasKey('k0'));
66  assertThat($map,EqualTo(array('k0'=>'v0','k1'=>'v1')));
67  }
68 }
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:28