FOSSology  4.4.0
Open Source License Compliance by Open Source Software
TestPgDbTest.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 namespace Fossology\Lib\Test;
9 
10 class TestPgDbTest extends \PHPUnit\Framework\TestCase
11 {
12 
13  public function testIfTestDbIsCreated()
14  {
15  return;
16  $this->markTestSkipped();
17  $dbName = 'fosstestone';
18  exec($cmd="dropdb -Ufossy -hlocalhost $dbName", $cmdOut, $cmdRtn);
19  if ($cmdRtn != 0) {
20  echo $cmdOut;
21  }
22  $testDb = new TestPgDb();
23  exec($cmd="psql -Ufossy -hlocalhost -l | grep -q $dbName", $cmdOut, $cmdRtn);
24  assertThat($cmdRtn,is(0));
25  }
26 
27  public function testGetDbManager()
28  {
29  $testDb = new TestPgDb();
30  $this->assertInstanceOf('Fossology\Lib\Db\DbManager', $testDb->getDbManager());
31  }
32 
33  public function testCreatePlainTables()
34  {
35  $testDb = new TestPgDb();
36  $testDb->createPlainTables(array('tag'));
37  $dbManager = $testDb->getDbManager();
38 
39  $dbManager->queryOnce("insert into tag (tag_pk,tag,tag_desc) values (1,'hello','world')");
40  $tag1 = $dbManager->getSingleRow('select * from tag where tag_pk=1');
41  assertThat($tag1,hasKey('tag_desc'));
42  assertThat($tag1['tag_desc'],is('world'));
43  }
44 
45  public function testInsertData()
46  {
47  $testDb = new TestPgDb();
48  $testDb->createPlainTables(array('perm_upload'));
49  $testDb->insertData(array('perm_upload'));
50  $tag1 = $testDb->getDbManager()->getSingleRow('select perm from perm_upload where perm_upload_pk=1');
51  assertThat($tag1,hasKey('perm'));
52  assertThat($tag1['perm'],is(10));
53  }
54 }
int Test
Definition: util.c:20