8 namespace Fossology\Lib\Proxy;
15 private $dbViewName =
"foo";
16 private $dbViewQuery =
"select 3.14";
19 private $dbManagerMock;
21 protected function setUp() :
void
23 $this->dbViewDao =
new DbViewProxy($this->dbViewQuery, $this->dbViewName);
25 $container = M::mock(
'ContainerBuilder');
26 $this->dbManagerMock = M::mock(DbManager::class);
27 $container->shouldReceive(
'get')->withArgs(array(
'db.manager'))->andReturn($this->dbManagerMock);
30 protected function tearDown() :
void
35 public function testGetDbViewName()
37 assertThat($this->dbViewDao->getDbViewName(),is($this->dbViewName));
40 public function testMaterialize()
42 $this->dbManagerMock->shouldReceive(
'queryOnce')->with(
"CREATE TEMPORARY TABLE $this->dbViewName AS $this->dbViewQuery", M::any());
43 $this->dbViewDao->materialize();
46 public function testMaterializeTwice()
48 $this->dbManagerMock->shouldReceive(
'queryOnce')->once();
49 $this->dbViewDao->materialize();
50 $this->dbViewDao->materialize();
53 public function testUnmaterializeAfterMaterialize()
55 $this->dbManagerMock->shouldReceive(
'queryOnce');
56 $this->dbViewDao->materialize();
57 $this->dbManagerMock->shouldReceive(
'queryOnce')->with(
"DROP TABLE $this->dbViewName");
58 $this->dbViewDao->unmaterialize();
61 public function testUnmaterializeWithoutMaterialize()
63 $this->dbManagerMock->shouldReceive(
'queryOnce')->never();
64 $this->dbViewDao->unmaterialize();
67 public function testAsCTE()
69 assertThat($this->dbViewDao->asCTE(),is(
"WITH $this->dbViewName AS (".$this->dbViewQuery.
")"));