26 private $dbViewName =
"foo";
27 private $dbViewQuery =
"select 3.14";
30 private $dbManagerMock;
32 protected function setUp()
34 $this->dbViewDao =
new DbViewProxy($this->dbViewQuery, $this->dbViewName);
36 $container = M::mock(
'ContainerBuilder');
37 $this->dbManagerMock = M::mock(DbManager::class);
38 $container->shouldReceive(
'get')->withArgs(array(
'db.manager'))->andReturn($this->dbManagerMock);
41 protected function tearDown()
46 public function testGetDbViewName()
48 assertThat($this->dbViewDao->getDbViewName(),is($this->dbViewName));
51 public function testMaterialize()
53 $this->dbManagerMock->shouldReceive(
'queryOnce')->with(
"CREATE TEMPORARY TABLE $this->dbViewName AS $this->dbViewQuery", M::any());
54 $this->dbViewDao->materialize();
57 public function testMaterializeTwice()
59 $this->dbManagerMock->shouldReceive(
'queryOnce')->once();
60 $this->dbViewDao->materialize();
61 $this->dbViewDao->materialize();
64 public function testUnmaterializeAfterMaterialize()
66 $this->dbManagerMock->shouldReceive(
'queryOnce');
67 $this->dbViewDao->materialize();
68 $this->dbManagerMock->shouldReceive(
'queryOnce')->with(
"DROP TABLE $this->dbViewName");
69 $this->dbViewDao->unmaterialize();
72 public function testUnmaterializeWithoutMaterialize()
74 $this->dbManagerMock->shouldReceive(
'queryOnce')->never();
75 $this->dbViewDao->unmaterialize();
78 public function testAsCTE()
80 assertThat($this->dbViewDao->asCTE(),is(
"WITH $this->dbViewName AS (".$this->dbViewQuery.
")"));