FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
DbViewProxyTest.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\Proxy;
20 
22 use Mockery as M;
23 
24 class DbViewProxyTest extends \PHPUnit\Framework\TestCase
25 {
26  private $dbViewName = "foo";
27  private $dbViewQuery = "select 3.14";
29  private $dbViewDao;
30  private $dbManagerMock;
31 
32  protected function setUp()
33  {
34  $this->dbViewDao = new DbViewProxy($this->dbViewQuery, $this->dbViewName);
35  global $container;
36  $container = M::mock('ContainerBuilder');
37  $this->dbManagerMock = M::mock(DbManager::class);
38  $container->shouldReceive('get')->withArgs(array('db.manager'))->andReturn($this->dbManagerMock);
39  }
40 
41  protected function tearDown()
42  {
43  M::close();
44  }
45 
46  public function testGetDbViewName()
47  {
48  assertThat($this->dbViewDao->getDbViewName(),is($this->dbViewName));
49  }
50 
51  public function testMaterialize()
52  {
53  $this->dbManagerMock->shouldReceive('queryOnce')->with("CREATE TEMPORARY TABLE $this->dbViewName AS $this->dbViewQuery", M::any());
54  $this->dbViewDao->materialize();
55  }
56 
57  public function testMaterializeTwice()
58  {
59  $this->dbManagerMock->shouldReceive('queryOnce')->once();
60  $this->dbViewDao->materialize();
61  $this->dbViewDao->materialize();
62  }
63 
64  public function testUnmaterializeAfterMaterialize()
65  {
66  $this->dbManagerMock->shouldReceive('queryOnce');
67  $this->dbViewDao->materialize();
68  $this->dbManagerMock->shouldReceive('queryOnce')->with("DROP TABLE $this->dbViewName");
69  $this->dbViewDao->unmaterialize();
70  }
71 
72  public function testUnmaterializeWithoutMaterialize()
73  {
74  $this->dbManagerMock->shouldReceive('queryOnce')->never();
75  $this->dbViewDao->unmaterialize();
76  }
77 
78  public function testAsCTE()
79  {
80  assertThat($this->dbViewDao->asCTE(),is("WITH $this->dbViewName AS (".$this->dbViewQuery.")"));
81  }
82 }